X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fcli.c;h=d702699f1f9b9e05cbd0e26bf39e2cd9c6265b91;hb=17332291e15183d71d88ed868275e3cb53917180;hp=8c15f5fb4e58e256873e007ce86b09432f07d897;hpb=2159c273c9d3361571a6ff1ab63d9bc76582fbab;p=avr-crypto-lib.git diff --git a/test_src/cli.c b/test_src/cli.c index 8c15f5f..d702699 100644 --- a/test_src/cli.c +++ b/test_src/cli.c @@ -1,6 +1,6 @@ /* cli.c */ /* - This file is part of the Crypto-avr-lib/microcrypt-lib. + This file is part of the This file is part of the AVR-Crypto-Lib. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify @@ -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; }