- return 0;
-}
-
-static int cmd_help(char *cmd, char *arg);
-
-static const struct command {
- char name[16];
- int (*func)(char *cmd, char *arg);
- const char *blurb;
-} commands[] = {
- { "explain", cmd_explain, "Explain a C declaration." },
- { "simplify", cmd_simplify, "Simplify a C declaration." },
- { "help", cmd_help, "Print this list of commands." },
- { "quit", cmd_quit, "Quit the program." },
- { "exit", cmd_quit, NULL }
-};
-static const size_t ncommands = sizeof commands / sizeof commands[0];
+ int rc, ret = 0, saved_errno;
+ char *line = NULL;
+ size_t n;
+
+ while (getline(&line, &n, stdin) >= 0) {
+ char *c = strchr(line, '\n');
+ if (c)
+ *c = '\0';
+
+ rc = run_command(line, false);
+ if (rc < 0)
+ ret = -1;
+ else if (rc > 0)
+ break;
+ }