void command_loop(void)
{
- int c, i, done = 0, fetchable = 0, prompted = 0;
+ int i, 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) {
- done = command(ct, c, v);
- } else {
- fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
- }
- }
- doneline(input, v);
+ done = qemuio_command(cmdline[i]);
}
if (cmdline) {
g_free(cmdline);
if (!fetchable) {
continue;
}
+
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);
+ done = qemuio_command(input);
+ free(input);
prompted = 0;
fetchable = 0;
return rval;
}
-void
-doneline(
- char *input,
- char **vec)
-{
- free(input);
- free(vec);
-}
-
#define EXABYTES(x) ((long long)(x) << 60)
#define PETABYTES(x) ((long long)(x) << 50)
#define TERABYTES(x) ((long long)(x) << 40)
/* from input.h */
char **breakline(char *input, int *count);
-void doneline(char *input, char **vec);
char *fetchline(void);
void cvtstr(double value, char *str, size_t sz);
extern char *progname;
+bool qemuio_command(const char *cmd);
+
#endif /* __COMMAND_H__ */
return 1;
}
+bool qemuio_command(const char *cmd)
+{
+ char *input;
+ const cmdinfo_t *ct;
+ char **v;
+ int c;
+ bool done = false;
+
+ input = g_strdup(cmd);
+ 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]);
+ }
+ }
+ g_free(input);
+ g_free(v);
+
+ return done;
+}
+
static void __attribute((constructor)) init_qemuio_commands(void)
{
/* initialize commands */