ReactOS  0.4.14-dev-52-g6116262
interpreter.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS DiskPart
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/system/diskpart/interpreter.c
5  * PURPOSE: Reads the user input and then invokes the selected
6  * command by the user.
7  * PROGRAMMERS: Lee Schroeder
8  */
9 
10 #include "diskpart.h"
11 
14 
15 
17 {
57 };
58 
59 
60 /* FUNCTIONS *****************************************************************/
61 
62 /*
63  * InterpretCmd(char *cmd_line, char *arg_line):
64  * compares the command name to a list of available commands, and
65  * determines which function to invoke.
66  */
67 BOOL
69 {
70  PCOMMAND cmdptr;
71 
72  /* If no args provided */
73  if (argc < 1)
74  return TRUE;
75 
76  /* First, determine if the user wants to exit
77  or to use a comment */
78  if(wcsicmp(argv[0], L"exit") == 0)
79  return FALSE;
80 
81  if(wcsicmp(argv[0], L"rem") == 0)
82  return TRUE;
83 
84  /* Scan internal command table */
85  for (cmdptr = cmds; cmdptr->name; cmdptr++)
86  {
87  if (wcsicmp(argv[0], cmdptr->name) == 0)
88  return cmdptr->func(argc, argv);
89  }
90 
91  help_cmdlist();
92 
93  return TRUE;
94 }
95 
96 
97 /*
98  * InterpretScript(char *line):
99  * The main function used for when reading commands from scripts.
100  */
101 BOOL
103 {
104  LPWSTR args_vector[MAX_ARGS_COUNT];
105  INT args_count = 0;
106  BOOL bWhiteSpace = TRUE;
107  LPWSTR ptr;
108 
109  memset(args_vector, 0, sizeof(args_vector));
110 
111  ptr = input_line;
112  while (*ptr != 0)
113  {
114  if (iswspace(*ptr) || *ptr == L'\n')
115  {
116  *ptr = 0;
117  bWhiteSpace = TRUE;
118  }
119  else
120  {
121  if ((bWhiteSpace != FALSE) && (args_count < MAX_ARGS_COUNT))
122  {
123  args_vector[args_count] = ptr;
124  args_count++;
125  }
126 
127  bWhiteSpace = FALSE;
128  }
129 
130  ptr++;
131  }
132 
133  /* sends the string to find the command */
134  return InterpretCmd(args_count, args_vector);
135 }
136 
137 
138 /*
139  * InterpretMain():
140  * Contents for the main program loop as it reads each line, and then
141  * it sends the string to interpret_line, where it determines what
142  * command to use.
143  */
144 VOID
146 {
147  WCHAR input_line[MAX_STRING_SIZE];
148  LPWSTR args_vector[MAX_ARGS_COUNT];
149  INT args_count = 0;
150  BOOL bWhiteSpace = TRUE;
151  BOOL bRun = TRUE;
152  LPWSTR ptr;
153 
154  while (bRun != FALSE)
155  {
156  args_count = 0;
157  memset(args_vector, 0, sizeof(args_vector));
158 
159  /* Shown just before the input where the user places commands */
161 
162  /* Get input from the user. */
163  fgetws(input_line, MAX_STRING_SIZE, stdin);
164 
165  ptr = input_line;
166  while (*ptr != 0)
167  {
168  if (iswspace(*ptr) || *ptr == L'\n')
169  {
170  *ptr = 0;
171  bWhiteSpace = TRUE;
172  }
173  else
174  {
175  if ((bWhiteSpace != FALSE) && (args_count < MAX_ARGS_COUNT))
176  {
177  args_vector[args_count] = ptr;
178  args_count++;
179  }
180  bWhiteSpace = FALSE;
181  }
182  ptr++;
183  }
184 
185  /* Send the string to find the command */
186  bRun = InterpretCmd(args_count, args_vector);
187  }
188 }
#define IDS_HELP_CMD_DESC_REPAIR
Definition: resource.h:98
#define IDS_HELP_CMD_DESC_BREAK
Definition: resource.h:74
#define IDS_HELP_CMD_REPAIR
Definition: resource.h:138
#define IDS_HELP_CMD_REMOVE
Definition: resource.h:137
BOOL filesystems_main(INT argc, LPWSTR *argv)
Definition: filesystems.c:11
#define IDS_HELP_CMD_DETACH
Definition: resource.h:122
BOOL attributes_main(INT argc, LPWSTR *argv)
Definition: attributes.c:11
static int argc
Definition: ServiceArgs.c:12
#define IDS_HELP_CMD_MERGE
Definition: resource.h:133
#define IDS_HELP_CMD_DESC_REM
Definition: resource.h:96
#define TRUE
Definition: types.h:120
BOOL setid_main(INT argc, LPWSTR *argv)
Definition: setid.c:11
BOOL shrink_main(INT argc, LPWSTR *argv)
Definition: shrink.c:11
VOID help_cmdlist(VOID)
Definition: help.c:15
#define IDS_HELP_CMD_COMPACT
Definition: resource.h:118
#define IDS_HELP_CMD_SETID
Definition: resource.h:143
#define IDS_HELP_CMD_RESCAN
Definition: resource.h:139
BOOL help_main(INT argc, LPWSTR *argv)
Definition: help.c:33
BOOL break_main(INT argc, LPWSTR *argv)
Definition: break.c:11
#define IDS_HELP_CMD_DESC_HELP
Definition: resource.h:88
#define IDS_HELP_CMD_DESC_OFFLINE
Definition: resource.h:94
#define IDS_HELP_CMD_SHRINK
Definition: resource.h:144
BOOL convert_main(INT argc, LPWSTR *argv)
Definition: convert.c:11
#define IDS_NONE
Definition: resource.h:122
BOOL format_main(INT argc, LPWSTR *argv)
Definition: format.c:11
BOOL recover_main(INT argc, LPWSTR *argv)
Definition: recover.c:11
#define IDS_HELP_CMD_FORMAT
Definition: resource.h:127
INT(* func)(INT, WCHAR **)
Definition: main.c:17
FILE * stdin
BOOL rescan_main(INT argc, LPWSTR *argv)
Definition: rescan.c:11
BOOL InterpretScript(LPWSTR input_line)
Definition: interpreter.c:102
BOOL add_main(INT argc, LPWSTR *argv)
Definition: add.c:11
#define IDS_HELP_CMD_DESC_UNIQUEID
Definition: resource.h:105
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
#define IDS_HELP_CMD_EXTEND
Definition: resource.h:125
#define IDS_HELP_CMD_CREATE
Definition: resource.h:120
#define IDS_HELP_CMD_DESC_COMPACT
Definition: resource.h:76
#define IDS_HELP_CMD_ADD
Definition: resource.h:111
#define IDS_HELP_CMD_DESC_IMPORT
Definition: resource.h:89
#define IDS_HELP_CMD_DESC_EXTEND
Definition: resource.h:83
BOOL detail_main(INT argc, LPWSTR *argv)
Definition: detail.c:11
#define IDS_HELP_CMD_CONVERT
Definition: resource.h:119
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_HELP_CMD_DESC_CREATE
Definition: resource.h:78
static PVOID ptr
Definition: dispmode.c:27
BOOL assign_main(INT argc, LPWSTR *argv)
Definition: assign.c:11
#define IDS_HELP_CMD_DESC_SAN
Definition: resource.h:101
#define IDS_HELP_CMD_RECOVER
Definition: resource.h:136
smooth NULL
Definition: ftsmooth.c:416
BOOL compact_main(INT argc, LPWSTR *argv)
Definition: compact.c:11
BOOL active_main(INT argc, LPWSTR *argv)
Definition: active.c:11
#define IDS_HELP_CMD_BREAK
Definition: resource.h:116
#define IDS_HELP_CMD_DESC_GPT
Definition: resource.h:87
#define IDS_HELP_CMD_ATTRIBUTES
Definition: resource.h:114
BOOL uniqueid_main(INT argc, LPWSTR *argv)
Definition: uniqueid.c:11
#define IDS_HELP_CMD_LIST
Definition: resource.h:132
VOID InterpretMain(VOID)
Definition: interpreter.c:145
#define IDS_HELP_CMD_DESC_SHRINK
Definition: resource.h:104
#define IDS_HELP_CMD_DESC_DETAIL
Definition: resource.h:80
#define MAX_STRING_SIZE
Definition: diskpart.h:69
#define IDS_HELP_CMD_DESC_DELETE
Definition: resource.h:79
#define IDS_HELP_CMD_CLEAN
Definition: resource.h:117
#define IDS_HELP_CMD_DESC_EXIT
Definition: resource.h:82
#define IDS_HELP_CMD_FILESYSTEMS
Definition: resource.h:126
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL detach_main(INT argc, LPWSTR *argv)
Definition: detach.c:11
#define IDS_HELP_CMD_DESC_RECOVER
Definition: resource.h:95
#define IDS_HELP_CMD_UNIQUEID
Definition: resource.h:145
#define IDS_HELP_CMD_INACTIVE
Definition: resource.h:131
#define IDS_HELP_CMD_DESC_ACTIVE
Definition: resource.h:68
#define IDS_HELP_CMD_IMPORT
Definition: resource.h:130
BOOL select_main(INT argc, LPWSTR *argv)
Definition: select.c:161
#define iswspace(_c)
Definition: ctype.h:669
#define IDS_HELP_CMD_SELECT
Definition: resource.h:142
#define IDS_HELP_CMD_DELETE
Definition: resource.h:121
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
BOOL inactive_main(INT argc, LPWSTR *argv)
Definition: inactive.c:11
#define IDS_HELP_CMD_DESC_EXPAND
Definition: resource.h:84
static const WCHAR L[]
Definition: oid.c:1250
BOOL list_main(INT argc, LPWSTR *argv)
Definition: list.c:235
#define IDS_HELP_CMD_ASSIGN
Definition: resource.h:112
#define IDS_APP_PROMPT
Definition: resource.h:18
#define IDS_HELP_CMD_DESC_AUTOMOUNT
Definition: resource.h:73
#define IDS_HELP_CMD_DESC_ADD
Definition: resource.h:69
BOOL create_main(INT argc, LPWSTR *argv)
Definition: create.c:11
#define IDS_HELP_CMD_DESC_DETACH
Definition: resource.h:81
#define IDS_HELP_CMD_DETAIL
Definition: resource.h:123
#define wcsicmp
Definition: string.h:1152
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:68
BOOL remove_main(INT argc, LPWSTR *argv)
Definition: remove.c:11
#define IDS_HELP_CMD_DESC_INACTIVE
Definition: resource.h:90
BOOL delete_main(INT argc, LPWSTR *argv)
Definition: delete.c:11
#define IDS_HELP_CMD_EXPAND
Definition: resource.h:124
#define IDS_HELP_CMD_GPT
Definition: resource.h:128
#define MAX_ARGS_COUNT
Definition: diskpart.h:70
#define IDS_HELP_CMD_DESC_FS
Definition: resource.h:85
#define IDS_HELP_CMD_ATTACH
Definition: resource.h:113
BOOL extend_main(INT argc, LPWSTR *argv)
Definition: extend.c:11
BOOL retain_main(INT argc, LPWSTR *argv)
Definition: retain.c:11
BOOL import_main(INT argc, LPWSTR *argv)
Definition: import.c:11
#define IDS_HELP_CMD_SAN
Definition: resource.h:141
BOOL automount_main(INT argc, LPWSTR *argv)
Definition: automount.c:11
#define IDS_HELP_CMD_AUTOMOUNT
Definition: resource.h:115
BOOL expand_main(INT argc, LPWSTR *argv)
Definition: expand.c:11
BOOL offline_main(INT argc, LPWSTR *argv)
Definition: offline.c:11
BOOL online_main(INT argc, LPWSTR *argv)
Definition: online.c:11
BOOL attach_main(INT argc, LPWSTR *argv)
Definition: attach.c:11
#define IDS_HELP_CMD_DESC_SETID
Definition: resource.h:103
BOOL exit_main(INT argc, LPWSTR *argv)
BOOL repair_main(INT argc, LPWSTR *argv)
Definition: repair.c:11
#define IDS_HELP_CMD_ONLINE
Definition: resource.h:135
#define IDS_HELP_CMD_DESC_SELECT
Definition: resource.h:102
#define IDS_HELP_CMD_ACTIVE
Definition: resource.h:110
#define StdOut
Definition: stream.h:76
#define IDS_HELP_CMD_DESC_ONLINE
Definition: resource.h:93
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
#define IDS_HELP_CMD_DESC_RESCAN
Definition: resource.h:99
BOOL clean_main(INT argc, LPWSTR *argv)
Definition: clean.c:11
#define IDS_HELP_CMD_RETAIN
Definition: resource.h:140
#define IDS_HELP_CMD_DESC_REMOVE
Definition: resource.h:97
BOOL rem_main(INT argc, LPWSTR *argv)
#define IDS_HELP_CMD_DESC_ASSIGN
Definition: resource.h:70
BOOL merge_main(INT argc, LPWSTR *argv)
Definition: merge.c:11
#define IDS_HELP_CMD_DESC_ATTACH
Definition: resource.h:72
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDS_HELP_CMD_DESC_MERGE
Definition: resource.h:92
Definition: main.c:14
#define memset(x, y, z)
Definition: compat.h:39
#define IDS_HELP_CMD_OFFLINE
Definition: resource.h:134
#define IDS_HELP_CMD_DESC_CONVERT
Definition: resource.h:77
#define IDS_HELP_CMD_DESC_RETAIN
Definition: resource.h:100
BOOL gpt_main(INT argc, LPWSTR *argv)
Definition: gpt.c:11
COMMAND cmds[]
Definition: interpreter.c:16
#define IDS_HELP_CMD_DESC_ATTRIBUTES
Definition: resource.h:71
#define IDS_HELP_CMD_DESC_LIST
Definition: resource.h:91
BOOL san_main(INT argc, LPWSTR *argv)
Definition: san.c:11
#define IDS_HELP_CMD_HELP
Definition: resource.h:129
WCHAR * name
Definition: main.c:16
#define IDS_HELP_CMD_DESC_CLEAN
Definition: resource.h:75
#define IDS_HELP_CMD_DESC_FORMAT
Definition: resource.h:86