@@ -144,6 +144,8 @@ static char **parse_args(char *line, int *argcp)
144
144
* dst ++ = c ;
145
145
}
146
146
}
147
+ /* Let the last substring is null-terminated */
148
+ * dst ++ = '\0' ;
147
149
148
150
/* Now assemble into array of strings */
149
151
char * * argv = calloc_or_fail (argc , sizeof (char * ), "parse_args" );
@@ -158,12 +160,43 @@ static char **parse_args(char *line, int *argcp)
158
160
return argv ;
159
161
}
160
162
163
+ /* Handles forced console termination for record_error and do_quit */
164
+ static bool force_quit (int argc , char * argv [])
165
+ {
166
+ cmd_element_t * c = cmd_list ;
167
+ bool ok = true;
168
+ while (c ) {
169
+ cmd_element_t * ele = c ;
170
+ c = c -> next ;
171
+ free_block (ele , sizeof (cmd_element_t ));
172
+ }
173
+
174
+ param_element_t * p = param_list ;
175
+ while (p ) {
176
+ param_element_t * ele = p ;
177
+ p = p -> next ;
178
+ free_block (ele , sizeof (param_element_t ));
179
+ }
180
+
181
+ while (buf_stack )
182
+ pop_file ();
183
+
184
+ for (int i = 0 ; i < quit_helper_cnt ; i ++ ) {
185
+ ok = ok && quit_helpers [i ](argc , argv );
186
+ }
187
+
188
+ quit_flag = true;
189
+ return ok ;
190
+ }
191
+
161
192
static void record_error ()
162
193
{
163
194
err_cnt ++ ;
164
195
if (err_cnt >= err_limit ) {
165
- report (1 , "Error limit exceeded. Stopping command execution" );
166
- quit_flag = true;
196
+ report (
197
+ 1 ,
198
+ "Error limit exceeded. Stopping command execution, and quitting" );
199
+ force_quit (0 , NULL );
167
200
}
168
201
}
169
202
@@ -224,30 +257,7 @@ void set_echo(bool on)
224
257
/* Built-in commands */
225
258
static bool do_quit (int argc , char * argv [])
226
259
{
227
- cmd_element_t * c = cmd_list ;
228
- bool ok = true;
229
- while (c ) {
230
- cmd_element_t * ele = c ;
231
- c = c -> next ;
232
- free_block (ele , sizeof (cmd_element_t ));
233
- }
234
-
235
- param_element_t * p = param_list ;
236
- while (p ) {
237
- param_element_t * ele = p ;
238
- p = p -> next ;
239
- free_block (ele , sizeof (param_element_t ));
240
- }
241
-
242
- while (buf_stack )
243
- pop_file ();
244
-
245
- for (int i = 0 ; i < quit_helper_cnt ; i ++ ) {
246
- ok = ok && quit_helpers [i ](argc , argv );
247
- }
248
-
249
- quit_flag = true;
250
- return ok ;
260
+ return force_quit (argc , argv );
251
261
}
252
262
253
263
static bool do_help (int argc , char * argv [])
@@ -345,7 +355,7 @@ static bool do_option(int argc, char *argv[])
345
355
static bool do_source (int argc , char * argv [])
346
356
{
347
357
if (argc < 2 ) {
348
- report (1 , "No source file given" );
358
+ report (1 , "No source file given. Use 'source <file>'. " );
349
359
return false;
350
360
}
351
361
@@ -360,14 +370,15 @@ static bool do_source(int argc, char *argv[])
360
370
static bool do_log (int argc , char * argv [])
361
371
{
362
372
if (argc < 2 ) {
363
- report (1 , "No log file given" );
373
+ report (1 , "No log file given. Use 'log <file>'. " );
364
374
return false;
365
375
}
366
376
367
377
bool result = set_logfile (argv [1 ]);
368
378
if (!result )
369
379
report (1 , "Couldn't open log file '%s'" , argv [1 ]);
370
380
381
+ printf ("Logging enabled: %s\n" , argv [1 ]);
371
382
return result ;
372
383
}
373
384
@@ -427,7 +438,7 @@ void init_cmd()
427
438
"Display or set options. See 'Options' section for details" ,
428
439
"[name val]" );
429
440
ADD_COMMAND (quit , "Exit program" , "" );
430
- ADD_COMMAND (source , "Read commands from source file" , "" );
441
+ ADD_COMMAND (source , "Read commands from source file" , "file " );
431
442
ADD_COMMAND (log , "Copy output to file" , "file" );
432
443
ADD_COMMAND (time , "Time command execution" , "cmd arg ..." );
433
444
ADD_COMMAND (web , "Read commands from builtin web server" , "[port]" );
@@ -577,7 +588,7 @@ static int cmd_select(int nfds,
577
588
FD_ZERO (readfds );
578
589
FD_SET (infd , readfds );
579
590
580
- /* If web not ready listen */
591
+ /* If web_fd is available, add to readfds */
581
592
if (web_fd != -1 )
582
593
FD_SET (web_fd , readfds );
583
594
0 commit comments