ReactOS 0.4.15-dev-8235-gcd88a97
help.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS NetSh
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Network Shell builtin help command and support functions
5 * COPYRIGHT: Copyright 2023 Eric Kohl <eric.kohl@reactos.org>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "precomp.h"
11
12#define NDEBUG
13#include <debug.h>
14
15/* FUNCTIONS ******************************************************************/
16
17static
18VOID
20 _In_ PCONTEXT_ENTRY pContext,
21 _Inout_ LPWSTR pszBuffer,
22 _In_ DWORD cchLength)
23{
24 if (pContext->pParentContext != NULL)
25 {
26 GetContextFullName(pContext->pParentContext, pszBuffer, cchLength);
27 wcscat(pszBuffer, L" ");
28 wcscat(pszBuffer, pContext->pszContextName);
29 }
30 else
31 {
32 wcscpy(pszBuffer, L"netsh");
33 }
34}
35
36
37static
38VOID
40 PCONTEXT_ENTRY pContext)
41{
42 PCONTEXT_ENTRY pSubContext;
43 PCOMMAND_ENTRY pCommand;
44 PCOMMAND_GROUP pGroup;
45 WCHAR szBuffer[80];
46
47 if (pContext != pRootContext)
48 HelpContext(pContext->pParentContext);
49
50 if (pContext == pCurrentContext)
51 {
52 ConPrintf(StdOut, L"\nCommands in this context:\n");
53 }
54 else if (pContext == pRootContext)
55 {
56 ConPrintf(StdOut, L"\nCommands in the netsh-context:\n");
57 }
58 else
59 {
60 GetContextFullName(pContext, szBuffer, 80);
61 ConPrintf(StdOut, L"\nCommands in the %s-context:\n", szBuffer);
62 }
63
64 pCommand = pContext->pCommandListHead;
65 while (pCommand != NULL)
66 {
67 if (LoadStringW(pContext->hModule, pCommand->dwShortCmdHelpToken, szBuffer, 80) == 0)
68 szBuffer[0] = UNICODE_NULL;
69 ConPrintf(StdOut, L"%-15s - %s\n", pCommand->pwszCmdToken, szBuffer);
70 pCommand = pCommand->pNext;
71 }
72
73 pGroup = pContext->pGroupListHead;
74 while (pGroup != NULL)
75 {
76 if (LoadStringW(pContext->hModule, pGroup->dwShortCmdHelpToken, szBuffer, 80) == 0)
77 szBuffer[0] = UNICODE_NULL;
78 ConPrintf(StdOut, L"%-15s - %s\n", pGroup->pwszCmdGroupToken, szBuffer);
79 pGroup = pGroup->pNext;
80 }
81
82 pSubContext = pContext->pSubContextHead;
83 while (pSubContext != NULL)
84 {
85 GetContextFullName(pSubContext, szBuffer, 80);
86 ConPrintf(StdOut, L"%-15s - Changes to the \"%s\" context.\n", pSubContext->pszContextName, szBuffer);
87 pSubContext = pSubContext->pNext;
88 }
89}
90
91
92VOID
94 PCOMMAND_GROUP pGroup)
95{
96 PCOMMAND_ENTRY pCommand;
97 WCHAR szBuffer[64];
98
100
101 ConPrintf(StdOut, L"\nCommands in this context:\n");
102
103 pCommand = pGroup->pCommandListHead;
104 while (pCommand != NULL)
105 {
106 swprintf(szBuffer, L"%s %s", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
107 ConPrintf(StdOut, L"%-15s - ", szBuffer);
109 pCommand = pCommand->pNext;
110 }
111}
112
113
114DWORD
115WINAPI
117 LPCWSTR pwszMachine,
118 LPWSTR *ppwcArguments,
119 DWORD dwCurrentIndex,
120 DWORD dwArgCount,
123 BOOL *pbDone)
124{
125 PCONTEXT_ENTRY pContext;
126
128
129 pContext = pCurrentContext;
130 if (pContext == NULL)
131 {
132 DPRINT1("HelpCommand: invalid context %p\n", pContext);
133 return 1;
134 }
135
136 HelpContext(pContext);
137
139 {
142 while (pContext != NULL)
143 {
144 ConPrintf(StdOut, L" %s", pContext->pszContextName);
145 pContext = pContext->pNext;
146 }
147 ConPuts(StdOut, L"\n");
148 }
149 ConPuts(StdOut, L"\n");
150
151 return ERROR_SUCCESS;
152}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
PCONTEXT_ENTRY pRootContext
Definition: context.c:17
PCONTEXT_ENTRY pCurrentContext
Definition: context.c:18
DWORD WINAPI HelpCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: help.c:116
static VOID GetContextFullName(_In_ PCONTEXT_ENTRY pContext, _Inout_ LPWSTR pszBuffer, _In_ DWORD cchLength)
Definition: help.c:19
static VOID HelpContext(PCONTEXT_ENTRY pContext)
Definition: help.c:39
VOID HelpGroup(PCOMMAND_GROUP pGroup)
Definition: help.c:93
#define IDS_HELP_HEADER
Definition: resource.h:18
#define IDS_SUBCONTEXT_HEADER
Definition: resource.h:19
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
Definition: precomp.h:73
LPCWSTR pwszCmdToken
Definition: precomp.h:77
DWORD dwShortCmdHelpToken
Definition: precomp.h:79
struct _COMMAND_ENTRY * pNext
Definition: precomp.h:75
PCOMMAND_ENTRY pCommandListHead
Definition: precomp.h:93
LPCWSTR pwszCmdGroupToken
Definition: precomp.h:89
struct _COMMAND_GROUP * pNext
Definition: precomp.h:87
DWORD dwShortCmdHelpToken
Definition: precomp.h:90
Definition: precomp.h:98
PWSTR pszContextName
Definition: precomp.h:104
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:114
HMODULE hModule
Definition: precomp.h:106
struct _CONTEXT_ENTRY * pParentContext
Definition: precomp.h:102
struct _CONTEXT_ENTRY * pNext
Definition: precomp.h:100
PCOMMAND_GROUP pGroupListHead
Definition: precomp.h:111
PCOMMAND_ENTRY pCommandListHead
Definition: precomp.h:108
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3749
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185