ReactOS 0.4.15-dev-8002-gbbb3b00
interpreter.c File Reference
#include "diskpart.h"
#include "diskpart_msg.h"
Include dependency graph for interpreter.c:

Go to the source code of this file.

Functions

BOOL exit_main (INT argc, LPWSTR *argv)
 
BOOL rem_main (INT argc, LPWSTR *argv)
 
BOOL InterpretCmd (int argc, LPWSTR *argv)
 
BOOL InterpretScript (LPWSTR input_line)
 
VOID InterpretMain (VOID)
 

Variables

COMMAND cmds []
 

Function Documentation

◆ exit_main()

BOOL exit_main ( INT  argc,
LPWSTR argv 
)

◆ InterpretCmd()

BOOL InterpretCmd ( int  argc,
LPWSTR argv 
)

Definition at line 108 of file interpreter.c.

111{
112 PCOMMAND cmdptr;
113 PCOMMAND cmdptr1 = NULL;
114 PCOMMAND cmdptr2 = NULL;
115 PCOMMAND cmdptr3 = NULL;
116
117 /* If no args provided */
118 if (argc < 1)
119 return TRUE;
120
121 /* First, determine if the user wants to exit
122 or to use a comment */
123 if (wcsicmp(argv[0], L"exit") == 0)
124 return FALSE;
125
126 if (wcsicmp(argv[0], L"rem") == 0)
127 return TRUE;
128
129 /* Scan internal command table */
130 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
131 {
132 if ((cmdptr1 == NULL) &&
133 (cmdptr->cmd1 != NULL) && (wcsicmp(argv[0], cmdptr->cmd1) == 0))
134 cmdptr1 = cmdptr;
135
136 if ((cmdptr2 == NULL) &&
137 (argc >= 2) &&
138 (cmdptr->cmd1 != NULL) && (wcsicmp(argv[0], cmdptr->cmd1) == 0) &&
139 (cmdptr->cmd2 != NULL) && (wcsicmp(argv[1], cmdptr->cmd2) == 0))
140 cmdptr2 = cmdptr;
141
142 if ((cmdptr3 == NULL) &&
143 (argc >= 3) &&
144 (cmdptr->cmd1 != NULL) && (wcsicmp(argv[0], cmdptr->cmd1) == 0) &&
145 (cmdptr->cmd2 != NULL) && (wcsicmp(argv[1], cmdptr->cmd2) == 0) &&
146 (cmdptr->cmd3 != NULL) && (wcsicmp(argv[2], cmdptr->cmd3) == 0))
147 cmdptr3 = cmdptr;
148 }
149
150 if (cmdptr3 != NULL)
151 {
152 if (cmdptr3->func == NULL)
153 return HelpCommand(cmdptr3);
154 else
155 return cmdptr3->func(argc, argv);
156 }
157 else if (cmdptr2 != NULL)
158 {
159 if (cmdptr2->func == NULL)
160 return HelpCommand(cmdptr2);
161 else
162 return cmdptr2->func(argc, argv);
163 }
164 else if (cmdptr1 != NULL)
165 {
166 if (cmdptr1->func == NULL)
167 return HelpCommand(cmdptr1);
168 else
169 return cmdptr1->func(argc, argv);
170 }
171
173
174 return TRUE;
175}
static int argc
Definition: ServiceArgs.c:12
DWORD WINAPI HelpCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: help.c:116
VOID HelpCommandList(VOID)
Definition: help.c:16
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsicmp
Definition: compat.h:15
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
Definition: main.c:15
INT(* func)(INT, WCHAR **)
Definition: main.c:17
PWSTR cmd3
Definition: diskpart.h:59
PWSTR cmd2
Definition: diskpart.h:58
PWSTR cmd1
Definition: diskpart.h:57
COMMAND cmds[]
Definition: interpreter.c:17

Referenced by InterpretMain(), and InterpretScript().

◆ InterpretMain()

VOID InterpretMain ( VOID  )

Definition at line 231 of file interpreter.c.

232{
233 WCHAR input_line[MAX_STRING_SIZE];
234 LPWSTR args_vector[MAX_ARGS_COUNT];
235 INT args_count = 0;
236 BOOL bWhiteSpace = TRUE;
237 BOOL bQuote = FALSE;
238 BOOL bRun = TRUE;
239 LPWSTR ptr;
240
241 while (bRun != FALSE)
242 {
243 args_count = 0;
244 memset(args_vector, 0, sizeof(args_vector));
245
246 /* Shown just before the input where the user places commands */
248
249 /* Get input from the user. */
250 fgetws(input_line, MAX_STRING_SIZE, stdin);
251
252 bQuote = FALSE;
253 ptr = input_line;
254 while (*ptr != 0)
255 {
256 if (*ptr == L'"')
257 bQuote = !bQuote;
258
259 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
260 {
261 *ptr = 0;
262 bWhiteSpace = TRUE;
263 }
264 else
265 {
266 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
267 {
268 args_vector[args_count] = ptr;
269 args_count++;
270 }
271 bWhiteSpace = FALSE;
272 }
273 ptr++;
274 }
275
276 /* Send the string to find the command */
277 bRun = InterpretCmd(args_count, args_vector);
278 }
279}
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define MAX_STRING_SIZE
Definition: precomp.h:34
#define MAX_ARGS_COUNT
Definition: precomp.h:35
#define IDS_APP_PROMPT
Definition: resource.h:13
unsigned int BOOL
Definition: ntddk_ex.h:94
#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
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:108
int32_t INT
Definition: typedefs.h:58
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 ( LPWSTR  input_line)

Definition at line 183 of file interpreter.c.

184{
185 LPWSTR args_vector[MAX_ARGS_COUNT];
186 INT args_count = 0;
187 BOOL bWhiteSpace = TRUE;
188 BOOL bQuote = FALSE;
189 LPWSTR ptr;
190
191 memset(args_vector, 0, sizeof(args_vector));
192
193 bQuote = FALSE;
194 ptr = input_line;
195 while (*ptr != 0)
196 {
197 if (*ptr == L'"')
198 bQuote = !bQuote;
199
200 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
201 {
202 *ptr = 0;
203 bWhiteSpace = TRUE;
204 }
205 else
206 {
207 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
208 {
209 args_vector[args_count] = ptr;
210 args_count++;
211 }
212
213 bWhiteSpace = FALSE;
214 }
215
216 ptr++;
217 }
218
219 /* sends the string to find the command */
220 return InterpretCmd(args_count, args_vector);
221}

◆ rem_main()

BOOL rem_main ( INT  argc,
LPWSTR argv 
)

Variable Documentation

◆ cmds

COMMAND cmds[]

Definition at line 17 of file interpreter.c.

Referenced by InterpretCmd().