X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fcli.c;h=37bbb25490b294b6889a59428aa8e62d4a37ea36;hb=6718048fd9038c98523eae722545bb0279e0bc21;hp=8c15f5fb4e58e256873e007ce86b09432f07d897;hpb=2159c273c9d3361571a6ff1ab63d9bc76582fbab;p=avr-crypto-lib.git diff --git a/test_src/cli.c b/test_src/cli.c index 8c15f5f..37bbb25 100644 --- a/test_src/cli.c +++ b/test_src/cli.c @@ -29,6 +29,7 @@ #include #include #include +#include "config.h" int16_t findstring_d0(const char* str, const char* v){ uint8_t i=0; @@ -56,18 +57,34 @@ int16_t findstring_d0_P(const char* str, PGM_P v){ return -1; } -int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){ - uint8_t i=0; - while(pgm_read_byte(v)){ - if(!strcmp_P(str, v)){ - (fpt[i])(); - return i; +#ifdef CLI_AUTO_HELP +#include "uart.h" + +void cli_auto_help_P(PGM_P dbzstr){ + char c; + uart_putstr_P(PSTR("\r\n[auto help] available commands are:\r\n\t")); + do{ + while((c=pgm_read_byte(dbzstr++))!=0){ + uart_putc(c); } - while(pgm_read_byte(v++)) /* go to the next string */ - ; - ++i; + uart_putstr_P(PSTR("\r\n\t")); + }while((c=pgm_read_byte(dbzstr))!=0); + uart_putstr_P(PSTR("\r\n")); +} + +#endif + +int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){ + int16_t i=0; + i=findstring_d0_P(str, v); + if(i!=-1){ + if(fpt[i]) + fpt[i](); + return i; + }else{ + cli_auto_help_P(v); + return -1; } - return -1; }