mirror of https://github.com/xqemu/xqemu.git
monitor: Introduce get_command_name()
Move code to extract command name into a function of its own, this clearifies the code and let us remove two variables from monitor_handle_command(). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
7869001b8f
commit
4590fd80b8
44
monitor.c
44
monitor.c
|
@ -2381,6 +2381,32 @@ static int get_str(char *buf, int buf_size, const char **pp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Store the command-name in cmdname, and return a pointer to
|
||||||
|
* the remaining of the command string.
|
||||||
|
*/
|
||||||
|
static const char *get_command_name(const char *cmdline,
|
||||||
|
char *cmdname, size_t nlen)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
const char *p, *pstart;
|
||||||
|
|
||||||
|
p = cmdline;
|
||||||
|
while (qemu_isspace(*p))
|
||||||
|
p++;
|
||||||
|
if (*p == '\0')
|
||||||
|
return NULL;
|
||||||
|
pstart = p;
|
||||||
|
while (*p != '\0' && *p != '/' && !qemu_isspace(*p))
|
||||||
|
p++;
|
||||||
|
len = p - pstart;
|
||||||
|
if (len > nlen - 1)
|
||||||
|
len = nlen - 1;
|
||||||
|
memcpy(cmdname, pstart, len);
|
||||||
|
cmdname[len] = '\0';
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
static int default_fmt_format = 'x';
|
static int default_fmt_format = 'x';
|
||||||
static int default_fmt_size = 4;
|
static int default_fmt_size = 4;
|
||||||
|
|
||||||
|
@ -2388,8 +2414,8 @@ static int default_fmt_size = 4;
|
||||||
|
|
||||||
static void monitor_handle_command(Monitor *mon, const char *cmdline)
|
static void monitor_handle_command(Monitor *mon, const char *cmdline)
|
||||||
{
|
{
|
||||||
const char *p, *pstart, *typestr;
|
const char *p, *typestr;
|
||||||
int c, nb_args, len, i, has_arg;
|
int c, nb_args, i, has_arg;
|
||||||
const mon_cmd_t *cmd;
|
const mon_cmd_t *cmd;
|
||||||
char cmdname[256];
|
char cmdname[256];
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
@ -2413,19 +2439,9 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* extract the command name */
|
/* extract the command name */
|
||||||
p = cmdline;
|
p = get_command_name(cmdline, cmdname, sizeof(cmdname));
|
||||||
while (qemu_isspace(*p))
|
if (!p)
|
||||||
p++;
|
|
||||||
if (*p == '\0')
|
|
||||||
return;
|
return;
|
||||||
pstart = p;
|
|
||||||
while (*p != '\0' && *p != '/' && !qemu_isspace(*p))
|
|
||||||
p++;
|
|
||||||
len = p - pstart;
|
|
||||||
if (len > sizeof(cmdname) - 1)
|
|
||||||
len = sizeof(cmdname) - 1;
|
|
||||||
memcpy(cmdname, pstart, len);
|
|
||||||
cmdname[len] = '\0';
|
|
||||||
|
|
||||||
/* find the command */
|
/* find the command */
|
||||||
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
|
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
|
||||||
|
|
Loading…
Reference in New Issue