Mercurial > hg > index.cgi
annotate lwbasic/main.c @ 70:ceab04fd2969
Fixed premature installation of external reference under UNDEFEXTERN pragma; should not resolve to external references until after the initial parsing pass
author | lost@l-w.ca |
---|---|
date | Sun, 10 Apr 2011 13:15:12 -0600 |
parents | bcd532a90e53 |
children |
rev | line source |
---|---|
22 | 1 /* |
2 main.c | |
3 | |
4 Copyright © 2011 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 /* | |
23 main program startup handling for lwbasic | |
24 */ | |
25 | |
26 #include <stdlib.h> | |
27 #include <stdio.h> | |
25 | 28 #include <stdarg.h> |
22 | 29 |
30 #include <lw_cmdline.h> | |
31 #include <lw_string.h> | |
32 #include <lw_alloc.h> | |
33 | |
25 | 34 #define __main_c_seen__ |
22 | 35 #include "lwbasic.h" |
36 | |
37 #define PROGVER "lwbasic from " PACKAGE_STRING | |
38 | |
39 static struct lw_cmdline_options options[] = | |
40 { | |
41 { "output", 'o', "FILE", 0, "Output to FILE"}, | |
42 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"}, | |
43 { 0 } | |
44 }; | |
45 | |
46 static int parse_opts(int key, char *arg, void *data) | |
47 { | |
48 cstate *state = data; | |
49 | |
50 switch (key) | |
51 { | |
52 case 'o': | |
53 if (state -> output_file) | |
54 lw_free(state -> output_file); | |
55 state -> output_file = lw_strdup(arg); | |
56 break; | |
57 | |
58 case 'd': | |
59 if (!arg) | |
60 state -> debug_level = 50; | |
61 else | |
62 state -> debug_level = atoi(arg); | |
63 break; | |
64 | |
65 case lw_cmdline_key_end: | |
66 return 0; | |
67 | |
68 case lw_cmdline_key_arg: | |
69 if (state -> input_file) | |
70 { | |
71 fprintf(stderr, "Already have an input file; ignoring %s\n", arg); | |
72 } | |
73 else | |
74 { | |
75 state -> input_file = lw_strdup(arg); | |
76 } | |
77 break; | |
78 | |
79 default: | |
80 return lw_cmdline_err_unknown; | |
81 } | |
82 | |
83 return 0; | |
84 } | |
85 | |
86 static struct lw_cmdline_parser cmdline_parser = | |
87 { | |
88 options, | |
89 parse_opts, | |
90 "INPUTFILE", | |
91 "lwbasic, a compiler for a dialect of Basic\vPlease report bugs to lost@l-w.ca.", | |
92 PROGVER | |
93 }; | |
94 | |
30
bcd532a90e53
Renamed "compiler" to "parser" for more consistent terminology
lost@l-w.ca
parents:
25
diff
changeset
|
95 extern void parser(cstate *state); |
25 | 96 |
22 | 97 int main(int argc, char **argv) |
98 { | |
99 cstate state = { 0 }; | |
100 | |
101 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &state); | |
102 | |
30
bcd532a90e53
Renamed "compiler" to "parser" for more consistent terminology
lost@l-w.ca
parents:
25
diff
changeset
|
103 parser(&state); |
25 | 104 |
22 | 105 exit(0); |
106 } | |
25 | 107 |
108 void lwb_error(const char *fmt, ...) | |
109 { | |
110 va_list args; | |
111 | |
112 va_start(args, fmt); | |
113 vfprintf(stderr, fmt, args); | |
114 va_end(args); | |
115 | |
116 exit(1); | |
117 } |