diff --git a/programs/system/shell/History.txt b/programs/system/shell/History.txt index 7c87f1de80..066a19c6f7 100644 --- a/programs/system/shell/History.txt +++ b/programs/system/shell/History.txt @@ -1,3 +1,7 @@ +Shell 0.7.1 // 19.10.2013 // Albom +* Исправлена ошибка, связанная с зависанием при попытке чтения пустой истории команд (по клавишам Up и Down) + + Shell 0.7.0 // 13.10.2013 // Albom * Переработан модуль ввода команды (добавлена обработка клавиш "влево", "вправо", Del) * Мелкие исправления diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index 73423ea4e8..b805182e08 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -1,5 +1,5 @@ -#define SHELL_VERSION "0.7.0" +#define SHELL_VERSION "0.7.1" extern char PATH[256]; extern char PARAM[256]; @@ -18,7 +18,7 @@ unsigned ALIAS_NUM = 0; char CMD[256]; char CMD_HISTORY[CMD_HISTORY_NUM][256]; -char CMD_NUM; +char CMD_NUM = 0; char CMD_HISTORY_NUM_REAL = 0; /// =========================================================== diff --git a/programs/system/shell/modules/module_command.c b/programs/system/shell/modules/module_command.c index d86fe6c5f7..2b2ab66569 100644 --- a/programs/system/shell/modules/module_command.c +++ b/programs/system/shell/modules/module_command.c @@ -1,40 +1,29 @@ /// =========================================================== -void command_history_add(char command[]) +void command_history_add() { -if ( (0 != strcmp( CMD_HISTORY[0], CMD)) && - (0 != strcmp( CMD_HISTORY[1], CMD)) && - (0 != strcmp( CMD_HISTORY[2], CMD)) && - (0 != strcmp( CMD_HISTORY[3], CMD)) && - (0 != strcmp( CMD_HISTORY[4], CMD)) && - (0 != strcmp( CMD_HISTORY[5], CMD)) && - (0 != strcmp( CMD_HISTORY[6], CMD)) && - (0 != strcmp( CMD_HISTORY[7], CMD)) && - (0 != strcmp( CMD_HISTORY[8], CMD)) && - (0 != strcmp( CMD_HISTORY[9], CMD)) ) +int i; - { - strcpy(CMD_HISTORY[9], CMD_HISTORY[8]); - strcpy(CMD_HISTORY[8], CMD_HISTORY[7]); - strcpy(CMD_HISTORY[7], CMD_HISTORY[6]); - strcpy(CMD_HISTORY[6], CMD_HISTORY[5]); - strcpy(CMD_HISTORY[5], CMD_HISTORY[4]); - strcpy(CMD_HISTORY[4], CMD_HISTORY[3]); - strcpy(CMD_HISTORY[3], CMD_HISTORY[2]); - strcpy(CMD_HISTORY[2], CMD_HISTORY[1]); - strcpy(CMD_HISTORY[1], CMD_HISTORY[0]); +for (i = 0; i < CMD_HISTORY_NUM_REAL; i++) + if ( 0 == strcmp( CMD_HISTORY[i], CMD ) ) + return; - strcpy(CMD_HISTORY[0], CMD); - - if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM) - CMD_HISTORY_NUM_REAL++; - - } +for (i = CMD_HISTORY_NUM_REAL; i > 0 ; i--) + strcpy(CMD_HISTORY[i], CMD_HISTORY[i-1]); + +strcpy(CMD_HISTORY[0], CMD); + +if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM-1) + CMD_HISTORY_NUM_REAL++; + +CMD_NUM = 0; } + + /// =========================================================== void command_get() @@ -67,7 +56,7 @@ for (;;) case 13: // ENTER printf("\n\r"); - command_history_add(CMD); + command_history_add(); return; @@ -174,51 +163,51 @@ for (;;) case 80: // Down - for (i = 0; i < CMD_HISTORY_NUM; i++) + + if (CMD_HISTORY_NUM_REAL > 0) { - for (i = cmdPos; i < cmdLen; i++) - printf(" "); + for (i = cmdPos; i < cmdLen; i++) + printf(" "); - for (i = cmdLen; i > 0; i--) - printf("%c %c", 8, 8); + for (i = cmdLen; i > 0; i--) + printf("%c %c", 8, 8); - if (CMD_NUM < CMD_HISTORY_NUM-1) - CMD_NUM++; - else + if (CMD_NUM < CMD_HISTORY_NUM_REAL-1) + CMD_NUM++; + else CMD_NUM = 0; printf( CMD_HISTORY[CMD_NUM] ); strcpy(CMD, CMD_HISTORY[CMD_NUM]); - cmdLen = strlen(CMD); - if ((cmdPos = strlen(CMD)) != 0) - break; + cmdLen = strlen(CMD); + cmdPos = strlen(CMD); } - + break; case 72: // Up - for (i = 0; i < CMD_HISTORY_NUM; i++) + if (CMD_HISTORY_NUM_REAL > 0) { - for (i = cmdPos; i < cmdLen; i++) - printf(" "); + for (i = cmdPos; i < cmdLen; i++) + printf(" "); - for (i = cmdLen; i > 0; i--) - printf("%c %c", 8, 8); + for (i = cmdLen; i > 0; i--) + printf("%c %c", 8, 8); - if (CMD_NUM > 0) - CMD_NUM--; - else - CMD_NUM = CMD_HISTORY_NUM-1; + if (CMD_NUM > 0) + CMD_NUM--; + else + CMD_NUM = CMD_HISTORY_NUM_REAL-1; printf( CMD_HISTORY[CMD_NUM] ); strcpy(CMD, CMD_HISTORY[CMD_NUM]); - cmdLen = strlen(CMD); - if ((cmdPos = strlen(CMD)) != 0) - break; + cmdLen = strlen(CMD); + cmdPos = strlen(CMD); + } break;