[FSUTIL]
authorPierre Schweitzer <pierre@reactos.org>
Tue, 5 Sep 2017 13:24:00 +0000 (13:24 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 5 Sep 2017 13:24:00 +0000 (13:24 +0000)
Avoid code duplication++

svn path=/trunk/; revision=75766

reactos/base/applications/cmdutils/fsutil/common.c
reactos/base/applications/cmdutils/fsutil/dirty.c
reactos/base/applications/cmdutils/fsutil/fsutil.c
reactos/base/applications/cmdutils/fsutil/fsutil.h

index 563b52c..ca6cb95 100644 (file)
@@ -45,3 +45,24 @@ int FindHandler(int argc,
 
     return ret;
 }
+
+void PrintDefaultUsage(const TCHAR * Command,
+                       const TCHAR * SubCommand,
+                       HandlerItem * HandlersList,
+                       int HandlerListCount)
+{
+    int i;
+
+    /* If we were given a command, print it's not supported */
+    if (SubCommand != NULL)
+    {
+        _ftprintf(stderr, _T("Unhandled%scommand: %s\n"), Command, SubCommand);
+    }
+
+    /* And dump any available command */
+    _ftprintf(stderr, _T("---- Handled%scommands ----\n\n"), Command);
+    for (i = 0; i < HandlerListCount; ++i)
+    {
+        _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command, HandlersList[i].Desc);
+    }
+}
index cec651e..e20d431 100644 (file)
@@ -74,20 +74,8 @@ SetMain(int argc, const TCHAR *argv[])
 static void
 PrintUsage(const TCHAR * Command)
 {
-    int i;
-
-    /* If we were given a command, print it's not supported */
-    if (Command != NULL)
-    {
-        _ftprintf(stderr, _T("Unhandled DIRTY command: %s\n"), Command);
-    }
-
-    /* And dump any available command */
-    _ftprintf(stderr, _T("---- Handled DIRTY commands ----\n\n"));
-    for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
-    {
-        _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command, HandlersList[i].Desc);
-    }
+    PrintDefaultUsage(_T(" DIRTY "), Command, (HandlerItem *)&HandlersList,
+                      (sizeof(HandlersList) / sizeof(HandlersList[0])));
 }
 
 int
index 293b721..e1fa664 100644 (file)
@@ -19,20 +19,8 @@ static HandlerItem HandlersList[] =
 static void
 PrintUsage(const TCHAR * Command)
 {
-    int i;
-
-    /* If we were given a command, print it's not supported */
-    if (Command != NULL)
-    {
-        _ftprintf(stderr, _T("Unhandled command: %s\n"), Command);
-    }
-
-    /* And dump any available command */
-    _ftprintf(stderr, _T("---- Handled commands ----\n\n"));
-    for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
-    {
-        _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command, HandlersList[i].Desc);
-    }
+    PrintDefaultUsage(_T(" "), Command, (HandlerItem *)&HandlersList,
+                      (sizeof(HandlersList) / sizeof(HandlersList[0])));
 }
 
 int
index bd4a306..acbcc94 100644 (file)
@@ -18,4 +18,9 @@ int FindHandler(int argc,
                 int HandlerListCount,
                 void (*UsageHelper)(const TCHAR *));
 
+void PrintDefaultUsage(const TCHAR * Command,
+                       const TCHAR * SubCommand,
+                       HandlerItem * HandlersList,
+                       int HandlerListCount);
+
 #endif