]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/cli.c
renaming to AVR-Crypto-Lib
[avr-crypto-lib.git] / test_src / cli.c
index 8c15f5fb4e58e256873e007ce86b09432f07d897..d702699f1f9b9e05cbd0e26bf39e2cd9c6265b91 100644 (file)
@@ -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 <stdint.h>
 #include <string.h>
 #include <avr/pgmspace.h>
+#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;
 }