diff options
author | Pavel Borzenkov <pavel.borzenkov@gmail.com> | 2011-10-31 22:53:36 +0400 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-11-07 08:01:15 +0000 |
commit | 81beeec429f6bb8b0323e418a6aeef1a17b0cefa (patch) | |
tree | 2922d4fd6e14aecea2d0ea05db1550a9e598b327 /cmd.c | |
parent | 932eacc158c064935c7bab920c88a93a629e1ca4 (diff) |
cmd: Fix coding style in cmd.c
Before the next patches, fix coding style of the affected functions.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 168 |
1 files changed, 82 insertions, 86 deletions
@@ -45,13 +45,11 @@ compare(const void *a, const void *b) ((const cmdinfo_t *)b)->name); } -void -add_command( - const cmdinfo_t *ci) +void add_command(const cmdinfo_t *ci) { - cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); - cmdtab[ncmds - 1] = *ci; - qsort(cmdtab, ncmds, sizeof(*cmdtab), compare); + cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); + cmdtab[ncmds - 1] = *ci; + qsort(cmdtab, ncmds, sizeof(*cmdtab), compare); } static int @@ -122,16 +120,15 @@ find_command( return NULL; } -void -add_user_command(char *optarg) +void add_user_command(char *optarg) { - ncmdline++; - cmdline = realloc(cmdline, sizeof(char*) * (ncmdline)); - if (!cmdline) { - perror("realloc"); - exit(1); - } - cmdline[ncmdline-1] = optarg; + ncmdline++; + cmdline = realloc(cmdline, ncmdline * sizeof(char *)); + if (!cmdline) { + perror("realloc"); + exit(1); + } + cmdline[ncmdline-1] = optarg; } static int @@ -160,45 +157,44 @@ static void prep_fetchline(void *opaque) static char *get_prompt(void); -void -command_loop(void) +void command_loop(void) { - int c, i, j = 0, 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) { - if (ct->flags & CMD_FLAG_GLOBAL) - done = command(ct, c, v); - else { - j = 0; - while (!done && (j = args_command(j))) - done = command(ct, c, v); - } - } else - fprintf(stderr, _("command \"%s\" not found\n"), - v[0]); - } - doneline(input, v); - } - if (cmdline) { - free(cmdline); - return; + int c, i, j = 0, 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) { + if (ct->flags & CMD_FLAG_GLOBAL) { + done = command(ct, c, v); + } else { + j = 0; + while (!done && (j = args_command(j))) { + done = command(ct, c, v); + } + } + } else { + fprintf(stderr, _("command \"%s\" not found\n"), v[0]); + } } + doneline(input, v); + } + if (cmdline) { + free(cmdline); + return; + } - while (!done) { + while (!done) { if (!prompted) { printf("%s", get_prompt()); fflush(stdout); @@ -212,22 +208,24 @@ command_loop(void) if (!fetchable) { continue; } - if ((input = fetchline()) == 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); + 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); prompted = 0; fetchable = 0; - } + } qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL); } @@ -331,29 +329,27 @@ static char *qemu_strsep(char **input, const char *delim) return result; } -char ** -breakline( - char *input, - int *count) +char **breakline(char *input, int *count) { - int c = 0; - char *p; - char **rval = calloc(sizeof(char *), 1); - - while (rval && (p = qemu_strsep(&input, " ")) != NULL) { - if (!*p) - continue; - c++; - rval = realloc(rval, sizeof(*rval) * (c + 1)); - if (!rval) { - c = 0; - break; - } - rval[c - 1] = p; - rval[c] = NULL; - } - *count = c; - return rval; + int c = 0; + char *p; + char **rval = calloc(sizeof(char *), 1); + + while (rval && (p = qemu_strsep(&input, " ")) != NULL) { + if (!*p) { + continue; + } + c++; + rval = realloc(rval, sizeof(*rval) * (c + 1)); + if (!rval) { + c = 0; + break; + } + rval[c - 1] = p; + rval[c] = NULL; + } + *count = c; + return rval; } void |