diff --git a/src/commandline/cmdlinelib.c b/src/commandline/cmdlinelib.c index d49bad30..2e8e9c19 100644 --- a/src/commandline/cmdlinelib.c +++ b/src/commandline/cmdlinelib.c @@ -1,5 +1,5 @@ #include "cmdlinelib.h" -#include "command.h" +#include #include #include #include @@ -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 \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 6ba61753..3074f18d 100644 --- a/src/commandline/commands/help.c +++ b/src/commandline/commands/help.c @@ -1,7 +1,7 @@ -#include "command.h" -#include "console.h" #include +#include #include +#include 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 \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 662ad7b0..d859b2c0 100644 --- a/src/commandline/commands/nvo_cmd.c +++ b/src/commandline/commands/nvo_cmd.c @@ -3,10 +3,11 @@ #include #include #include -#include +#include #include #include #include +#include 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 \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 \n", - .desc = "Set stored option", .exec = set_exec, }; diff --git a/src/commandline/commands/test.c b/src/commandline/commands/test.c index 1d370124..59b0b72b 100644 --- a/src/commandline/commands/test.c +++ b/src/commandline/commands/test.c @@ -1,5 +1,5 @@ -#include "command.h" -#include "console.h" +#include +#include 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 077933d0..6cb2ee70 100644 --- a/src/commandline/commands/test2.c +++ b/src/commandline/commands/test2.c @@ -1,5 +1,5 @@ -#include "command.h" -#include "console.h" +#include +#include 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, }; diff --git a/src/include/command.h b/src/include/command.h deleted file mode 100644 index 113ca2f0..00000000 --- a/src/include/command.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COMMAND_H -#define COMMAND_H - -#include - -struct command { - const char *name; // The name of the command - const char *usage; // Description of how to use the command - const char *desc; // Short description of the command - int ( *exec ) ( int argc, char **argv); // The command function to call -}; - -#define __command __table ( commands, 01 ) -#endif -