version 1.1.1.4, 2018/04/24 18:56:54
|
version 1.1.1.5, 2018/04/24 19:18:01
|
Line 45 compare(const void *a, const void *b)
|
Line 45 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 = g_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 |
Line 122 find_command(
|
Line 120 find_command(
|
return NULL; |
return NULL; |
} |
} |
|
|
void |
void add_user_command(char *optarg) |
add_user_command(char *optarg) |
|
{ |
{ |
ncmdline++; |
cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *)); |
cmdline = realloc(cmdline, sizeof(char*) * (ncmdline)); |
cmdline[ncmdline-1] = optarg; |
if (!cmdline) { |
|
perror("realloc"); |
|
exit(1); |
|
} |
|
cmdline[ncmdline-1] = optarg; |
|
} |
} |
|
|
static int |
static int |
Line 160 static void prep_fetchline(void *opaque)
|
Line 152 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) { |
|
g_free(cmdline); |
|
return; |
|
} |
|
|
while (!done) { |
while (!done) { |
if (!prompted) { |
if (!prompted) { |
printf("%s", get_prompt()); |
printf("%s", get_prompt()); |
fflush(stdout); |
fflush(stdout); |
Line 212 command_loop(void)
|
Line 203 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); |
} |
} |
|
|
Line 331 static char *qemu_strsep(char **input, c
|
Line 324 static char *qemu_strsep(char **input, c
|
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); |
|
char **tmp; |
while (rval && (p = qemu_strsep(&input, " ")) != NULL) { |
|
if (!*p) |
while (rval && (p = qemu_strsep(&input, " ")) != NULL) { |
continue; |
if (!*p) { |
c++; |
continue; |
rval = realloc(rval, sizeof(*rval) * (c + 1)); |
} |
if (!rval) { |
c++; |
c = 0; |
tmp = realloc(rval, sizeof(*rval) * (c + 1)); |
break; |
if (!tmp) { |
} |
free(rval); |
rval[c - 1] = p; |
rval = NULL; |
rval[c] = NULL; |
c = 0; |
} |
break; |
*count = c; |
} else { |
return rval; |
rval = tmp; |
|
} |
|
rval[c - 1] = p; |
|
rval[c] = NULL; |
|
} |
|
*count = c; |
|
return rval; |
} |
} |
|
|
void |
void |
Line 389 cvtnum(
|
Line 385 cvtnum(
|
if (sp[1] != '\0') |
if (sp[1] != '\0') |
return -1LL; |
return -1LL; |
|
|
c = tolower(*sp); |
c = qemu_tolower(*sp); |
switch (c) { |
switch (c) { |
default: |
default: |
return i; |
return i; |