+ cli_tx(' ');
+ cli_putstr_P(item.cmd_name);
+ i=maxcmdlength-strlen_P(item.cmd_name);
+ while(i--)
+ cli_tx(' ');
+ cli_putstr_P(PSTR(" - "));
+ if(item.cmd_param_str==NULL){
+ cli_putstr_P(PSTR("none \t- 0x"));
+ } else {
+ if(item.cmd_param_str==(void*)1){
+ cli_putstr_P(PSTR("yes \t- 0x"));
+ } else {
+ cli_putstr_P(item.cmd_param_str);
+ cli_putstr_P(PSTR(" \t- 0x"));
+ }
+ }
+ cli_hexdump(&item.cmd_function, 2);
+ cli_putstr_P(PSTR("\r\n"));
+ }
+}
+
+void echo_ctrl(char* s){
+ s = strstrip(s);
+ if(s==NULL || *s=='\0'){
+ cli_putstr_P(PSTR("\r\necho is "));
+ cli_putstr_P(cli_echo?PSTR("on"):PSTR("off"));
+ cli_putstr_P(PSTR("\r\n"));
+ }
+ strlwr(s);
+ if(!strcmp_P(s, PSTR("true")) || !strcmp_P(s, PSTR("on")) || *s=='1'){
+ cli_echo=1;
+ }
+ if(!strcmp_P(s, PSTR("false")) || !strcmp_P(s, PSTR("off")) || *s=='0'){
+ cli_echo=0;
+ }
+}
+
+typedef void(*str_fpt)(char*);
+#define CLI_ENTER 13
+#define CLI_BACKSPACE 8
+#define CLI_TABULATOR 9
+
+int8_t search_and_call(char* cmd, uint16_t maxcmdlength, PGM_VOID_P cmdlist){
+ PGM_VOID_P cmdlist_orig = cmdlist;
+ if(*cmd=='\0' || *cmd=='#')
+ return 1;
+ if(!strcmp_P(cmd, PSTR("exit")))
+ return 0;
+ if((!strcmp_P(cmd, PSTR("help"))) || (!strcmp_P(cmd, PSTR("?")))){
+ cli_auto_help(maxcmdlength, cmdlist);
+ return 1;
+ }
+ uint16_t fwlength=firstword_length(cmd);
+ char fw[fwlength+1];
+ memcpy(fw, cmd, fwlength);
+ fw[fwlength] = '\0';
+ cmdlist_entry_t item;
+ do{
+ item.cmd_name = (void*)pgm_read_word(cmdlist+0);
+ item.cmd_param_str = (void*)pgm_read_word(cmdlist+2);
+ item.cmd_function = (void_fpt)pgm_read_word(cmdlist+4);
+ cmdlist = (uint8_t*)cmdlist+CMDLIST_ENTRY_SIZE;
+ }while(item.cmd_name!=NULL && strcmp_P(fw, item.cmd_name));
+ if(item.cmd_name==NULL){
+ cli_auto_help(maxcmdlength, cmdlist_orig);
+ } else {
+ if(item.cmd_function==NULL)
+ return 2;
+ switch((uint16_t)item.cmd_param_str){
+ case 0:
+ item.cmd_function();
+ break;
+ case 1:
+ if(cmd[fwlength]=='\0'){
+ ((str_fpt)item.cmd_function)(cmd+fwlength);
+ } else {
+ ((str_fpt)item.cmd_function)(cmd+fwlength+1);
+ }
+ break;
+ default:
+ cli_putstr_P(PSTR("\r\nparam parsing currently not implemented!\r\n"));
+ break;
+ }
+
+ }
+ return 1;
+}
+
+uint16_t max_cmd_length(PGM_VOID_P cmdlist){
+ uint16_t t,ret=0;
+ char* str;
+ for(;;){
+ str = (char*)pgm_read_word(cmdlist);
+ cmdlist = (uint8_t*)cmdlist + CMDLIST_ENTRY_SIZE;
+ if(str==NULL)
+ return ret;
+ t = strlen_P(str);
+ if(t>ret)
+ ret=t;