regsvr32: Convert if-else blocks to switch statement (try 3)

Hugh McMaster hugh.mcmaster at outlook.com
Thu Jun 11 01:09:36 CDT 2015


The main difficulty is handling Unix format filenames with the parser.

---
 programs/regsvr32/regsvr32.c | 46 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index 624acd6..f4cdb5e 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -52,6 +52,7 @@
 #include "wine/port.h"
 
 #include <string.h>
+#include <ctype.h>
 #include <windows.h>
 #include <ole2.h>
 #include "regsvr32.h"
@@ -221,11 +222,26 @@ 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 the current argument is a Unix format file name, skip to the next loop. */
+        if (strlen(argv[i]) > 2 && argv[i][2] != ':')
+            continue;
+
+        /* The Microsoft version treats all arguments beginning with a forward slash (/)
+         * or hyphen (-) as flags. Therefore, we should should skip to the next loop for
+         * any argument that does not have either of these characters as argv[i][0].
+         */
+        if (argv[i][0] != '/' && argv[i][0] != '-')
+            continue;
+
+        switch (tolower(argv[i][1]))
+        {
+        case 'u':
+            Unregister = TRUE;
+            break;
+        case 's':
+            Silent = TRUE;
+            break;
+        case 'i':
         {
             CHAR* command_line = argv[i] + strlen("/i");
 
@@ -266,18 +282,28 @@ int main(int argc, char* argv[])
             {
                 wsCommandLine = EmptyLine;
             }
+            break;
         }
-        else if((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n")))
+        case 'n':
             CallRegister = FALSE;
-        else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c")))
+            break;
+        case 'c':
             /* console output */;
-        else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':'))
-        {
+            break;
+        default:
             output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]);
             output_write(STRING_USAGE);
             return 1;
         }
-        else
+    }
+
+    for (i = 1; i < argc; i++)
+    {
+        /* Skip any argument flags */
+        if (strlen(argv[i]) == 2 && (argv[i][0] == '/' || argv[i][0] == '-'))
+            continue;
+
+        if (argv[i][2] != ':')
         {
             char *DllName = argv[i];
             int res = 0;
-- 
1.9.1




More information about the wine-patches mailing list