programs/regsvr32: Move /i command line code to a separate function
Hugh McMaster
hugh.mcmaster at outlook.com
Mon Jun 15 06:46:06 CDT 2015
I've kept argv[i] + strlen("/i") in the call to parse_command_line() to
indicate where the strlen("/i") refers to.
If the arithmetic is moved to the new function, the reference of
strlen("/i") may not be clear.
---
programs/regsvr32/regsvr32.c | 83 ++++++++++++++++++++++++--------------------
1 file changed, 46 insertions(+), 37 deletions(-)
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c
index 624acd6..4e15335 100644
--- a/programs/regsvr32/regsvr32.c
+++ b/programs/regsvr32/regsvr32.c
@@ -202,6 +202,50 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line)
return 0;
}
+static WCHAR *parse_command_line(char *command_line)
+{
+ WCHAR *wsCommandLine;
+
+ if (command_line[0] == ':' && command_line[1])
+ {
+ int len = strlen(command_line);
+
+ command_line++;
+ len--;
+ /* remove double quotes */
+ if (command_line[0] == '"')
+ {
+ command_line++;
+ len--;
+ 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 = NULL;
+ }
+ }
+ else
+ {
+ wsCommandLine = NULL;
+ }
+
+ return wsCommandLine;
+}
+
int main(int argc, char* argv[])
{
int i;
@@ -227,45 +271,10 @@ int main(int argc, char* argv[])
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])
- {
- int len = strlen(command_line);
-
- command_line++;
- len--;
- /* remove double quotes */
- if (command_line[0] == '"')
- {
- command_line++;
- len--;
- 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;
- }
- }
- else
- {
+ wsCommandLine = parse_command_line(argv[i] + strlen("/i"));
+ if (!wsCommandLine)
wsCommandLine = EmptyLine;
- }
}
else if((!strcasecmp(argv[i], "/n"))||(!strcasecmp(argv[i], "-n")))
CallRegister = FALSE;
--
1.9.1
More information about the wine-patches
mailing list