aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2019-08-17 13:26:00 +0100
committerFreeArtMan <dos21h@gmail.com>2019-08-17 13:26:00 +0100
commit700b5bc2b24bf9fd8e69f0586739c692be0dc2cb (patch)
tree12a966c2cd9627de71a670d213e330c35a16f551
parent5483357fa0c2cceb4ed449bd14874c320ccb90a3 (diff)
downloadihe-700b5bc2b24bf9fd8e69f0586739c692be0dc2cb.tar.gz
ihe-700b5bc2b24bf9fd8e69f0586739c692be0dc2cb.zip
updated lib, compiles
-rw-r--r--ihe.c77
-rw-r--r--libcmd/cmd_parse.c30
-rw-r--r--libcmd/cmd_parse.ragel6
3 files changed, 67 insertions, 46 deletions
diff --git a/ihe.c b/ihe.c
index b00fc8d..14d64ff 100644
--- a/ihe.c
+++ b/ihe.c
@@ -1,9 +1,12 @@
#include "ihe.h"
#include "core.h"
+/* Global variables */
+cmd_mng_t cmd_mng;
static int cmd_loop = 1;
extern cmd_table_t tab[];
+
#define CMK_KEYMAP1(KEY) (in_buf[0]==(KEY)&&(ret_read==1))
#define CMD_IN_BUF_SIZE 32
@@ -388,34 +391,34 @@ CMD COMMANDS
*/
cmd_table_t tab[] = {
- {"version", c_version },
- {"arg", c_arg },
+ {"version", c_version , NULL, NULL, NULL},
+ {"arg", c_arg , NULL, NULL, NULL},
//{"quit", c_quit},
- {"help", c_help},
- {"?", c_help},
- {"open", c_open},
- {"close", c_close},
- {"info", c_info},
- {"seek", c_seek},
- {"pos", c_pos},
- {"size", c_size},
- {"blk", c_blk},
- {"read", c_read},
- {"dump", c_dump},
- {"dumpx", c_dumpx},
- {"dumps", c_dumps},
- {"write", c_write},
- {"writes", c_writes},
- {"resize", c_resize},
- {"flags", c_flags},
- {"manifesto", c_manifesto},
- {"ls", c_ls},
- {"pwd", c_pwd},
- {"cd", c_cd},
+ {"help", c_help, NULL, NULL, NULL},
+ {"?", c_help, NULL, NULL, NULL},
+ {"open", c_open, NULL, NULL, NULL},
+ {"close", c_close, NULL, NULL, NULL},
+ {"info", c_info, NULL, NULL, NULL},
+ {"seek", c_seek, NULL, NULL, NULL},
+ {"pos", c_pos, NULL, NULL, NULL},
+ {"size", c_size, NULL, NULL, NULL},
+ {"blk", c_blk, NULL, NULL, NULL},
+ {"read", c_read, NULL, NULL, NULL},
+ {"dump", c_dump, NULL, NULL, NULL},
+ {"dumpx", c_dumpx, NULL, NULL, NULL},
+ {"dumps", c_dumps, NULL, NULL, NULL},
+ {"write", c_write, NULL, NULL, NULL},
+ {"writes", c_writes, NULL, NULL, NULL},
+ {"resize", c_resize, NULL, NULL, NULL},
+ {"flags", c_flags, NULL, NULL, NULL},
+ {"manifesto", c_manifesto, NULL, NULL, NULL},
+ {"ls", c_ls, NULL, NULL, NULL},
+ {"pwd", c_pwd, NULL, NULL, NULL},
+ {"cd", c_cd, NULL, NULL, NULL},
//{"create", c_create},
//{"th", c_th},
//{"tw", c_tw},
- {NULL, NULL }
+ {NULL, NULL , NULL, NULL, NULL},
};
@@ -423,6 +426,7 @@ cmd_table_t tab[] = {
int main( int argc, char **argv )
{
const int sz_buf = 1024;
+ int err;
uint8_t in_buf[sz_buf];
int ret_read;
int new_c=0, new_r=0, old_r=0, old_c=0;
@@ -445,6 +449,14 @@ int main( int argc, char **argv )
cmd_in_buf_t cmd_in;
cmd_buf_clean( &cmd_in );
+ //clean cmd manager structure that is global
+ memset(&cmd_mng, 0, sizeof(cmd_mng));
+
+ //register command table
+ cmd_mng.table = tab;
+ cmd_mng.flag_history = 0;
+ cmd_mng.flag_autocomplete = 1;
+
if ( term_init( &ts ) == -1 )
printf("Some err when init\n");
@@ -493,6 +505,7 @@ int main( int argc, char **argv )
//cmd_buf_print( &cmd_in, 2 );
cmd_in.buf[cmd_in.cur_sz] = '\n';
cmd_in.buf[cmd_in.cur_sz+1] = 0;
+ #warning "Auto complete"
cmd_tab_autocomplete( cmd_in.buf );
//cmd_buf_print( &cmd_in, 2 );
write(1,"$",1);
@@ -538,11 +551,13 @@ int main( int argc, char **argv )
continue;
}
*/
-
+
+ /*
iter = ptr->next;
args = cmd_arg_create( iter );
cmd_tok_destroy( ptr->next );
ptr->next = NULL;
+ */
/*
for (i=0; i<args->argc; i++)
@@ -551,14 +566,18 @@ int main( int argc, char **argv )
}
*/
-
+ /*
if (cmd_exec(tab, args) != 0)
{
printf("!Unknown command\n");
+ }*/
+ err = cmd_mng_exec( &cmd_mng, cmd_in.buf, cmd_in.cur_sz );
+ if (err!=CMD_EOK)
+ {
+ printf("Unknow command\n");
}
-
- cmd_arg_destroy( args );
+ //cmd_arg_destroy( args );
cmd_buf_clean( &cmd_in );
write(1,"$",1);
@@ -566,6 +585,8 @@ int main( int argc, char **argv )
}
+ cmd_mng_free( &cmd_mng );
+
term_clr_scr( &ts );
term_set_orig_mode( &ts );
diff --git a/libcmd/cmd_parse.c b/libcmd/cmd_parse.c
index b9904e9..0377e1d 100644
--- a/libcmd/cmd_parse.c
+++ b/libcmd/cmd_parse.c
@@ -7,8 +7,8 @@
#define TADD(T,S,E,SZ) {cmd_tok_t *t=cmd_tok_create(S,E,SZ,T);cmd_tok_add(tl,t);tl=tl->next;}
//#define TADD(T,S,E)
-#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n");
-//#define PR_TK_DBG(S) ;
+//#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n");
+#define PR_TK_DBG(S) ;
char *new_string( const char *start, const char *end )
{
@@ -111,7 +111,7 @@ static const int cmd_error = 0;
static const int cmd_en_main = 6;
-#line 75 "cmd_parse.ragel"
+#line 62 "cmd_parse.ragel"
int parse_cmd( cmd_tok_t *tl, const char *str, size_t str_size )
@@ -126,7 +126,7 @@ int parse_cmd( cmd_tok_t *tl, const char *str, size_t str_size )
/*save for cmd_begin state*/
//char *ts_cb=0, *te_cb=0;
- printf("PE:%s %02x\n",pe,(unsigned char)*pe);
+ //printf("PE:%s %02x\n",pe,(unsigned char)*pe);
/*
variables used in state machine
@@ -141,7 +141,7 @@ int parse_cmd( cmd_tok_t *tl, const char *str, size_t str_size )
act = 0;
}
-#line 96 "cmd_parse.ragel"
+#line 83 "cmd_parse.ragel"
#line 147 "cmd_parse.c"
{
@@ -235,39 +235,39 @@ _eof_trans:
{te = p+1;}
break;
case 4:
-#line 60 "cmd_parse.ragel"
+#line 53 "cmd_parse.ragel"
{act = 2;}
break;
case 5:
-#line 62 "cmd_parse.ragel"
+#line 55 "cmd_parse.ragel"
{te = p+1;{PR_TK_DBG("qstr = ");TADD(CMDT_QSTR, ts,te,te-ts);}}
break;
case 6:
-#line 64 "cmd_parse.ragel"
+#line 57 "cmd_parse.ragel"
{te = p+1;{PR_TK_DBG("sp = ");TADD(CMDT_SP, ts,te,te-ts);}}
break;
case 7:
-#line 59 "cmd_parse.ragel"
+#line 52 "cmd_parse.ragel"
{te = p;p--;{PR_TK_DBG("hex = ");TADD(CMDT_HEX, ts,te,te-ts);}}
break;
case 8:
-#line 60 "cmd_parse.ragel"
+#line 53 "cmd_parse.ragel"
{te = p;p--;{PR_TK_DBG("dec = ");TADD(CMDT_INT, ts,te,te-ts);}}
break;
case 9:
-#line 61 "cmd_parse.ragel"
+#line 54 "cmd_parse.ragel"
{te = p;p--;{PR_TK_DBG("bin = ");TADD(CMDT_BIN, ts,te,te-ts);}}
break;
case 10:
-#line 63 "cmd_parse.ragel"
+#line 56 "cmd_parse.ragel"
{te = p;p--;{PR_TK_DBG("word = ");TADD(CMDT_WORD, ts,te,te-ts);}}
break;
case 11:
-#line 66 "cmd_parse.ragel"
+#line 58 "cmd_parse.ragel"
{te = p;p--;{PR_TK_DBG("float= ");TADD(CMDT_FLOAT, ts,te,te-ts);}}
break;
case 12:
-#line 60 "cmd_parse.ragel"
+#line 53 "cmd_parse.ragel"
{{p = ((te))-1;}{PR_TK_DBG("dec = ");TADD(CMDT_INT, ts,te,te-ts);}}
break;
case 13:
@@ -319,7 +319,7 @@ _again:
_out: {}
}
-#line 97 "cmd_parse.ragel"
+#line 84 "cmd_parse.ragel"
if ( cs == cmd_error )
{
diff --git a/libcmd/cmd_parse.ragel b/libcmd/cmd_parse.ragel
index 482ad8d..0775802 100644
--- a/libcmd/cmd_parse.ragel
+++ b/libcmd/cmd_parse.ragel
@@ -5,8 +5,8 @@
#define TADD(T,S,E,SZ) {cmd_tok_t *t=cmd_tok_create(S,E,SZ,T);cmd_tok_add(tl,t);tl=tl->next;}
//#define TADD(T,S,E)
-#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n");
-//#define PR_TK_DBG(S) ;
+//#define PR_TK_DBG(S) printf(S);fwrite(ts,1,te-ts,stdout);printf("\n");
+#define PR_TK_DBG(S) ;
char *new_string( const char *start, const char *end )
{
@@ -73,7 +73,7 @@ int parse_cmd( cmd_tok_t *tl, const char *str, size_t str_size )
/*save for cmd_begin state*/
//char *ts_cb=0, *te_cb=0;
- printf("PE:%s %02x\n",pe,(unsigned char)*pe);
+ //printf("PE:%s %02x\n",pe,(unsigned char)*pe);
/*
variables used in state machine