[Finsh] code cleanup
This commit is contained in:
parent
1f8a0668d2
commit
6a624356e4
|
@ -69,6 +69,8 @@ typedef unsigned long u_long;
|
||||||
!defined(__ADSPBLACKFIN__) && \
|
!defined(__ADSPBLACKFIN__) && \
|
||||||
!defined(_MSC_VER)
|
!defined(_MSC_VER)
|
||||||
|
|
||||||
|
/* only for GNU GCC */
|
||||||
|
|
||||||
#if !(defined(__GNUC__) && defined(__x86_64__))
|
#if !(defined(__GNUC__) && defined(__x86_64__))
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
#else
|
#else
|
||||||
|
@ -79,13 +81,6 @@ typedef unsigned int size_t;
|
||||||
#define NULL RT_NULL
|
#define NULL RT_NULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define memset rt_memset
|
|
||||||
#define strlen rt_strlen
|
|
||||||
#define strncpy rt_strncpy
|
|
||||||
#define strncmp rt_strncmp
|
|
||||||
|
|
||||||
int strcmp (const char *s1, const char *s2);
|
|
||||||
char *strdup(const char *s);
|
|
||||||
#else
|
#else
|
||||||
/* use libc of armcc */
|
/* use libc of armcc */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -94,8 +89,8 @@ char *strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FINSH_VERSION_MAJOR 0
|
#define FINSH_VERSION_MAJOR 1
|
||||||
#define FINSH_VERSION_MINOR 5
|
#define FINSH_VERSION_MINOR 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup finsh
|
* @addtogroup finsh
|
||||||
|
|
|
@ -288,6 +288,8 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
struct finsh_node* sibling;
|
struct finsh_node* sibling;
|
||||||
|
|
||||||
parameters = 0;
|
parameters = 0;
|
||||||
|
if (finsh_node_child(node) != NULL)
|
||||||
|
{
|
||||||
sibling = finsh_node_sibling(finsh_node_child(node));
|
sibling = finsh_node_sibling(finsh_node_child(node));
|
||||||
while (sibling != NULL)
|
while (sibling != NULL)
|
||||||
{
|
{
|
||||||
|
@ -302,11 +304,12 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
finsh_code_byte(FINSH_OP_SYSCALL);
|
finsh_code_byte(FINSH_OP_SYSCALL);
|
||||||
finsh_code_byte(parameters);
|
finsh_code_byte(parameters);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* assign expression */
|
/* assign expression */
|
||||||
case FINSH_NODE_SYS_ASSIGN:
|
case FINSH_NODE_SYS_ASSIGN:
|
||||||
if (finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
||||||
{
|
{
|
||||||
switch (finsh_node_child(node)->data_type)
|
switch (finsh_node_child(node)->data_type)
|
||||||
{
|
{
|
||||||
|
@ -368,7 +371,7 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
|
|
||||||
/* pre-increase */
|
/* pre-increase */
|
||||||
case FINSH_NODE_SYS_PREINC:
|
case FINSH_NODE_SYS_PREINC:
|
||||||
if (finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
||||||
{
|
{
|
||||||
struct finsh_var* var;
|
struct finsh_var* var;
|
||||||
var = finsh_node_child(node)->id.var;
|
var = finsh_node_child(node)->id.var;
|
||||||
|
@ -449,7 +452,7 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
|
|
||||||
/* pre-decrease */
|
/* pre-decrease */
|
||||||
case FINSH_NODE_SYS_PREDEC:
|
case FINSH_NODE_SYS_PREDEC:
|
||||||
if (finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
||||||
{
|
{
|
||||||
struct finsh_var* var;
|
struct finsh_var* var;
|
||||||
var = finsh_node_child(node)->id.var;
|
var = finsh_node_child(node)->id.var;
|
||||||
|
@ -530,7 +533,7 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
|
|
||||||
/* increase */
|
/* increase */
|
||||||
case FINSH_NODE_SYS_INC:
|
case FINSH_NODE_SYS_INC:
|
||||||
if (finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
||||||
{
|
{
|
||||||
struct finsh_var* var;
|
struct finsh_var* var;
|
||||||
var = finsh_node_child(node)->id.var;
|
var = finsh_node_child(node)->id.var;
|
||||||
|
@ -620,7 +623,7 @@ static int finsh_compile(struct finsh_node* node)
|
||||||
|
|
||||||
/* decrease */
|
/* decrease */
|
||||||
case FINSH_NODE_SYS_DEC:
|
case FINSH_NODE_SYS_DEC:
|
||||||
if (finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID)
|
||||||
{
|
{
|
||||||
struct finsh_var* var;
|
struct finsh_var* var;
|
||||||
var = finsh_node_child(node)->id.var;
|
var = finsh_node_child(node)->id.var;
|
||||||
|
|
|
@ -473,17 +473,16 @@ static int token_proc_escape(struct finsh_token* self)
|
||||||
static void token_proc_number(struct finsh_token* self)
|
static void token_proc_number(struct finsh_token* self)
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
int b;
|
|
||||||
char *p, buf[128];
|
char *p, buf[128];
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
p = buf;
|
p = buf;
|
||||||
b = 10;
|
|
||||||
|
|
||||||
ch = token_next_char(self);
|
ch = token_next_char(self);
|
||||||
if ( ch == '0' )
|
if ( ch == '0' )
|
||||||
{
|
{
|
||||||
|
int b;
|
||||||
ch = token_next_char(self);
|
ch = token_next_char(self);
|
||||||
if ( ch == 'x' || ch == 'X' )/*it's a hex number*/
|
if ( ch == 'x' || ch == 'X' )/*it's a hex number*/
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,7 +104,6 @@ struct finsh_var* finsh_var_lookup(const char* name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
#ifdef RT_USING_HEAP
|
||||||
extern char *strdup(const char *s);
|
|
||||||
void finsh_sysvar_append(const char* name, u_char type, void* var_addr)
|
void finsh_sysvar_append(const char* name, u_char type, void* var_addr)
|
||||||
{
|
{
|
||||||
/* create a sysvar */
|
/* create a sysvar */
|
||||||
|
@ -114,7 +113,7 @@ void finsh_sysvar_append(const char* name, u_char type, void* var_addr)
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
{
|
{
|
||||||
item->next = NULL;
|
item->next = NULL;
|
||||||
item->sysvar.name = strdup(name);
|
item->sysvar.name = rt_strdup(name);
|
||||||
item->sysvar.type = type;
|
item->sysvar.type = type;
|
||||||
item->sysvar.var = var_addr;
|
item->sysvar.var = var_addr;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,6 @@ void finsh_vm_run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
#ifdef RT_USING_HEAP
|
||||||
extern char *strdup(const char *s);
|
|
||||||
void finsh_syscall_append(const char* name, syscall_func func)
|
void finsh_syscall_append(const char* name, syscall_func func)
|
||||||
{
|
{
|
||||||
/* create the syscall */
|
/* create the syscall */
|
||||||
|
@ -82,7 +81,7 @@ void finsh_syscall_append(const char* name, syscall_func func)
|
||||||
if (item != RT_NULL)
|
if (item != RT_NULL)
|
||||||
{
|
{
|
||||||
item->next = NULL;
|
item->next = NULL;
|
||||||
item->syscall.name = strdup(name);
|
item->syscall.name = rt_strdup(name);
|
||||||
item->syscall.func = func;
|
item->syscall.func = func;
|
||||||
|
|
||||||
if (global_syscall_list == NULL)
|
if (global_syscall_list == NULL)
|
||||||
|
|
|
@ -54,29 +54,6 @@ ALIGN(RT_ALIGN_SIZE)
|
||||||
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
||||||
struct finsh_shell* shell;
|
struct finsh_shell* shell;
|
||||||
|
|
||||||
#if !defined (RT_USING_NEWLIB) && !defined (RT_USING_MINILIBC)
|
|
||||||
int strcmp (const char *s1, const char *s2)
|
|
||||||
{
|
|
||||||
while (*s1 && *s1 == *s2) s1++, s2++;
|
|
||||||
|
|
||||||
return (*s1 - *s2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
|
||||||
char *strdup(const char *s)
|
|
||||||
{
|
|
||||||
size_t len = strlen(s) + 1;
|
|
||||||
char *tmp = (char *)rt_malloc(len);
|
|
||||||
|
|
||||||
if(!tmp) return NULL;
|
|
||||||
|
|
||||||
rt_memcpy(tmp, s, len);
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
|
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
const char* finsh_get_prompt()
|
const char* finsh_get_prompt()
|
||||||
|
|
Loading…
Reference in New Issue