ReactOS 0.4.16-dev-2615-g89221f5
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 104 of file help.c.

107{
108 return _wcsicmp(((PHELP_ENTRY)p1)->pszCommand, ((PHELP_ENTRY)p2)->pszCommand);
109}
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
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 277 of file help.c.

281{
282 LPWSTR pszCommandBuffer;
283 DWORD_PTR Args[2];
284
285 DPRINT("PrintCommandHelp(%p %p %p)\n", pContext, pGroup, pCommand);
286
287 pszCommandBuffer = HeapAlloc(GetProcessHeap(), 0, TINY_HELP_BUFFER_SIZE * sizeof(WCHAR));
288 if (pszCommandBuffer == NULL)
289 return;
290
291 wcscpy(pszCommandBuffer, pCommand->pwszCmdToken);
292 if (pGroup)
293 {
294 wcscat(pszCommandBuffer, L" ");
295 wcscat(pszCommandBuffer, pGroup->pwszCmdGroupToken);
296 }
297
298 Args[0] = (DWORD_PTR)pszCommandBuffer;
299 Args[1] = (DWORD_PTR)NULL;
300
302 pContext->hModule,
304 pCommand->dwCmdHlpToken,
306 (va_list *)&Args);
307 ConPuts(StdOut, L"\n");
308
309 HeapFree(GetProcessHeap(), 0, pszCommandBuffer);
310}
char ** Args
Definition: acdebug.h:353
#define TINY_HELP_BUFFER_SIZE
Definition: help.c:17
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
char * va_list
Definition: vadefs.h:50
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 114 of file help.c.

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

Referenced by PrintContext(), and PrintContextHelp().

◆ PrintContextHelp()

VOID PrintContextHelp ( _In_ PCONTEXT_ENTRY  pContext)

Definition at line 341 of file help.c.

343{
345 PrintContext(pContext);
346 PrintSubcontexts(pContext);
348}
static VOID PrintSubcontexts(_In_ PCONTEXT_ENTRY pContext)
Definition: help.c:233
#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 314 of file help.c.

318{
319 PCOMMAND_GROUP pGroup;
320
321 if (bRecurse)
322 {
323 if (pContext != pRootContext)
324 PrintGroupHelp(pContext->pParentContext, pszGroupName, bRecurse);
325 }
326
327 pGroup = pContext->pGroupListHead;
328 while (pGroup != NULL)
329 {
330 if (_wcsicmp(pszGroupName, pGroup->pwszCmdGroupToken) == 0)
331 {
333 PrintShortGroupCommands(pContext, pGroup);
334 }
335 pGroup = pGroup->pNext;
336 }
337}
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:314

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 swprintf(szBuffer1, L"%s %s", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
94 LoadStringW(pContext->hModule, pCommand->dwShortCmdHelpToken, szBuffer2, _countof(szBuffer2));
95
96 ConPrintf(StdOut, L"%-15s - %s", szBuffer1, szBuffer2);
97 pCommand = pCommand->pNext;
98 }
99}
#define swprintf
Definition: precomp.h:40

Referenced by PrintGroupHelp().

◆ PrintSubcontexts()

static VOID PrintSubcontexts ( _In_ PCONTEXT_ENTRY  pContext)
static

Definition at line 233 of file help.c.

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

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

Referenced by PrintSubcontexts().