[PATCH 1/6] regsvr32: Convert if-else blocks to switch statement
Hugh McMaster
hugh.mcmaster at outlook.com
Sun Jun 7 06:13:54 CDT 2015
This makes converting the codebase to Unicode much simpler.
Note that the diff around /i looks complex, but it is just the indenting change.
---
programs/regsvr32/regsvr32.c | 86 ++++++++++++++++++++++++--------------------
1 file changed, 48 insertions(+), 38 deletions(-)
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index 624acd6..560f834 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,62 +222,71 @@ int main(int argc, char* argv[])
*/
for(i = 1; i < argc; i++)
{
- if ((!strcasecmp(argv[i], "/u")) ||(!strcasecmp(argv[i], "-u")))
+ if ((argv[i][0] == '/' || argv[i][0] == '-') && (!argv[i][2] || argv[i][2] == ':'))
+ {
+ switch (tolower(argv[i][1]))
+ {
+ case 'u':
Unregister = TRUE;
- else if ((!strcasecmp(argv[i], "/s"))||(!strcasecmp(argv[i], "-s")))
+ break;
+ case 's':
Silent = TRUE;
- else if ((!strncasecmp(argv[i], "/i", strlen("/i")))||(!strncasecmp(argv[i], "-i", strlen("-i"))))
- {
- CHAR* command_line = argv[i] + strlen("/i");
-
- CallInstall = TRUE;
- if (command_line[0] == ':' && command_line[1])
+ break;
+ case '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);
+ }
+ else
+ {
+ wsCommandLine = EmptyLine;
}
- }
- 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;
}
+ break;
}
- else
- {
- wsCommandLine = EmptyLine;
+ case 'n':
+ CallRegister = FALSE;
+ break;
+ case 'c':
+ /* console output */;
+ break;
+ default:
+ 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.9.1
More information about the wine-patches
mailing list