]> git.cryptolib.org Git - avr-crypto-lib.git/blob - cli.c
15e5448fd595dda4a22c522b552d0b364810b940
[avr-crypto-lib.git] / cli.c
1 /**
2  * 
3  * author: Daniel Otte
4  * email:  daniel.otte@rub.de
5  * license: GPLv3
6  * 
7  * components to help implementing simple command based interaction
8  * 
9  **/
10  
11 #include <stdint.h>
12 #include <string.h>
13 #include <avr/pgmspace.h>
14
15 int16_t findstring_d0(const char* str, const char* v){
16         uint8_t i=0;
17         while(*v){      
18                 if(!strcmp(str, v)){
19                         return i;
20                 }
21                 while(*v++) /* go to the next string */
22                 ;
23                 ++i;
24         }
25         return -1;
26 }
27  
28 int16_t findstring_d0_P(const char* str, PGM_P v){
29         uint8_t i=0;
30         while(pgm_read_byte(v)){        
31                 if(!strcmp_P(str, v)){
32                         return i;
33                 }
34                 while(pgm_read_byte(v++)) /* go to the next string */
35                 ;
36                 ++i;
37         }
38         return -1;
39
40
41 int16_t execcommand_d0_P(const char* str, PGM_P v, void(*fpt[])(void) ){
42         uint8_t i=0;
43         while(pgm_read_byte(v)){        
44                 if(!strcmp_P(str, v)){
45                         (fpt[i])();
46                         return i;
47                 }
48                 while(pgm_read_byte(v++)) /* go to the next string */
49                 ;
50                 ++i;
51         }
52         return -1;
53 }
54
55