]> git.draconx.ca Git - cdecl99.git/blob - src/cdecl99.c
Implement the interactive cdecl99 loop.
[cdecl99.git] / src / cdecl99.c
1 #include <config.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <getopt.h>
5 #include "readline.h"
6 #include "cdecl.h"
7
8 static const char *progname = "cdecl99";
9 static const char sopts[] = "VH";
10 static const struct option lopts[] = {
11         { "version", 0, NULL, 'V' },
12         { "help",    0, NULL, 'H' },
13         { 0 }
14 };
15
16 static void print_version(void)
17 {
18         puts(PACKAGE_STRING);
19         puts("Copyright (C) 2011 Nick Bowler.");
20         puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.");
21         puts("This is free software: you are free to change and redistribute it.");
22         puts("There is NO WARRANTY, to the extent permitted by law.");
23 }
24
25 static void print_usage(FILE *f)
26 {
27         fprintf(f, "Usage: %s [options]\n", progname);
28 }
29
30 static void print_help(void)
31 {
32         print_usage(stdout);
33         puts("Detailed help coming soon.");
34 }
35
36 static int repl(void)
37 {
38         struct cdecl *decl;
39         print_version();
40
41         for (char *line; (line = readline("> ")); free(line)) {
42                 decl = cdecl_parse_decl(line);
43                 cdecl_free(decl);
44         }
45
46         return 0;
47 }
48
49 int main(int argc, char **argv)
50 {
51         int opt;
52
53         if (argc > 0)
54                 progname = argv[0];
55
56         while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
57                 switch (opt) {
58                 case 'V':
59                         print_version();
60                         return EXIT_SUCCESS;
61                 case 'H':
62                         print_help();
63                         return EXIT_SUCCESS;
64                 default:
65                         print_usage(stderr);
66                         return EXIT_FAILURE;
67                 }
68         }
69
70         if (repl() != 0)
71                 return EXIT_FAILURE;
72
73         return EXIT_SUCCESS;
74 }