ReactOS 0.4.15-dev-7961-gdcf9eb0
interpreter.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for interpreter.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL InterpretCommand (_In_ LPWSTR *argv, _In_ DWORD dwArgCount)
 
BOOL InterpretScript (_In_ LPWSTR pszInputLine)
 
VOID InterpretInteractive (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file interpreter.c.

Function Documentation

◆ InterpretCommand()

BOOL InterpretCommand ( _In_ LPWSTR argv,
_In_ DWORD  dwArgCount 
)

Definition at line 18 of file interpreter.c.

21{
22 PCONTEXT_ENTRY pContext, pSubContext;
23 PCOMMAND_ENTRY pCommand;
24 PCOMMAND_GROUP pGroup;
25 BOOL bDone = FALSE;
26 DWORD dwHelpLevel = 0;
27 DWORD dwError = ERROR_SUCCESS;
28
29 /* If no args provided */
30 if (dwArgCount == 0)
31 return TRUE;
32
33 if (pCurrentContext == NULL)
34 {
35 DPRINT1("InterpretCmd: invalid context %p\n", pCurrentContext);
36 return FALSE;
37 }
38
39 if ((wcsicmp(argv[dwArgCount - 1], L"?") == 0) ||
40 (wcsicmp(argv[dwArgCount - 1], L"help") == 0))
41 {
42 dwHelpLevel = dwArgCount - 1;
43 }
44
45 pContext = pCurrentContext;
46
47 while (TRUE)
48 {
49 pCommand = pContext->pCommandListHead;
50 while (pCommand != NULL)
51 {
52 if (wcsicmp(argv[0], pCommand->pwszCmdToken) == 0)
53 {
54 if (dwHelpLevel == 1)
55 {
57 return TRUE;
58 }
59 else
60 {
61 dwError = pCommand->pfnCmdHandler(NULL, argv, 0, dwArgCount, 0, NULL, &bDone);
62 if (dwError != ERROR_SUCCESS)
63 {
64 ConPrintf(StdOut, L"Error: %lu\n\n");
66 }
67 return !bDone;
68 }
69 }
70
71 pCommand = pCommand->pNext;
72 }
73
74 pGroup = pContext->pGroupListHead;
75 while (pGroup != NULL)
76 {
77 if (wcsicmp(argv[0], pGroup->pwszCmdGroupToken) == 0)
78 {
79 if (dwHelpLevel == 1)
80 {
81 HelpGroup(pGroup);
82 return TRUE;
83 }
84
85 pCommand = pGroup->pCommandListHead;
86 while (pCommand != NULL)
87 {
88 if ((dwArgCount > 1) && (wcsicmp(argv[1], pCommand->pwszCmdToken) == 0))
89 {
90 if (dwHelpLevel == 2)
91 {
93 return TRUE;
94 }
95 else
96 {
97 dwError = pCommand->pfnCmdHandler(NULL, argv, 1, dwArgCount, 0, NULL, &bDone);
98 if (dwError != ERROR_SUCCESS)
99 {
100 ConPrintf(StdOut, L"Error: %lu\n\n");
102 return TRUE;
103 }
104 return !bDone;
105 }
106 }
107
108 pCommand = pCommand->pNext;
109 }
110
111 HelpGroup(pGroup);
112 return TRUE;
113 }
114
115 pGroup = pGroup->pNext;
116 }
117
118 if (pContext == pCurrentContext)
119 {
120 pSubContext = pContext->pSubContextHead;
121 while (pSubContext != NULL)
122 {
123 if (wcsicmp(argv[0], pSubContext->pszContextName) == 0)
124 {
125 pCurrentContext = pSubContext;
126 return TRUE;
127 }
128
129 pSubContext = pSubContext->pNext;
130 }
131 }
132
133 if (pContext == pRootContext)
134 break;
135
136 pContext = pContext->pParentContext;
137 }
138
140
141 return TRUE;
142}
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
#define StdErr
Definition: fc.c:15
PCONTEXT_ENTRY pRootContext
Definition: context.c:17
PCONTEXT_ENTRY pCurrentContext
Definition: context.c:18
VOID HelpGroup(PCOMMAND_GROUP pGroup)
Definition: help.c:93
#define IDS_INVALID_COMMAND
Definition: resource.h:14
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsicmp
Definition: compat.h:15
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
Definition: precomp.h:73
DWORD dwCmdHlpToken
Definition: precomp.h:80
PFN_HANDLE_CMD pfnCmdHandler
Definition: precomp.h:78
LPCWSTR pwszCmdToken
Definition: precomp.h:77
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
Definition: precomp.h:98
PWSTR pszContextName
Definition: precomp.h:104
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:114
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

Referenced by InterpretInteractive(), InterpretScript(), and wmain().

◆ InterpretInteractive()

VOID InterpretInteractive ( VOID  )

Definition at line 188 of file interpreter.c.

189{
190 WCHAR input_line[MAX_STRING_SIZE];
191 LPWSTR args_vector[MAX_ARGS_COUNT];
192 DWORD dwArgCount = 0;
193 BOOL bWhiteSpace = TRUE;
194 BOOL bRun = TRUE;
195 LPWSTR ptr;
196
197 while (bRun != FALSE)
198 {
199 dwArgCount = 0;
200 memset(args_vector, 0, sizeof(args_vector));
201
202 /* Shown just before the input where the user places commands */
203// ConResPuts(StdOut, IDS_APP_PROMPT);
204 ConPuts(StdOut, L"netsh");
206 {
207 ConPuts(StdOut, L" ");
209 }
210 ConPuts(StdOut, L">");
211
212 /* Get input from the user. */
213 fgetws(input_line, MAX_STRING_SIZE, stdin);
214
215 ptr = input_line;
216 while (*ptr != 0)
217 {
218 if (iswspace(*ptr) || *ptr == L'\n')
219 {
220 *ptr = 0;
221 bWhiteSpace = TRUE;
222 }
223 else
224 {
225 if ((bWhiteSpace != FALSE) && (dwArgCount < MAX_ARGS_COUNT))
226 {
227 args_vector[dwArgCount] = ptr;
228 dwArgCount++;
229 }
230 bWhiteSpace = FALSE;
231 }
232 ptr++;
233 }
234
235 /* Send the string to find the command */
236 bRun = InterpretCommand(args_vector, dwArgCount);
237 }
238}
BOOL InterpretCommand(_In_ LPWSTR *argv, _In_ DWORD dwArgCount)
Definition: interpreter.c:18
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define MAX_STRING_SIZE
Definition: precomp.h:34
#define MAX_ARGS_COUNT
Definition: precomp.h:35
#define iswspace(_c)
Definition: ctype.h:669
#define stdin
Definition: stdio.h:98
static PVOID ptr
Definition: dispmode.c:27
#define memset(x, y, z)
Definition: compat.h:39
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by wmain().

◆ InterpretScript()

BOOL InterpretScript ( _In_ LPWSTR  pszInputLine)

Definition at line 150 of file interpreter.c.

152{
153 LPWSTR args_vector[MAX_ARGS_COUNT];
154 DWORD dwArgCount = 0;
155 BOOL bWhiteSpace = TRUE;
156 LPWSTR ptr;
157
158 memset(args_vector, 0, sizeof(args_vector));
159
160 ptr = pszInputLine;
161 while (*ptr != 0)
162 {
163 if (iswspace(*ptr) || *ptr == L'\n')
164 {
165 *ptr = 0;
166 bWhiteSpace = TRUE;
167 }
168 else
169 {
170 if ((bWhiteSpace != FALSE) && (dwArgCount < MAX_ARGS_COUNT))
171 {
172 args_vector[dwArgCount] = ptr;
173 dwArgCount++;
174 }
175
176 bWhiteSpace = FALSE;
177 }
178
179 ptr++;
180 }
181
182 /* sends the string to find the command */
183 return InterpretCommand(args_vector, dwArgCount);
184}

Referenced by RunScript().