1212#define NDEBUG
1313#include <debug.h>
1414
15+ #define HUGE_HELP_BUFFER_SIZE 2048
16+ #define SMALL_HELP_BUFFER_SIZE 160
17+ #define TINY_HELP_BUFFER_SIZE 80
18+
1519typedef enum
1620{
1721 Command ,
6064PrintCurrentContextHeader (
6165 _In_ PCONTEXT_ENTRY pContext )
6266{
63- WCHAR szBuffer [80 ];
67+ WCHAR szBuffer [SMALL_HELP_BUFFER_SIZE ];
6468
6569 if (pContext == pCurrentContext )
6670 {
6771 ConResPrintf (StdOut , IDS_THIS_COMMANDS );
6872 }
6973 else
7074 {
71- GetContextFullName (pContext , szBuffer , 80 );
75+ GetContextFullName (pContext , szBuffer , SMALL_HELP_BUFFER_SIZE );
7276 ConResPrintf (StdOut , IDS_CONTEXT_COMMANDS , szBuffer );
7377 }
7478}
@@ -81,14 +85,14 @@ PrintShortGroupCommands(
8185 _In_ PCOMMAND_GROUP pGroup )
8286{
8387 PCOMMAND_ENTRY pCommand ;
84- WCHAR szBuffer1 [64 ];
85- WCHAR szBuffer2 [80 ];
88+ WCHAR szBuffer1 [TINY_HELP_BUFFER_SIZE ];
89+ WCHAR szBuffer2 [SMALL_HELP_BUFFER_SIZE ];
8690
8791 pCommand = pGroup -> pCommandListHead ;
8892 while (pCommand != NULL )
8993 {
9094 swprintf (szBuffer1 , L"%s %s" , pGroup -> pwszCmdGroupToken , pCommand -> pwszCmdToken );
91- LoadStringW (pContext -> hModule , pCommand -> dwShortCmdHelpToken , szBuffer2 , 80 );
95+ LoadStringW (pContext -> hModule , pCommand -> dwShortCmdHelpToken , szBuffer2 , SMALL_HELP_BUFFER_SIZE );
9296
9397 ConPrintf (StdOut , L"%-15s - %s" , szBuffer1 , szBuffer2 );
9498 pCommand = pCommand -> pNext ;
@@ -116,7 +120,7 @@ PrintContext(
116120 PCONTEXT_ENTRY pSubContext ;
117121 PHELP_ENTRY pHelpArray = NULL ;
118122 DWORD dwCount = 0 , dwIndex ;
119- WCHAR szBuffer [80 ];
123+ WCHAR szBuffer [SMALL_HELP_BUFFER_SIZE ];
120124
121125 DPRINT ("PrintContext()\n" );
122126
@@ -198,13 +202,13 @@ PrintContext(
198202 {
199203 case Command :
200204 case Group :
201- if (LoadStringW (pContext -> hModule , pHelpArray [dwIndex ].dwHelpId , szBuffer , 80 ) == 0 )
205+ if (LoadStringW (pContext -> hModule , pHelpArray [dwIndex ].dwHelpId , szBuffer , SMALL_HELP_BUFFER_SIZE ) == 0 )
202206 szBuffer [0 ] = UNICODE_NULL ;
203207 ConPrintf (StdOut , L"%-15s - %s" , pHelpArray [dwIndex ].pszCommand , szBuffer );
204208 break ;
205209
206210 case SubContext :
207- GetContextFullName (pHelpArray [dwIndex ].Pointer .pSubContext , szBuffer , 80 );
211+ GetContextFullName (pHelpArray [dwIndex ].Pointer .pSubContext , szBuffer , SMALL_HELP_BUFFER_SIZE );
208212 ConPrintf (StdOut , L"%-15s - Changes to the \"%s\" context.\n" , pHelpArray [dwIndex ].pszCommand , szBuffer );
209213 break ;
210214 }
@@ -273,12 +277,58 @@ PrintSubcontexts(
273277VOID
274278PrintCommandHelp (
275279 _In_ PCONTEXT_ENTRY pContext ,
280+ _In_ PCOMMAND_GROUP pGroup ,
276281 _In_ PCOMMAND_ENTRY pCommand )
277282{
278- WCHAR szBuffer [80 ];
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+
312+ FormatMessageW (FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY ,
313+ pszInBuffer ,
314+ 0 ,
315+ 0 ,
316+ pszOutBuffer ,
317+ HUGE_HELP_BUFFER_SIZE ,
318+ (va_list * )& Args );
319+
320+ ConPuts (StdOut , pszOutBuffer );
321+ ConPuts (StdOut , L"\n" );
322+
323+ done :
324+ if (pszCommandBuffer )
325+ HeapFree (GetProcessHeap (), 0 , pszCommandBuffer );
326+
327+ if (pszOutBuffer )
328+ HeapFree (GetProcessHeap (), 0 , pszOutBuffer );
279329
280- LoadStringW ( pContext -> hModule , pCommand -> dwCmdHlpToken , szBuffer , 80 );
281- ConPrintf ( StdOut , szBuffer );
330+ if ( pszInBuffer )
331+ HeapFree ( GetProcessHeap (), 0 , pszInBuffer );
282332}
283333
284334
0 commit comments