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
164
cmd.c
164
cmd.c
@ -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;
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user