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
164
cmd.c
164
cmd.c
|
@ -45,13 +45,11 @@ 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;
|
||||||
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
|
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -122,16 +120,15 @@ 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);
|
||||||
}
|
}
|
||||||
cmdline[ncmdline-1] = optarg;
|
cmdline[ncmdline-1] = optarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -160,45 +157,44 @@ 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;
|
||||||
char **v;
|
char **v;
|
||||||
const cmdinfo_t *ct;
|
const cmdinfo_t *ct;
|
||||||
|
|
||||||
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);
|
}
|
||||||
}
|
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) {
|
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
|
} else {
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
v[0]);
|
}
|
||||||
}
|
|
||||||
doneline(input, v);
|
|
||||||
}
|
|
||||||
if (cmdline) {
|
|
||||||
free(cmdline);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
doneline(input, v);
|
||||||
|
}
|
||||||
|
if (cmdline) {
|
||||||
|
free(cmdline);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
if (!prompted) {
|
if (!prompted) {
|
||||||
printf("%s", get_prompt());
|
printf("%s", get_prompt());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -212,22 +208,24 @@ command_loop(void)
|
||||||
if (!fetchable) {
|
if (!fetchable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((input = fetchline()) == NULL)
|
input = fetchline();
|
||||||
break;
|
if (input == NULL) {
|
||||||
v = breakline(input, &c);
|
break;
|
||||||
if (c) {
|
}
|
||||||
ct = find_command(v[0]);
|
v = breakline(input, &c);
|
||||||
if (ct)
|
if (c) {
|
||||||
done = command(ct, c, v);
|
ct = find_command(v[0]);
|
||||||
else
|
if (ct) {
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
done = command(ct, c, v);
|
||||||
v[0]);
|
} else {
|
||||||
}
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
doneline(input, v);
|
}
|
||||||
|
}
|
||||||
|
doneline(input, v);
|
||||||
|
|
||||||
prompted = 0;
|
prompted = 0;
|
||||||
fetchable = 0;
|
fetchable = 0;
|
||||||
}
|
}
|
||||||
qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
|
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;
|
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++;
|
}
|
||||||
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
c++;
|
||||||
if (!rval) {
|
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
||||||
c = 0;
|
if (!rval) {
|
||||||
break;
|
c = 0;
|
||||||
}
|
break;
|
||||||
rval[c - 1] = p;
|
}
|
||||||
rval[c] = NULL;
|
rval[c - 1] = p;
|
||||||
}
|
rval[c] = NULL;
|
||||||
*count = c;
|
}
|
||||||
return rval;
|
*count = c;
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue