ReactOS 0.4.16-dev-1946-g52006dd
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
wcscat
wcscpy
#define L(x)
Definition: resources.c:13

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

◆ HelpCompare()

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

Definition at line 105 of file help.c.

108{
109 return _wcsicmp(((PHELP_ENTRY)p1)->pszCommand, ((PHELP_ENTRY)p2)->pszCommand);
110}
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
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 278 of file help.c.

282{
283 LPWSTR pszInBuffer = NULL, pszOutBuffer = NULL, pszCommandBuffer = NULL;
284 DWORD_PTR Args[2];
285
286 DPRINT("PrintCommandHelp(%p %p %p)\n", pContext, pGroup, pCommand);
287
288 pszInBuffer = HeapAlloc(GetProcessHeap(), 0, HUGE_HELP_BUFFER_SIZE * sizeof(WCHAR));
289 if (pszInBuffer == NULL)
290 goto done;
291
292 pszOutBuffer = HeapAlloc(GetProcessHeap(), 0, HUGE_HELP_BUFFER_SIZE * sizeof(WCHAR));
293 if (pszOutBuffer == NULL)
294 goto done;
295
296 pszCommandBuffer = HeapAlloc(GetProcessHeap(), 0, TINY_HELP_BUFFER_SIZE * sizeof(WCHAR));
297 if (pszCommandBuffer == NULL)
298 goto done;
299
300 wcscpy(pszCommandBuffer, pCommand->pwszCmdToken);
301 if (pGroup)
302 {
303 wcscat(pszCommandBuffer, L" ");
304 wcscat(pszCommandBuffer, pGroup->pwszCmdGroupToken);
305 }
306
307 LoadStringW(pContext->hModule, pCommand->dwCmdHlpToken, pszInBuffer, HUGE_HELP_BUFFER_SIZE);
308
309 Args[0] = (DWORD_PTR)pszCommandBuffer;
310 Args[1] = (DWORD_PTR)NULL;
311
313 pszInBuffer,
314 0,
315 0,
316 pszOutBuffer,
318 (va_list *)&Args);
319
320 ConPuts(StdOut, pszOutBuffer);
321 ConPuts(StdOut, L"\n");
322
323done:
324 if (pszCommandBuffer)
325 HeapFree(GetProcessHeap(), 0, pszCommandBuffer);
326
327 if (pszOutBuffer)
328 HeapFree(GetProcessHeap(), 0, pszOutBuffer);
329
330 if (pszInBuffer)
331 HeapFree(GetProcessHeap(), 0, pszInBuffer);
332}
char ** Args
Definition: acdebug.h:353
char * va_list
Definition: acmsvcex.h:78
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
#define HUGE_HELP_BUFFER_SIZE
Definition: help.c:15
#define TINY_HELP_BUFFER_SIZE
Definition: help.c:17
#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
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
#define DPRINT
Definition: sndvol32.h:73
#define DWORD_PTR
Definition: treelist.c:76
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:398
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:401
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by InterpretCommand().

◆ PrintContext()

static VOID PrintContext ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 115 of file help.c.

117{
118 PCOMMAND_ENTRY pCommand;
119 PCOMMAND_GROUP pGroup;
120 PCONTEXT_ENTRY pSubContext;
121 PHELP_ENTRY pHelpArray = NULL;
122 DWORD dwCount = 0, dwIndex;
124
125 DPRINT("PrintContext()\n");
126
127 if (pContext != pRootContext)
128 PrintContext(pContext->pParentContext);
129
131
132 /* Count short commands */
133 pCommand = pContext->pCommandListHead;
134 while (pCommand != NULL)
135 {
136 dwCount++;
137 pCommand = pCommand->pNext;
138 }
139
140 /* Count short groups */
141 pGroup = pContext->pGroupListHead;
142 while (pGroup != NULL)
143 {
144 dwCount++;
145 pGroup = pGroup->pNext;
146 }
147
148 /* Count short subcontexts */
149 pSubContext = pContext->pSubContextHead;
150 while (pSubContext != NULL)
151 {
152 dwCount++;
153 pSubContext = pSubContext->pNext;
154 }
155
156 pHelpArray = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCount * sizeof(HELP_ENTRY));
157 if (pHelpArray == NULL)
158 return;
159
160 dwIndex = 0;
161
162 /* Add short commands */
163 pCommand = pContext->pCommandListHead;
164 while (pCommand != NULL)
165 {
166 pHelpArray[dwIndex].Type = Command;
167 pHelpArray[dwIndex].pszCommand = pCommand->pwszCmdToken;
168 pHelpArray[dwIndex].dwHelpId = pCommand->dwShortCmdHelpToken;
169// pHelpArray[dwIndex].Pointer.pCommand = pCommand;
170 dwIndex++;
171 pCommand = pCommand->pNext;
172 }
173
174 /* Add short groups */
175 pGroup = pContext->pGroupListHead;
176 while (pGroup != NULL)
177 {
178 pHelpArray[dwIndex].Type = Group;
179 pHelpArray[dwIndex].pszCommand = pGroup->pwszCmdGroupToken;
180 pHelpArray[dwIndex].dwHelpId = pGroup->dwShortCmdHelpToken;
181// pHelpArray[dwIndex].Pointer.pGroup = pGroup;
182 dwIndex++;
183 pGroup = pGroup->pNext;
184 }
185
186 /* Count short subcontexts */
187 pSubContext = pContext->pSubContextHead;
188 while (pSubContext != NULL)
189 {
190 pHelpArray[dwIndex].Type = SubContext;
191 pHelpArray[dwIndex].pszCommand = pSubContext->pszContextName;
192 pHelpArray[dwIndex].Pointer.pSubContext = pSubContext;
193 dwIndex++;
194 pSubContext = pSubContext->pNext;
195 }
196
197 qsort(pHelpArray, dwCount, sizeof(HELP_ENTRY), HelpCompare);
198
199 for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
200 {
201 switch (pHelpArray[dwIndex].Type)
202 {
203 case Command:
204 case Group:
205 if (LoadStringW(pContext->hModule, pHelpArray[dwIndex].dwHelpId, szBuffer, SMALL_HELP_BUFFER_SIZE) == 0)
206 szBuffer[0] = UNICODE_NULL;
207 ConPrintf(StdOut, L"%-15s - %s", pHelpArray[dwIndex].pszCommand, szBuffer);
208 break;
209
210 case SubContext:
211 GetContextFullName(pHelpArray[dwIndex].Pointer.pSubContext, szBuffer, SMALL_HELP_BUFFER_SIZE);
212 ConPrintf(StdOut, L"%-15s - Changes to the \"%s\" context.\n", pHelpArray[dwIndex].pszCommand, szBuffer);
213 break;
214 }
215 }
216
217 if (pHelpArray)
218 HeapFree(GetProcessHeap(), 0, pHelpArray);
219}
Type
Definition: Type.h:7
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
static int HelpCompare(_In_ const void *p1, _In_ const void *p2)
Definition: help.c:105
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:115
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned long DWORD
Definition: ntddk_ex.h:95
#define UNICODE_NULL
HELP_TYPE Type
Definition: help.c:28
PWSTR pszCommand
Definition: help.c:29
DWORD dwHelpId
Definition: help.c:30
union HELP_ENTRY::@18 Pointer
PCONTEXT_ENTRY pSubContext
Definition: help.c:35
Definition: precomp.h:80
PWSTR pwszCmdToken
Definition: precomp.h:84
DWORD dwShortCmdHelpToken
Definition: precomp.h:86
struct _COMMAND_ENTRY * pNext
Definition: precomp.h:82
struct _COMMAND_GROUP * pNext
Definition: precomp.h:94
PWSTR pwszCmdGroupToken
Definition: precomp.h:96
DWORD dwShortCmdHelpToken
Definition: precomp.h:97
Definition: precomp.h:105
PWSTR pszContextName
Definition: precomp.h:112
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:126
struct _CONTEXT_ENTRY * pNext
Definition: precomp.h:107

