Mercurial > ~dholland > hg > tradcpp > index.cgi
annotate main.c @ 139:6eaaa9c4e87f
Added tag release-0.3.1 for changeset 85b66cc0344e
author | David A. Holland |
---|---|
date | Tue, 09 Jul 2013 13:48:53 -0400 |
parents | 0816803b22d1 |
children | 904f7a9827e3 |
rev | line source |
---|---|
30 | 1 /*- |
2 * Copyright (c) 2010 The NetBSD Foundation, Inc. | |
3 * All rights reserved. | |
4 * | |
5 * This code is derived from software contributed to The NetBSD Foundation | |
6 * by David A. Holland. | |
7 * | |
8 * Redistribution and use in source and binary forms, with or without | |
9 * modification, are permitted provided that the following conditions | |
10 * are met: | |
11 * 1. Redistributions of source code must retain the above copyright | |
12 * notice, this list of conditions and the following disclaimer. | |
13 * 2. Redistributions in binary form must reproduce the above copyright | |
14 * notice, this list of conditions and the following disclaimer in the | |
15 * documentation and/or other materials provided with the distribution. | |
16 * | |
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 * POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
30 #include <stdbool.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
31 #include <stdio.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
32 #include <stdlib.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
33 #include <string.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
34 #include <errno.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
35 #include <err.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
36 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
37 #include "version.h" |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
38 #include "config.h" |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
39 #include "utils.h" |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
40 #include "array.h" |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
41 #include "mode.h" |
8 | 42 #include "place.h" |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
43 #include "files.h" |
15 | 44 #include "directive.h" |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
45 #include "macro.h" |
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 struct mode mode = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
48 .werror = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
49 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
50 .input_allow_dollars = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
51 .input_tabstop = 8, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
52 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
53 .do_stdinc = true, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
54 .do_stddef = true, |
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 .do_output = true, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
57 .output_linenumbers = true, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
58 .output_retain_comments = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
59 .output_file = NULL, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
60 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
61 .do_depend = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
62 .depend_report_system = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
63 .depend_assume_generated = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
64 .depend_issue_fakerules = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
65 .depend_quote_target = true, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
66 .depend_target = NULL, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
67 .depend_file = NULL, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
68 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
69 .do_macrolist = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
70 .macrolist_include_stddef = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
71 .macrolist_include_expansions = false, |
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 .do_trace = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
74 .trace_namesonly = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
75 .trace_indented = false, |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
78 struct warns warns = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
79 .endiflabels = true, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
80 .nestcomment = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
81 .undef = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
82 .unused = false, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
83 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
84 |
71 | 85 /* this is always true, but can be set explicitly with -traditional */ |
86 static bool traditional = true; | |
87 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
88 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
89 // commandline macros |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
90 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
91 struct commandline_macro { |
11 | 92 struct place where; |
15 | 93 struct place where2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
94 const char *macro; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
95 const char *expansion; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
98 static struct array commandline_macros; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
99 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
100 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
101 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
102 commandline_macros_init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
103 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
104 array_init(&commandline_macros); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
109 commandline_macros_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
110 { |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
111 unsigned i, num; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
112 struct commandline_macro *cm; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
113 |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
114 num = array_num(&commandline_macros); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
115 for (i=0; i<num; i++) { |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
116 cm = array_get(&commandline_macros, i); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
117 dofree(cm, sizeof(*cm)); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
118 } |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
119 array_setsize(&commandline_macros, 0); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
120 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
121 array_cleanup(&commandline_macros); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
122 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
123 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
124 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
125 void |
15 | 126 commandline_macro_add(const struct place *p, const char *macro, |
127 const struct place *p2, const char *expansion) | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
128 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
129 struct commandline_macro *cm; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
130 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
131 cm = domalloc(sizeof(*cm)); |
11 | 132 cm->where = *p; |
15 | 133 cm->where2 = *p2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
134 cm->macro = macro; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
135 cm->expansion = expansion; |
86 | 136 |
137 array_add(&commandline_macros, cm, NULL); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
138 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
139 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
140 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
141 void |
7 | 142 commandline_def(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
143 { |
15 | 144 struct place p2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
145 char *val; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
146 |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
147 if (*str == '\0') { |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
148 warnx("-D: macro name expected"); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
149 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
150 } |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
151 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
152 val = strchr(str, '='); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
153 if (val != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
154 *val = '\0'; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
155 val++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
156 } |
15 | 157 |
158 if (val) { | |
159 p2 = *p; | |
160 p2.column += strlen(str); | |
161 } else { | |
162 place_setbuiltin(&p2, 1); | |
163 } | |
164 commandline_macro_add(p, str, &p2, val ? val : "1"); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
165 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
168 void |
7 | 169 commandline_undef(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
170 { |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
171 if (*str == '\0') { |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
172 warnx("-D: macro name expected"); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
173 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
174 } |
15 | 175 commandline_macro_add(p, str, p, NULL); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
176 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
177 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
178 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
179 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
180 apply_commandline_macros(void) |
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 struct commandline_macro *cm; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
183 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
184 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
185 num = array_num(&commandline_macros); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
186 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
187 cm = array_get(&commandline_macros, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
188 if (cm->expansion != NULL) { |
18 | 189 macro_define_plain(&cm->where, cm->macro, |
190 &cm->where2, cm->expansion); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
191 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
192 macro_undef(cm->macro); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
193 } |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
194 dofree(cm, sizeof(*cm)); |
4
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_setsize(&commandline_macros, 0); |
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 |
7 | 201 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
|
202 { |
11 | 203 struct place p; |
7 | 204 |
11 | 205 place_setbuiltin(&p, num); |
18 | 206 macro_define_plain(&p, name, &p, val); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
207 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
208 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
209 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
210 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
211 apply_builtin_macros(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
212 { |
7 | 213 unsigned n = 1; |
214 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
215 #ifdef CONFIG_OS |
7 | 216 apply_builtin_macro(n++, CONFIG_OS, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
217 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
218 #ifdef CONFIG_OS_2 |
7 | 219 apply_builtin_macro(n++, CONFIG_OS_2, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
220 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
221 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
222 #ifdef CONFIG_CPU |
7 | 223 apply_builtin_macro(n++, CONFIG_CPU, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
224 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
225 #ifdef CONFIG_CPU_2 |
7 | 226 apply_builtin_macro(n++, CONFIG_CPU_2, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
227 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
228 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
229 #ifdef CONFIG_SIZE |
7 | 230 apply_builtin_macro(n++, CONFIG_SIZE, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
231 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
232 #ifdef CONFIG_BINFMT |
7 | 233 apply_builtin_macro(n++, CONFIG_BINFMT, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
234 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
235 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
236 #ifdef CONFIG_COMPILER |
7 | 237 apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR); |
238 apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR); | |
239 apply_builtin_macro(n++, "__VERSION__", VERSION_LONG); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
240 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
241 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
242 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
243 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
244 // extra included files |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
245 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
246 struct commandline_file { |
11 | 247 struct place where; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
248 char *name; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
249 bool suppress_output; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
250 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
251 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
252 static struct array commandline_files; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
253 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
254 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
255 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
256 commandline_files_init(void) |
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 array_init(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
259 } |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
262 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
263 commandline_files_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
264 { |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
265 unsigned i, num; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
266 struct commandline_file *cf; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
267 |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
268 num = array_num(&commandline_files); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
269 for (i=0; i<num; i++) { |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
270 cf = array_get(&commandline_files, i); |
136 | 271 if (cf != NULL) { |
272 dofree(cf, sizeof(*cf)); | |
273 } | |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
274 } |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
275 array_setsize(&commandline_files, 0); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
276 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
277 array_cleanup(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
278 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
279 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
280 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
281 void |
7 | 282 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
|
283 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
284 struct commandline_file *cf; |
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 cf = domalloc(sizeof(*cf)); |
11 | 287 cf->where = *p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
288 cf->name = name; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
289 cf->suppress_output = suppress_output; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
290 array_add(&commandline_files, cf, NULL); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
291 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
292 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
293 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
294 void |
7 | 295 commandline_addfile_output(const struct place *p, char *name) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
296 { |
7 | 297 commandline_addfile(p, name, false); |
4
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
300 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
301 void |
7 | 302 commandline_addfile_nooutput(const struct place *p, char *name) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
303 { |
7 | 304 commandline_addfile(p, name, true); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
305 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
306 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
307 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
308 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
309 read_commandline_files(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
310 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
311 struct commandline_file *cf; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
312 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
313 bool save = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
314 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
315 num = array_num(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
316 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
317 cf = array_get(&commandline_files, i); |
136 | 318 array_set(&commandline_files, i, NULL); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
319 if (cf->suppress_output) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
320 save = mode.do_output; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
321 mode.do_output = false; |
11 | 322 file_readquote(&cf->where, cf->name); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
323 mode.do_output = save; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
324 } else { |
11 | 325 file_readquote(&cf->where, cf->name); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
326 } |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
327 dofree(cf, sizeof(*cf)); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
328 } |
5
7c489c73d62b
Clear commandline_files after processing it.
David A. Holland
parents:
4
diff
changeset
|
329 array_setsize(&commandline_files, 0); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
330 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
331 |
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 // include path accumulation |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
334 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
335 static struct stringarray incpath_quote; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
336 static struct stringarray incpath_user; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
337 static struct stringarray incpath_system; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
338 static struct stringarray incpath_late; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
339 static const char *sysroot; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
340 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
341 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
342 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
343 incpath_init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
344 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
345 stringarray_init(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
346 stringarray_init(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
347 stringarray_init(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
348 stringarray_init(&incpath_late); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
349 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
350 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
351 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
352 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
353 incpath_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
354 { |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
355 stringarray_setsize(&incpath_quote, 0); |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
356 stringarray_setsize(&incpath_user, 0); |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
357 stringarray_setsize(&incpath_system, 0); |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
358 stringarray_setsize(&incpath_late, 0); |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
359 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
360 stringarray_cleanup(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
361 stringarray_cleanup(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
362 stringarray_cleanup(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
363 stringarray_cleanup(&incpath_late); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
364 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
365 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
366 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
367 void |
7 | 368 commandline_isysroot(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
369 { |
7 | 370 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
371 sysroot = dir; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
372 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
375 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
376 commandline_addincpath(struct stringarray *arr, char *s) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
377 { |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
378 if (*s == '\0') { |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
379 warnx("Empty include path"); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
380 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
381 } |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
382 stringarray_add(arr, s, NULL); |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
386 void |
7 | 387 commandline_addincpath_quote(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
388 { |
7 | 389 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
390 commandline_addincpath(&incpath_quote, dir); |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
394 void |
7 | 395 commandline_addincpath_user(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
396 { |
7 | 397 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
398 commandline_addincpath(&incpath_user, dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
399 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
400 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
401 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
402 void |
7 | 403 commandline_addincpath_system(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
404 { |
7 | 405 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
406 commandline_addincpath(&incpath_system, dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
407 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
408 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
409 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
410 void |
7 | 411 commandline_addincpath_late(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
412 { |
7 | 413 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
414 commandline_addincpath(&incpath_late, dir); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
417 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
418 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
419 loadincludepath(void) |
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 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
422 const char *dir; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
423 char *t; |
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 num = stringarray_num(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
426 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
427 dir = stringarray_get(&incpath_quote, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
428 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
429 } |
112 | 430 files_addquotepath(NULL, false); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
431 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
432 num = stringarray_num(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
433 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
434 dir = stringarray_get(&incpath_user, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
435 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
436 files_addbracketpath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
437 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
438 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
439 if (mode.do_stdinc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
440 if (sysroot != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
441 t = dostrdup3(sysroot, "/", CONFIG_LOCALINCLUDE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
442 freestringlater(t); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
443 dir = t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
444 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
445 dir = CONFIG_LOCALINCLUDE; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
446 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
447 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
448 files_addbracketpath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
449 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
450 if (sysroot != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
451 t = dostrdup3(sysroot, "/", CONFIG_SYSTEMINCLUDE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
452 freestringlater(t); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
453 dir = t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
454 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
455 dir = CONFIG_SYSTEMINCLUDE; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
456 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
457 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
458 files_addbracketpath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
459 } |
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 num = stringarray_num(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
462 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
463 dir = stringarray_get(&incpath_system, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
464 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
465 files_addbracketpath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
466 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
467 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
468 num = stringarray_num(&incpath_late); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
469 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
470 dir = stringarray_get(&incpath_late, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
471 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
472 files_addbracketpath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
473 } |
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 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
477 // silly commandline stuff |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
478 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
479 static const char *commandline_prefix; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
480 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
481 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
482 void |
7 | 483 commandline_setprefix(const struct place *p, char *prefix) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
484 { |
7 | 485 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
486 commandline_prefix = prefix; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
487 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
488 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
489 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
490 void |
7 | 491 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
|
492 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
493 char *s; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
494 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
495 if (commandline_prefix == NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
496 warnx("-iprefix needed"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
497 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
498 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
499 s = dostrdup3(commandline_prefix, "/", dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
500 freestringlater(s); |
7 | 501 commandline_addincpath_user(p, s); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
502 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
505 void |
7 | 506 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
|
507 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
508 char *s; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
509 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
510 if (commandline_prefix == NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
511 warnx("-iprefix needed"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
512 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
513 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
514 s = dostrdup3(commandline_prefix, "/", dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
515 freestringlater(s); |
7 | 516 commandline_addincpath_late(p, s); |
4
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
519 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
520 void |
7 | 521 commandline_setstd(const struct place *p, char *std) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
522 { |
7 | 523 (void)p; |
6 | 524 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
525 if (!strcmp(std, "krc")) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
526 return; |
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 warnx("Standard %s not supported by this preprocessor", std); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
529 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
530 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
533 void |
7 | 534 commandline_setlang(const struct place *p, char *lang) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
535 { |
7 | 536 (void)p; |
6 | 537 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
538 if (!strcmp(lang, "c") || !strcmp(lang, "assembler-with-cpp")) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
539 return; |
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 warnx("Language %s not supported by this preprocessor", lang); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
542 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
543 } |
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 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
546 // complex modes |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
547 |
98 | 548 DEAD static |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
549 void |
7 | 550 commandline_iremap(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
551 { |
7 | 552 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
553 /* XXX */ |
6 | 554 (void)str; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
555 warnx("-iremap not supported"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
556 die(); |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
560 void |
7 | 561 commandline_tabstop(const struct place *p, char *s) |
4
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 char *t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
564 unsigned long val; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
565 |
7 | 566 (void)p; |
6 | 567 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
568 t = strchr(s, '='); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
569 if (t == NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
570 /* should not happen */ |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
571 warnx("Invalid tabstop"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
572 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
573 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
574 t++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
575 errno = 0; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
576 val = strtoul(t, &t, 10); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
577 if (errno || *t != '\0') { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
578 warnx("Invalid tabstop"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
579 die(); |
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 if (val > 64) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
582 warnx("Preposterously large tabstop"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
583 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
584 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
585 mode.input_tabstop = val; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
586 } |
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 * macrolist |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
590 */ |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
591 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
592 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
593 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
594 commandline_dD(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
595 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
596 mode.do_macrolist = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
597 mode.macrolist_include_stddef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
598 mode.macrolist_include_expansions = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
599 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
600 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
601 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
602 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
603 commandline_dM(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
604 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
605 mode.do_macrolist = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
606 mode.macrolist_include_stddef = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
607 mode.macrolist_include_expansions = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
608 mode.do_output = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
609 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
612 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
613 commandline_dN(void) |
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 mode.do_macrolist = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
616 mode.macrolist_include_stddef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
617 mode.macrolist_include_expansions = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
620 /* |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
621 * include trace |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
624 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
625 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
626 commandline_dI(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
627 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
628 mode.do_trace = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
629 mode.trace_namesonly = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
630 mode.trace_indented = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
633 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
634 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
635 commandline_H(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
636 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
637 mode.do_trace = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
638 mode.trace_namesonly = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
639 mode.trace_indented = true; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
642 /* |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
643 * depend |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
646 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
647 void |
7 | 648 commandline_setdependtarget(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
649 { |
7 | 650 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
651 mode.depend_target = str; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
652 mode.depend_quote_target = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
655 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
656 void |
7 | 657 commandline_setdependtarget_quoted(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
658 { |
7 | 659 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
660 mode.depend_target = str; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
661 mode.depend_quote_target = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
662 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
665 void |
7 | 666 commandline_setdependoutput(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
667 { |
7 | 668 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
669 mode.depend_file = str; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
670 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
671 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
672 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
673 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
674 commandline_M(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
675 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
676 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
677 mode.depend_report_system = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
678 mode.do_output = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
679 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
680 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
681 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
682 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
683 commandline_MM(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
684 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
685 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
686 mode.depend_report_system = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
687 mode.do_output = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
688 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
689 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
690 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
691 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
692 commandline_MD(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
693 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
694 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
695 mode.depend_report_system = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
696 } |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
699 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
700 commandline_MMD(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
701 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
702 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
703 mode.depend_report_system = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
704 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
705 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
706 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
707 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
708 commandline_wall(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
709 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
710 warns.nestcomment = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
711 warns.undef = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
712 warns.unused = true; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
715 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
716 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
717 commandline_wnoall(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
718 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
719 warns.nestcomment = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
720 warns.undef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
721 warns.unused = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
724 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
725 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
726 commandline_wnone(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
727 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
728 warns.nestcomment = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
729 warns.endiflabels = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
730 warns.undef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
731 warns.unused = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
732 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
733 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
734 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
735 // options |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
736 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
737 struct flag_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
738 const char *string; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
739 bool *flag; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
740 bool setto; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
741 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
742 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
743 struct act_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
744 const char *string; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
745 void (*func)(void); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
746 }; |
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 struct prefix_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
749 const char *string; |
7 | 750 void (*func)(const struct place *, char *); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
751 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
752 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
753 struct arg_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
754 const char *string; |
7 | 755 void (*func)(const struct place *, char *); |
4
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 static const struct flag_option flag_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
759 { "C", &mode.output_retain_comments, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
760 { "CC", &mode.output_retain_comments, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
761 { "MG", &mode.depend_assume_generated, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
762 { "MP", &mode.depend_issue_fakerules, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
763 { "P", &mode.output_linenumbers, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
764 { "Wcomment", &warns.nestcomment, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
765 { "Wendif-labels", &warns.endiflabels, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
766 { "Werror", &mode.werror, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
767 { "Wno-comment", &warns.nestcomment, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
768 { "Wno-endif-labels", &warns.endiflabels, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
769 { "Wno-error", &mode.werror, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
770 { "Wno-undef", &warns.undef, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
771 { "Wno-unused-macros", &warns.unused, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
772 { "Wundef", &warns.undef, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
773 { "Wunused-macros", &warns.unused, true }, |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
774 { "fdollars-in-identifiers", &mode.input_allow_dollars, true }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
775 { "fno-dollars-in-identifiers", &mode.input_allow_dollars, false }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
776 { "nostdinc", &mode.do_stdinc, false }, |
71 | 777 { "traditional", &traditional, true }, |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
778 { "undef", &mode.do_stddef, false }, |
4
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 static const unsigned num_flag_options = HOWMANY(flag_options); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
781 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
782 static const struct act_option act_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
783 { "H", commandline_H }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
784 { "M", commandline_M }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
785 { "MD", commandline_MD }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
786 { "MM", commandline_MM }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
787 { "MMD", commandline_MMD }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
788 { "Wall", commandline_wall }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
789 { "Wno-all", commandline_wnoall }, |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
790 { "dD", commandline_dD }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
791 { "dI", commandline_dI }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
792 { "dM", commandline_dM }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
793 { "dN", commandline_dN }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
794 { "w", commandline_wnone }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
795 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
796 static const unsigned num_act_options = HOWMANY(act_options); |
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 static const struct prefix_option prefix_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
799 { "D", commandline_def }, |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
800 { "I", commandline_addincpath_user }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
801 { "U", commandline_undef }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
802 { "ftabstop=", commandline_tabstop }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
803 { "std=", commandline_setstd }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
804 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
805 static const unsigned num_prefix_options = HOWMANY(prefix_options); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
806 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
807 static const struct arg_option arg_options[] = { |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
808 { "MF", commandline_setdependoutput }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
809 { "MQ", commandline_setdependtarget_quoted }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
810 { "MT", commandline_setdependtarget }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
811 { "idirafter", commandline_addincpath_late }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
812 { "imacros", commandline_addfile_nooutput }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
813 { "include", commandline_addfile_output }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
814 { "iprefix", commandline_setprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
815 { "iquote", commandline_addincpath_quote }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
816 { "iremap", commandline_iremap }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
817 { "isysroot", commandline_isysroot }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
818 { "isystem", commandline_addincpath_system }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
819 { "iwithprefix", commandline_addincpath_late_withprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
820 { "iwithprefixbefore", commandline_addincpath_user_withprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
821 { "x", commandline_setlang }, |
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 static const unsigned num_arg_options = HOWMANY(arg_options); |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
826 bool |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
827 check_flag_option(const char *opt) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
828 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
829 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
830 int r; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
831 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
832 for (i=0; i<num_flag_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
833 r = strcmp(opt, flag_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
834 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
835 *flag_options[i].flag = flag_options[i].setto; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
836 return true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
837 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
838 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
839 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
840 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
841 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
842 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
843 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
844 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
845 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
846 bool |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
847 check_act_option(const char *opt) |
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 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
850 int r; |
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 for (i=0; i<num_act_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
853 r = strcmp(opt, act_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
854 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
855 act_options[i].func(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
856 return true; |
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 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
859 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
860 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
861 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
862 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
863 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
864 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
865 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
866 bool |
7 | 867 check_prefix_option(const struct place *p, char *opt) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
868 { |
44
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
869 unsigned i, len; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
870 int r; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
871 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
872 for (i=0; i<num_prefix_options; i++) { |
44
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
873 len = strlen(prefix_options[i].string); |
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
874 r = strncmp(opt, prefix_options[i].string, len); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
875 if (r == 0) { |
44
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
876 prefix_options[i].func(p, opt + len); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
877 return true; |
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 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
880 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
881 } |
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 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
884 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
887 bool |
7 | 888 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
|
889 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
890 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
891 int r; |
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 for (i=0; i<num_arg_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
894 r = strcmp(opt, arg_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
895 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
896 if (arg == NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
897 warnx("Option -%s requires an argument", opt); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
898 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
899 } |
7 | 900 arg_options[i].func(argplace, arg); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
901 return true; |
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 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
904 break; |
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 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
907 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
908 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
909 |
98 | 910 DEAD static |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
911 void |
137 | 912 usage(const char *argv0, const char *fmt, ...) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
913 { |
105
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
914 const char *progname; |
137 | 915 va_list ap; |
105
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
916 |
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
917 progname = strrchr(argv0, '/'); |
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
918 progname = progname == NULL ? argv0 : progname + 1; |
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
919 |
137 | 920 fprintf(stderr, "%s: ", progname); |
921 va_start(ap, fmt); | |
922 vfprintf(stderr, fmt, ap); | |
923 va_end(ap); | |
924 fprintf(stderr, "\n"); | |
925 | |
105
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
926 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
927 fprintf(stderr, "Common options:\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
928 fprintf(stderr, " -C Retain comments\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
929 fprintf(stderr, " -Dmacro[=def] Predefine macro\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
930 fprintf(stderr, " -Idir Add to include path\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
931 fprintf(stderr, " -M Issue depend info\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
932 fprintf(stderr, " -MD Issue depend info and output\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
933 fprintf(stderr, " -MM -M w/o system headers\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
934 fprintf(stderr, " -MMD -MD w/o system headers\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
935 fprintf(stderr, " -nostdinc Drop default include path\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
936 fprintf(stderr, " -Umacro Undefine macro\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
937 fprintf(stderr, " -undef Undefine everything\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
938 fprintf(stderr, " -Wall Enable all warnings\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
939 fprintf(stderr, " -Werror Make warnings into errors\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
940 fprintf(stderr, " -w Disable all warnings\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
941 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
942 } |
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 // exit and cleanup |
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 static struct stringarray freestrings; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
948 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
949 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
950 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
951 init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
952 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
953 stringarray_init(&freestrings); |
6 | 954 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
955 incpath_init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
956 commandline_macros_init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
957 commandline_files_init(); |
6 | 958 |
10 | 959 place_init(); |
6 | 960 files_init(); |
15 | 961 directive_init(); |
17 | 962 macros_init(); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
963 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
964 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
965 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
966 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
967 cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
968 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
969 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
970 |
17 | 971 macros_cleanup(); |
15 | 972 directive_cleanup(); |
6 | 973 files_cleanup(); |
10 | 974 place_cleanup(); |
6 | 975 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
976 commandline_files_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
977 commandline_macros_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
978 incpath_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
979 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
980 num = stringarray_num(&freestrings); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
981 for (i=0; i<num; i++) { |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
982 dostrfree(stringarray_get(&freestrings, i)); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
983 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
984 stringarray_setsize(&freestrings, 0); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
985 stringarray_cleanup(&freestrings); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
986 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
987 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
988 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
989 die(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
990 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
991 cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
992 exit(EXIT_FAILURE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
993 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
994 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
995 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
996 freestringlater(char *s) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
997 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
998 stringarray_add(&freestrings, s, NULL); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
999 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1000 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1001 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1002 // main |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1003 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1004 int |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1005 main(int argc, char *argv[]) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1006 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1007 const char *inputfile = NULL; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1008 const char *outputfile = NULL; |
11 | 1009 struct place cmdplace; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1010 int i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1011 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1012 init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1013 |
7 | 1014 for (i=1; i<argc; i++) { |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1015 if (argv[i][0] != '-') { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1016 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1017 } |
14 | 1018 place_setcommandline(&cmdplace, i, 1); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1019 if (check_flag_option(argv[i]+1)) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1020 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1021 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1022 if (check_act_option(argv[i]+1)) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1023 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1024 } |
11 | 1025 if (check_prefix_option(&cmdplace, argv[i]+1)) { |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1026 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1027 } |
14 | 1028 place_setcommandline(&cmdplace, i+1, 1); |
11 | 1029 if (check_arg_option(argv[i]+1, &cmdplace, argv[i+1])) { |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1030 i++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1031 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1032 } |
137 | 1033 usage(argv[0], "Invalid option %s", argv[i]); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1034 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1035 if (i < argc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1036 inputfile = argv[i++]; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1037 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1038 if (i < argc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1039 outputfile = argv[i++]; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1040 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1041 if (i < argc) { |
137 | 1042 usage(argv[0], "Extra non-option argument %s", argv[i]); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1043 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1044 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1045 mode.output_file = outputfile; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1046 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1047 loadincludepath(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1048 apply_builtin_macros(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1049 apply_commandline_macros(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1050 read_commandline_files(); |
11 | 1051 place_setnowhere(&cmdplace); |
1052 file_readabsolute(&cmdplace, inputfile); | |
7 | 1053 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1054 cleanup(); |
6 | 1055 if (complain_failed()) { |
1056 return EXIT_FAILURE; | |
1057 } | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1058 return EXIT_SUCCESS; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1059 } |