/* cli.c */
/*
This file is part of the ARM-Crypto-Lib.
- Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
+ Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
/**
- * \brief outputs a zero-terminated string from ram to the console
+ * \brief ouputs a zero-terminated string from ram to the console
*/
void cli_putstr(const char* s){
if(!cli_tx)
/**
* \brief reads a line or max n characters from the console
- * Writes characters from the console into the supplied buffer until a '\r'
- * character is received or until n character a read (whatever happens first).
+ * Writes characters from the console into the supplyed buffer until a '\r'
+ * character is recieved or until n character a read (whatever happens first).
* The string will always be terminated by a '\0' character, so the buffer
* should have at least a size of n+1.
*/
char c;
if(n==0)
return 2;
- while((c=cli_getc_cecho())!='\0' && c!='\r' && n--){
+ while((c=cli_getc_cecho())!='\0' && c!='\r' && n){
+ --n;
*s++=c;
}
*s='\0';
static
int8_t search_and_call(char* cmd, uint32_t maxcmdlength, const cmdlist_entry_t* cmdlist){
- const cmdlist_entry_t* cmdlist_orig = cmdlist;
+ const cmdlist_entry_t* cmdlist_orig=cmdlist;
+ if(!cmdlist){
+ return 3;
+ }
if(*cmd=='\0' || *cmd=='#')
return 1;
if(!strcmp(cmd, "exit"))
memcpy(fw, cmd, fwlength);
fw[fwlength] = '\0';
cmdlist_entry_t item;
- do{
- memcpy(&item, cmdlist, sizeof(cmdlist_entry_t));
- cmdlist += 1;
- }while(item.cmd_name!=NULL && strcmp(fw, item.cmd_name));
- if(item.cmd_name==NULL){
+ while(cmdlist->cmd_name && strcmp(fw, cmdlist->cmd_name)){
+ ++cmdlist;
+ }
+ if(!cmdlist->cmd_name){
cli_auto_help(maxcmdlength, cmdlist_orig);
} else {
- if(item.cmd_function==NULL)
- return 2;
+ memcpy(&item, cmdlist, sizeof(cmdlist_entry_t));
switch((uint32_t)item.cmd_param_str){
case 0:
item.cmd_function();
return 1;
}
-static const
+static
uint16_t max_cmd_length(const cmdlist_entry_t* cmdlist){
uint16_t t,ret=0;
const char* str;
for(;;){
str = cmdlist->cmd_name;
- cmdlist += 1;
+ ++cmdlist;
if(str==NULL){
return ret;
}
ref[0]='\0';
/* check if we are behind the first word */
while(buffer[i]){
- if(!isgraph(buffer[i++]))
+ if(!isgraph((uint8_t)(buffer[i++])))
return 0;
}
for(;;){
itemstr = cmdlist->cmd_name;
if(itemstr==NULL)
break;
- cmdlist += 1;
+ ++cmdlist;
if(!strncmp(buffer, itemstr, i)){
if(!ref[0]){
strcpy(ref, itemstr);
c = cli_rx();
switch (c){
case CLI_ENTER:
- if((exit_code=search_and_call(cli_buffer, maxcmdlength, cmd_desc))<=0){
+ if((exit_code = search_and_call(cli_buffer, maxcmdlength, cmd_desc))<=0){
free(cli_buffer);
return exit_code;
}