mirror of https://github.com/xemu-project/xemu.git
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>
This commit is contained in:
parent
932eacc158
commit
81beeec429
48
cmd.c
48
cmd.c
|
@ -45,9 +45,7 @@ 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;
|
||||
|
@ -122,11 +120,10 @@ find_command(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
add_user_command(char *optarg)
|
||||
void add_user_command(char *optarg)
|
||||
{
|
||||
ncmdline++;
|
||||
cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
|
||||
cmdline = realloc(cmdline, ncmdline * sizeof(char *));
|
||||
if (!cmdline) {
|
||||
perror("realloc");
|
||||
exit(1);
|
||||
|
@ -160,8 +157,7 @@ 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;
|
||||
|
@ -171,8 +167,7 @@ command_loop(void)
|
|||
for (i = 0; !done && i < ncmdline; i++) {
|
||||
input = strdup(cmdline[i]);
|
||||
if (!input) {
|
||||
fprintf(stderr,
|
||||
_("cannot strdup command '%s': %s\n"),
|
||||
fprintf(stderr, _("cannot strdup command '%s': %s\n"),
|
||||
cmdline[i], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
@ -180,16 +175,17 @@ command_loop(void)
|
|||
if (c) {
|
||||
ct = find_command(v[0]);
|
||||
if (ct) {
|
||||
if (ct->flags & CMD_FLAG_GLOBAL)
|
||||
if (ct->flags & CMD_FLAG_GLOBAL) {
|
||||
done = command(ct, c, v);
|
||||
else {
|
||||
} else {
|
||||
j = 0;
|
||||
while (!done && (j = args_command(j)))
|
||||
while (!done && (j = args_command(j))) {
|
||||
done = command(ct, c, v);
|
||||
}
|
||||
} else
|
||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
||||
v[0]);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||
}
|
||||
}
|
||||
doneline(input, v);
|
||||
}
|
||||
|
@ -212,16 +208,18 @@ command_loop(void)
|
|||
if (!fetchable) {
|
||||
continue;
|
||||
}
|
||||
if ((input = fetchline()) == NULL)
|
||||
input = fetchline();
|
||||
if (input == NULL) {
|
||||
break;
|
||||
}
|
||||
v = breakline(input, &c);
|
||||
if (c) {
|
||||
ct = find_command(v[0]);
|
||||
if (ct)
|
||||
if (ct) {
|
||||
done = command(ct, c, v);
|
||||
else
|
||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
||||
v[0]);
|
||||
} else {
|
||||
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||
}
|
||||
}
|
||||
doneline(input, v);
|
||||
|
||||
|
@ -331,18 +329,16 @@ 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)
|
||||
if (!*p) {
|
||||
continue;
|
||||
}
|
||||
c++;
|
||||
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
||||
if (!rval) {
|
||||
|
|
Loading…
Reference in New Issue