summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--finsh/shell.c118
1 files changed, 58 insertions, 60 deletions
diff --git a/finsh/shell.c b/finsh/shell.c
index dbeef89cfa..706f69ffa6 100644
--- a/finsh/shell.c
+++ b/finsh/shell.c
@@ -29,10 +29,6 @@
extern char rt_serial_getc(void);
#endif
-
-
-
-
#define FINSH_USING_HISTORY
#if defined(__CC_ARM) /* ARMCC compiler */
@@ -47,7 +43,7 @@ extern char rt_serial_getc(void);
#pragma section="FSymTab"
#pragma section="VSymTab"
#endif
-#elif defined(__GCC__)
+#elif defined(__GNUC__)
#ifdef FINSH_USING_SYMTAB
extern int __fsymtab_start;
extern int __fsymtab_end;
@@ -206,7 +202,7 @@ void finsh_thread_entry(void* parameter)
#endif
stat = WAIT_NORMAL;
- current_history = 0;
+ current_history = 0;
use_history = 0;
finsh_init(&parser);
@@ -225,11 +221,11 @@ void finsh_thread_entry(void* parameter)
char ch;
#ifndef RT_USING_DEVICE
- ch = rt_serial_getc();
+ ch = rt_serial_getc();
if (ch != 0)
#else
rt_err_t rx_result;
- rx_result = rt_device_read(finsh_device, 0, &ch, 1);
+ rx_result = rt_device_read(finsh_device, 0, &ch, 1);
if (ch != 0 && rx_result == 1)
#endif
{
@@ -257,48 +253,48 @@ void finsh_thread_entry(void* parameter)
if (stat == WAIT_FUNC_KEY)
{
- stat = WAIT_NORMAL;
-
+ stat = WAIT_NORMAL;
+
if (ch == 0x41) /* up key */
{
/* prev history */
- if (current_history > 0)current_history --;
- else
- {
- current_history = 0;
- continue;
- }
+ if (current_history > 0)current_history --;
+ else
+ {
+ current_history = 0;
+ continue;
+ }
/* copy the history command */
memcpy(line, &finsh_cmd_history[current_history][0],
FINSH_CMD_SIZE);
- pos = strlen(line);
- use_history = 1;
+ pos = strlen(line);
+ use_history = 1;
}
else if (ch == 0x42) /* down key */
{
- /* next history */
+ /* next history */
if (current_history < finsh_history_count - 1)
- current_history ++;
- else
- {
- current_history = finsh_history_count - 1;
- continue;
- }
+ current_history ++;
+ else
+ {
+ current_history = finsh_history_count - 1;
+ continue;
+ }
memcpy(line, &finsh_cmd_history[current_history][0],
- FINSH_CMD_SIZE);
+ FINSH_CMD_SIZE);
pos = strlen(line);
- use_history = 1;
- }
-
- if (use_history)
- {
- rt_kprintf("\033[2K\r");
+ use_history = 1;
+ }
+
+ if (use_history)
+ {
+ rt_kprintf("\033[2K\r");
rt_kprintf("finsh>>%s", line);
- continue;
+ continue;
}
- }
+ }
#endif
/*
* handle tab key
@@ -306,8 +302,8 @@ void finsh_thread_entry(void* parameter)
if (ch == '\t')
{
/* auto complete */
- finsh_auto_complete(&line[0]);
- /* re-calculate position */
+ finsh_auto_complete(&line[0]);
+ /* re-calculate position */
pos = strlen(line);
continue;
}
@@ -316,20 +312,20 @@ void finsh_thread_entry(void* parameter)
* handle backspace key
*/
if (ch == 0x7f)
- {
+ {
if (pos != 0) rt_kprintf("%c", ch);
line[pos--] = 0;
if (pos < 0) pos = 0;
continue;
}
- line[pos] = ch;
+ line[pos] = ch;
rt_kprintf("%c", line[pos]);
/* if it's the end of line, break */
if (line[pos] == 0xd || line[pos] == 0xa)
- {
+ {
/* change to ';' and break */
line[pos] = ';';
break;
@@ -338,18 +334,18 @@ void finsh_thread_entry(void* parameter)
pos ++;
}
}
- }
+ }
- if (pos == 0)
- {
- rt_kprintf("\n");
- continue;
- }
+ if (pos == 0)
+ {
+ rt_kprintf("\n");
+ continue;
+ }
-#ifdef FINSH_USING_HISTORY
- if (use_history == 0)
+#ifdef FINSH_USING_HISTORY
+ if (use_history == 0)
{
- /* push history */
+ /* push history */
if (finsh_history_count >= FINSH_HISTORY_LINES)
{
/* move history */
@@ -358,23 +354,23 @@ void finsh_thread_entry(void* parameter)
{
memcpy(&finsh_cmd_history[index][0],
&finsh_cmd_history[index + 1][0], FINSH_CMD_SIZE);
- }
+ }
memset(&finsh_cmd_history[index][0], 0, FINSH_CMD_SIZE);
- memcpy(&finsh_cmd_history[index][0], line, pos);
-
- /* it's the maximum history */
+ memcpy(&finsh_cmd_history[index][0], line, pos);
+
+ /* it's the maximum history */
finsh_history_count = FINSH_HISTORY_LINES;
- }
- else
+ }
+ else
{
memset(&finsh_cmd_history[finsh_history_count][0], 0, FINSH_CMD_SIZE);
- memcpy(&finsh_cmd_history[finsh_history_count][0], line, pos);
-
- /* increase count and set current history position */
- finsh_history_count ++;
+ memcpy(&finsh_cmd_history[finsh_history_count][0], line, pos);
+
+ /* increase count and set current history position */
+ finsh_history_count ++;
}
- }
- current_history = finsh_history_count;
+ }
+ current_history = finsh_history_count;
#endif
rt_kprintf("\n");
@@ -441,6 +437,8 @@ void finsh_system_init()
finsh_system_var_init(__section_begin("VSymTab"),
__section_end("VSymTab"));
#elif defined (__GNUC__) /* GNU GCC Compiler */
+ finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
+ finsh_system_var_init(&__vsymtab_start, &__vsymtab_start);
#endif
#endif