ReactOS 0.4.17-dev-470-gf9e3448
help.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for help.c:

Go to the source code of this file.

Classes

struct  HELP_ENTRY
 

Macros

#define NDEBUG
 
#define HUGE_HELP_BUFFER_SIZE   2048
 
#define SMALL_HELP_BUFFER_SIZE   160
 
#define TINY_HELP_BUFFER_SIZE   80
 

Typedefs

typedef enum HELP_TYPEPHELP_TYPE
 
typedef struct HELP_ENTRYPHELP_ENTRY
 

Enumerations

enum  HELP_TYPE { Command , Group , SubContext }
 

Functions

static VOID GetContextFullName (_In_ PCONTEXT_ENTRY pContext, _Inout_ LPWSTR pszBuffer, _In_ DWORD cchLength)
 
static VOID PrintCurrentContextHeader (_In_ PCONTEXT_ENTRY pContext)
 
static VOID PrintShortGroupCommands (_In_ PCONTEXT_ENTRY pContext, _In_ PCOMMAND_GROUP pGroup)
 
static int HelpCompare (_In_ const void *p1, _In_ const void *p2)
 
static VOID PrintContext (_In_ PCONTEXT_ENTRY pContext)
 
static int SubContextCompare (_In_ const void *p1, _In_ const void *p2)
 
static VOID PrintSubcontexts (_In_ PCONTEXT_ENTRY pContext)
 
VOID PrintCommandHelp (_In_ PCONTEXT_ENTRY pContext, _In_ PCOMMAND_GROUP pGroup, _In_ PCOMMAND_ENTRY pCommand)
 
VOID PrintGroupHelp (_In_ PCONTEXT_ENTRY pContext, _In_ LPWSTR pszGroupName, _In_ BOOL bRecurse)
 
VOID PrintContextHelp (_In_ PCONTEXT_ENTRY pContext)
 

Macro Definition Documentation

◆ HUGE_HELP_BUFFER_SIZE

#define HUGE_HELP_BUFFER_SIZE   2048

Definition at line 15 of file help.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file help.c.

◆ SMALL_HELP_BUFFER_SIZE

#define SMALL_HELP_BUFFER_SIZE   160

Definition at line 16 of file help.c.

◆ TINY_HELP_BUFFER_SIZE

#define TINY_HELP_BUFFER_SIZE   80

Definition at line 17 of file help.c.

Typedef Documentation

◆ PHELP_ENTRY

◆ PHELP_TYPE

Enumeration Type Documentation

◆ HELP_TYPE

Enumerator
Command 
Group 
SubContext 

Definition at line 19 of file help.c.

