563b52cf6c3508672026adeb6e5aa6b0e6860968
[reactos.git] / reactos / base / applications / cmdutils / fsutil / common.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS FS utility tool
4 * FILE: base/applications/cmdutils/common.c
5 * PURPOSE: FSutil common functions
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7 */
8
9 #include "fsutil.h"
10
11 int FindHandler(int argc,
12 const TCHAR *argv[],
13 HandlerItem * HandlersList,
14 int HandlerListCount,
15 void (*UsageHelper)(const TCHAR *))
16 {
17 int i;
18 int ret;
19 const TCHAR * Command;
20
21 ret = 1;
22 Command = NULL;
23 i = HandlerListCount;
24
25 /* If we have a command, does it match a known one? */
26 if (argc > 1)
27 {
28 /* Browse all the known commands finding the right one */
29 Command = argv[1];
30 for (i = 0; i < HandlerListCount; ++i)
31 {
32 if (_tcsicmp(Command, HandlersList[i].Command) == 0)
33 {
34 ret = HandlersList[i].Handler(argc - 1, &argv[1]);
35 break;
36 }
37 }
38 }
39
40 /* We failed finding someone to handle the caller's needs, print out */
41 if (i == HandlerListCount)
42 {
43 UsageHelper(Command);
44 }
45
46 return ret;
47 }