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);
|
((const cmdinfo_t *)b)->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void add_command(const cmdinfo_t *ci)
|
||||||
add_command(
|
|
||||||
const cmdinfo_t *ci)
|
|
||||||
{
|
{
|
||||||
cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
|
cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
|
||||||
cmdtab[ncmds - 1] = *ci;
|
cmdtab[ncmds - 1] = *ci;
|
||||||
|
@ -122,11 +120,10 @@ find_command(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void add_user_command(char *optarg)
|
||||||
add_user_command(char *optarg)
|
|
||||||
{
|
{
|
||||||
ncmdline++;
|
ncmdline++;
|
||||||
cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
|
cmdline = realloc(cmdline, ncmdline * sizeof(char *));
|
||||||
if (!cmdline) {
|
if (!cmdline) {
|
||||||
perror("realloc");
|
perror("realloc");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -160,8 +157,7 @@ static void prep_fetchline(void *opaque)
|
||||||
|
|
||||||
static char *get_prompt(void);
|
static char *get_prompt(void);
|
||||||
|
|
||||||
void
|
void command_loop(void)
|
||||||
command_loop(void)
|
|
||||||
{
|
{
|
||||||
int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
|
int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
|
||||||
char *input;
|
char *input;
|
||||||
|
@ -171,8 +167,7 @@ command_loop(void)
|
||||||
for (i = 0; !done && i < ncmdline; i++) {
|
for (i = 0; !done && i < ncmdline; i++) {
|
||||||
input = strdup(cmdline[i]);
|
input = strdup(cmdline[i]);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, _("cannot strdup command '%s': %s\n"),
|
||||||
_("cannot strdup command '%s': %s\n"),
|
|
||||||
cmdline[i], strerror(errno));
|
cmdline[i], strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -180,16 +175,17 @@ command_loop(void)
|
||||||
if (c) {
|
if (c) {
|
||||||
ct = find_command(v[0]);
|
ct = find_command(v[0]);
|
||||||
if (ct) {
|
if (ct) {
|
||||||
if (ct->flags & CMD_FLAG_GLOBAL)
|
if (ct->flags & CMD_FLAG_GLOBAL) {
|
||||||
done = command(ct, c, v);
|
done = command(ct, c, v);
|
||||||
else {
|
} else {
|
||||||
j = 0;
|
j = 0;
|
||||||
while (!done && (j = args_command(j)))
|
while (!done && (j = args_command(j))) {
|
||||||
done = command(ct, c, v);
|
done = command(ct, c, v);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
} else {
|
||||||
v[0]);
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
doneline(input, v);
|
doneline(input, v);
|
||||||
}
|
}
|
||||||
|
@ -212,16 +208,18 @@ command_loop(void)
|
||||||
if (!fetchable) {
|
if (!fetchable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((input = fetchline()) == NULL)
|
input = fetchline();
|
||||||
|
if (input == NULL) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
v = breakline(input, &c);
|
v = breakline(input, &c);
|
||||||
if (c) {
|
if (c) {
|
||||||
ct = find_command(v[0]);
|
ct = find_command(v[0]);
|
||||||
if (ct)
|
if (ct) {
|
||||||
done = command(ct, c, v);
|
done = command(ct, c, v);
|
||||||
else
|
} else {
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
v[0]);
|
}
|
||||||
}
|
}
|
||||||
doneline(input, v);
|
doneline(input, v);
|
||||||
|
|
||||||
|
@ -331,18 +329,16 @@ static char *qemu_strsep(char **input, const char *delim)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **
|
char **breakline(char *input, int *count)
|
||||||
breakline(
|
|
||||||
char *input,
|
|
||||||
int *count)
|
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
char *p;
|
char *p;
|
||||||
char **rval = calloc(sizeof(char *), 1);
|
char **rval = calloc(sizeof(char *), 1);
|
||||||
|
|
||||||
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
||||||
if (!*p)
|
if (!*p) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
c++;
|
c++;
|
||||||
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
|
Loading…
Reference in New Issue