summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/cmd.c b/cmd.c
index c1d43fc..9ceab86 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,5 @@
#include "cmd.h"
+#include "cmd_parse.h"
cmd_tok_t* cmd_tok_create( char *s, char *e, int sz, int type )
{
@@ -272,12 +273,16 @@ int cmd_exec( cmd_table_t *tbl, cmd_arg_t *arg )
cmd_arg_t *sub_arg = NULL;
- if ( arg->argc < 1 )
+ //there could be 0 arguments
+ if ( arg->argc < 0 )
{
printf("Hm ... no arguments\n");
return -1;
}
+ if ( arg->argc == 0 )
+ return 0;
+
i = 0;
while ( (tbl[i].cmd != NULL) && (tbl[i].clb != NULL) )
{
@@ -315,9 +320,7 @@ int cmd_exec( cmd_table_t *tbl, cmd_arg_t *arg )
}
i++;
- }
-
-
+ }
return ret;
}
@@ -484,6 +487,70 @@ void cmd_acq_free( struct cmd_acq_head_t *acq )
return;
}
+char* cmd_mng_history( cmd_mng_t *cmng, int index )
+{
+ char *ret=NULL;
+
+
+
+ return ret;
+}
+
+char* cmd_mng_autocomplete( cmd_mng_t *cmng, char *cmd )
+{
+ char *ret=NULL;
+
+
+
+ return ret;
+}
+
+int cmd_mng_exec( cmd_mng_t *cmng, const char *cmd, size_t sz_cmd )
+{
+ int ret = CMD_EOK;
+ int fret = 0;
+ cmd_tok_t tl, *ptr_tl = &tl, *iter = NULL;
+ cmd_arg_t *args = NULL;
+
+ // Init values
+ memset( &tl, 0, sizeof( cmd_tok_t ));
+
+ fret = parse_cmd( ptr_tl, cmd, sz_cmd );
+ if ( fret != 0 )
+ {
+ ret = CMD_EEXE;
+ goto error_exe; //if err memleak from parse_cmd?
+ }
+
+ //printf("T:%d\n", ptr_tl->next);
+ iter = ptr_tl->next;
+ args = cmd_arg_create( iter );
+ cmd_tok_destroy( ptr_tl->next );
+ ptr_tl->next = NULL;
+
+ //int i;
+ //for (i=0;i<args->argc;i++)
+ //{
+ // printf("A:%s\n",args->argv[i]);
+ //}
+
+ if (cmd_exec(cmng->table, args) != 0)
+ {
+ ret = CMD_ECMD;
+ goto error_cmd;
+ }
+
+ cmd_arg_destroy( args );
+
+ return ret;
+error_cmd:
+ cmd_arg_destroy( args );
+
+error_exe:
+
+ return ret;
+}
+
/*
Clothest match function
AA AB = (1) equile <100%