made the command line parser not ignore any switch just before it didn't have a switch before it

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3461 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-02-04 20:03:30 +00:00
parent 1214352131
commit b1a527c4ce
5 changed files with 51 additions and 29 deletions

View file

@ -104,39 +104,50 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam,
cmdline = state_command_line; cmdline = state_command_line;
if (*cmdline == '\"') seekchar = *cmdline++; if (*cmdline == '\"') seekchar = *cmdline++;
while (*cmdline && *cmdline != seekchar) cmdline=CharNext(cmdline); cmdline=findchar(cmdline, seekchar);
cmdline=CharNext(cmdline); cmdline=CharNext(cmdline);
realcmds=cmdline; realcmds=cmdline;
for (;;) while (*cmdline)
{ {
// skip over any spaces // skip over any spaces
while (*cmdline == ' ') cmdline=CharNext(cmdline); while (*cmdline == ' ') cmdline=CharNext(cmdline);
if (cmdline[0] != '/') break; // find out if this parm is quoted
cmdline++; if (cmdline[0] == '"')
{
cmdline++;
seekchar = '\"';
}
else seekchar = ' ';
if (cmdline[0] == '/')
{
cmdline++;
// this only works with spaces because they have just one bit on // this only works with spaces because they have just one bit on
#define END_OF_ARG(c) (((c)|' ')==' ') #define END_OF_ARG(c) (((c)|' ')==' ')
#if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT)
if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1])) if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1]))
cl_flags |= FH_FLAGS_SILENT; cl_flags |= FH_FLAGS_SILENT;
#endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT #endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT
#ifdef NSIS_CONFIG_CRC_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT
if (*(DWORD*)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4])) if (*(DWORD*)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4]))
cl_flags |= FH_FLAGS_NO_CRC; cl_flags |= FH_FLAGS_NO_CRC;
#endif//NSIS_CONFIG_CRC_SUPPORT #endif//NSIS_CONFIG_CRC_SUPPORT
if (*(WORD*)cmdline == CHAR2_TO_WORD('D','=')) if (*(WORD*)cmdline == CHAR2_TO_WORD('D','='))
{ {
cmdline[-2]=0; // keep this from being passed to uninstaller if necessary cmdline[-2]=0; // keep this from being passed to uninstaller if necessary
mystrcpy(state_install_directory,cmdline+2); mystrcpy(state_install_directory,cmdline+2);
cmdline=""; // prevent further processing of cmdline cmdline=""; // prevent further processing of cmdline
break; // not necessary, but for some reason makes smaller exe :) }
} }
// skip over our parm // skip over our parm
while (!END_OF_ARG(*cmdline)) cmdline=CharNext(cmdline); cmdline = findchar(cmdline, seekchar);
// skip the quote
if (*cmdline = '\"')
cmdline++;
} }
m_Err = loadHeaders(cl_flags); m_Err = loadHeaders(cl_flags);

View file

@ -230,7 +230,7 @@ __forceinline int NSISCALL ui_doinstall(void)
{ {
char *p2=CharNext(p); char *p2=CharNext(p);
p=p2; p=p2;
while (*p2 && *p2 != '\"') p2=CharNext(p2); p2 = findchar(p2, '"');
*p2=0; *p2=0;
} }
// p is the path now, check for .exe extension // p is the path now, check for .exe extension

View file

@ -251,7 +251,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
while (c) while (c)
{ {
WIN32_FIND_DATA *fd; WIN32_FIND_DATA *fd;
while (*p != '\\' && *p) p=CharNext(p); p = findchar(p, '\\');
c=*p; c=*p;
*p=0; *p=0;
fd = file_exists(buf1); fd = file_exists(buf1);

View file

@ -132,6 +132,15 @@ char *NSISCALL addtrailingslash(char *str)
return *CharPrev(str,str+mystrlen(str)); return *CharPrev(str,str+mystrlen(str));
}*/ }*/
char * NSISCALL findchar(char *str, char c)
{
while (*str && *str != c)
{
str = CharNext(str);
}
return str;
}
void NSISCALL trimslashtoend(char *buf) void NSISCALL trimslashtoend(char *buf)
{ {
char *p = buf + mystrlen(buf); char *p = buf + mystrlen(buf);
@ -166,12 +175,9 @@ char * NSISCALL skip_root(char *path)
int x = 2; int x = 2;
while (x--) while (x--)
{ {
while (*p2 != '\\') p2 = findchar(p2, '\\');
{ if (!*p2)
if (!*p2) return NULL;
return NULL;
p2 = CharNext(p2);
}
p2 = CharNext(p2); p2 = CharNext(p2);
} }
@ -580,28 +586,32 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab)
char * NSISCALL validate_filename(char *in) { char * NSISCALL validate_filename(char *in) {
char *nono = "*?|<>/\":"; char *nono = "*?|<>/\":";
short cur_char = 0;
char *out; char *out;
char *out_save; char *out_save;
while (*in == ' ') in = CharNext(in); while (*in == ' ') in = CharNext(in);
if (in[0] == '\\' && in[1] == '\\' && in[2] == '?' && in[3] == '\\') { if (in[0] == '\\' && in[1] == '\\' && in[2] == '?' && in[3] == '\\')
{
// at least four bytes // at least four bytes
in += 4; in += 4;
} }
if (*in) { if (*in)
{
// at least two bytes // at least two bytes
if (validpathspec(in)) in += 2; if (validpathspec(in)) in += 2;
} }
out = out_save = in; out = out_save = in;
while (*(char*)&cur_char = *in) { while (*in)
if (cur_char > 31 && !mystrstri(nono, (char*)&cur_char)) { {
if (*in > 31 && !*findchar(nono, *in))
{
mini_memcpy(out, in, CharNext(in) - in); mini_memcpy(out, in, CharNext(in) - in);
out = CharNext(out); out = CharNext(out);
} }
in = CharNext(in); in = CharNext(in);
} }
*out = 0; *out = 0;
do { do
{
out = CharPrev(out_save, out); out = CharPrev(out_save, out);
if (*out == ' ' || *out == '\\') if (*out == ' ' || *out == '\\')
*out = 0; *out = 0;

View file

@ -60,6 +60,7 @@ int NSISCALL validpathspec(char *ubuf);
char * NSISCALL addtrailingslash(char *str); char * NSISCALL addtrailingslash(char *str);
//char NSISCALL lastchar(const char *str); //char NSISCALL lastchar(const char *str);
#define lastchar(str) *CharPrev(str,str+mystrlen(str)) #define lastchar(str) *CharPrev(str,str+mystrlen(str))
char * NSISCALL findchar(char *str, char c);
void NSISCALL trimslashtoend(char *buf); void NSISCALL trimslashtoend(char *buf);
char * NSISCALL skip_root(char *path); char * NSISCALL skip_root(char *path);
int NSISCALL is_valid_instpath(char *s); int NSISCALL is_valid_instpath(char *s);