提交 8fc7ef33 编写于 作者: M Mupceet

shell 优化

Signed-off-by: NMupceet <laiguizhong@huawei.com>
上级 645ad4cf
......@@ -22,19 +22,10 @@
#include "init_param.h"
static BShellHandle g_handle = NULL;
static int32_t ShellOuput(const char *data, int32_t len)
{
for (int32_t i = 0; i < len; i++) {
putchar(*(data + i));
}
(void)fflush(stdout);
return len;
}
BShellHandle GetShellHandle(void)
{
if (g_handle == NULL) {
BShellInfo info = {PARAM_SHELL_DEFAULT_PROMPT, NULL, ShellOuput};
BShellInfo info = {PARAM_SHELL_DEFAULT_PROMPT, NULL};
BShellEnvInit(&g_handle, &info);
}
return g_handle;
......
......@@ -87,10 +87,9 @@ typedef struct BShellParam_ {
typedef struct BShellInfo_ {
char *prompt;
BShellInput_ input;
BShellOutput_ output;
} BShellInfo;
int BShellEnvInit(BShellHandle *handle, BShellInfo *info);
int BShellEnvInit(BShellHandle *handle, const BShellInfo *info);
int BShellEnvStart(BShellHandle handle);
void BShellEnvDestory(BShellHandle handle);
......
......@@ -95,12 +95,12 @@ static int32_t BShellCmdExit(BShellHandle handle, int32_t argc, char *argv[])
int32_t BShellEnvOutput(BShellHandle handle, char *fmt, ...)
{
BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
va_list list;
va_list list;
va_start(list, fmt);
vfprintf(stdout, fmt, list);
int len = vfprintf(stdout, fmt, list);
va_end(list);
(void)fflush(stdout);
return 0;
return len;
}
int32_t BShellEnvOutputString(BShellHandle handle, const char *string)
......@@ -108,7 +108,7 @@ int32_t BShellEnvOutputString(BShellHandle handle, const char *string)
BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
printf("%s", string);
(void)fflush(stdout);
return 0;
return strlen(string);
}
int32_t BShellEnvOutputPrompt(BShellHandle handle, const char *prompt)
......@@ -402,7 +402,7 @@ void BShellEnvLoop(BShellHandle handle)
}
}
int32_t BShellEnvInit(BShellHandle *handle, BShellInfo *info)
int32_t BShellEnvInit(BShellHandle *handle, const BShellInfo *info)
{
BSH_CHECK(handle != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
BSH_CHECK(info != NULL && info->prompt != NULL, return BSH_INVALID_PARAM, "Invalid cmd name");
......@@ -413,7 +413,6 @@ int32_t BShellEnvInit(BShellHandle *handle, BShellInfo *info)
shell->cursor = 0;
shell->shellState = BSH_IN_NORMAL;
shell->input = info->input;
shell->output = info->output;
shell->prompt = strdup(info->prompt);
shell->command = NULL;
shell->param = NULL;
......
......@@ -91,7 +91,6 @@ typedef struct BShellEnv_ {
BShellKey *keyHandle;
BShellStatus status;
BShellInput_ input;
BShellOutput_ output;
char data[BSH_COMMAND_MAX_LENGTH];
} BShellEnv;
......
......@@ -30,15 +30,6 @@ static void signalHandler(int signal)
exit(0);
}
static int32_t ShellOuput(const char *data, int32_t len)
{
for (int32_t i = 0; i < len; i++) {
putchar(*(data + i));
}
(void)fflush(stdout);
return len;
}
static int32_t ShellInput(char *data, int32_t len)
{
for (int32_t i = 0; i < len; i++) {
......@@ -50,7 +41,7 @@ static int32_t ShellInput(char *data, int32_t len)
BShellHandle GetShellHandle(void)
{
if (g_handle == NULL) {
BShellInfo info = {PARAM_SHELL_DEFAULT_PROMPT, ShellInput, ShellOuput};
BShellInfo info = {PARAM_SHELL_DEFAULT_PROMPT, ShellInput};
BShellEnvInit(&g_handle, &info);
}
return g_handle;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册