Referenced by PrintContext(), and PrintContextHelp().

◆ PrintContextHelp()

VOID PrintContextHelp ( _In_ PCONTEXT_ENTRY  pContext)

Definition at line 363 of file help.c.

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

Referenced by InterpretCommand().

◆ PrintCurrentContextHeader()

static VOID PrintCurrentContextHeader ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 64 of file help.c.

66{
68
69 if (pContext == pCurrentContext)
70 {
72 }
73 else
74 {
75 GetContextFullName(pContext, szBuffer, SMALL_HELP_BUFFER_SIZE);
77 }
78}
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 336 of file help.c.

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

Referenced by InterpretCommand(), and PrintGroupHelp().

◆ PrintShortGroupCommands()

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

Definition at line 83 of file help.c.

86{
87 PCOMMAND_ENTRY pCommand;
90
91 pCommand = pGroup->pCommandListHead;
92 while (pCommand != NULL)
93 {
94 swprintf(szBuffer1, L"%s %s", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
95 LoadStringW(pContext->hModule, pCommand->dwShortCmdHelpToken, szBuffer2, SMALL_HELP_BUFFER_SIZE);
96
97 ConPrintf(StdOut, L"%-15s - %s", szBuffer1, szBuffer2);
98 pCommand = pCommand->pNext;
99 }
100}
#define swprintf
Definition: precomp.h:40

Referenced by PrintGroupHelp().

◆ PrintSubcontexts()

static VOID PrintSubcontexts ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 234 of file help.c.

236{
237 PCONTEXT_ENTRY pSubContext, *pSubContextArray = NULL;
238 DWORD dwCount, dwIndex;
239
240 if (pContext->pSubContextHead == NULL)
241 return;
242
243 dwCount = 0;
244 pSubContext = pContext->pSubContextHead;
245 while (pSubContext != NULL)
246 {
247 dwCount++;
248 pSubContext = pSubContext->pNext;
249 }
250
251 pSubContextArray = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(PCONTEXT_ENTRY));
252 if (pSubContextArray == NULL)
253 return;
254
255 dwIndex = 0;
256 pSubContext = pContext->pSubContextHead;
257 while (pSubContext != NULL)
258 {
259 pSubContextArray[dwIndex] = pSubContext;
260 dwIndex++;
261 pSubContext = pSubContext->pNext;
262 }
263
264 qsort(pSubContextArray, dwCount, sizeof(PCONTEXT_ENTRY), SubContextCompare);
265
267 for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
268 {
269 ConPrintf(StdOut, L" %s", pSubContextArray[dwIndex]->pszContextName);
270 }
271 ConPuts(StdOut, L"\n");
272
273 HeapFree(GetProcessHeap(), 0, pSubContextArray);
274}
static int SubContextCompare(_In_ const void *p1, _In_ const void *p2)
Definition: help.c:224
#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 224 of file help.c.

227{
228 return _wcsicmp((*((PCONTEXT_ENTRY*)p1))->pszContextName, (*((PCONTEXT_ENTRY*)p2))->pszContextName);
229}

Referenced by PrintSubcontexts().