#include <string.h>
#include <ctype.h>
#include <errno.h>
+#include <sys/time.h>
+#include <getopt.h>
#include "cmd.h"
+#include "qemu-aio.h"
#define _(x) x /* not gettext support yet */
-extern int optind;
-
/* from libxcmd/command.c */
cmdinfo_t *cmdtab;
args_func = af;
}
+static void prep_fetchline(void *opaque)
+{
+ int *fetchable = opaque;
+
+ qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
+ *fetchable= 1;
+}
+
+static char *get_prompt(void);
+
void
command_loop(void)
{
- int c, i, j = 0, done = 0;
+ int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
char *input;
char **v;
const cmdinfo_t *ct;
free(cmdline);
return;
}
+
while (!done) {
+ if (!prompted) {
+ printf("%s", get_prompt());
+ fflush(stdout);
+ qemu_aio_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, NULL,
+ NULL, &fetchable);
+ prompted = 1;
+ }
+
+ qemu_aio_wait();
+
+ if (!fetchable) {
+ continue;
+ }
if ((input = fetchline()) == NULL)
break;
v = breakline(input, &c);
v[0]);
}
doneline(input, v);
+
+ prompted = 0;
+ fetchable = 0;
}
+ qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
}
/* from libxcmd/input.c */
if (!line)
return NULL;
- printf("%s", get_prompt());
- fflush(stdout);
if (!fgets(line, MAXREADLINESZ, stdin)) {
free(line);
return NULL;
}
#endif
+static char *qemu_strsep(char **input, const char *delim)
+{
+ char *result = *input;
+ if (result != NULL) {
+ char *p;
+
+ for (p = result; *p != '\0'; p++) {
+ if (strchr(delim, *p)) {
+ break;
+ }
+ }
+ if (*p == '\0') {
+ *input = NULL;
+ } else {
+ *p = '\0';
+ *input = p + 1;
+ }
+ }
+ return result;
+}
+
char **
breakline(
char *input,
char *p;
char **rval = calloc(sizeof(char *), 1);
- while (rval && (p = strsep(&input, " ")) != NULL) {
+ while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
if (!*p)
continue;
c++;