From: Hugh McMaster Subject: [Patch 1/2] regsvr32: Simplify command line handling Message-Id: Date: Thu, 7 Aug 2014 23:29:52 +1000 This patch simplifies the command line handling in programs/regsvr32/regsvr32.c. It is necessary to make the conversion from ANSI to Unicode straightforward (see patch 2/2). Thank you to Michael Stefaniuc for answering all of my questions. Changelog: regsvr32: Simplify command line handling. From 4c6918193e62af58b6c8416410ef3bd78109da9c Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Thu, 7 Aug 2014 22:32:21 +1000 Subject: [PATCH 1/2] regsvr32: Simplify command line handling --- programs/regsvr32/regsvr32.c | 76 +++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 624acd6..88e9e8f 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -204,7 +204,7 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) int main(int argc, char* argv[]) { - int i; + int i, ch; BOOL CallRegister = TRUE; BOOL CallInstall = FALSE; BOOL Unregister = FALSE; @@ -221,62 +221,60 @@ int main(int argc, char* argv[]) */ for(i = 1; i < argc; i++) { - if ((!strcasecmp(argv[i], "/u")) ||(!strcasecmp(argv[i], "-u"))) - Unregister = TRUE; - else if ((!strcasecmp(argv[i], "/s"))||(!strcasecmp(argv[i], "-s"))) - Silent = TRUE; - else if ((!strncasecmp(argv[i], "/i", strlen("/i")))||(!strncasecmp(argv[i], "-i", strlen("-i")))) + if ((argv[i][0] == '/' || argv[i][0] == '-') && (!argv[i][2] || argv[i][2] == ':')) { - CHAR* command_line = argv[i] + strlen("/i"); + ch = tolower(argv[i][1]); - CallInstall = TRUE; - if (command_line[0] == ':' && command_line[1]) + if (ch == 'u') + Unregister = TRUE; + else if (ch == 's') + Silent = TRUE; + else if (ch == 'n') + CallRegister = FALSE; + else if (ch == 'c') + /* console output */; + else if (ch == 'i') { - int len = strlen(command_line); + char* command_line = argv[i] + 2; /* "/i" */ - command_line++; - len--; - /* remove double quotes */ - if (command_line[0] == '"') + CallInstall = TRUE; + if (command_line[0] == ':' && command_line[1]) { + int len = strlen(command_line); + command_line++; len--; - if (command_line[0]) + /* remove double quotes */ + if (command_line[0] == '"') { + command_line++; len--; - command_line[len] = 0; + if (command_line[0]) + { + len--; + command_line[len] = 0; + } } - } - if (command_line[0]) - { - len = MultiByteToWideChar(CP_ACP, 0, command_line, -1, - NULL, 0); - wsCommandLine = HeapAlloc(GetProcessHeap(), 0, - len * sizeof(WCHAR)); - if (wsCommandLine) - MultiByteToWideChar(CP_ACP, 0, command_line, -1, - wsCommandLine, len); + if (command_line[0]) + { + len = MultiByteToWideChar(CP_ACP, 0, command_line, -1, NULL, 0); + wsCommandLine = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + if (wsCommandLine) + MultiByteToWideChar(CP_ACP, 0, command_line, -1, wsCommandLine, len); + } + else + wsCommandLine = EmptyLine; } else - { wsCommandLine = EmptyLine; - } } else { - wsCommandLine = EmptyLine; + output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); + output_write(STRING_USAGE); + return 1; } } - else if((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n"))) - CallRegister = FALSE; - else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c"))) - /* console output */; - else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':')) - { - output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); - output_write(STRING_USAGE); - return 1; - } else { char *DllName = argv[i]; -- 1.8.3.2