[PATCH 2/5] programs/regsvr32: Simplify input handling

Hugh McMaster hugh.mcmaster at outlook.com
Thu May 28 06:14:17 CDT 2015


This makes the conversion to Unicode much easier.

---
 programs/regsvr32/regsvr32.c | 79 ++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 39 deletions(-)

diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index f823f5b..181019b 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,63 @@ 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((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n")))
-            CallRegister = FALSE;
-        else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c")))
-            /* console output */;
-        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] + strlen("/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 (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.9.1




More information about the wine-patches mailing list