[FSUTIL]
[reactos.git] / reactos / base / applications / cmdutils / fsutil / fsutil.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS FS utility tool
4 * FILE: base/applications/cmdutils/fsutil.c
5 * PURPOSE: FSutil main
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7 */
8
9 #include "fsutil.h"
10
11 /* Add handlers here for commands */
12 int DirtyMain(int argc, const TCHAR *argv[]);
13 static HandlerItem HandlersList[] =
14 {
15 /* Proc, name, help */
16 { DirtyMain, _T("dirty"), _T("Manipulates the dirty bit") },
17 };
18
19 static void
20 PrintUsage(const TCHAR * Command)
21 {
22 int i;
23
24 /* If we were given a command, print it's not supported */
25 if (Command != NULL)
26 {
27 _ftprintf(stderr, _T("Unhandled command: %s\n"), Command);
28 }
29
30 /* And dump any available command */
31 _ftprintf(stderr, _T("---- Handled commands ----\n\n"));
32 for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
33 {
34 _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command, HandlersList[i].Desc);
35 }
36 }
37
38 int
39 __cdecl
40 _tmain(int argc, const TCHAR *argv[])
41 {
42 int i;
43 int ret;
44 const TCHAR * Command;
45
46 ret = 1;
47 Command = NULL;
48 i = (sizeof(HandlersList) / sizeof(HandlersList[0]));
49
50 /* If we have a command, does it match a known one? */
51 if (argc > 1)
52 {
53 /* Browse all the known commands finding the right one */
54 Command = argv[1];
55 for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
56 {
57 if (_tcsicmp(Command, HandlersList[i].Command) == 0)
58 {
59 ret = HandlersList[i].Handler(argc - 1, &argv[1]);
60 break;
61 }
62 }
63 }
64
65 /* We failed finding someone to handle the caller's needs, print out */
66 if (i == (sizeof(HandlersList) / sizeof(HandlersList[0])))
67 {
68 PrintUsage(Command);
69 }
70
71 return ret;
72 }