mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[FSUTIL]
Avoid code duplication svn path=/trunk/; revision=75765
This commit is contained in:
parent
7f463d43db
commit
e03a7274dc
5 changed files with 60 additions and 60 deletions
|
@ -1,4 +1,5 @@
|
|||
list(APPEND SOURCE
|
||||
common.c
|
||||
dirty.c
|
||||
fsutil.c
|
||||
fsutil.h)
|
||||
|
|
47
reactos/base/applications/cmdutils/fsutil/common.c
Normal file
47
reactos/base/applications/cmdutils/fsutil/common.c
Normal file
|
@ -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@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;
|
||||
}
|
|
@ -93,34 +93,7 @@ PrintUsage(const TCHAR * Command)
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -39,34 +39,7 @@ int
|
|||
__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);
|
||||
}
|
||||
|
|
|
@ -12,4 +12,10 @@ typedef struct
|
|||
const TCHAR * Desc;
|
||||
} HandlerItem;
|
||||
|
||||
int FindHandler(int argc,
|
||||
const TCHAR *argv[],
|
||||
HandlerItem * HandlersList,
|
||||
int HandlerListCount,
|
||||
void (*UsageHelper)(const TCHAR *));
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue