[finsh] fix the '\0' issue when use shell in linux telnet

This commit is contained in:
Bernard Xiong 2015-09-24 03:06:26 +00:00
parent be9b3d1df6
commit 353f511cb0
1 changed files with 72 additions and 67 deletions

View File

@ -52,16 +52,16 @@
static struct rt_thread finsh_thread;
ALIGN(RT_ALIGN_SIZE)
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
struct finsh_shell* shell;
struct finsh_shell *shell;
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
#if defined(RT_USING_DFS)
#include <dfs_posix.h>
#endif
const char* finsh_get_prompt()
const char *finsh_get_prompt()
{
#define _MSH_PROMPT "msh "
#define _PROMPT "finsh "
#define _MSH_PROMPT "msh "
#define _PROMPT "finsh "
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
#ifdef FINSH_USING_MSH
@ -98,7 +98,7 @@ static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
*
* @param device_name the name of new input device.
*/
void finsh_set_device(const char* device_name)
void finsh_set_device(const char *device_name)
{
rt_device_t dev = RT_NULL;
@ -113,7 +113,7 @@ void finsh_set_device(const char* device_name)
/* check whether it's a same device */
if (dev == shell->device) return;
/* open this device and set the new device in finsh shell */
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX |\
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
RT_DEVICE_FLAG_STREAM) == RT_EOK)
{
if (shell->device != RT_NULL)
@ -139,7 +139,7 @@ void finsh_set_device(const char* device_name)
*
* @return the finsh shell input device name is returned.
*/
const char* finsh_get_device()
const char *finsh_get_device()
{
RT_ASSERT(shell != RT_NULL);
return shell->device->parent.name;
@ -174,7 +174,7 @@ rt_uint32_t finsh_get_echo()
return shell->echo_mode;
}
static void shell_auto_complete(char* prefix)
static void shell_auto_complete(char *prefix)
{
rt_kprintf("\n");
@ -187,7 +187,7 @@ static void shell_auto_complete(char* prefix)
#endif
{
#ifndef FINSH_USING_MSH_ONLY
extern void list_prefix(char* prefix);
extern void list_prefix(char * prefix);
list_prefix(prefix);
#endif
}
@ -196,12 +196,12 @@ static void shell_auto_complete(char* prefix)
}
#ifndef FINSH_USING_MSH_ONLY
void finsh_run_line(struct finsh_parser* parser, const char *line)
void finsh_run_line(struct finsh_parser *parser, const char *line)
{
const char* err_str;
const char *err_str;
rt_kprintf("\n");
finsh_parser_run(parser, (unsigned char*)line);
finsh_parser_run(parser, (unsigned char *)line);
/* compile node root */
if (finsh_errno() == 0)
@ -241,13 +241,13 @@ void finsh_run_line(struct finsh_parser* parser, const char *line)
#endif
#ifdef FINSH_USING_HISTORY
static rt_bool_t shell_handle_history(struct finsh_shell* shell)
static rt_bool_t shell_handle_history(struct finsh_shell *shell)
{
#if defined(_WIN32)
int i;
rt_kprintf("\r");
for(i=0; i<= 60; i++)
for (i = 0; i <= 60; i++)
putchar(' ');
rt_kprintf("\r");
@ -258,7 +258,7 @@ static rt_bool_t shell_handle_history(struct finsh_shell* shell)
return RT_FALSE;
}
static void shell_push_history(struct finsh_shell* shell)
static void shell_push_history(struct finsh_shell *shell)
{
if (shell->line_position != 0)
{
@ -294,7 +294,7 @@ static void shell_push_history(struct finsh_shell* shell)
#ifndef RT_USING_HEAP
struct finsh_shell _shell;
#endif
void finsh_thread_entry(void* parameter)
void finsh_thread_entry(void *parameter)
{
char ch;
@ -424,7 +424,10 @@ void finsh_thread_entry(void* parameter)
char next;
if (rt_device_read(shell->device, 0, &next, 1) == 1)
ch = next;
{
if (next == '\0') ch = 'r'; /* linux telnet will issue '\0' */
else ch = next;
}
else ch = '\r';
}
/* handle tab key */
@ -479,26 +482,26 @@ void finsh_thread_entry(void* parameter)
/* handle end of line, break */
if (ch == '\r' || ch == '\n')
{
#ifdef FINSH_USING_HISTORY
#ifdef FINSH_USING_HISTORY
shell_push_history(shell);
#endif
#endif
#ifdef FINSH_USING_MSH
#ifdef FINSH_USING_MSH
if (msh_is_used() == RT_TRUE)
{
rt_kprintf("\n");
msh_exec(shell->line, shell->line_position);
}
else
#endif
#endif
{
#ifndef FINSH_USING_MSH_ONLY
#ifndef FINSH_USING_MSH_ONLY
/* add ';' and run the command line */
shell->line[shell->line_position] = ';';
if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line);
else rt_kprintf("\n");
#endif
#endif
}
rt_kprintf(FINSH_PROMPT);
@ -547,30 +550,30 @@ void finsh_thread_entry(void* parameter)
}
}
void finsh_system_function_init(const void* begin, const void* end)
void finsh_system_function_init(const void *begin, const void *end)
{
_syscall_table_begin = (struct finsh_syscall*) begin;
_syscall_table_end = (struct finsh_syscall*) end;
_syscall_table_begin = (struct finsh_syscall *) begin;
_syscall_table_end = (struct finsh_syscall *) end;
}
void finsh_system_var_init(const void* begin, const void* end)
void finsh_system_var_init(const void *begin, const void *end)
{
_sysvar_table_begin = (struct finsh_sysvar*) begin;
_sysvar_table_end = (struct finsh_sysvar*) end;
_sysvar_table_begin = (struct finsh_sysvar *) begin;
_sysvar_table_end = (struct finsh_sysvar *) end;
}
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
#ifdef FINSH_USING_SYMTAB
#pragma section="FSymTab"
#pragma section="VSymTab"
#endif
#ifdef FINSH_USING_SYMTAB
#pragma section="FSymTab"
#pragma section="VSymTab"
#endif
#elif defined(__ADSPBLACKFIN__) /* for VisaulDSP++ Compiler*/
#ifdef FINSH_USING_SYMTAB
extern "asm" int __fsymtab_start;
extern "asm" int __fsymtab_end;
extern "asm" int __vsymtab_start;
extern "asm" int __vsymtab_end;
#endif
#ifdef FINSH_USING_SYMTAB
extern "asm" int __fsymtab_start;
extern "asm" int __fsymtab_end;
extern "asm" int __vsymtab_start;
extern "asm" int __vsymtab_end;
#endif
#elif defined(_MSC_VER)
#pragma section("FSymTab$a", read)
const char __fsym_begin_name[] = "__start";
@ -609,9 +612,9 @@ int finsh_system_init(void)
extern const int VSymTab$$Base;
extern const int VSymTab$$Limit;
finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
#ifndef FINSH_USING_MSH_ONLY
#ifndef FINSH_USING_MSH_ONLY
finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit);
#endif
#endif
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
finsh_system_function_init(__section_begin("FSymTab"),
__section_end("FSymTab"));
@ -631,10 +634,12 @@ int finsh_system_init(void)
#elif defined(_MSC_VER)
unsigned int *ptr_begin, *ptr_end;
ptr_begin = (unsigned int*)&__fsym_begin; ptr_begin += (sizeof(struct finsh_syscall)/sizeof(unsigned int));
ptr_begin = (unsigned int *)&__fsym_begin;
ptr_begin += (sizeof(struct finsh_syscall) / sizeof(unsigned int));
while (*ptr_begin == 0) ptr_begin ++;
ptr_end = (unsigned int*) &__fsym_end; ptr_end --;
ptr_end = (unsigned int *) &__fsym_end;
ptr_end --;
while (*ptr_end == 0) ptr_end --;
finsh_system_function_init(ptr_begin, ptr_end);
@ -643,7 +648,7 @@ int finsh_system_init(void)
/* create or set shell structure */
#ifdef RT_USING_HEAP
shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell));
shell = (struct finsh_shell *)rt_malloc(sizeof(struct finsh_shell));
if (shell == RT_NULL)
{
rt_kprintf("no memory for shell\n");