* [Qemu-devel] [PATCH 1/4] monitor: Remove unused variable
[not found] <cover.1244582237.git.lcapitulino@redhat.com>
@ 2009-06-09 21:20 ` Luiz Capitulino
2009-06-09 21:21 ` [Qemu-devel] [PATCH 2/4] monitor: Introduce get_command_name() Luiz Capitulino
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2009-06-09 21:20 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori
The local pointer 'q' is not used by monitor_handle_command().
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/monitor.c b/monitor.c
index 7620bde..11716de 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2389,7 +2389,6 @@ static int default_fmt_size = 4;
static void monitor_handle_command(Monitor *mon, const char *cmdline)
{
const char *p, *pstart, *typestr;
- char *q;
int c, nb_args, len, i, has_arg;
const mon_cmd_t *cmd;
char cmdname[256];
@@ -2415,7 +2414,6 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
/* extract the command name */
p = cmdline;
- q = cmdname;
while (qemu_isspace(*p))
p++;
if (*p == '\0')
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/4] monitor: Introduce get_command_name()
[not found] <cover.1244582237.git.lcapitulino@redhat.com>
2009-06-09 21:20 ` [Qemu-devel] [PATCH 1/4] monitor: Remove unused variable Luiz Capitulino
@ 2009-06-09 21:21 ` Luiz Capitulino
2009-06-09 21:21 ` [Qemu-devel] [PATCH 3/4] monitor: Remove uneeded goto Luiz Capitulino
2009-06-09 21:22 ` [Qemu-devel] [PATCH 4/4] monitor: Remove uneeded 'return' statement Luiz Capitulino
3 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2009-06-09 21:21 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori
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>
---
monitor.c | 44 ++++++++++++++++++++++++++++++--------------
1 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/monitor.c b/monitor.c
index 11716de..9b11341 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2381,6 +2381,32 @@ static int get_str(char *buf, int buf_size, const char **pp)
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_size = 4;
@@ -2388,8 +2414,8 @@ static int default_fmt_size = 4;
static void monitor_handle_command(Monitor *mon, const char *cmdline)
{
- const char *p, *pstart, *typestr;
- int c, nb_args, len, i, has_arg;
+ const char *p, *typestr;
+ int c, nb_args, i, has_arg;
const mon_cmd_t *cmd;
char cmdname[256];
char buf[1024];
@@ -2413,19 +2439,9 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
#endif
/* extract the command name */
- p = cmdline;
- while (qemu_isspace(*p))
- p++;
- if (*p == '\0')
+ p = get_command_name(cmdline, cmdname, sizeof(cmdname));
+ if (!p)
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 */
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 3/4] monitor: Remove uneeded goto
[not found] <cover.1244582237.git.lcapitulino@redhat.com>
2009-06-09 21:20 ` [Qemu-devel] [PATCH 1/4] monitor: Remove unused variable Luiz Capitulino
2009-06-09 21:21 ` [Qemu-devel] [PATCH 2/4] monitor: Introduce get_command_name() Luiz Capitulino
@ 2009-06-09 21:21 ` Luiz Capitulino
2009-06-09 21:22 ` [Qemu-devel] [PATCH 4/4] monitor: Remove uneeded 'return' statement Luiz Capitulino
3 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2009-06-09 21:21 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori
The 'found' goto in monitor_handle_command() can be dropped if we check
for 'cmd->name' after looking up for the command to execute.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/monitor.c b/monitor.c
index 9b11341..0ef3bce 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2446,11 +2446,13 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
/* find the command */
for(cmd = mon_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(cmdname, cmd->name))
- goto found;
+ break;
+ }
+
+ if (cmd->name == NULL) {
+ monitor_printf(mon, "unknown command: '%s'\n", cmdname);
+ return;
}
- monitor_printf(mon, "unknown command: '%s'\n", cmdname);
- return;
- found:
for(i = 0; i < MAX_ARGS; i++)
str_allocated[i] = NULL;
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 4/4] monitor: Remove uneeded 'return' statement
[not found] <cover.1244582237.git.lcapitulino@redhat.com>
` (2 preceding siblings ...)
2009-06-09 21:21 ` [Qemu-devel] [PATCH 3/4] monitor: Remove uneeded goto Luiz Capitulino
@ 2009-06-09 21:22 ` Luiz Capitulino
3 siblings, 0 replies; 4+ messages in thread
From: Luiz Capitulino @ 2009-06-09 21:22 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori
The 'return' statement at the of monitor_handle_command() is not
needed and can be removed.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
monitor.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 0ef3bce..6b45f6c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2728,7 +2728,6 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
fail:
for(i = 0; i < MAX_ARGS; i++)
qemu_free(str_allocated[i]);
- return;
}
static void cmd_completion(const char *name, const char *list)
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread