summaryrefslogtreecommitdiff
path: root/components/finsh/shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'components/finsh/shell.c')
-rw-r--r--components/finsh/shell.c189
1 files changed, 34 insertions, 155 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 87dc6e0745..48651d2c4f 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -19,75 +19,62 @@
*/
#include <rthw.h>
+#include <string.h>
+#include <stdio.h>
#ifdef RT_USING_FINSH
-#include "finsh.h"
#include "shell.h"
-
-#ifdef FINSH_USING_MSH
#include "msh.h"
-#endif
-#ifdef _WIN32
-#include <stdio.h> /* for putchar */
-#endif
+#if defined(RT_USING_DFS)
+ #include <dfs_posix.h>
+#endif /* RT_USING_DFS */
/* finsh thread */
#ifndef RT_USING_HEAP
-static struct rt_thread finsh_thread;
-ALIGN(RT_ALIGN_SIZE)
-static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
-struct finsh_shell _shell;
+ static struct rt_thread finsh_thread;
+ ALIGN(RT_ALIGN_SIZE)
+ static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
+ struct finsh_shell _shell;
#endif
/* finsh symtab */
#ifdef FINSH_USING_SYMTAB
-struct finsh_syscall *_syscall_table_begin = NULL;
-struct finsh_syscall *_syscall_table_end = NULL;
-struct finsh_sysvar *_sysvar_table_begin = NULL;
-struct finsh_sysvar *_sysvar_table_end = NULL;
+ struct finsh_syscall *_syscall_table_begin = NULL;
+ struct finsh_syscall *_syscall_table_end = NULL;
#endif
struct finsh_shell *shell;
static char *finsh_prompt_custom = RT_NULL;
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
-struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call)
+struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call)
{
unsigned int *ptr;
- ptr = (unsigned int*) (call + 1);
- while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end))
+ ptr = (unsigned int *)(call + 1);
+ while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *) _syscall_table_end))
ptr ++;
- return (struct finsh_syscall*)ptr;
+ return (struct finsh_syscall *)ptr;
}
-struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call)
-{
- unsigned int *ptr;
- ptr = (unsigned int*) (call + 1);
- while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _sysvar_table_end))
- ptr ++;
-
- return (struct finsh_sysvar*)ptr;
-}
#endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */
#ifdef RT_USING_HEAP
-int finsh_set_prompt(const char * prompt)
+int finsh_set_prompt(const char *prompt)
{
- if(finsh_prompt_custom)
+ if (finsh_prompt_custom)
{
rt_free(finsh_prompt_custom);
finsh_prompt_custom = RT_NULL;
}
/* strdup */
- if(prompt)
+ if (prompt)
{
- finsh_prompt_custom = (char *)rt_malloc(strlen(prompt)+1);
- if(finsh_prompt_custom)
+ finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1);
+ if (finsh_prompt_custom)
{
strcpy(finsh_prompt_custom, prompt);
}
@@ -97,14 +84,10 @@ int finsh_set_prompt(const char * prompt)
}
#endif /* RT_USING_HEAP */
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif /* RT_USING_DFS */
+#define _MSH_PROMPT "msh "
const char *finsh_get_prompt(void)
{
-#define _MSH_PROMPT "msh "
-#define _PROMPT "finsh "
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
/* check prompt mode */
@@ -114,17 +97,12 @@ const char *finsh_get_prompt(void)
return finsh_prompt;
}
- if(finsh_prompt_custom)
+ if (finsh_prompt_custom)
{
- strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt)-1);
+ strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
return finsh_prompt;
}
-
-#ifdef FINSH_USING_MSH
- if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
- else
-#endif
- strcpy(finsh_prompt, _PROMPT);
+ strcpy(finsh_prompt, _MSH_PROMPT);
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
/* get current working directory */
@@ -288,7 +266,8 @@ rt_uint32_t finsh_get_echo()
* @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than
* FINSH_PASSWORD_MIN or greater than FINSH_PASSWORD_MAX
*/
-rt_err_t finsh_set_password(const char *password) {
+rt_err_t finsh_set_password(const char *password)
+{
rt_ubase_t level;
rt_size_t pw_len = rt_strlen(password);
@@ -372,71 +351,12 @@ static void finsh_wait_auth(void)
static void shell_auto_complete(char *prefix)
{
-
rt_kprintf("\n");
-#ifdef FINSH_USING_MSH
- if (msh_is_used() == RT_TRUE)
- {
- msh_auto_complete(prefix);
- }
- else
-#endif
- {
-#ifndef FINSH_USING_MSH_ONLY
- extern void list_prefix(char * prefix);
- list_prefix(prefix);
-#endif
- }
+ msh_auto_complete(prefix);
rt_kprintf("%s%s", FINSH_PROMPT, prefix);
}
-#ifndef FINSH_USING_MSH_ONLY
-void finsh_run_line(struct finsh_parser *parser, const char *line)
-{
- const char *err_str;
-
- if(shell->echo_mode)
- rt_kprintf("\n");
- finsh_parser_run(parser, (unsigned char *)line);
-
- /* compile node root */
- if (finsh_errno() == 0)
- {
- finsh_compiler_run(parser->root);
- }
- else
- {
- err_str = finsh_error_string(finsh_errno());
- rt_kprintf("%s\n", err_str);
- }
-
- /* run virtual machine */
- if (finsh_errno() == 0)
- {
- char ch;
- finsh_vm_run();
-
- ch = (unsigned char)finsh_stack_bottom();
- if (ch > 0x20 && ch < 0x7e)
- {
- rt_kprintf("\t'%c', %d, 0x%08x\n",
- (unsigned char)finsh_stack_bottom(),
- (unsigned int)finsh_stack_bottom(),
- (unsigned int)finsh_stack_bottom());
- }
- else
- {
- rt_kprintf("\t%d, 0x%08x\n",
- (unsigned int)finsh_stack_bottom(),
- (unsigned int)finsh_stack_bottom());
- }
- }
-
- finsh_flush(parser);
-}
-#endif
-
#ifdef FINSH_USING_HISTORY
static rt_bool_t shell_handle_history(struct finsh_shell *shell)
{
@@ -508,10 +428,6 @@ void finsh_thread_entry(void *parameter)
shell->echo_mode = 0;
#endif
-#ifndef FINSH_USING_MSH_ONLY
- finsh_init(&shell->parser);
-#endif
-
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
/* set console device as shell device */
if (shell->device == RT_NULL)
@@ -694,26 +610,9 @@ void finsh_thread_entry(void *parameter)
#ifdef FINSH_USING_HISTORY
shell_push_history(shell);
#endif
-
-#ifdef FINSH_USING_MSH
- if (msh_is_used() == RT_TRUE)
- {
- if (shell->echo_mode)
- rt_kprintf("\n");
- msh_exec(shell->line, shell->line_position);
- }
- else
-#endif
- {
-#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
- if (shell->echo_mode) rt_kprintf("\n");
-#endif
- }
+ if (shell->echo_mode)
+ rt_kprintf("\n");
+ msh_exec(shell->line, shell->line_position);
rt_kprintf(FINSH_PROMPT);
memset(shell->line, 0, sizeof(shell->line));
@@ -766,23 +665,14 @@ void finsh_system_function_init(const void *begin, const void *end)
_syscall_table_end = (struct finsh_syscall *) 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;
-}
-
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
#ifdef FINSH_USING_SYMTAB
-#pragma section="FSymTab"
-#pragma section="VSymTab"
+ #pragma section="FSymTab"
#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;
+ extern "asm" int __fsymtab_start;
+ extern "asm" int __fsymtab_end;
#endif
#elif defined(_MSC_VER)
#pragma section("FSymTab$a", read)
@@ -820,32 +710,21 @@ int finsh_system_init(void)
#ifdef __ARMCC_VERSION /* ARM C Compiler */
extern const int FSymTab$$Base;
extern const int FSymTab$$Limit;
- extern const int VSymTab$$Base;
- extern const int VSymTab$$Limit;
finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
-#ifndef FINSH_USING_MSH_ONLY
- finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit);
-#endif
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
finsh_system_function_init(__section_begin("FSymTab"),
__section_end("FSymTab"));
- finsh_system_var_init(__section_begin("VSymTab"),
- __section_end("VSymTab"));
#elif defined (__GNUC__) || defined(__TI_COMPILER_VERSION__) || defined(__TASKING__)
/* GNU GCC Compiler and TI CCS */
extern const int __fsymtab_start;
extern const int __fsymtab_end;
- extern const int __vsymtab_start;
- extern const int __vsymtab_end;
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
- finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
- finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#elif defined(_MSC_VER)
unsigned int *ptr_begin, *ptr_end;
- if(shell)
+ if (shell)
{
rt_kprintf("finsh shell already init.\n");
return RT_EOK;