diff options
author | Kevin Wolf <kwolf@redhat.com> | 2013-06-05 14:19:32 +0200 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2013-06-06 11:27:04 +0200 |
commit | dd5832967ac3fe96bd5bf9f199639176998ead69 (patch) | |
tree | a5053905409672db4fc98332fcc44824ed01a521 /cmd.c | |
parent | 797ac58cb2093ab9192d8998a1fef85d87cc8661 (diff) |
qemu-io: Factor out qemuio_command
It's duplicated code. Move it to qemu-io-cmds.c because it's not
dependent on any static data of the qemu-io tool.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 43 |
1 files changed, 5 insertions, 38 deletions
@@ -138,28 +138,11 @@ static char *get_prompt(void); void command_loop(void) { - int c, i, done = 0, fetchable = 0, prompted = 0; + int i, done = 0, fetchable = 0, prompted = 0; char *input; - char **v; - const cmdinfo_t *ct; for (i = 0; !done && i < ncmdline; i++) { - input = strdup(cmdline[i]); - if (!input) { - fprintf(stderr, _("cannot strdup command '%s': %s\n"), - cmdline[i], strerror(errno)); - exit(1); - } - v = breakline(input, &c); - if (c) { - ct = find_command(v[0]); - if (ct) { - done = command(ct, c, v); - } else { - fprintf(stderr, _("command \"%s\" not found\n"), v[0]); - } - } - doneline(input, v); + done = qemuio_command(cmdline[i]); } if (cmdline) { g_free(cmdline); @@ -179,20 +162,13 @@ void command_loop(void) if (!fetchable) { continue; } + input = fetchline(); if (input == NULL) { break; } - v = breakline(input, &c); - if (c) { - ct = find_command(v[0]); - if (ct) { - done = command(ct, c, v); - } else { - fprintf(stderr, _("command \"%s\" not found\n"), v[0]); - } - } - doneline(input, v); + done = qemuio_command(input); + free(input); prompted = 0; fetchable = 0; @@ -328,15 +304,6 @@ char **breakline(char *input, int *count) return rval; } -void -doneline( - char *input, - char **vec) -{ - free(input); - free(vec); -} - #define EXABYTES(x) ((long long)(x) << 60) #define PETABYTES(x) ((long long)(x) << 50) #define TERABYTES(x) ((long long)(x) << 40) |