Browse Source

fix down and then up key bug.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@313 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 years ago
parent
commit
612898fe8c
1 changed files with 15 additions and 10 deletions
  1. 15 10
      finsh/shell.c

+ 15 - 10
finsh/shell.c

@@ -13,6 +13,7 @@
  * 2006-05-08     Bernard      change finsh thread stack to 2048
  * 2006-05-08     Bernard      change finsh thread stack to 2048
  * 2006-06-03     Bernard      add support for skyeye
  * 2006-06-03     Bernard      add support for skyeye
  * 2006-09-24     Bernard      remove the code related with hardware
  * 2006-09-24     Bernard      remove the code related with hardware
+ * 2010-01-18     Bernard      fix down then up key bug.
  */
  */
 
 
 #include <rtthread.h>
 #include <rtthread.h>
@@ -22,7 +23,7 @@
 
 
 /*
 /*
  * Add by caoxl 2009-10-14
  * Add by caoxl 2009-10-14
- * 
+ *
  */
  */
 #ifdef QEMU_CAOXL
 #ifdef QEMU_CAOXL
 #define  memcpy(a,b,c)	rt_memcpy(a,b,c)
 #define  memcpy(a,b,c)	rt_memcpy(a,b,c)
@@ -113,7 +114,7 @@ char *strdup(const char *s)
 	return tmp;
 	return tmp;
 }
 }
 #endif
 #endif
-
+
 #if !defined(__CC_ARM) && !defined(__ICCARM__)
 #if !defined(__CC_ARM) && !defined(__ICCARM__)
 int isalpha( int ch )
 int isalpha( int ch )
 {
 {
@@ -143,7 +144,7 @@ int atoi(const char* s)
 int isprint(unsigned char ch)
 int isprint(unsigned char ch)
 {
 {
     return (unsigned int)(ch - ' ') < 127u - ' ';
     return (unsigned int)(ch - ' ') < 127u - ' ';
-}
+}
 #endif
 #endif
 #endif
 #endif
 
 
@@ -233,7 +234,7 @@ void finsh_thread_entry(void* parameter)
 				{
 				{
 #ifdef FINSH_USING_HISTORY
 #ifdef FINSH_USING_HISTORY
 					/*
 					/*
-					 * handle up and down key 
+					 * handle up and down key
 					 * up key  : 0x1b 0x5b 0x41
 					 * up key  : 0x1b 0x5b 0x41
 					 * down key: 0x1b 0x5b 0x42
 					 * down key: 0x1b 0x5b 0x42
 					 */
 					 */
@@ -268,7 +269,7 @@ void finsh_thread_entry(void* parameter)
 							}
 							}
 
 
 							/* copy the history command */
 							/* copy the history command */
-							memcpy(line, &finsh_cmd_history[current_history][0], 
+							memcpy(line, &finsh_cmd_history[current_history][0],
 								FINSH_CMD_SIZE);
 								FINSH_CMD_SIZE);
 							pos = strlen(line);
 							pos = strlen(line);
 							use_history = 1;
 							use_history = 1;
@@ -280,16 +281,20 @@ void finsh_thread_entry(void* parameter)
 								current_history ++;
 								current_history ++;
 							else
 							else
 							{
 							{
-								current_history = finsh_history_count - 1;
-								continue;
+								/* set to the end of history */
+								if (finsh_history_count != 0)
+								{
+									current_history = finsh_history_count - 1;
+								}
+								else continue;
 							}
 							}
 
 
-							memcpy(line, &finsh_cmd_history[current_history][0], 
+							memcpy(line, &finsh_cmd_history[current_history][0],
 								FINSH_CMD_SIZE);
 								FINSH_CMD_SIZE);
 							pos = strlen(line);
 							pos = strlen(line);
 							use_history = 1;
 							use_history = 1;
 						}
 						}
-						
+
 						if (use_history)
 						if (use_history)
 						{
 						{
 							rt_kprintf("\033[2K\r");
 							rt_kprintf("\033[2K\r");
@@ -354,7 +359,7 @@ void finsh_thread_entry(void* parameter)
 				int index;
 				int index;
 				for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
 				for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
 				{
 				{
-					memcpy(&finsh_cmd_history[index][0], 
+					memcpy(&finsh_cmd_history[index][0],
 						&finsh_cmd_history[index + 1][0], FINSH_CMD_SIZE);
 						&finsh_cmd_history[index + 1][0], FINSH_CMD_SIZE);
 				}
 				}
 				memset(&finsh_cmd_history[index][0], 0, FINSH_CMD_SIZE);
 				memset(&finsh_cmd_history[index][0], 0, FINSH_CMD_SIZE);