Author: pschweitzer
Date: Tue Sep 5 13:10:16 2017
New Revision: 75765
URL:
http://svn.reactos.org/svn/reactos?rev=75765&view=rev
Log:
[FSUTIL]
Avoid code duplication
Added:
trunk/reactos/base/applications/cmdutils/fsutil/common.c (with props)
Modified:
trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt
trunk/reactos/base/applications/cmdutils/fsutil/dirty.c
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h
Modified: trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt [iso-8859-1]
(original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt [iso-8859-1] Tue Sep 5
13:10:16 2017
@@ -1,4 +1,5 @@
list(APPEND SOURCE
+ common.c
dirty.c
fsutil.c
fsutil.h)
Added: trunk/reactos/base/applications/cmdutils/fsutil/common.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/common.c (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/common.c [iso-8859-1] Tue Sep 5
13:10:16 2017
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS FS utility tool
+ * FILE: base/applications/cmdutils/common.c
+ * PURPOSE: FSutil common functions
+ * PROGRAMMERS: Pierre Schweitzer <pierre(a)reactos.org>
+ */
+
+#include "fsutil.h"
+
+int FindHandler(int argc,
+ const TCHAR *argv[],
+ HandlerItem * HandlersList,
+ int HandlerListCount,
+ void (*UsageHelper)(const TCHAR *))
+{
+ int i;
+ int ret;
+ const TCHAR * Command;
+
+ ret = 1;
+ Command = NULL;
+ i = HandlerListCount;
+
+ /* If we have a command, does it match a known one? */
+ if (argc > 1)
+ {
+ /* Browse all the known commands finding the right one */
+ Command = argv[1];
+ for (i = 0; i < HandlerListCount; ++i)
+ {
+ if (_tcsicmp(Command, HandlersList[i].Command) == 0)
+ {
+ ret = HandlersList[i].Handler(argc - 1, &argv[1]);
+ break;
+ }
+ }
+ }
+
+ /* We failed finding someone to handle the caller's needs, print out */
+ if (i == HandlerListCount)
+ {
+ UsageHelper(Command);
+ }
+
+ return ret;
+}
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/common.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/cmdutils/fsutil/dirty.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/dirty.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/dirty.c [iso-8859-1] Tue Sep 5
13:10:16 2017
@@ -93,34 +93,7 @@
int
DirtyMain(int argc, const TCHAR *argv[])
{
- int i;
- int ret;
- const TCHAR * Command;
-
- ret = 1;
- Command = NULL;
- i = (sizeof(HandlersList) / sizeof(HandlersList[0]));
-
- /* If we have a command, does it match a known one? */
- if (argc > 1)
- {
- /* Browse all the known commands finding the right one */
- Command = argv[1];
- for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
- {
- if (_tcsicmp(Command, HandlersList[i].Command) == 0)
- {
- ret = HandlersList[i].Handler(argc - 1, &argv[1]);
- break;
- }
- }
- }
-
- /* We failed finding someone to handle the caller's needs, print out */
- if (i == (sizeof(HandlersList) / sizeof(HandlersList[0])))
- {
- PrintUsage(Command);
- }
-
- return ret;
+ return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
+ (sizeof(HandlersList) / sizeof(HandlersList[0])),
+ PrintUsage);
}
Modified: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c [iso-8859-1] Tue Sep 5
13:10:16 2017
@@ -39,34 +39,7 @@
__cdecl
_tmain(int argc, const TCHAR *argv[])
{
- int i;
- int ret;
- const TCHAR * Command;
-
- ret = 1;
- Command = NULL;
- i = (sizeof(HandlersList) / sizeof(HandlersList[0]));
-
- /* If we have a command, does it match a known one? */
- if (argc > 1)
- {
- /* Browse all the known commands finding the right one */
- Command = argv[1];
- for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
- {
- if (_tcsicmp(Command, HandlersList[i].Command) == 0)
- {
- ret = HandlersList[i].Handler(argc - 1, &argv[1]);
- break;
- }
- }
- }
-
- /* We failed finding someone to handle the caller's needs, print out */
- if (i == (sizeof(HandlersList) / sizeof(HandlersList[0])))
- {
- PrintUsage(Command);
- }
-
- return ret;
+ return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
+ (sizeof(HandlersList) / sizeof(HandlersList[0])),
+ PrintUsage);
}
Modified: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h [iso-8859-1] Tue Sep 5
13:10:16 2017
@@ -12,4 +12,10 @@
const TCHAR * Desc;
} HandlerItem;
+int FindHandler(int argc,
+ const TCHAR *argv[],
+ HandlerItem * HandlersList,
+ int HandlerListCount,
+ void (*UsageHelper)(const TCHAR *));
+
#endif