From b1a527c4ceb80e6d74824509d1f2e26a9141a842 Mon Sep 17 00:00:00 2001 From: kichik Date: Wed, 4 Feb 2004 20:03:30 +0000 Subject: [PATCH] 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 --- Source/exehead/Main.c | 41 ++++++++++++++++++++++++++--------------- Source/exehead/Ui.c | 2 +- Source/exehead/exec.c | 2 +- Source/exehead/util.c | 34 ++++++++++++++++++++++------------ Source/exehead/util.h | 1 + 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index 4d71b39c..63236bce 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -104,39 +104,50 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, cmdline = state_command_line; if (*cmdline == '\"') seekchar = *cmdline++; - while (*cmdline && *cmdline != seekchar) cmdline=CharNext(cmdline); + cmdline=findchar(cmdline, seekchar); cmdline=CharNext(cmdline); realcmds=cmdline; - for (;;) + while (*cmdline) { // skip over any spaces while (*cmdline == ' ') cmdline=CharNext(cmdline); - if (cmdline[0] != '/') break; - cmdline++; + // find out if this parm is quoted + if (cmdline[0] == '"') + { + cmdline++; + seekchar = '\"'; + } + else seekchar = ' '; + if (cmdline[0] == '/') + { + cmdline++; // this only works with spaces because they have just one bit on #define END_OF_ARG(c) (((c)|' ')==' ') #if defined(NSIS_CONFIG_VISIBLE_SUPPORT) && defined(NSIS_CONFIG_SILENT_SUPPORT) - if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1])) - cl_flags |= FH_FLAGS_SILENT; + if (cmdline[0] == 'S' && END_OF_ARG(cmdline[1])) + cl_flags |= FH_FLAGS_SILENT; #endif//NSIS_CONFIG_SILENT_SUPPORT && NSIS_CONFIG_VISIBLE_SUPPORT #ifdef NSIS_CONFIG_CRC_SUPPORT - if (*(DWORD*)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4])) - cl_flags |= FH_FLAGS_NO_CRC; + if (*(DWORD*)cmdline == CHAR4_TO_DWORD('N','C','R','C') && END_OF_ARG(cmdline[4])) + cl_flags |= FH_FLAGS_NO_CRC; #endif//NSIS_CONFIG_CRC_SUPPORT - if (*(WORD*)cmdline == CHAR2_TO_WORD('D','=')) - { - cmdline[-2]=0; // keep this from being passed to uninstaller if necessary - mystrcpy(state_install_directory,cmdline+2); - cmdline=""; // prevent further processing of cmdline - break; // not necessary, but for some reason makes smaller exe :) + if (*(WORD*)cmdline == CHAR2_TO_WORD('D','=')) + { + cmdline[-2]=0; // keep this from being passed to uninstaller if necessary + mystrcpy(state_install_directory,cmdline+2); + cmdline=""; // prevent further processing of cmdline + } } // 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); diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index f821b0af..19e3c90a 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -230,7 +230,7 @@ __forceinline int NSISCALL ui_doinstall(void) { char *p2=CharNext(p); p=p2; - while (*p2 && *p2 != '\"') p2=CharNext(p2); + p2 = findchar(p2, '"'); *p2=0; } // p is the path now, check for .exe extension diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 6c3917be..f8c5aa4b 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -251,7 +251,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) while (c) { WIN32_FIND_DATA *fd; - while (*p != '\\' && *p) p=CharNext(p); + p = findchar(p, '\\'); c=*p; *p=0; fd = file_exists(buf1); diff --git a/Source/exehead/util.c b/Source/exehead/util.c index 22e4780f..c83f2a37 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -132,6 +132,15 @@ char *NSISCALL addtrailingslash(char *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) { char *p = buf + mystrlen(buf); @@ -166,12 +175,9 @@ char * NSISCALL skip_root(char *path) int x = 2; while (x--) { - while (*p2 != '\\') - { - if (!*p2) - return NULL; - p2 = CharNext(p2); - } + p2 = findchar(p2, '\\'); + if (!*p2) + return NULL; p2 = CharNext(p2); } @@ -580,28 +586,32 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab) char * NSISCALL validate_filename(char *in) { char *nono = "*?|<>/\":"; - short cur_char = 0; char *out; char *out_save; 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 in += 4; } - if (*in) { + if (*in) + { // at least two bytes if (validpathspec(in)) in += 2; } out = out_save = in; - while (*(char*)&cur_char = *in) { - if (cur_char > 31 && !mystrstri(nono, (char*)&cur_char)) { + while (*in) + { + if (*in > 31 && !*findchar(nono, *in)) + { mini_memcpy(out, in, CharNext(in) - in); out = CharNext(out); } in = CharNext(in); } *out = 0; - do { + do + { out = CharPrev(out_save, out); if (*out == ' ' || *out == '\\') *out = 0; diff --git a/Source/exehead/util.h b/Source/exehead/util.h index 5e336a28..48e5094a 100644 --- a/Source/exehead/util.h +++ b/Source/exehead/util.h @@ -60,6 +60,7 @@ int NSISCALL validpathspec(char *ubuf); char * NSISCALL addtrailingslash(char *str); //char NSISCALL lastchar(const char *str); #define lastchar(str) *CharPrev(str,str+mystrlen(str)) +char * NSISCALL findchar(char *str, char c); void NSISCALL trimslashtoend(char *buf); char * NSISCALL skip_root(char *path); int NSISCALL is_valid_instpath(char *s);