20{
21 Command,
22 Group,
enum HELP_TYPE * PHELP_TYPE
HELP_TYPE
Definition: help.c:20
@ Group
Definition: help.c:22
@ SubContext
Definition: help.c:23
@ Command
Definition: help.c:21

Function Documentation

◆ GetContextFullName()

static VOID GetContextFullName ( _In_ PCONTEXT_ENTRY  pContext,
_Inout_ LPWSTR  pszBuffer,
_In_ DWORD  cchLength 
)
static

Definition at line 44 of file help.c.

48{
49 if (pContext != pRootContext)
50 {
51 GetContextFullName(pContext->pParentContext, pszBuffer, cchLength);
52 wcscat(pszBuffer, L" ");
53 wcscat(pszBuffer, pContext->pszContextName);
54 }
55 else
56 {
57 wcscpy(pszBuffer, pContext->pszContextName);
58 }
59}
PCONTEXT_ENTRY pRootContext
Definition: context.c:26
static VOID GetContextFullName(_In_ PCONTEXT_ENTRY pContext, _Inout_ LPWSTR pszBuffer, _In_ DWORD cchLength)
Definition: help.c:44
#define L(x)
Definition: resources.c:13
wcscat
wcscpy

Referenced by GetContextFullName(), PrintContext(), and PrintCurrentContextHeader().

◆ HelpCompare()

static int HelpCompare ( _In_ const void p1,
_In_ const void p2 
)
static

Definition at line 108 of file help.c.

111{
112 return _wcsicmp(((PHELP_ENTRY)p1)->pszCommand, ((PHELP_ENTRY)p2)->pszCommand);
113}
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
Definition: help.c:27

Referenced by PrintContext().

◆ PrintCommandHelp()

VOID PrintCommandHelp ( _In_ PCONTEXT_ENTRY  pContext,
_In_ PCOMMAND_GROUP  pGroup,
_In_ PCOMMAND_ENTRY  pCommand 
)

Definition at line 296 of file help.c.

300{
301 LPWSTR pszCommandBuffer;
302 DWORD_PTR Args[2];
303 DWORD dwLength = 1;
304
305 DPRINT("PrintCommandHelp(%p %p %p)\n", pContext, pGroup, pCommand);
306
307 if (!CheckOsVersion(pCommand->pfnOsVersionCheck))
308 return;
309
310 dwLength += wcslen(pCommand->pwszCmdToken);
311 if (pGroup)
312 dwLength += (wcslen(pGroup->pwszCmdGroupToken) + 1);
313
314 pszCommandBuffer = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
315 if (pszCommandBuffer == NULL)
316 return;
317
318 _swprintf(pszCommandBuffer, L"%s%s%s",
319 (pGroup) ? pGroup->pwszCmdGroupToken : L"",
320 (pGroup) ? L" " : L"",
321 pCommand->pwszCmdToken);
322
323 Args[0] = (DWORD_PTR)pszCommandBuffer;
324 Args[1] = (DWORD_PTR)NULL;
325
327 pContext->hModule,
329 pCommand->dwCmdHlpToken,
331 (va_list *)&Args);
332 ConPuts(StdOut, L"\n");
333
334 HeapFree(GetProcessHeap(), 0, pszCommandBuffer);
335}
char ** Args
Definition: acdebug.h:353
BOOL CheckOsVersion(_In_ PNS_OSVERSIONCHECK pfnOsVersionCheck)
Definition: wmi.c:35
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define StdOut
Definition: conutils_noros.h:6
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static DWORD DWORD * dwLength
Definition: fusion.c:86
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
char * va_list
Definition: vadefs.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
INT ConResMsgPrintfExV(IN PCON_STREAM Stream, IN HINSTANCE hInstance OPTIONAL, IN DWORD dwFlags, IN UINT uID, IN LANGID LanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1216
short WCHAR
Definition: pedump.c:58
#define DPRINT
Definition: sndvol32.h:73
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define DWORD_PTR
Definition: treelist.c:76
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint16_t * LPWSTR
Definition: typedefs.h:56
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:401

Referenced by InterpretCommand().

◆ PrintContext()

static VOID PrintContext ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 118 of file help.c.

120{
121 PCOMMAND_ENTRY pCommand;
122 PCOMMAND_GROUP pGroup;
123 PCONTEXT_ENTRY pSubContext;
124 PHELP_ENTRY pHelpArray = NULL;
125 DWORD dwCount = 0, dwIndex;
127
128 DPRINT("PrintContext()\n");
129
130 if (pContext != pRootContext)
131 PrintContext(pContext->pParentContext);
132
134
135 /* Count short commands */
136 pCommand = pContext->pCommandListHead;
137 while (pCommand != NULL)
138 {
139 dwCount++;
140 pCommand = pCommand->pNext;
141 }
142
143 /* Count short groups */
144 pGroup = pContext->pGroupListHead;
145 while (pGroup != NULL)
146 {
147 dwCount++;
148 pGroup = pGroup->pNext;
149 }
150
151 /* Count short subcontexts */
152 pSubContext = pContext->pSubContextHead;
153 while (pSubContext != NULL)
154 {
155 dwCount++;
156 pSubContext = pSubContext->pNext;
157 }
158
159 pHelpArray = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCount * sizeof(HELP_ENTRY));
160 if (pHelpArray == NULL)
161 return;
162
163 dwIndex = 0;
164
165 /* Add short commands */
166 pCommand = pContext->pCommandListHead;
167 while (pCommand != NULL)
168 {
169 pHelpArray[dwIndex].Type = Command;
170 pHelpArray[dwIndex].pszCommand = pCommand->pwszCmdToken;
171 pHelpArray[dwIndex].dwHelpId = pCommand->dwShortCmdHelpToken;
172 pHelpArray[dwIndex].Pointer.pCommand = pCommand;
173 dwIndex++;
174 pCommand = pCommand->pNext;
175 }
176
177 /* Add short groups */
178 pGroup = pContext->pGroupListHead;
179 while (pGroup != NULL)
180 {
181 pHelpArray[dwIndex].Type = Group;
182 pHelpArray[dwIndex].pszCommand = pGroup->pwszCmdGroupToken;
183 pHelpArray[dwIndex].dwHelpId = pGroup->dwShortCmdHelpToken;
184 pHelpArray[dwIndex].Pointer.pGroup = pGroup;
185 dwIndex++;
186 pGroup = pGroup->pNext;
187 }
188
189 /* Count short subcontexts */
190 pSubContext = pContext->pSubContextHead;
191 while (pSubContext != NULL)
192 {
193 pHelpArray[dwIndex].Type = SubContext;
194 pHelpArray[dwIndex].pszCommand = pSubContext->pszContextName;
195 pHelpArray[dwIndex].Pointer.pSubContext = pSubContext;
196 dwIndex++;
197 pSubContext = pSubContext->pNext;
198 }
199
200 qsort(pHelpArray, dwCount, sizeof(HELP_ENTRY), HelpCompare);
201
202 for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
203 {
204 switch (pHelpArray[dwIndex].Type)
205 {
206 case Command:
207 if (CheckOsVersion(pHelpArray[dwIndex].Pointer.pCommand->pfnOsVersionCheck))
208 {
209 if (LoadStringW(pContext->hModule, pHelpArray[dwIndex].dwHelpId, szBuffer, _countof(szBuffer)) == 0)
210 szBuffer[0] = UNICODE_NULL;
211 ConPrintf(StdOut, L"%-15s - %s", pHelpArray[dwIndex].pszCommand, szBuffer);
212 }
213 break;
214
215 case Group:
216 if (CheckOsVersion(pHelpArray[dwIndex].Pointer.pGroup->pfnOsVersionCheck))
217 {
218 if (LoadStringW(pContext->hModule, pHelpArray[dwIndex].dwHelpId, szBuffer, _countof(szBuffer)) == 0)
219 szBuffer[0] = UNICODE_NULL;
220 ConPrintf(StdOut, L"%-15s - %s", pHelpArray[dwIndex].pszCommand, szBuffer);
221 }
222 break;
223
224 case SubContext:
225 if (CheckOsVersion(pHelpArray[dwIndex].Pointer.pSubContext->pfnOsVersionCheck))
226 {
227 GetContextFullName(pHelpArray[dwIndex].Pointer.pSubContext, szBuffer, _countof(szBuffer));
228 ConPrintf(StdOut, L"%-15s - Changes to the \"%s\" context.\n", pHelpArray[dwIndex].pszCommand, szBuffer);
229 }
230 break;
231 }
232 }
233
234 if (pHelpArray)
235 HeapFree(GetProcessHeap(), 0, pHelpArray);
236}
Type
Definition: Type.h:7
static int HelpCompare(_In_ const void *p1, _In_ const void *p2)
Definition: help.c:108
static VOID PrintCurrentContextHeader(_In_ PCONTEXT_ENTRY pContext)
Definition: help.c:64
#define SMALL_HELP_BUFFER_SIZE
Definition: help.c:16
static VOID PrintContext(_In_ PCONTEXT_ENTRY pContext)
Definition: help.c:118
void ConPrintf(FILE *fp, LPCWSTR psz,...)
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP void __cdecl qsort(void *, size_t, size_t, int(__cdecl *)(const void *, const void *))
#define UNICODE_NULL
#define LoadStringW
Definition: utils.h:64
#define _countof(array)
Definition: sndvol32.h:70
HELP_TYPE Type
Definition: help.c:28
union HELP_ENTRY::@19 Pointer
PWSTR pszCommand
Definition: help.c:29
DWORD dwHelpId
Definition: help.c:30
PCONTEXT_ENTRY pSubContext
Definition: help.c:35
PCOMMAND_ENTRY pCommand
Definition: help.c:33
PCOMMAND_GROUP pGroup
Definition: help.c:34
Definition: precomp.h:74
PWSTR pwszCmdToken
Definition: precomp.h:78
DWORD dwShortCmdHelpToken
Definition: precomp.h:80
struct _COMMAND_ENTRY * pNext
Definition: precomp.h:76
struct _COMMAND_GROUP * pNext
Definition: precomp.h:89
PWSTR pwszCmdGroupToken
Definition: precomp.h:91
DWORD dwShortCmdHelpToken
Definition: precomp.h:92
Definition: precomp.h:101
PWSTR pszContextName
Definition: precomp.h:108
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:123
struct _CONTEXT_ENTRY * pNext
Definition: precomp.h:103

