xref: /reactos/base/system/diskpart/help.c (revision e59e6ba0)
1 /*
2  * PROJECT:         ReactOS DiskPart
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            base/system/diskpart/help.c
5  * PURPOSE:         Manages all the partitions of the OS in an interactive way.
6  * PROGRAMMERS:     Lee Schroeder
7  */
8 
9 #include "diskpart.h"
10 
11 /*
12  * HelpCommandList():
13  * shows all the available commands and basic descriptions for diskpart
14  */
15 VOID
16 HelpCommandList(VOID)
17 {
18     PCOMMAND cmdptr;
19     WCHAR szFormat[64];
20     WCHAR szOutput[256];
21 
22     K32LoadStringW(GetModuleHandle(NULL), IDS_HELP_FORMAT_STRING, szFormat, ARRAYSIZE(szFormat));
23 
24     /* Print the header information */
25     ConResPuts(StdOut, IDS_APP_HEADER);
26     ConPuts(StdOut, L"\n");
27 
28     /* List all the commands and the basic descriptions */
29     for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
30     {
31         if ((cmdptr->cmd1 != NULL) &&
32             (cmdptr->cmd2 == NULL) &&
33             (cmdptr->cmd3 == NULL) &&
34             (cmdptr->help != IDS_NONE))
35         {
36             K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
37             ConPrintf(StdOut, szFormat, cmdptr->cmd1, szOutput);
38         }
39     }
40 
41     ConPuts(StdOut, L"\n");
42 }
43 
44 
45 BOOL
46 HelpCommand(
47     PCOMMAND pCommand)
48 {
49     PCOMMAND cmdptr;
50     BOOL bSubCommands = FALSE;
51     WCHAR szFormat[64];
52     WCHAR szOutput[256];
53 
54     K32LoadStringW(GetModuleHandle(NULL), IDS_HELP_FORMAT_STRING, szFormat, ARRAYSIZE(szFormat));
55 
56     ConPuts(StdOut, L"\n");
57 
58     /* List all the commands and the basic descriptions */
59     for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
60     {
61         if (pCommand->cmd1 != NULL && pCommand->cmd2 == NULL && pCommand->cmd3 == NULL)
62         {
63             if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
64                 (cmdptr->cmd2 != NULL) &&
65                 (cmdptr->cmd3 == NULL) &&
66                 (cmdptr->help != IDS_NONE))
67             {
68                 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
69                 ConPrintf(StdOut, szFormat, cmdptr->cmd2, szOutput);
70                 bSubCommands = TRUE;
71             }
72         }
73         else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 == NULL)
74         {
75             if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
76                 (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
77                 (cmdptr->cmd3 != NULL) &&
78                 (cmdptr->help != IDS_NONE))
79             {
80                 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
81                 ConPrintf(StdOut, szFormat, cmdptr->cmd3, szOutput);
82                 bSubCommands = TRUE;
83             }
84         }
85         else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 != NULL)
86         {
87             if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
88                 (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
89                 (wcsicmp(pCommand->cmd3, cmdptr->cmd3) == 0) &&
90                 (cmdptr->help_detail != MSG_NONE))
91             {
92                 ConMsgPuts(StdOut,
93                            FORMAT_MESSAGE_FROM_HMODULE,
94                            NULL,
95                            cmdptr->help_detail,
96                            LANG_USER_DEFAULT);
97                 bSubCommands = TRUE;
98             }
99         }
100     }
101 
102     if ((bSubCommands == FALSE) && (pCommand->help_detail != MSG_NONE))
103     {
104         ConMsgPuts(StdOut,
105                    FORMAT_MESSAGE_FROM_HMODULE,
106                    NULL,
107                    pCommand->help_detail,
108                    LANG_USER_DEFAULT);
109     }
110 
111     ConPuts(StdOut, L"\n");
112 
113     return TRUE;
114 }
115 
116 
117 /* help_main(char *arg):
118  * main entry point for the help command. Gives help to users who needs it.
119  */
120 BOOL help_main(INT argc, LPWSTR *argv)
121 {
122     PCOMMAND cmdptr;
123     PCOMMAND cmdptr1 = NULL;
124     PCOMMAND cmdptr2 = NULL;
125     PCOMMAND cmdptr3 = NULL;
126 
127     if (argc == 1)
128     {
129         HelpCommandList();
130         return TRUE;
131     }
132 
133     /* Scan internal command table */
134     for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
135     {
136         if ((cmdptr1 == NULL) &&
137             (wcsicmp(argv[1], cmdptr->cmd1) == 0))
138             cmdptr1 = cmdptr;
139 
140         if ((cmdptr2 == NULL) &&
141             (argc >= 3) &&
142             (wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
143             (wcsicmp(argv[2], cmdptr->cmd2) == 0))
144             cmdptr2 = cmdptr;
145 
146         if ((cmdptr3 == NULL) &&
147             (argc >= 4) &&
148             (wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
149             (wcsicmp(argv[2], cmdptr->cmd2) == 0) &&
150             (wcsicmp(argv[3], cmdptr->cmd3) == 0))
151             cmdptr3 = cmdptr;
152     }
153 
154     if (cmdptr3 != NULL)
155     {
156         return HelpCommand(cmdptr3);
157     }
158     else if (cmdptr2 != NULL)
159     {
160         return HelpCommand(cmdptr2);
161     }
162     else if (cmdptr1 != NULL)
163     {
164         return HelpCommand(cmdptr1);
165     }
166 
167     HelpCommandList();
168 
169     return TRUE;
170 }
171