[DISKPART]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 23 Oct 2011 12:04:48 +0000 (12:04 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 23 Oct 2011 12:04:48 +0000 (12:04 +0000)
- Add a simple usage function (/? option).
- Simplify the interpreter loop a little bit.

svn path=/trunk/; revision=54241

reactos/base/system/diskpart/diskpart.c
reactos/base/system/diskpart/diskpart.h
reactos/base/system/diskpart/interpreter.c
reactos/base/system/diskpart/lang/en-US.rc
reactos/base/system/diskpart/resource.h

index 9063600..7718d42 100644 (file)
@@ -66,7 +66,6 @@ int wmain(int argc, const WCHAR *argv[])
 {
     WCHAR szComputerName[MAX_STRING_SIZE];
     DWORD comp_size = MAX_STRING_SIZE;
-    BOOL interpreter_running = TRUE;
     LPCWSTR file_name = NULL;
     int i;
     int timeout = 0;
@@ -121,6 +120,11 @@ int wmain(int argc, const WCHAR *argv[])
                     timeout = _wtoi(argv[i]);
                 }
             }
+            else if (wcscmp(&argv[i][1], L"?") == 0)
+            {
+                PrintResourceString(IDS_APP_USAGE);
+                return EXIT_SUCCESS;
+            }
         }
     }
 
@@ -132,8 +136,7 @@ int wmain(int argc, const WCHAR *argv[])
     }
     else
     {
-        while (interpreter_running)
-            interpreter_running = interpret_main();
+        interpret_main();
     }
 
     /* Let the user know the program is exiting */
index 75f6cf2..cc16c89 100644 (file)
@@ -3,7 +3,7 @@
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/system/diskpart/diskpart.c
  * PURPOSE:         Manages all the partitions of the OS in
- *                                     an interactive way
+ *                  an interactive way
  * PROGRAMMERS:     Lee Schroeder
  */
 #ifndef DISKPART_H
@@ -139,8 +139,8 @@ VOID help_inactive(INT argc, WCHAR **argv);
 
 /* interpreter.c */
 BOOL interpret_script(WCHAR *line);
-BOOL interpret_main(VOID);
 BOOL interpret_cmd(INT argc, WCHAR **argv);
+VOID interpret_main(VOID);
 
 /* list.c */
 BOOL list_main(INT argc, WCHAR **argv);
index 9c04dbe..23b63f7 100644 (file)
@@ -3,7 +3,7 @@
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/system/diskpart/interpreter.c
  * PURPOSE:         Reads the user input and then envokes the selected
- *                                     command by the user.
+ *                  command by the user.
  * PROGRAMMERS:     Lee Schroeder
  */
 
@@ -52,7 +52,7 @@ COMMAND cmds[] =
     {L"setid",       setid_main,       help_setid},
     {L"shrink",      shrink_main,      help_shrink},
     {L"uniqueid",    uniqueid_main,    help_uniqueid},
-    {NULL,              NULL,             NULL}
+    {NULL,           NULL,             NULL}
 };
 
 
@@ -144,45 +144,49 @@ interpret_script(WCHAR *input_line)
  * it sends the string to interpret_line, where it determines what
  * command to use.
  */
-BOOL
+VOID
 interpret_main(VOID)
 {
     WCHAR input_line[MAX_STRING_SIZE];
     WCHAR *args_vector[MAX_ARGS_COUNT];
     INT args_count = 0;
     BOOL bWhiteSpace = TRUE;
+    BOOL bRun = TRUE;
     WCHAR *ptr;
 
-    memset(args_vector, 0, sizeof(args_vector));
+    while (bRun == TRUE)
+    {
+        memset(args_vector, 0, sizeof(args_vector));
 
-    /* shown just before the input where the user places commands */
-    PrintResourceString(IDS_APP_PROMPT);
+        /* shown just before the input where the user places commands */
+        PrintResourceString(IDS_APP_PROMPT);
 
-    /* gets input from the user. */
-    fgetws(input_line, MAX_STRING_SIZE, stdin);
+        /* gets input from the user. */
+        fgetws(input_line, MAX_STRING_SIZE, stdin);
 
-    ptr = input_line;
-    while (*ptr != 0)
-    {
-        if (iswspace(*ptr) || *ptr == L'\n')
-        {
-            *ptr = 0;
-            bWhiteSpace = TRUE;
-        }
-        else
+        ptr = input_line;
+        while (*ptr != 0)
         {
-            if ((bWhiteSpace == TRUE) && (args_count < MAX_ARGS_COUNT))
+            if (iswspace(*ptr) || *ptr == L'\n')
             {
-                args_vector[args_count] = ptr;
-                args_count++;
+                *ptr = 0;
+                bWhiteSpace = TRUE;
             }
+            else
+            {
+                if ((bWhiteSpace == TRUE) && (args_count < MAX_ARGS_COUNT))
+                {
+                    args_vector[args_count] = ptr;
+                    args_count++;
+                }
 
-            bWhiteSpace = FALSE;
+                bWhiteSpace = FALSE;
+            }
+
+            ptr++;
         }
 
-        ptr++;
+        /* sends the string to find the command */
+        bRun = interpret_cmd(args_count, args_vector);
     }
-
-    /* sends the string to find the command */
-    return interpret_cmd(args_count, args_vector);
 }
index 95d096e..3a05fd0 100644 (file)
@@ -14,6 +14,11 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
 STRINGTABLE DISCARDABLE
 BEGIN
     IDS_APP_HEADER, "\nReactOS DiskPart version %s\n"
+    IDS_APP_USAGE, "Diskpart command line syntax:\ndiskpart [/s <script file>] [/t <timeout value>] [/?]\n\
+/s <script file>   - Runs the given script file.\n\
+/t <timeout value> - Waits for the given time (in seconds) after running a\n\
+                     script file.\n\
+/?                 - Shows this help text."
     IDS_APP_LICENSE, "Licensed under the GNU GPLv2\n"
     IDS_APP_CURR_COMPUTER, "On computer: %s\n\n"
     IDS_APP_LEAVING, "\nLeaving DiskPart...\n"
index 1f4f8c4..c8408d8 100644 (file)
@@ -3,13 +3,14 @@
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/system/diskpart/lang/resource.h
  * PURPOSE:         Manages all the partitions of the OS in
- *                                     an interactive way
+ *                  an interactive way
  * PROGRAMMERS:     Lee Schroeder
  */
 #ifndef RESOURCE_H
 #define RESOURCE_H
 
 #define IDS_APP_HEADER                  0
+#define IDS_APP_USAGE                   1
 #define IDS_APP_LICENSE                 2
 #define IDS_APP_CURR_COMPUTER           3
 #define IDS_APP_LEAVING                 4