annotate main.c @ 8:97243badae69

split place stuff to its own file
author David A. Holland
date Sun, 19 Dec 2010 19:15:55 -0500
parents b8167949474a
children 800f3a560a3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1 #include <stdbool.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
2 #include <stdio.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
3 #include <stdlib.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
4 #include <string.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
5 #include <errno.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
6 #include <err.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
7
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
8 #include "version.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
9 #include "config.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
10 #include "utils.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
11 #include "array.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
12 #include "mode.h"
8
97243badae69 split place stuff to its own file
David A. Holland
parents: 7
diff changeset
13 #include "place.h"
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
14 #include "files.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
15 #include "macro.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
16
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
17 struct mode mode = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
18 .werror = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
19
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
20 .input_allow_dollars = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
21 .input_tabstop = 8,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
22
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
23 .do_stdinc = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
24 .do_stddef = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
25
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
26 .do_output = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
27 .output_linenumbers = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
28 .output_retain_comments = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
29 .output_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
30
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
31 .do_depend = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
32 .depend_report_system = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
33 .depend_assume_generated = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
34 .depend_issue_fakerules = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
35 .depend_quote_target = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
36 .depend_target = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
37 .depend_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
38
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
39 .do_macrolist = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
40 .macrolist_include_stddef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
41 .macrolist_include_expansions = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
42
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
43 .do_trace = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
44 .trace_namesonly = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
45 .trace_indented = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
46 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
47
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
48 struct warns warns = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
49 .endiflabels = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
50 .nestcomment = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
51 .undef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
52 .unused = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
53 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
54
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
55 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
56 // commandline macros
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
57
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
58 struct commandline_macro {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
59 struct place *place;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
60 const char *macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
61 const char *expansion;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
62 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
63
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
64 static struct array commandline_macros;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
65
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
66 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
67 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
68 commandline_macros_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
69 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
70 array_init(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
71 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
72
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
73 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
74 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
75 commandline_macros_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
76 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
77 array_cleanup(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
78 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
79
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
80 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
81 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
82 commandline_macro_add(const struct place *p,
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
83 const char *macro, const char *expansion)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
84 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
85 struct commandline_macro *cm;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
86
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
87 cm = domalloc(sizeof(*cm));
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
88 cm->place = place_clone(p);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
89 cm->macro = macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
90 cm->expansion = expansion;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
91 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
92
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
93 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
94 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
95 commandline_def(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
96 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
97 char *val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
98
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
99 val = strchr(str, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
100 if (val != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
101 *val = '\0';
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
102 val++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
103 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
104 commandline_macro_add(p, str, val ? val : "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
105 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
106
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
107 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
108 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
109 commandline_undef(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
110 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
111 commandline_macro_add(p, str, NULL);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
112 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
113
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
114 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
115 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
116 apply_commandline_macros(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
117 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
118 struct commandline_macro *cm;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
119 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
120
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
121 num = array_num(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
122 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
123 cm = array_get(&commandline_macros, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
124 if (cm->expansion != NULL) {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
125 macro_define(cm->place, cm->macro, cm->expansion);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
126 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
127 macro_undef(cm->macro);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
128 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
129 place_destroy(cm->place);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
130 free(cm);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
131 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
132 array_setsize(&commandline_macros, 0);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
133 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
134
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
135 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
136 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
137 apply_builtin_macro(unsigned num, const char *name, const char *val)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
138 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
139 struct place *p;
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
140
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
141 p = place_gettemporary();
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
142 place_setbuiltin(p, num);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
143 macro_define(p, name, val);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
144 place_puttemporary(p);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
145 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
146
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
147 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
148 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
149 apply_builtin_macros(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
150 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
151 unsigned n = 1;
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
152
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
153 #ifdef CONFIG_OS
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
154 apply_builtin_macro(n++, CONFIG_OS, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
155 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
156 #ifdef CONFIG_OS_2
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
157 apply_builtin_macro(n++, CONFIG_OS_2, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
158 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
159
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
160 #ifdef CONFIG_CPU
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
161 apply_builtin_macro(n++, CONFIG_CPU, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
162 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
163 #ifdef CONFIG_CPU_2
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
164 apply_builtin_macro(n++, CONFIG_CPU_2, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
165 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
166
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
167 #ifdef CONFIG_SIZE
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
168 apply_builtin_macro(n++, CONFIG_SIZE, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
169 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
170 #ifdef CONFIG_BINFMT
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
171 apply_builtin_macro(n++, CONFIG_BINFMT, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
172 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
173
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
174 #ifdef CONFIG_COMPILER
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
175 apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
176 apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
177 apply_builtin_macro(n++, "__VERSION__", VERSION_LONG);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
178 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
179 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
180
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
181 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
182 // extra included files
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
183
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
184 struct commandline_file {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
185 struct place *place;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
186 char *name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
187 bool suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
188 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
189
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
190 static struct array commandline_files;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
191
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
192 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
193 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
194 commandline_files_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
195 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
196 array_init(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
197 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
198
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
199 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
200 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
201 commandline_files_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
202 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
203 array_cleanup(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
204 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
205
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
206 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
207 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
208 commandline_addfile(const struct place *p, char *name, bool suppress_output)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
209 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
210 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
211
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
212 cf = domalloc(sizeof(*cf));
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
213 cf->place = place_clone(p);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
214 cf->name = name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
215 cf->suppress_output = suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
216 array_add(&commandline_files, cf, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
217 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
218
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
219 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
220 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
221 commandline_addfile_output(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
222 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
223 commandline_addfile(p, name, false);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
224 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
225
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
226 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
227 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
228 commandline_addfile_nooutput(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
229 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
230 commandline_addfile(p, name, true);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
231 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
232
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
233 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
234 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
235 read_commandline_files(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
236 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
237 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
238 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
239 bool save = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
240
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
241 num = array_num(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
242 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
243 cf = array_get(&commandline_files, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
244 if (cf->suppress_output) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
245 save = mode.do_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
246 mode.do_output = false;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
247 file_readquote(cf->place, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
248 mode.do_output = save;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
249 } else {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
250 file_readquote(cf->place, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
251 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
252 place_destroy(cf->place);
5
7c489c73d62b Clear commandline_files after processing it.
David A. Holland
parents: 4
diff changeset
253 free(cf);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
254 }
5
7c489c73d62b Clear commandline_files after processing it.
David A. Holland
parents: 4
diff changeset
255 array_setsize(&commandline_files, 0);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
256 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
257
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
258 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
259 // include path accumulation
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
260
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
261 static struct stringarray incpath_quote;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
262 static struct stringarray incpath_user;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
263 static struct stringarray incpath_system;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
264 static struct stringarray incpath_late;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
265 static const char *sysroot;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
266
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
267 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
268 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
269 incpath_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
270 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
271 stringarray_init(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
272 stringarray_init(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
273 stringarray_init(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
274 stringarray_init(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
275 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
276
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
277 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
278 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
279 incpath_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
280 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
281 stringarray_cleanup(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
282 stringarray_cleanup(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
283 stringarray_cleanup(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
284 stringarray_cleanup(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
285 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
286
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
287 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
288 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
289 commandline_isysroot(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
290 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
291 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
292 sysroot = dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
293 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
294
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
295 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
296 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
297 commandline_addincpath(struct stringarray *arr, char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
298 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
299 stringarray_add(arr, s, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
300 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
301
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
302 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
303 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
304 commandline_addincpath_quote(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
305 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
306 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
307 commandline_addincpath(&incpath_quote, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
308 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
309
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
310 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
311 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
312 commandline_addincpath_user(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
313 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
314 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
315 commandline_addincpath(&incpath_user, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
316 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
317
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
318 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
319 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
320 commandline_addincpath_system(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
321 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
322 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
323 commandline_addincpath(&incpath_system, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
324 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
325
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
326 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
327 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
328 commandline_addincpath_late(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
329 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
330 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
331 commandline_addincpath(&incpath_late, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
332 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
333
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
334 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
335 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
336 loadincludepath(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
337 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
338 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
339 const char *dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
340 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
341
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
342 num = stringarray_num(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
343 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
344 dir = stringarray_get(&incpath_quote, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
345 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
346 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
347 files_addquotepath(".", false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
348
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
349 num = stringarray_num(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
350 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
351 dir = stringarray_get(&incpath_user, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
352 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
353 files_addbracketpath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
354 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
355
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
356 if (mode.do_stdinc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
357 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
358 t = dostrdup3(sysroot, "/", CONFIG_LOCALINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
359 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
360 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
361 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
362 dir = CONFIG_LOCALINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
363 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
364 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
365 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
366
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
367 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
368 t = dostrdup3(sysroot, "/", CONFIG_SYSTEMINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
369 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
370 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
371 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
372 dir = CONFIG_SYSTEMINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
373 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
374 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
375 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
376 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
377
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
378 num = stringarray_num(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
379 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
380 dir = stringarray_get(&incpath_system, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
381 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
382 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
383 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
384
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
385 num = stringarray_num(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
386 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
387 dir = stringarray_get(&incpath_late, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
388 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
389 files_addbracketpath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
390 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
391 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
392
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
393 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
394 // silly commandline stuff
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
395
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
396 static const char *commandline_prefix;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
397
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
398 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
399 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
400 commandline_setprefix(const struct place *p, char *prefix)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
401 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
402 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
403 commandline_prefix = prefix;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
404 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
405
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
406 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
407 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
408 commandline_addincpath_user_withprefix(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
409 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
410 char *s;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
411
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
412 if (commandline_prefix == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
413 warnx("-iprefix needed");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
414 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
415 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
416 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
417 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
418 commandline_addincpath_user(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
419 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
420
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
421 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
422 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
423 commandline_addincpath_late_withprefix(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
424 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
425 char *s;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
426
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
427 if (commandline_prefix == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
428 warnx("-iprefix needed");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
429 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
430 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
431 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
432 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
433 commandline_addincpath_late(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
434 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
435
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
436 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
437 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
438 commandline_setstd(const struct place *p, char *std)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
439 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
440 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
441
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
442 if (!strcmp(std, "krc")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
443 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
444 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
445 warnx("Standard %s not supported by this preprocessor", std);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
446 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
447 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
448
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
449 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
450 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
451 commandline_setlang(const struct place *p, char *lang)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
452 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
453 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
454
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
455 if (!strcmp(lang, "c") || !strcmp(lang, "assembler-with-cpp")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
456 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
457 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
458 warnx("Language %s not supported by this preprocessor", lang);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
459 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
460 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
461
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
462 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
463 // complex modes
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
464
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
465 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
466 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
467 commandline_iremap(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
468 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
469 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
470 /* XXX */
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
471 (void)str;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
472 warnx("-iremap not supported");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
473 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
474 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
475
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
476 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
477 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
478 commandline_tabstop(const struct place *p, char *s)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
479 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
480 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
481 unsigned long val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
482
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
483 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
484
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
485 t = strchr(s, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
486 if (t == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
487 /* should not happen */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
488 warnx("Invalid tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
489 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
490 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
491 t++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
492 errno = 0;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
493 val = strtoul(t, &t, 10);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
494 if (errno || *t != '\0') {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
495 warnx("Invalid tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
496 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
497 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
498 if (val > 64) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
499 warnx("Preposterously large tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
500 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
501 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
502 mode.input_tabstop = val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
503 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
504
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
505 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
506 * macrolist
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
507 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
508
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
509 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
510 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
511 commandline_dD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
512 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
513 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
514 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
515 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
516 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
517
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
518 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
519 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
520 commandline_dM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
521 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
522 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
523 mode.macrolist_include_stddef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
524 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
525 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
526 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
527
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
528 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
529 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
530 commandline_dN(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
531 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
532 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
533 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
534 mode.macrolist_include_expansions = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
535 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
536
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
537 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
538 * include trace
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
539 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
540
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
541 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
542 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
543 commandline_dI(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
544 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
545 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
546 mode.trace_namesonly = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
547 mode.trace_indented = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
548 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
549
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
550 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
551 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
552 commandline_H(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
553 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
554 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
555 mode.trace_namesonly = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
556 mode.trace_indented = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
557 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
558
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
559 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
560 * depend
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
561 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
562
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
563 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
564 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
565 commandline_setdependtarget(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
566 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
567 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
568 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
569 mode.depend_quote_target = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
570 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
571
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
572 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
573 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
574 commandline_setdependtarget_quoted(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
575 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
576 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
577 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
578 mode.depend_quote_target = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
579 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
580
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
581 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
582 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
583 commandline_setdependoutput(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
584 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
585 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
586 mode.depend_file = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
587 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
588
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
589 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
590 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
591 commandline_M(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
592 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
593 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
594 mode.depend_report_system = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
595 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
596 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
597
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
598 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
599 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
600 commandline_MM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
601 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
602 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
603 mode.depend_report_system = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
604 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
605 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
606
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
607 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
608 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
609 commandline_MD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
610 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
611 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
612 mode.depend_report_system = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
613 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
614
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
615 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
616 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
617 commandline_MMD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
618 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
619 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
620 mode.depend_report_system = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
621 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
622
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
623 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
624 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
625 commandline_wall(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
626 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
627 warns.nestcomment = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
628 warns.undef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
629 warns.unused = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
630 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
631
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
632 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
633 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
634 commandline_wnoall(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
635 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
636 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
637 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
638 warns.unused = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
639 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
640
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
641 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
642 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
643 commandline_wnone(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
644 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
645 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
646 warns.endiflabels = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
647 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
648 warns.unused = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
649 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
650
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
651 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
652 // options
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
653
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
654 struct flag_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
655 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
656 bool *flag;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
657 bool setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
658 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
659
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
660 struct act_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
661 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
662 void (*func)(void);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
663 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
664
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
665 struct prefix_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
666 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
667 void (*func)(const struct place *, char *);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
668 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
669
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
670 struct arg_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
671 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
672 void (*func)(const struct place *, char *);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
673 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
674
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
675 static const struct flag_option flag_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
676 { "C", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
677 { "CC", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
678 { "fdollars-in-identifiers", &mode.input_allow_dollars, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
679 { "fno-dollars-in-identifiers", &mode.input_allow_dollars, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
680 { "MG", &mode.depend_assume_generated, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
681 { "MP", &mode.depend_issue_fakerules, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
682 { "nostdinc", &mode.do_stdinc, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
683 { "P", &mode.output_linenumbers, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
684 { "undef", &mode.do_stddef, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
685 { "Wcomment", &warns.nestcomment, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
686 { "Wendif-labels", &warns.endiflabels, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
687 { "Werror", &mode.werror, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
688 { "Wno-comment", &warns.nestcomment, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
689 { "Wno-endif-labels", &warns.endiflabels, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
690 { "Wno-error", &mode.werror, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
691 { "Wno-undef", &warns.undef, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
692 { "Wno-unused-macros", &warns.unused, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
693 { "Wundef", &warns.undef, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
694 { "Wunused-macros", &warns.unused, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
695 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
696 static const unsigned num_flag_options = HOWMANY(flag_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
697
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
698 static const struct act_option act_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
699 { "dD", commandline_dD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
700 { "dI", commandline_dI },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
701 { "dM", commandline_dM },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
702 { "dN", commandline_dN },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
703 { "H", commandline_H },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
704 { "M", commandline_M },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
705 { "MD", commandline_MD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
706 { "MM", commandline_MM },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
707 { "MMD", commandline_MMD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
708 { "Wall", commandline_wall },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
709 { "Wno-all", commandline_wnoall },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
710 { "w", commandline_wnone },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
711 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
712 static const unsigned num_act_options = HOWMANY(act_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
713
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
714 static const struct prefix_option prefix_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
715 { "D", commandline_def },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
716 { "ftabstop=", commandline_tabstop },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
717 { "I", commandline_addincpath_user },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
718 { "std=", commandline_setstd },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
719 { "U", commandline_undef },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
720 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
721 static const unsigned num_prefix_options = HOWMANY(prefix_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
722
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
723 static const struct arg_option arg_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
724 { "idirafter", commandline_addincpath_late },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
725 { "imacros", commandline_addfile_nooutput },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
726 { "include", commandline_addfile_output },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
727 { "iprefix", commandline_setprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
728 { "iquote", commandline_addincpath_quote },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
729 { "iremap", commandline_iremap },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
730 { "isysroot", commandline_isysroot },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
731 { "isystem", commandline_addincpath_system },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
732 { "iwithprefix", commandline_addincpath_late_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
733 { "iwithprefixbefore", commandline_addincpath_user_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
734 { "MF", commandline_setdependoutput },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
735 { "MT", commandline_setdependtarget },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
736 { "MQ", commandline_setdependtarget_quoted },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
737 { "x", commandline_setlang },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
738 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
739 static const unsigned num_arg_options = HOWMANY(arg_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
740
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
741 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
742 bool
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
743 check_flag_option(const char *opt)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
744 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
745 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
746 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
747
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
748 for (i=0; i<num_flag_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
749 r = strcmp(opt, flag_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
750 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
751 *flag_options[i].flag = flag_options[i].setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
752 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
753 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
754 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
755 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
756 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
757 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
758 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
759 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
760
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
761 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
762 bool
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
763 check_act_option(const char *opt)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
764 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
765 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
766 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
767
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
768 for (i=0; i<num_act_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
769 r = strcmp(opt, act_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
770 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
771 act_options[i].func();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
772 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
773 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
774 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
775 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
776 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
777 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
778 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
779 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
780
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
781 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
782 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
783 check_prefix_option(const struct place *p, char *opt)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
784 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
785 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
786 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
787
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
788 for (i=0; i<num_prefix_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
789 r = strncmp(opt, prefix_options[i].string,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
790 strlen(prefix_options[i].string));
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
791 if (r == 0) {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
792 prefix_options[i].func(p, opt);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
793 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
794 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
795 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
796 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
797 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
798 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
799 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
800 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
801
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
802 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
803 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
804 check_arg_option(const char *opt, const struct place *argplace, char *arg)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
805 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
806 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
807 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
808
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
809 for (i=0; i<num_arg_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
810 r = strcmp(opt, arg_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
811 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
812 if (arg == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
813 warnx("Option -%s requires an argument", opt);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
814 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
815 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
816 arg_options[i].func(argplace, arg);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
817 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
818 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
819 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
820 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
821 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
822 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
823 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
824 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
825
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
826 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
827 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
828 usage(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
829 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
830 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n",
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
831 getprogname());
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
832 fprintf(stderr, "Common options:\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
833 fprintf(stderr, " -C Retain comments\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
834 fprintf(stderr, " -Dmacro[=def] Predefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
835 fprintf(stderr, " -Idir Add to include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
836 fprintf(stderr, " -M Issue depend info\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
837 fprintf(stderr, " -MD Issue depend info and output\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
838 fprintf(stderr, " -MM -M w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
839 fprintf(stderr, " -MMD -MD w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
840 fprintf(stderr, " -nostdinc Drop default include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
841 fprintf(stderr, " -Umacro Undefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
842 fprintf(stderr, " -undef Undefine everything\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
843 fprintf(stderr, " -Wall Enable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
844 fprintf(stderr, " -Werror Make warnings into errors\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
845 fprintf(stderr, " -w Disable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
846 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
847 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
848
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
849 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
850 // exit and cleanup
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
851
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
852 static struct stringarray freestrings;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
853
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
854 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
855 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
856 init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
857 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
858 stringarray_init(&freestrings);
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
859
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
860 incpath_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
861 commandline_macros_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
862 commandline_files_init();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
863
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
864 files_init();
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
865 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
866
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
867 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
868 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
869 cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
870 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
871 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
872
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
873 files_cleanup();
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
874
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
875 commandline_files_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
876 commandline_macros_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
877 incpath_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
878
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
879 num = stringarray_num(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
880 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
881 free(stringarray_get(&freestrings, i));
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
882 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
883 stringarray_setsize(&freestrings, 0);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
884 stringarray_cleanup(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
885 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
886
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
887 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
888 die(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
889 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
890 cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
891 exit(EXIT_FAILURE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
892 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
893
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
894 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
895 freestringlater(char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
896 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
897 stringarray_add(&freestrings, s, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
898 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
899
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
900 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
901 // main
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
902
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
903 int
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
904 main(int argc, char *argv[])
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
905 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
906 const char *inputfile = NULL;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
907 const char *outputfile = NULL;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
908 struct place *p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
909 int i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
910
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
911 init();
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
912 p = place_gettemporary();
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
913
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
914 for (i=1; i<argc; i++) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
915 if (argv[i][0] != '-') {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
916 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
917 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
918 place_setcommandline(p, i);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
919 if (check_flag_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
920 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
921 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
922 if (check_act_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
923 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
924 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
925 if (check_prefix_option(p, argv[i]+1)) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
926 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
927 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
928 place_setcommandline(p, i+1);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
929 if (check_arg_option(argv[i]+1, p, argv[i+1])) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
930 i++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
931 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
932 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
933 usage();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
934 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
935 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
936 inputfile = argv[i++];
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
937 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
938 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
939 outputfile = argv[i++];
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
940 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
941 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
942 usage();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
943 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
944
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
945 mode.output_file = outputfile;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
946
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
947 loadincludepath();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
948 apply_builtin_macros();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
949 apply_commandline_macros();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
950 read_commandline_files();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
951 place_setnowhere(p);
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
952 file_readabsolute(p, inputfile);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
953
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
954 place_puttemporary(p);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
955 cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
956 if (complain_failed()) {
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
957 return EXIT_FAILURE;
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
958 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
959 return EXIT_SUCCESS;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
960 }