cmdlinelib.c now calls system() rather than doing its own tokenisation
[people/mcb30/gpxe.git] / src / commandline / cmdlinelib.c
index d49bad3..2e8e9c1 100644 (file)
@@ -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)){