Sync to trunk r65566.
[reactos.git] / base / applications / cmdutils / taskkill / taskkill.c
index 7a4d7f4..894e06a 100644 (file)
@@ -32,7 +32,7 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(taskkill);
 
-static int force_termination;
+static BOOL force_termination = FALSE;
 
 static WCHAR **task_list;
 static unsigned int task_count;
@@ -450,36 +450,46 @@ static BOOL add_to_task_list(WCHAR *name)
  * options are detected as parameters when placed after options that accept one. */
 static BOOL process_arguments(int argc, WCHAR *argv[])
 {
-    static const WCHAR slashForceTerminate[] = {'/','f',0};
-    static const WCHAR slashImage[] = {'/','i','m',0};
-    static const WCHAR slashPID[] = {'/','p','i','d',0};
-    static const WCHAR slashHelp[] = {'/','?',0};
-    static const WCHAR slashTerminateChildren[] = {'/','t',0};
+    static const WCHAR opForceTerminate[] = {'f',0};
+    static const WCHAR opImage[] = {'i','m',0};
+    static const WCHAR opPID[] = {'p','i','d',0};
+    static const WCHAR opHelp[] = {'?',0};
+    static const WCHAR opTerminateChildren[] = {'t',0};
 
     if (argc > 1)
     {
         int i;
-        BOOL has_im = 0, has_pid = 0;
+        WCHAR *argdata;
+        BOOL has_im = FALSE, has_pid = FALSE;
 
         /* Only the lone help option is recognized. */
-        if (argc == 2 && !strcmpW(slashHelp, argv[1]))
+        if (argc == 2)
         {
-            taskkill_message(STRING_USAGE);
-            exit(0);
+            argdata = argv[1];
+            if ((*argdata == '/' || *argdata == '-') && !strcmpW(opHelp, argdata + 1))
+            {
+                taskkill_message(STRING_USAGE);
+                exit(0);
+            }
         }
 
         for (i = 1; i < argc; i++)
         {
-            int got_im = 0, got_pid = 0;
+            BOOL got_im = FALSE, got_pid = FALSE;
+
+            argdata = argv[i];
+            if (*argdata != '/' && *argdata != '-')
+                goto invalid;
+            argdata++;
 
-            if (!strcmpiW(slashTerminateChildren, argv[i]))
-                WINE_FIXME("/T not supported\n");
-            if (!strcmpiW(slashForceTerminate, argv[i]))
-                force_termination = 1;
+            if (!strcmpiW(opTerminateChildren, argdata))
+                WINE_FIXME("argument T not supported\n");
+            if (!strcmpiW(opForceTerminate, argdata))
+                force_termination = TRUE;
             /* Options /IM and /PID appear to behave identically, except for
              * the fact that they cannot be specified at the same time. */
-            else if ((got_im = !strcmpiW(slashImage, argv[i])) ||
-                     (got_pid = !strcmpiW(slashPID, argv[i])))
+            else if ((got_im = !strcmpiW(opImage, argdata)) ||
+                     (got_pid = !strcmpiW(opPID, argdata)))
             {
                 if (!argv[i + 1])
                 {
@@ -488,8 +498,8 @@ static BOOL process_arguments(int argc, WCHAR *argv[])
                     return FALSE;
                 }
 
-                if (got_im) has_im = 1;
-                if (got_pid) has_pid = 1;
+                if (got_im) has_im = TRUE;
+                if (got_pid) has_pid = TRUE;
 
                 if (has_im && has_pid)
                 {
@@ -504,6 +514,7 @@ static BOOL process_arguments(int argc, WCHAR *argv[])
             }
             else
             {
+                invalid:
                 taskkill_message(STRING_INVALID_OPTION);
                 taskkill_message(STRING_USAGE);
                 return FALSE;