ReactOS 0.4.16-dev-1972-gf20c09f
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 111 of file interpreter.c.

114{
115 PCOMMAND cmdptr;
116 PCOMMAND cmdptr1 = NULL;
117 PCOMMAND cmdptr2 = NULL;
118 PCOMMAND cmdptr3 = NULL;
119
120 /* If no args provided */
121 if (argc < 1)
122 return TRUE;
123
124 /* First, determine if the user wants to exit
125 or to use a comment */
126 if (_wcsicmp(argv[0], L"exit") == 0)
127 return FALSE;
128
129 if (_wcsicmp(argv[0], L"rem") == 0)
130 return TRUE;
131
132 /* Scan internal command table */
133 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
134 {
135 if ((cmdptr1 == NULL) &&
136 (cmdptr->cmd1 != NULL) && (_wcsicmp(argv[0], cmdptr->cmd1) == 0))
137 cmdptr1 = cmdptr;
138
139 if ((cmdptr2 == NULL) &&
140 (argc >= 2) &&
141 (cmdptr->cmd1 != NULL) && (_wcsicmp(argv[0], cmdptr->cmd1) == 0) &&
142 (cmdptr->cmd2 != NULL) && (_wcsicmp(argv[1], cmdptr->cmd2) == 0))
143 cmdptr2 = cmdptr;
144
145 if ((cmdptr3 == NULL) &&
146 (argc >= 3) &&
147 (cmdptr->cmd1 != NULL) && (_wcsicmp(argv[0], cmdptr->cmd1) == 0) &&
148 (cmdptr->cmd2 != NULL) && (_wcsicmp(argv[1], cmdptr->cmd2) == 0) &&
149 (cmdptr->cmd3 != NULL) && (_wcsicmp(argv[2], cmdptr->cmd3) == 0))
150 cmdptr3 = cmdptr;
151 }
152
153 if (cmdptr3 != NULL)
154 {
155 if (cmdptr3->func == NULL)
156 return HelpCommand(cmdptr3);
157 else
158 return cmdptr3->func(argc, argv);
159 }
160 else if (cmdptr2 != NULL)
161 {
162 if (cmdptr2->func == NULL)
163 return HelpCommand(cmdptr2);
164 else
165 return cmdptr2->func(argc, argv);
166 }
167 else if (cmdptr1 != NULL)
168 {
169 if (cmdptr1->func == NULL)
170 return HelpCommand(cmdptr1);
171 else
172 return cmdptr1->func(argc, argv);
173 }
174
176
177 return TRUE;
178}
static int argc
Definition: ServiceArgs.c:12
COMMAND cmds[]
Definition: interpreter.c:17
BOOL HelpCommand(PCOMMAND pCommand)
Definition: help.c:46
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 L(x)
Definition: resources.c:13
#define argv
Definition: mplay32.c:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: _wcsicmp_nt.c:13
Definition: main.c:15
INT(* func)(INT, WCHAR **)
Definition: main.c:17
PWSTR cmd3
Definition: diskpart.h:64
PWSTR cmd2
Definition: diskpart.h:63
PWSTR cmd1
Definition: diskpart.h:62

Referenced by InterpretMain(), and InterpretScript().

◆ InterpretMain()

VOID InterpretMain ( VOID  )

Definition at line 234 of file interpreter.c.

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

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

Referenced by RunScript().

◆ 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().