9 static const char *progname = "cdecl99";
10 static const char sopts[] = "VH";
11 static const struct option lopts[] = {
12 { "version", 0, NULL, 'V' },
13 { "help", 0, NULL, 'H' },
17 static void print_version(void)
20 puts("Copyright (C) 2011 Nick Bowler.");
21 puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.");
22 puts("This is free software: you are free to change and redistribute it.");
23 puts("There is NO WARRANTY, to the extent permitted by law.");
26 static void print_usage(FILE *f)
28 fprintf(f, "Usage: %s [options]\n", progname);
31 static void print_help(void)
34 puts("Detailed help coming soon.");
37 static int cmd_explain(char *cmd, char *arg)
41 decl = cdecl_parse_decl(arg);
47 static int cmd_quit(char *cmd, char *arg)
52 static int cmd_help(char *cmd, char *arg);
54 static const struct command {
56 int (*func)(char *cmd, char *arg);
59 { "explain", cmd_explain, "Explain a C declaration." },
60 { "help", cmd_help, "Print this list of commands." },
61 { "quit", cmd_quit, "Quit the program." },
62 { "exit", cmd_quit, NULL }
64 static const size_t ncommands = sizeof commands / sizeof commands[0];
66 static int cmd_help(char *cmd, char *arg)
68 for (size_t i = 0; i < ncommands; i++) {
69 if (!commands[i].blurb)
72 printf("%s -- %s\n", commands[i].name, commands[i].blurb);
85 for (; (line = readline("> ")); free(line)) {
86 char *cmd = line + strspn(line, " \t");
87 char *arg = cmd + strcspn(cmd, " \t");
94 for (size_t i = 0; i < ncommands; i++) {
95 if (strcmp(cmd, commands[i].name) != 0)
98 ret = commands[i].func(cmd, arg);
104 fprintf(stderr, "Undefined command: %s\n", cmd);
115 int main(int argc, char **argv)
122 while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {