#include "cmdlinelib.h"
-#include "command.h"
+#include <gpxe/command.h>
#include <gpxe/tables.h>
#include <console.h>
#include <malloc.h>
}
}
-/*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){
case CMDLK_RETURN:
cmd->putchar('\n');
- cmdl_exec(cmd);
+ system ( cmd->buffer );
+ cmdl_clearbuffer(cmd);
cmd->refresh = 1;
break;
}
-
-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)){
}
}
-/*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)){
-#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 );
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,
};