1.移除mr_msh_recv_char函数降低降低调用深度。
2.dselect新增-g获取自身描述符命令。
This commit is contained in:
@@ -121,10 +121,7 @@ static void msh_insert_char(char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether the cursor is at the end of the buffer */
|
/* Check whether the cursor is at the end of the buffer */
|
||||||
if (msh.cursor == msh.bytes)
|
if (msh.cursor != msh.bytes)
|
||||||
{
|
|
||||||
msh.buf[msh.bytes] = c;
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
/* Insert the character */
|
/* Insert the character */
|
||||||
mr_msh_printf(MSH_INSERT_CHAR(1));
|
mr_msh_printf(MSH_INSERT_CHAR(1));
|
||||||
@@ -134,8 +131,8 @@ static void msh_insert_char(char c)
|
|||||||
{
|
{
|
||||||
msh.buf[i + 1] = msh.buf[i];
|
msh.buf[i + 1] = msh.buf[i];
|
||||||
}
|
}
|
||||||
msh.buf[msh.cursor] = c;
|
|
||||||
}
|
}
|
||||||
|
msh.buf[msh.cursor] = c;
|
||||||
msh.cursor++;
|
msh.cursor++;
|
||||||
msh.bytes++;
|
msh.bytes++;
|
||||||
msh.buf[msh.bytes] = '\0';
|
msh.buf[msh.bytes] = '\0';
|
||||||
@@ -165,7 +162,7 @@ static int msh_parse_cmd(void)
|
|||||||
/* Execute the command */
|
/* Execute the command */
|
||||||
for (const struct mr_msh_cmd *msh_cmd = ((&_mr_msh_cmd_start) + 1); msh_cmd < &_mr_msh_cmd_end; msh_cmd++)
|
for (const struct mr_msh_cmd *msh_cmd = ((&_mr_msh_cmd_start) + 1); msh_cmd < &_mr_msh_cmd_end; msh_cmd++)
|
||||||
{
|
{
|
||||||
if (strcmp(msh_cmd->name, msh.buf) != 0)
|
if (strncmp(msh_cmd->name, msh.buf, MR_CFG_MSH_NAME_MAX) != 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -356,18 +353,6 @@ static void msh_parse_key(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mr_msh_recv_char(char c)
|
|
||||||
{
|
|
||||||
/* Judgments are characters and keys */
|
|
||||||
if (MSH_IS_PRINTABLE(c) && (msh.key_bytes == 0))
|
|
||||||
{
|
|
||||||
msh_insert_char(c);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
msh_parse_key(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int msh_cmd_help(int argc, void *argv)
|
static int msh_cmd_help(int argc, void *argv)
|
||||||
{
|
{
|
||||||
for (const struct mr_msh_cmd *msh_cmd = ((&_mr_msh_cmd_start) + 1); msh_cmd < &_mr_msh_cmd_end; msh_cmd++)
|
for (const struct mr_msh_cmd *msh_cmd = ((&_mr_msh_cmd_start) + 1); msh_cmd < &_mr_msh_cmd_end; msh_cmd++)
|
||||||
@@ -537,7 +522,14 @@ void mr_msh_handle(void)
|
|||||||
char c;
|
char c;
|
||||||
while (mr_msh_input(&c) > 0)
|
while (mr_msh_input(&c) > 0)
|
||||||
{
|
{
|
||||||
mr_msh_recv_char(c);
|
/* Judgments are characters and keys */
|
||||||
|
if (MSH_IS_PRINTABLE(c) && (msh.key_bytes == 0))
|
||||||
|
{
|
||||||
|
msh_insert_char(c);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
msh_parse_key(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,13 @@ static int msh_cmd_dselect(int argc, void *argv)
|
|||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse <desc (>=0)> */
|
/* Parse <-g|desc (>=0)> */
|
||||||
|
if (strncmp(MR_MSH_GET_ARG(1), "-g", 2) == 0)
|
||||||
|
{
|
||||||
|
mr_msh_printf("%d\r\n", MSH_GET_DESC());
|
||||||
|
return MR_EOK;
|
||||||
|
} else
|
||||||
|
{
|
||||||
ret = sscanf(MR_MSH_GET_ARG(1), "%d", &desc);
|
ret = sscanf(MR_MSH_GET_ARG(1), "%d", &desc);
|
||||||
if ((ret < 1) || (desc < 0))
|
if ((ret < 1) || (desc < 0))
|
||||||
{
|
{
|
||||||
@@ -155,10 +161,16 @@ static int msh_cmd_dselect(int argc, void *argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Switch to the new descriptor */
|
/* Switch to the new descriptor */
|
||||||
return msh_update_path(desc);
|
ret = msh_update_path(desc);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
mr_msh_printf("error: %s\r\n", mr_strerror(ret));
|
||||||
|
}
|
||||||
|
return MR_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
mr_msh_printf("usage: dselect <desc (>=0)>\r\n");
|
mr_msh_printf("usage: dselect <desc (>=0)|-g>\r\n");
|
||||||
return MR_EINVAL;
|
return MR_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user