Referenced by PrintContext(), and PrintContextHelp().

◆ PrintContextHelp()

VOID PrintContextHelp ( _In_ PCONTEXT_ENTRY  pContext)

Definition at line 366 of file help.c.

368{
370 PrintContext(pContext);
371 PrintSubcontexts(pContext);
373}
static VOID PrintSubcontexts(_In_ PCONTEXT_ENTRY pContext)
Definition: help.c:251
#define IDS_HELP_FOOTER
Definition: resource.h:20
#define IDS_HELP_HEADER
Definition: resource.h:19
void ConResPrintf(FILE *fp, UINT nID,...)

Referenced by InterpretCommand().

◆ PrintCurrentContextHeader()

static VOID PrintCurrentContextHeader ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 64 of file help.c.

66{
67 if (pContext == pCurrentContext)
68 {
70 }
71 else
72 {
74 GetContextFullName(pContext, szBuffer, _countof(szBuffer));
76 }
77}
PCONTEXT_ENTRY pCurrentContext
Definition: context.c:27
#define IDS_CONTEXT_COMMANDS
Definition: resource.h:16
#define IDS_THIS_COMMANDS
Definition: resource.h:15

Referenced by PrintContext(), and PrintGroupHelp().

◆ PrintGroupHelp()

VOID PrintGroupHelp ( _In_ PCONTEXT_ENTRY  pContext,
_In_ LPWSTR  pszGroupName,
_In_ BOOL  bRecurse 
)

