Shell 0.7.1. Pressing Up and Down keys was causing hanging up the program when command history was empty (but nobody cares). Fixed.

git-svn-id: svn://kolibrios.org@4050 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Albom 2013-10-19 07:13:02 +00:00
parent eedc7e81df
commit 817c27709e
3 changed files with 47 additions and 54 deletions

View File

@ -1,3 +1,7 @@
Shell 0.7.1 // 19.10.2013 // Albom
* ˆá¯à ¢«¥­  ®è¨¡ª , á¢ï§ ­­ ï á § ¢¨á ­¨¥¬ ¯à¨ ¯®¯ë⪥ ç⥭¨ï ¯ãá⮩ ¨áâ®à¨¨ ª®¬ ­¤ (¯® ª« ¢¨è ¬ Up ¨ Down)
Shell 0.7.0 // 13.10.2013 // Albom Shell 0.7.0 // 13.10.2013 // Albom
* <20>¥à¥à ¡®â ­ ¬®¤ã«ì ¢¢®¤  ª®¬ ­¤ë (¤®¡ ¢«¥­  ®¡à ¡®âª  ª« ¢¨è "¢«¥¢®", "¢¯à ¢®", Del) * <20>¥à¥à ¡®â ­ ¬®¤ã«ì ¢¢®¤  ª®¬ ­¤ë (¤®¡ ¢«¥­  ®¡à ¡®âª  ª« ¢¨è "¢«¥¢®", "¢¯à ¢®", Del)
* Œ¥«ª¨¥ ¨á¯à ¢«¥­¨ï * Œ¥«ª¨¥ ¨á¯à ¢«¥­¨ï

View File

@ -1,5 +1,5 @@
#define SHELL_VERSION "0.7.0" #define SHELL_VERSION "0.7.1"
extern char PATH[256]; extern char PATH[256];
extern char PARAM[256]; extern char PARAM[256];
@ -18,7 +18,7 @@ unsigned ALIAS_NUM = 0;
char CMD[256]; char CMD[256];
char CMD_HISTORY[CMD_HISTORY_NUM][256]; char CMD_HISTORY[CMD_HISTORY_NUM][256];
char CMD_NUM; char CMD_NUM = 0;
char CMD_HISTORY_NUM_REAL = 0; char CMD_HISTORY_NUM_REAL = 0;
/// =========================================================== /// ===========================================================

View File

@ -1,40 +1,29 @@
/// =========================================================== /// ===========================================================
void command_history_add(char command[]) void command_history_add()
{ {
if ( (0 != strcmp( CMD_HISTORY[0], CMD)) && int i;
(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)) )
{ for (i = 0; i < CMD_HISTORY_NUM_REAL; i++)
strcpy(CMD_HISTORY[9], CMD_HISTORY[8]); if ( 0 == strcmp( CMD_HISTORY[i], CMD ) )
strcpy(CMD_HISTORY[8], CMD_HISTORY[7]); return;
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]);
strcpy(CMD_HISTORY[0], CMD); for (i = CMD_HISTORY_NUM_REAL; i > 0 ; i--)
strcpy(CMD_HISTORY[i], CMD_HISTORY[i-1]);
if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM) strcpy(CMD_HISTORY[0], CMD);
CMD_HISTORY_NUM_REAL++;
} if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM-1)
CMD_HISTORY_NUM_REAL++;
CMD_NUM = 0;
} }
/// =========================================================== /// ===========================================================
void command_get() void command_get()
@ -67,7 +56,7 @@ for (;;)
case 13: // ENTER case 13: // ENTER
printf("\n\r"); printf("\n\r");
command_history_add(CMD); command_history_add();
return; return;
@ -174,25 +163,25 @@ for (;;)
case 80: // Down case 80: // Down
for (i = 0; i < CMD_HISTORY_NUM; i++)
if (CMD_HISTORY_NUM_REAL > 0)
{ {
for (i = cmdPos; i < cmdLen; i++) for (i = cmdPos; i < cmdLen; i++)
printf(" "); printf(" ");
for (i = cmdLen; i > 0; i--) for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8); printf("%c %c", 8, 8);
if (CMD_NUM < CMD_HISTORY_NUM-1) if (CMD_NUM < CMD_HISTORY_NUM_REAL-1)
CMD_NUM++; CMD_NUM++;
else else
CMD_NUM = 0; CMD_NUM = 0;
printf( CMD_HISTORY[CMD_NUM] ); printf( CMD_HISTORY[CMD_NUM] );
strcpy(CMD, CMD_HISTORY[CMD_NUM]); strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD); cmdLen = strlen(CMD);
if ((cmdPos = strlen(CMD)) != 0) cmdPos = strlen(CMD);
break;
} }
@ -200,25 +189,25 @@ for (;;)
case 72: // Up case 72: // Up
for (i = 0; i < CMD_HISTORY_NUM; i++) if (CMD_HISTORY_NUM_REAL > 0)
{ {
for (i = cmdPos; i < cmdLen; i++) for (i = cmdPos; i < cmdLen; i++)
printf(" "); printf(" ");
for (i = cmdLen; i > 0; i--) for (i = cmdLen; i > 0; i--)
printf("%c %c", 8, 8); printf("%c %c", 8, 8);
if (CMD_NUM > 0) if (CMD_NUM > 0)
CMD_NUM--; CMD_NUM--;
else else
CMD_NUM = CMD_HISTORY_NUM-1; CMD_NUM = CMD_HISTORY_NUM_REAL-1;
printf( CMD_HISTORY[CMD_NUM] ); printf( CMD_HISTORY[CMD_NUM] );
strcpy(CMD, CMD_HISTORY[CMD_NUM]); strcpy(CMD, CMD_HISTORY[CMD_NUM]);
cmdLen = strlen(CMD); cmdLen = strlen(CMD);
if ((cmdPos = strlen(CMD)) != 0) cmdPos = strlen(CMD);
break;
} }
break; break;