summaryrefslogtreecommitdiffstats
path: root/cmd.h
diff options
context:
space:
mode:
Diffstat (limited to 'cmd.h')
-rw-r--r--cmd.h87
1 files changed, 83 insertions, 4 deletions
diff --git a/cmd.h b/cmd.h
index 736cb2b..a5e349a 100644
--- a/cmd.h
+++ b/cmd.h
@@ -13,14 +13,35 @@
#define CMDT_INT 1
#define CMDT_HEX 2
#define CMDT_BIN 3
-#define CMDT_STR 4
-#define CMDT_WORD 5
-#define CMDT_SP 6
+#define CMDT_QSTR 4
+#define CMDT_STR 5
+#define CMDT_WORD 6
+#define CMDT_SP 7
#define CMDE_NONE 0 //do nothing
#define CMDE_AUTOCOMPLETE 1 //try to auto complete first command
#define CMDE_ALIAS 2 //command aliases
+#define CMD_EOK 0 //all ok
+#define CMD_EEXE 1 //command execution error
+#define CMD_ECMD 2 //unknown command
+
+#define CMD_HISTORY_SIZE 16 //fixed size history
+
+/*
+Arch
+
+[CLI]------->[PARSE]
+[FILE]----/
+
+[PARSE]-------->[[EXEC]->[HISTORY] other extra features]
+[CMDLIST]----/
+*/
+
+/*
+Token list that comes from parser
+*/
+
typedef struct cmd_tok_t
{
char *s,*e;
@@ -29,6 +50,10 @@ typedef struct cmd_tok_t
struct cmd_tok_t *next;
} cmd_tok_t;
+/*
+Argument list passed to callback cmd functions
+*/
+
typedef struct cmd_arg_t
{
int argc;
@@ -39,13 +64,21 @@ typedef struct cmd_arg_t
int __sub_cmd; // if 1 then dont free argv stuff
} cmd_arg_t;
+/*
+Table of defined commands
+*/
typedef struct cmd_table_t
{
char *cmd;
- int (*clb)(cmd_arg_t*);
+ int (*clb)(cmd_arg_t*); //callback to command
+ int (*hlp)(cmd_arg_t*); //help command
+ int (*pre)(cmd_arg_t*); //preconditions for execution
} cmd_table_t;
+/*
+autocomplete suggestions from command list. Used for autcomplet "<TAB>"
+*/
struct cmd_acq_t
{
char *suggestion;
@@ -53,6 +86,25 @@ struct cmd_acq_t
};
SLIST_HEAD(cmd_acq_head_t,cmd_acq_t);
+/*
+Contain all non cli parsing execution things.
+Manage history and logging
+Manage command loading from file
+Manage autocomplete
+*/
+typedef struct cmd_mng_t
+{
+ int flag_history;
+ /*simple que*/
+ int history_size;
+ char *history[CMD_HISTORY_SIZE];
+
+ //not yet ready
+ //int flag_logging;
+
+ cmd_table_t *table;
+} cmd_mng_t;
+
cmd_tok_t* cmd_tok_create( char *s, char *e, int sz, int type );
int cmd_tok_add( cmd_tok_t *tok, cmd_tok_t *next );
int cmd_tok_print( cmd_tok_t *tok );
@@ -70,6 +122,33 @@ char* cmd_ac( cmd_table_t *tbl, const char *s ); //autocomplete
struct cmd_acq_head_t* cmd_acq( cmd_table_t *tbl, const char *s ); //autocomplete
void cmd_acq_free( struct cmd_acq_head_t *acq );
+/*
+If history is on.
+PARAM:
+ cmng - cli manager
+ index - index value in history
+RETURN:
+ [FREE] return value if there is under index
+*/
+char* cmd_mng_history( cmd_mng_t *cmng, int index );
+
+/*
+PARAM:
+ cmng
+ cmd - non complete command, not to execute, seach for suggestions
+RETURN:
+ [FREE] return string list of autocomplete commands
+*/
+char* cmd_mng_autocomplete( cmd_mng_t *cmng, char *cmd );
+/*
+PARAM:
+ cmng
+ cmd - command to execute expect NULL at the end
+RETURN:
+ return result of execution
+*/
+int cmd_mng_exec( cmd_mng_t *cmng, const char *cmd, size_t sz_cmd );
+
#define STR_AC_EQ(A,B) (strncmp_ac((A),(B),strlen(A))==(strlen(A)+1))
#define STR_AC_PEQ(A,B) (strncmp_ac((A),(B),strlen(A))<(strlen(A)))