ReactOS  0.4.15-dev-4594-g505ac65
interpreter.c File Reference
#include "diskpart.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 106 of file interpreter.c.

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

Referenced by InterpretMain(), and InterpretScript().

◆ InterpretMain()

VOID InterpretMain ( VOID  )

Definition at line 224 of file interpreter.c.

225 {
226  WCHAR input_line[MAX_STRING_SIZE];
227  LPWSTR args_vector[MAX_ARGS_COUNT];
228  INT args_count = 0;
229  BOOL bWhiteSpace = TRUE;
230  BOOL bRun = TRUE;
231  LPWSTR ptr;
232 
233  while (bRun != FALSE)
234  {
235  args_count = 0;
236  memset(args_vector, 0, sizeof(args_vector));
237 
238  /* Shown just before the input where the user places commands */
240 
241  /* Get input from the user. */
242  fgetws(input_line, MAX_STRING_SIZE, stdin);
243 
244  ptr = input_line;
245  while (*ptr != 0)
246  {
247  if (iswspace(*ptr) || *ptr == L'\n')
248  {
249  *ptr = 0;
250  bWhiteSpace = TRUE;
251  }
252  else
253  {
254  if ((bWhiteSpace != FALSE) && (args_count < MAX_ARGS_COUNT))
255  {
256  args_vector[args_count] = ptr;
257  args_count++;
258  }
259  bWhiteSpace = FALSE;
260  }
261  ptr++;
262  }
263 
264  /* Send the string to find the command */
265  bRun = InterpretCmd(args_count, args_vector);
266  }
267 }
#define TRUE
Definition: types.h:120
FILE * stdin
int32_t INT
Definition: typedefs.h:58
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define MAX_STRING_SIZE
Definition: diskpart.h:73
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define iswspace(_c)
Definition: ctype.h:669
#define IDS_APP_PROMPT
Definition: resource.h:18
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:106
#define MAX_ARGS_COUNT
Definition: diskpart.h:74
#define StdOut
Definition: fc.c:14
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39

Referenced by wmain().

◆ InterpretScript()

BOOL InterpretScript ( LPWSTR  input_line)

Definition at line 181 of file interpreter.c.

182 {
183  LPWSTR args_vector[MAX_ARGS_COUNT];
184  INT args_count = 0;
185  BOOL bWhiteSpace = TRUE;
186  LPWSTR ptr;
187 
188  memset(args_vector, 0, sizeof(args_vector));
189 
190  ptr = input_line;
191  while (*ptr != 0)
192  {
193  if (iswspace(*ptr) || *ptr == L'\n')
194  {
195  *ptr = 0;
196  bWhiteSpace = TRUE;
197  }
198  else
199  {
200  if ((bWhiteSpace != FALSE) && (args_count < MAX_ARGS_COUNT))
201  {
202  args_vector[args_count] = ptr;
203  args_count++;
204  }
205 
206  bWhiteSpace = FALSE;
207  }
208 
209  ptr++;
210  }
211 
212  /* sends the string to find the command */
213  return InterpretCmd(args_count, args_vector);
214 }
#define TRUE
Definition: types.h:120
int32_t INT
Definition: typedefs.h:58
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
#define iswspace(_c)
Definition: ctype.h:669
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:106
#define MAX_ARGS_COUNT
Definition: diskpart.h:74
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39

Referenced by RunScript().

◆ rem_main()

BOOL rem_main ( INT  argc,
LPWSTR argv 
)

Variable Documentation

◆ cmds

COMMAND cmds[]

Definition at line 16 of file interpreter.c.

Referenced by InterpretCmd().