Definition at line 339 of file help.c.

343{
344 PCOMMAND_GROUP pGroup;
345
346 if (bRecurse)
347 {
348 if (pContext != pRootContext)
349 PrintGroupHelp(pContext->pParentContext, pszGroupName, bRecurse);
350 }
351
352 pGroup = pContext->pGroupListHead;
353 while (pGroup != NULL)
354 {
355 if (_wcsicmp(pszGroupName, pGroup->pwszCmdGroupToken) == 0)
356 {
358 PrintShortGroupCommands(pContext, pGroup);
359 }
360 pGroup = pGroup->pNext;
361 }
362}
static VOID PrintShortGroupCommands(_In_ PCONTEXT_ENTRY pContext, _In_ PCOMMAND_GROUP pGroup)
Definition: help.c:82
VOID PrintGroupHelp(_In_ PCONTEXT_ENTRY pContext, _In_ LPWSTR pszGroupName, _In_ BOOL bRecurse)
Definition: help.c:339

Referenced by InterpretCommand(), and PrintGroupHelp().

◆ PrintShortGroupCommands()

static VOID PrintShortGroupCommands ( _In_ PCONTEXT_ENTRY  pContext,
_In_ PCOMMAND_GROUP  pGroup 
)
static

Definition at line 82 of file help.c.

85{
86 PCOMMAND_ENTRY pCommand;
89
90 pCommand = pGroup->pCommandListHead;
91 while (pCommand != NULL)
92 {
93 DPRINT("CheckVersion (Command) %S %S", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
94 if (CheckOsVersion(pCommand->pfnOsVersionCheck))
95 {
96 _swprintf(szBuffer1, L"%s %s", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
97 LoadStringW(pContext->hModule, pCommand->dwShortCmdHelpToken, szBuffer2, _countof(szBuffer2));
98
99 ConPrintf(StdOut, L"%-15s - %s", szBuffer1, szBuffer2);
100 }
101 pCommand = pCommand->pNext;
102 }
103}
#define TINY_HELP_BUFFER_SIZE
Definition: help.c:17
PNS_OSVERSIONCHECK pfnOsVersionCheck
Definition: precomp.h:83

Referenced by PrintGroupHelp().

◆ PrintSubcontexts()

static VOID PrintSubcontexts ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 251 of file help.c.

253{
254 PCONTEXT_ENTRY pSubContext, *pSubContextArray = NULL;
255 DWORD dwCount, dwIndex;
256
257 if (pContext->pSubContextHead == NULL)
258 return;
259
260 dwCount = 0;
261 pSubContext = pContext->pSubContextHead;
262 while (pSubContext != NULL)
263 {
264 dwCount++;
265 pSubContext = pSubContext->pNext;
266 }
267
268 pSubContextArray = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(PCONTEXT_ENTRY));
269 if (pSubContextArray == NULL)
270 return;
271
272 dwIndex = 0;
273 pSubContext = pContext->pSubContextHead;
274 while (pSubContext != NULL)
275 {
276 pSubContextArray[dwIndex] = pSubContext;
277 dwIndex++;
278 pSubContext = pSubContext->pNext;
279 }
280
281 qsort(pSubContextArray, dwCount, sizeof(PCONTEXT_ENTRY), SubContextCompare);
282
284 for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
285 {
286 if (CheckOsVersion(pSubContextArray[dwIndex]->pfnOsVersionCheck))
287 ConPrintf(StdOut, L" %s", pSubContextArray[dwIndex]->pszContextName);
288 }
289 ConPuts(StdOut, L"\n");
290
291 HeapFree(GetProcessHeap(), 0, pSubContextArray);
292}
static int SubContextCompare(_In_ const void *p1, _In_ const void *p2)
Definition: help.c:241
#define IDS_SUBCONTEXT_HEADER
Definition: resource.h:21

Referenced by PrintContextHelp().

◆ SubContextCompare()

static int SubContextCompare ( _In_ const void p1,
_In_ const void p2 
)
static

Definition at line 241 of file help.c.

244{
245 return _wcsicmp((*((PCONTEXT_ENTRY*)p1))->pszContextName, (*((PCONTEXT_ENTRY*)p2))->pszContextName);
246}

Referenced by PrintSubcontexts().