diff options
| author | Michael Brown | 2006-12-08 02:26:11 +0100 |
|---|---|---|
| committer | Michael Brown | 2006-12-08 02:26:11 +0100 |
| commit | 7de5d32ff534191232039a275c68ad3552d8ff58 (patch) | |
| tree | 0d2e07dda34d72384c30da64b960de8abd567aee /src/commandline | |
| parent | Added execv() and system(). (diff) | |
| download | ipxe-7de5d32ff534191232039a275c68ad3552d8ff58.tar.gz ipxe-7de5d32ff534191232039a275c68ad3552d8ff58.tar.xz ipxe-7de5d32ff534191232039a275c68ad3552d8ff58.zip | |
cmdlinelib.c now calls system() rather than doing its own tokenisation
(which was extremely heavy on calls to malloc()).
Moved include/command.h to include/gpxe/command.h, since it's
gPXE-specific.
Diffstat (limited to 'src/commandline')
| -rw-r--r-- | src/commandline/cmdlinelib.c | 172 | ||||
| -rw-r--r-- | src/commandline/commands/help.c | 35 | ||||
| -rw-r--r-- | src/commandline/commands/nvo_cmd.c | 7 | ||||
| -rw-r--r-- | src/commandline/commands/test.c | 6 | ||||
| -rw-r--r-- | src/commandline/commands/test2.c | 6 |
5 files changed, 18 insertions, 208 deletions
diff --git a/src/commandline/cmdlinelib.c b/src/commandline/cmdlinelib.c index d49bad300..2e8e9c199 100644 --- a/src/commandline/cmdlinelib.c +++ b/src/commandline/cmdlinelib.c @@ -1,5 +1,5 @@ #include "cmdlinelib.h" -#include "command.h" +#include <gpxe/command.h> #include <gpxe/tables.h> #include <console.h> #include <malloc.h> @@ -62,27 +62,6 @@ void cmdl_addstr(cmd_line* cmd, char* str) } } -/*void cmdl_addoutput_str(cmd_line* cmd, char output[CMDL_OUTPUT_SIZE]) -{ - if(cmdl_check(cmd) && output != NULL){ - if(!cmd->has_output){ - cmdl_clearoutput(cmd); - } - strncat(cmd->output, output, CMDL_OUTPUT_SIZE); - cmd->has_output = 1; - } -}*/ - -/*char* cmdl_getoutput(cmd_line* cmd) -{ - if(cmdl_check(cmd) && cmd->has_output){ - cmd->has_output = 0; - return cmd->output; - }else{ - return ""; - } -}*/ - void cmdl_setpropmt(cmd_line* cmd, char prompt[CMDL_PROMPT_SIZE]) { if(cmdl_check(cmd) && prompt != NULL){ @@ -178,7 +157,8 @@ void cmdl_parsechar(cmd_line* cmd, char in) case CMDLK_RETURN: cmd->putchar('\n'); - cmdl_exec(cmd); + system ( cmd->buffer ); + cmdl_clearbuffer(cmd); cmd->refresh = 1; break; @@ -261,142 +241,6 @@ void cmdl_tabcomplete(cmd_line *cmd) } - -void cmdl_exec(cmd_line* cmd) -{ - cmdl_param_list* params; - int unknown=1; - struct command *ccmd; - - params = cmdl_getparams(cmd->buffer); - - if(params == NULL){ - cmdl_clearbuffer(cmd); - return; - } - - if(params->argc > 0){ - if(!strcmp(params->argv[0], "exit") || !strcmp(params->argv[0], "quit")){ - cmdl_setexit(cmd, 1); -/* }else if(!strcmp(params->argv[0], "help")){ - if(params->argc > 1){ - cmdl_builtin_help(cmd, params->argv[1]); - }else{ - cmdl_builtin_help(cmd, ""); - }*/ - }else{ - for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { - if(!strcmp(ccmd->name, params->argv[0])){ - unknown = 0; - ccmd->exec(params->argc, params->argv); - break; - } - } - if(unknown){ - cmd->printf("%s: unknown command\n", params->argv[0]); - } - } - } - - free(params); - cmdl_clearbuffer(cmd); -} - -/*void cmdl_builtin_help(cmd_line* cmd, char* command){ - struct command *ccmd; - int unknown = 1; - if(strcmp(command, "") == 0){ - 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"); - - for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { - cmd->printf ("\t%s\t\t%s\n", ccmd->name, ccmd->desc ); - } - }else{ - if(!strcmp(command, "help")){ - cmd->printf("help - The help command\n\nUsage: help <command>\n\n\tExample:\n\t\thelp help\n"); - }else if(!strcmp(command, "exit") || !strcmp(command, "quit")){ - cmd->printf("exit, quit - The quit command\n\nUsage:\nquit or exit\n\n\tExample:\n\t\texit\n"); - }else{ - for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { - if(!strcmp(ccmd->name, command)){ - unknown = 0; - cmd->printf ("\t%s - %s\n\nUsage:\n%s\n", ccmd->name, ccmd->desc, ccmd->usage ); - break; - } - if(unknown){ - cmd->printf("\"%s\" isn't compiled in (does it exist?).\n", command); - } - } - } - - } -}*/ - -cmdl_param_list* cmdl_getparams(const char* command){ - cmdl_param_list* this; - char *result = NULL; - int count=0; - char *command2; - - this = (cmdl_param_list*)malloc(sizeof(cmdl_param_list)); - - if(this == NULL){ - return NULL; - } - - command2 = malloc(strlen(command) + 1); - - this->argc=0; - - strcpy(command2, command); - result = strtok(command2, " "); - - while( result != NULL ) { - this->argc++; - result = strtok( NULL, " "); - } - - this->argv = (char**)malloc(sizeof(char*) * this->argc); - if(this->argv == NULL){ - free(this); - return NULL; - } - - - strcpy(command2, command); - result = strtok(command2, " "); - - while( result != NULL && this->argc > count) { - this->argv[count] = (char*)malloc(sizeof(char) * (strlen(result) + 1)); - if(this->argv[count] == NULL){ - free(this); - return NULL; - } - strcpy(this->argv[count], result); - count++; - result = strtok( NULL, " "); - } - free(command2); - return this; -} - -/*char* cmdl_parse_getcmd(cmd_line* cmd){ - int i; - char* ret; - ret = (char*)malloc(1); - ret[0] = 0; - - for(i=0; i < CMDL_BUFFER_SIZE - 1; i++){ - if(cmd->buffer[i + 1] == ' ' || cmd->buffer[i + 1] == '\0'){ - free(ret); - ret = (char*)malloc(i+1); - strncat(ret, cmd->buffer, i+1); - break; - } - } - return ret; -}*/ - void cmdl_clearbuffer(cmd_line* cmd) { if(cmdl_check(cmd)){ @@ -408,16 +252,6 @@ void cmdl_clearbuffer(cmd_line* cmd) } } -/*void cmdl_clearoutput(cmd_line* cmd) -{ - if(cmdl_check(cmd)){ - int i; - for(i=0; i < CMDL_OUTPUT_SIZE; i++){ - cmd->output[i] = 0; - } - } -}*/ - int cmdl_movecursor(cmd_line* cmd, int direction) { if(cmdl_check(cmd)){ diff --git a/src/commandline/commands/help.c b/src/commandline/commands/help.c index 6ba617533..3074f18d0 100644 --- a/src/commandline/commands/help.c +++ b/src/commandline/commands/help.c @@ -1,7 +1,7 @@ -#include "command.h" -#include "console.h" #include <string.h> +#include <vsprintf.h> #include <gpxe/tables.h> +#include <gpxe/command.h> static struct command cmd_start[0] __table_start ( commands ); static struct command cmd_end[0] __table_end ( commands ); @@ -12,36 +12,19 @@ static int cmd_help_exec ( int argc, char **argv ) { struct command *ccmd; int unknown = 1; - if(argc == 1){ - printf("Available commands:\n\n exit - Exit the command line and boot\n"); - - for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { - printf (" %s - %s\n", ccmd->name, ccmd->desc ); - } - }else{ - if(!strcmp(argv[1], "exit") || !strcmp(argv[1], "quit")){ - printf("exit - Exit the command line and boot\n\nUsage:\n exit\n"); - }else{ - for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { - if(!strcmp(ccmd->name, argv[1])){ - unknown = 0; - printf ("%s - %s\n\nUsage:\n %s\n", ccmd->name, ccmd->desc, ccmd->usage ); - break; - } - } - if(unknown){ - printf("\"%s\" isn't compiled in (does it exist?).\n", argv[1]); - } - } - + + + printf("Available commands:\n\n exit - Exit the command line and boot\n"); + + for ( ccmd = cmd_start ; ccmd < cmd_end ; ccmd++ ) { + printf (" %s\n", ccmd->name ); } + return 0; } struct command help_command __command = { .name = "help", - .usage = "help <command>\n\nExample:\n help help\n", - .desc = "The help command", .exec = cmd_help_exec, }; diff --git a/src/commandline/commands/nvo_cmd.c b/src/commandline/commands/nvo_cmd.c index 662ad7b0d..d859b2c04 100644 --- a/src/commandline/commands/nvo_cmd.c +++ b/src/commandline/commands/nvo_cmd.c @@ -3,10 +3,11 @@ #include <string.h> #include <errno.h> #include <vsprintf.h> -#include <command.h> +#include <getopt.h> #include <gpxe/nvo.h> #include <gpxe/dhcp.h> #include <gpxe/settings.h> +#include <gpxe/command.h> void nvo_cmd_req() {} @@ -41,8 +42,6 @@ static int show_exec ( int argc, char **argv ) { struct command show_command __command = { .name = "show", - .usage = "show <identifier>\n", - .desc = "Show stored options", .exec = show_exec, }; @@ -78,7 +77,5 @@ static int set_exec ( int argc, char **argv ) { struct command set_command __command = { .name = "set", - .usage = "set <identifier> <value>\n", - .desc = "Set stored option", .exec = set_exec, }; diff --git a/src/commandline/commands/test.c b/src/commandline/commands/test.c index 1d3701247..59b0b72b7 100644 --- a/src/commandline/commands/test.c +++ b/src/commandline/commands/test.c @@ -1,5 +1,5 @@ -#include "command.h" -#include "console.h" +#include <vsprintf.h> +#include <gpxe/command.h> void test_req(){} @@ -15,8 +15,6 @@ static int cmd_test_exec ( int argc, char **argv ) { struct command test_command __command = { .name = "test", - .usage = "A test command\nIt does nothing at all\n\nExample:\n\ttest", - .desc = "Does nothing", .exec = cmd_test_exec, }; diff --git a/src/commandline/commands/test2.c b/src/commandline/commands/test2.c index 077933d0e..6cb2ee70b 100644 --- a/src/commandline/commands/test2.c +++ b/src/commandline/commands/test2.c @@ -1,5 +1,5 @@ -#include "command.h" -#include "console.h" +#include <vsprintf.h> +#include <gpxe/command.h> void test2_req(){} @@ -15,8 +15,6 @@ static int cmd_test2_exec ( int argc, char **argv ) { struct command test2_command __command = { .name = "test2", - .usage = "A test command\nIt does nothing at all\n\nExample:\n\ttest2", - .desc = "Does nothing", .exec = cmd_test2_exec, }; |
