|
@@ -1,5 +1,5 @@
|
1
|
1
|
#include "cmdlinelib.h"
|
2
|
|
-#include "command.h"
|
|
2
|
+#include <gpxe/command.h>
|
3
|
3
|
#include <gpxe/tables.h>
|
4
|
4
|
#include <console.h>
|
5
|
5
|
#include <malloc.h>
|
|
@@ -62,27 +62,6 @@ void cmdl_addstr(cmd_line* cmd, char* str)
|
62
|
62
|
}
|
63
|
63
|
}
|
64
|
64
|
|
65
|
|
-/*void cmdl_addoutput_str(cmd_line* cmd, char output[CMDL_OUTPUT_SIZE])
|
66
|
|
-{
|
67
|
|
- if(cmdl_check(cmd) && output != NULL){
|
68
|
|
- if(!cmd->has_output){
|
69
|
|
- cmdl_clearoutput(cmd);
|
70
|
|
- }
|
71
|
|
- strncat(cmd->output, output, CMDL_OUTPUT_SIZE);
|
72
|
|
- cmd->has_output = 1;
|
73
|
|
- }
|
74
|
|
-}*/
|
75
|
|
-
|
76
|
|
-/*char* cmdl_getoutput(cmd_line* cmd)
|
77
|
|
-{
|
78
|
|
- if(cmdl_check(cmd) && cmd->has_output){
|
79
|
|
- cmd->has_output = 0;
|
80
|
|
- return cmd->output;
|
81
|
|
- }else{
|
82
|
|
- return "";
|
83
|
|
- }
|
84
|
|
-}*/
|
85
|
|
-
|
86
|
65
|
void cmdl_setpropmt(cmd_line* cmd, char prompt[CMDL_PROMPT_SIZE])
|
87
|
66
|
{
|
88
|
67
|
if(cmdl_check(cmd) && prompt != NULL){
|
|
@@ -178,7 +157,8 @@ void cmdl_parsechar(cmd_line* cmd, char in)
|
178
|
157
|
|
179
|
158
|
case CMDLK_RETURN:
|
180
|
159
|
cmd->putchar('\n');
|
181
|
|
- cmdl_exec(cmd);
|
|
160
|
+ system ( cmd->buffer );
|
|
161
|
+ cmdl_clearbuffer(cmd);
|
182
|
162
|
cmd->refresh = 1;
|
183
|
163
|
break;
|
184
|
164
|
|
|
@@ -261,142 +241,6 @@ void cmdl_tabcomplete(cmd_line *cmd)
|
261
|
241
|
|
262
|
242
|
}
|
263
|
243
|
|
264
|
|
-
|
265
|
|
-void cmdl_exec(cmd_line* cmd)
|
266
|
|
-{
|
267
|
|
- cmdl_param_list* params;
|
268
|
|
- int unknown=1;
|
269
|
|
- struct command *ccmd;
|
270
|
|
-
|
271
|
|
- params = cmdl_getparams(cmd->buffer);
|
272
|
|
-
|
273
|
|
- if(params == NULL){
|
274
|
|
- cmdl_clearbuffer(cmd);
|
275
|
|
- return;
|
276
|
|
- }
|
277
|
|
-
|
278
|
|
- if(params->argc > 0){
|
279
|
|
- if(!strcmp(params->argv[0], "exit") || !strcmp(params->argv[0], "quit")){
|
280
|
|
- cmdl_setexit(cmd, 1);
|
281
|
|
-/* }else if(!strcmp(params->argv[0], "help")){
|
282
|
|
- if(params->argc > 1){
|
283
|
|
- cmdl_builtin_help(cmd, params->argv[1]);
|
284
|
|
- }else{
|
285
|
|
- cmdl_builtin_help(cmd, "");
|
286
|
|
- }*/
|
287
|
|
- }else{
|
288
|
|
- for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) {
|
289
|
|
- if(!strcmp(ccmd->name, params->argv[0])){
|
290
|
|
- unknown = 0;
|
291
|
|
- ccmd->exec(params->argc, params->argv);
|
292
|
|
- break;
|
293
|
|
- }
|
294
|
|
- }
|
295
|
|
- if(unknown){
|
296
|
|
- cmd->printf("%s: unknown command\n", params->argv[0]);
|
297
|
|
- }
|
298
|
|
- }
|
299
|
|
- }
|
300
|
|
-
|
301
|
|
- free(params);
|
302
|
|
- cmdl_clearbuffer(cmd);
|
303
|
|
-}
|
304
|
|
-
|
305
|
|
-/*void cmdl_builtin_help(cmd_line* cmd, char* command){
|
306
|
|
- struct command *ccmd;
|
307
|
|
- int unknown = 1;
|
308
|
|
- if(strcmp(command, "") == 0){
|
309
|
|
- cmd->printf("Built in commands:\n\n\thelp\t\tCommand usage help (\"help help\" for more info)\n\texit, quit\t\tExit the command line and boot\n\nCompiled in commands:\n\n");
|
310
|
|
-
|
311
|
|
- for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) {
|
312
|
|
- cmd->printf ("\t%s\t\t%s\n", ccmd->name, ccmd->desc );
|
313
|
|
- }
|
314
|
|
- }else{
|
315
|
|
- if(!strcmp(command, "help")){
|
316
|
|
- cmd->printf("help - The help command\n\nUsage: help <command>\n\n\tExample:\n\t\thelp help\n");
|
317
|
|
- }else if(!strcmp(command, "exit") || !strcmp(command, "quit")){
|
318
|
|
- cmd->printf("exit, quit - The quit command\n\nUsage:\nquit or exit\n\n\tExample:\n\t\texit\n");
|
319
|
|
- }else{
|
320
|
|
- for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) {
|
321
|
|
- if(!strcmp(ccmd->name, command)){
|
322
|
|
- unknown = 0;
|
323
|
|
- cmd->printf ("\t%s - %s\n\nUsage:\n%s\n", ccmd->name, ccmd->desc, ccmd->usage );
|
324
|
|
- break;
|
325
|
|
- }
|
326
|
|
- if(unknown){
|
327
|
|
- cmd->printf("\"%s\" isn't compiled in (does it exist?).\n", command);
|
328
|
|
- }
|
329
|
|
- }
|
330
|
|
- }
|
331
|
|
-
|
332
|
|
- }
|
333
|
|
-}*/
|
334
|
|
-
|
335
|
|
-cmdl_param_list* cmdl_getparams(const char* command){
|
336
|
|
- cmdl_param_list* this;
|
337
|
|
- char *result = NULL;
|
338
|
|
- int count=0;
|
339
|
|
- char *command2;
|
340
|
|
-
|
341
|
|
- this = (cmdl_param_list*)malloc(sizeof(cmdl_param_list));
|
342
|
|
-
|
343
|
|
- if(this == NULL){
|
344
|
|
- return NULL;
|
345
|
|
- }
|
346
|
|
-
|
347
|
|
- command2 = malloc(strlen(command) + 1);
|
348
|
|
-
|
349
|
|
- this->argc=0;
|
350
|
|
-
|
351
|
|
- strcpy(command2, command);
|
352
|
|
- result = strtok(command2, " ");
|
353
|
|
-
|
354
|
|
- while( result != NULL ) {
|
355
|
|
- this->argc++;
|
356
|
|
- result = strtok( NULL, " ");
|
357
|
|
- }
|
358
|
|
-
|
359
|
|
- this->argv = (char**)malloc(sizeof(char*) * this->argc);
|
360
|
|
- if(this->argv == NULL){
|
361
|
|
- free(this);
|
362
|
|
- return NULL;
|
363
|
|
- }
|
364
|
|
-
|
365
|
|
-
|
366
|
|
- strcpy(command2, command);
|
367
|
|
- result = strtok(command2, " ");
|
368
|
|
-
|
369
|
|
- while( result != NULL && this->argc > count) {
|
370
|
|
- this->argv[count] = (char*)malloc(sizeof(char) * (strlen(result) + 1));
|
371
|
|
- if(this->argv[count] == NULL){
|
372
|
|
- free(this);
|
373
|
|
- return NULL;
|
374
|
|
- }
|
375
|
|
- strcpy(this->argv[count], result);
|
376
|
|
- count++;
|
377
|
|
- result = strtok( NULL, " ");
|
378
|
|
- }
|
379
|
|
- free(command2);
|
380
|
|
- return this;
|
381
|
|
-}
|
382
|
|
-
|
383
|
|
-/*char* cmdl_parse_getcmd(cmd_line* cmd){
|
384
|
|
- int i;
|
385
|
|
- char* ret;
|
386
|
|
- ret = (char*)malloc(1);
|
387
|
|
- ret[0] = 0;
|
388
|
|
-
|
389
|
|
- for(i=0; i < CMDL_BUFFER_SIZE - 1; i++){
|
390
|
|
- if(cmd->buffer[i + 1] == ' ' || cmd->buffer[i + 1] == '\0'){
|
391
|
|
- free(ret);
|
392
|
|
- ret = (char*)malloc(i+1);
|
393
|
|
- strncat(ret, cmd->buffer, i+1);
|
394
|
|
- break;
|
395
|
|
- }
|
396
|
|
- }
|
397
|
|
- return ret;
|
398
|
|
-}*/
|
399
|
|
-
|
400
|
244
|
void cmdl_clearbuffer(cmd_line* cmd)
|
401
|
245
|
{
|
402
|
246
|
if(cmdl_check(cmd)){
|
|
@@ -408,16 +252,6 @@ void cmdl_clearbuffer(cmd_line* cmd)
|
408
|
252
|
}
|
409
|
253
|
}
|
410
|
254
|
|
411
|
|
-/*void cmdl_clearoutput(cmd_line* cmd)
|
412
|
|
-{
|
413
|
|
- if(cmdl_check(cmd)){
|
414
|
|
- int i;
|
415
|
|
- for(i=0; i < CMDL_OUTPUT_SIZE; i++){
|
416
|
|
- cmd->output[i] = 0;
|
417
|
|
- }
|
418
|
|
- }
|
419
|
|
-}*/
|
420
|
|
-
|
421
|
255
|
int cmdl_movecursor(cmd_line* cmd, int direction)
|
422
|
256
|
{
|
423
|
257
|
if(cmdl_check(cmd)){
|