[GFLAGS] Move code around to handle multiple options
[reactos.git] / modules / rosapps / applications / cmdutils / gflags / gflags.c
1 /*
2 * PROJECT: Global Flags utility
3 * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4 * PURPOSE: Global Flags utility entrypoint
5 * COPYRIGHT: Copyright 2017 Pierre Schweitzer (pierre@reactos.org)
6 * Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
7 */
8
9 #include "gflags.h"
10
11 static BOOL UsePageHeap = FALSE;
12
13
14 DWORD ReagFlagsFromRegistry(HKEY SubKey, PVOID Buffer, PWSTR Value, DWORD MaxLen)
15 {
16 DWORD Len, Flags, Type;
17
18 Len = MaxLen;
19 Flags = 0;
20 if (RegQueryValueEx(SubKey, Value, NULL, &Type, Buffer, &Len) == ERROR_SUCCESS && Type == REG_SZ)
21 {
22 Flags = wcstoul(Buffer, NULL, 16);
23 }
24
25 return Flags;
26 }
27
28 static BOOL ParseCmdline(int argc, LPWSTR argv[])
29 {
30 INT i;
31
32 if (argc < 2)
33 {
34 wprintf(L"Not enough args!\n");
35 return FALSE;
36 }
37
38 for (i = 1; i < argc; i++)
39 {
40 if (argv[i][0] == L'/')
41 {
42 if (argv[i][1] == L'p' && argv[i][2] == UNICODE_NULL)
43 {
44 UsePageHeap = TRUE;
45 return PageHeap_ParseCmdline(i + 1, argc, argv);
46 }
47 }
48 else
49 {
50 wprintf(L"Invalid option: %s\n", argv[i]);
51 return FALSE;
52 }
53 }
54
55 if (!UsePageHeap)
56 {
57 wprintf(L"Only page heap flags are supported\n");
58 return FALSE;
59 }
60
61 return TRUE;
62 }
63
64
65 int wmain(int argc, LPWSTR argv[])
66 {
67 if (!ParseCmdline(argc, argv))
68 {
69 wprintf(L"Usage: gflags /p [image.exe] [/enable|/disable [/full]]\n"
70 L"\timage.exe:\tImage you want to deal with\n"
71 L"\t/enable:\tenable page heap for the image\n"
72 L"\t/disable:\tdisable page heap for the image\n"
73 L"\t/full:\t\tactivate full debug page heap\n");
74 return 1;
75 }
76
77 if (UsePageHeap)
78 {
79 return PageHeap_Execute();
80 }
81 return 2;
82 }