Mercurial > ~dholland > hg > tradcpp > index.cgi
annotate main.c @ 163:e1dfa3f90b6c
Merge mismatch resulted in forgotten initialisation of isspecial.
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Fri, 27 Feb 2015 13:44:39 +0100 |
parents | 8cef6d7227a8 |
children | 3e7e696fe558 |
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> |
140 | 32 #include <stdarg.h> |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
33 #include <stdlib.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
34 #include <string.h> |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
35 #include <errno.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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
85 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
86 // commandline macros |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
87 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
88 struct commandline_macro { |
11 | 89 struct place where; |
15 | 90 struct place where2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
91 const char *macro; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
92 const char *expansion; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
93 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
94 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
95 static struct array commandline_macros; |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
98 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
99 commandline_macros_init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
100 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
101 array_init(&commandline_macros); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
102 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
105 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
106 commandline_macros_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
107 { |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
108 unsigned i, num; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
109 struct commandline_macro *cm; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
110 |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
111 num = array_num(&commandline_macros); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
112 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
|
113 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
|
114 dofree(cm, sizeof(*cm)); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
115 } |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
116 array_setsize(&commandline_macros, 0); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
117 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
118 array_cleanup(&commandline_macros); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
119 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
120 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
121 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
122 void |
15 | 123 commandline_macro_add(const struct place *p, const char *macro, |
124 const struct place *p2, const char *expansion) | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
125 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
126 struct commandline_macro *cm; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
127 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
128 cm = domalloc(sizeof(*cm)); |
11 | 129 cm->where = *p; |
15 | 130 cm->where2 = *p2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
131 cm->macro = macro; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
132 cm->expansion = expansion; |
86 | 133 |
134 array_add(&commandline_macros, cm, NULL); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
135 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
136 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
137 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
138 void |
7 | 139 commandline_def(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
140 { |
15 | 141 struct place p2; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
142 char *val; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
143 |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
144 if (*str == '\0') { |
143 | 145 complain(NULL, "-D: macro name expected"); |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
146 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
147 } |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
148 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
149 val = strchr(str, '='); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
150 if (val != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
151 *val = '\0'; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
152 val++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
153 } |
15 | 154 |
155 if (val) { | |
156 p2 = *p; | |
157 p2.column += strlen(str); | |
158 } else { | |
159 place_setbuiltin(&p2, 1); | |
160 } | |
161 commandline_macro_add(p, str, &p2, val ? val : "1"); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
162 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
163 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
164 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
165 void |
7 | 166 commandline_undef(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
167 { |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
168 if (*str == '\0') { |
143 | 169 complain(NULL, "-D: macro name expected"); |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
170 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
171 } |
15 | 172 commandline_macro_add(p, str, p, NULL); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
173 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
174 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
175 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
176 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
177 apply_commandline_macros(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
178 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
179 struct commandline_macro *cm; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
180 unsigned i, num; |
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 num = array_num(&commandline_macros); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
183 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
184 cm = array_get(&commandline_macros, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
185 if (cm->expansion != NULL) { |
18 | 186 macro_define_plain(&cm->where, cm->macro, |
187 &cm->where2, cm->expansion); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
188 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
189 macro_undef(cm->macro); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
190 } |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
191 dofree(cm, sizeof(*cm)); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
192 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
193 array_setsize(&commandline_macros, 0); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
194 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
197 void |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
198 apply_special_macros(unsigned *builtin_counter) |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
199 { |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
200 struct place p; |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
201 |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
202 place_setbuiltin(&p, ++(*builtin_counter)); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
203 macro_define_file(&p); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
204 place_setbuiltin(&p, ++(*builtin_counter)); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
205 macro_define_line(&p); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
206 } |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
207 |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
208 static |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
209 void |
7 | 210 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
|
211 { |
11 | 212 struct place p; |
7 | 213 |
11 | 214 place_setbuiltin(&p, num); |
18 | 215 macro_define_plain(&p, name, &p, val); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
216 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
217 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
218 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
219 void |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
220 apply_builtin_macros(unsigned *builtin_counter) |
4
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_OS |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
223 apply_builtin_macro(++(*builtin_counter), CONFIG_OS, "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_OS_2 |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
226 apply_builtin_macro(++(*builtin_counter), CONFIG_OS_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_CPU |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
230 apply_builtin_macro(++(*builtin_counter), CONFIG_CPU, "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_CPU_2 |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
233 apply_builtin_macro(++(*builtin_counter), CONFIG_CPU_2, "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_SIZE |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
237 apply_builtin_macro(++(*builtin_counter), CONFIG_SIZE, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
238 #endif |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
239 #ifdef CONFIG_BINFMT |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
240 apply_builtin_macro(++(*builtin_counter), CONFIG_BINFMT, "1"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
241 #endif |
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 #ifdef CONFIG_COMPILER |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
244 apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER, |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
245 VERSION_MAJOR); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
246 apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER_MINOR, |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
247 VERSION_MINOR); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
248 apply_builtin_macro(++(*builtin_counter), "__VERSION__", VERSION_LONG); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
249 #endif |
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 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
253 // extra included files |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
254 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
255 struct commandline_file { |
11 | 256 struct place where; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
257 char *name; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
258 bool suppress_output; |
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 struct array commandline_files; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
262 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
263 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
264 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
265 commandline_files_init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
266 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
267 array_init(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
268 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
269 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
270 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
271 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
272 commandline_files_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
273 { |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
274 unsigned i, num; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
275 struct commandline_file *cf; |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
276 |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
277 num = array_num(&commandline_files); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
278 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
|
279 cf = array_get(&commandline_files, i); |
136 | 280 if (cf != NULL) { |
281 dofree(cf, sizeof(*cf)); | |
282 } | |
135
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
283 } |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
284 array_setsize(&commandline_files, 0); |
eaae8014a94a
Don't assert and leak memory if failing during argument collection.
David A. Holland
parents:
122
diff
changeset
|
285 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
286 array_cleanup(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
287 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
288 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
289 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
290 void |
7 | 291 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
|
292 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
293 struct commandline_file *cf; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
294 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
295 cf = domalloc(sizeof(*cf)); |
11 | 296 cf->where = *p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
297 cf->name = name; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
298 cf->suppress_output = suppress_output; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
299 array_add(&commandline_files, cf, NULL); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
300 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
301 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
302 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
303 void |
7 | 304 commandline_addfile_output(const struct place *p, char *name) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
305 { |
7 | 306 commandline_addfile(p, name, false); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
307 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
308 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
309 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
310 void |
7 | 311 commandline_addfile_nooutput(const struct place *p, char *name) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
312 { |
7 | 313 commandline_addfile(p, name, true); |
4
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
316 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
317 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
318 read_commandline_files(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
319 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
320 struct commandline_file *cf; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
321 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
322 bool save = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
323 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
324 num = array_num(&commandline_files); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
325 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
326 cf = array_get(&commandline_files, i); |
136 | 327 array_set(&commandline_files, i, NULL); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
328 if (cf->suppress_output) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
329 save = mode.do_output; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
330 mode.do_output = false; |
11 | 331 file_readquote(&cf->where, cf->name); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
332 mode.do_output = save; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
333 } else { |
11 | 334 file_readquote(&cf->where, cf->name); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
335 } |
39
337110e7240a
Pass the size to free; it makes debug checking easier.
David A. Holland
parents:
38
diff
changeset
|
336 dofree(cf, sizeof(*cf)); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
337 } |
5
7c489c73d62b
Clear commandline_files after processing it.
David A. Holland
parents:
4
diff
changeset
|
338 array_setsize(&commandline_files, 0); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
339 } |
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 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
342 // include path accumulation |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
343 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
344 static struct stringarray incpath_quote; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
345 static struct stringarray incpath_user; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
346 static struct stringarray incpath_system; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
347 static struct stringarray incpath_late; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
348 static const char *sysroot; |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
351 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
352 incpath_init(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
353 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
354 stringarray_init(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
355 stringarray_init(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
356 stringarray_init(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
357 stringarray_init(&incpath_late); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
358 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
359 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
360 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
361 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
362 incpath_cleanup(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
363 { |
37
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
369 stringarray_cleanup(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
370 stringarray_cleanup(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
371 stringarray_cleanup(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
372 stringarray_cleanup(&incpath_late); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
375 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
376 void |
7 | 377 commandline_isysroot(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
378 { |
7 | 379 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
380 sysroot = dir; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
381 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
382 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
383 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
384 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
385 commandline_addincpath(struct stringarray *arr, char *s) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
386 { |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
387 if (*s == '\0') { |
143 | 388 complain(NULL, "Empty include directory"); |
122
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
389 die(); |
64c4de3709de
Complain if -[DIU] is given an empty argument.
David A. Holland
parents:
112
diff
changeset
|
390 } |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
391 stringarray_add(arr, s, NULL); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
392 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
393 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
394 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
395 void |
7 | 396 commandline_addincpath_quote(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
397 { |
7 | 398 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
399 commandline_addincpath(&incpath_quote, dir); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
402 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
403 void |
7 | 404 commandline_addincpath_user(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
405 { |
7 | 406 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
407 commandline_addincpath(&incpath_user, dir); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
410 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
411 void |
7 | 412 commandline_addincpath_system(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
413 { |
7 | 414 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
415 commandline_addincpath(&incpath_system, dir); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
418 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
419 void |
7 | 420 commandline_addincpath_late(const struct place *p, char *dir) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
421 { |
7 | 422 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
423 commandline_addincpath(&incpath_late, dir); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
426 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
427 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
428 loadincludepath(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
429 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
430 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
431 const char *dir; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
432 char *t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
433 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
434 num = stringarray_num(&incpath_quote); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
435 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
436 dir = stringarray_get(&incpath_quote, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
437 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
438 } |
112 | 439 files_addquotepath(NULL, false); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
440 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
441 num = stringarray_num(&incpath_user); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
442 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
443 dir = stringarray_get(&incpath_user, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
444 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
445 files_addbracketpath(dir, false); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
448 if (mode.do_stdinc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
449 if (sysroot != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
450 t = dostrdup3(sysroot, "/", CONFIG_LOCALINCLUDE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
451 freestringlater(t); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
452 dir = t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
453 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
454 dir = CONFIG_LOCALINCLUDE; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
455 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
456 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
457 files_addbracketpath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
458 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
459 if (sysroot != NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
460 t = dostrdup3(sysroot, "/", CONFIG_SYSTEMINCLUDE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
461 freestringlater(t); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
462 dir = t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
463 } else { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
464 dir = CONFIG_SYSTEMINCLUDE; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
465 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
466 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
467 files_addbracketpath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
468 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
469 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
470 num = stringarray_num(&incpath_system); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
471 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
472 dir = stringarray_get(&incpath_system, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
473 files_addquotepath(dir, true); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
474 files_addbracketpath(dir, true); |
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 num = stringarray_num(&incpath_late); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
478 for (i=0; i<num; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
479 dir = stringarray_get(&incpath_late, i); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
480 files_addquotepath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
481 files_addbracketpath(dir, false); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
482 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
483 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
484 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
485 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
486 // silly commandline stuff |
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 static const char *commandline_prefix; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
489 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
490 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
491 void |
7 | 492 commandline_setprefix(const struct place *p, char *prefix) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
493 { |
7 | 494 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
495 commandline_prefix = prefix; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
496 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
497 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
498 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
499 void |
7 | 500 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
|
501 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
502 char *s; |
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 if (commandline_prefix == NULL) { |
143 | 505 complain(NULL, "-iprefix needed"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
506 die(); |
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 s = dostrdup3(commandline_prefix, "/", dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
509 freestringlater(s); |
7 | 510 commandline_addincpath_user(p, s); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
511 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
512 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
513 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
514 void |
7 | 515 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
|
516 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
517 char *s; |
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 if (commandline_prefix == NULL) { |
143 | 520 complain(NULL, "-iprefix needed"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
521 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
522 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
523 s = dostrdup3(commandline_prefix, "/", dir); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
524 freestringlater(s); |
7 | 525 commandline_addincpath_late(p, s); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
526 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
527 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
528 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
529 void |
7 | 530 commandline_setstd(const struct place *p, char *std) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
531 { |
7 | 532 (void)p; |
6 | 533 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
534 if (!strcmp(std, "krc")) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
535 return; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
536 } |
143 | 537 complain(NULL, "Standard %s not supported by this preprocessor", std); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
538 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
539 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
540 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
541 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
542 void |
7 | 543 commandline_setlang(const struct place *p, char *lang) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
544 { |
7 | 545 (void)p; |
6 | 546 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
547 if (!strcmp(lang, "c") || !strcmp(lang, "assembler-with-cpp")) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
548 return; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
549 } |
143 | 550 complain(NULL, "Language %s not supported by this preprocessor", lang); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
551 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
552 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
553 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
554 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
555 // complex modes |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
556 |
98 | 557 DEAD static |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
558 void |
7 | 559 commandline_iremap(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
560 { |
7 | 561 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
562 /* XXX */ |
6 | 563 (void)str; |
143 | 564 complain(NULL, "-iremap not supported"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
565 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
566 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
567 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
568 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
569 void |
7 | 570 commandline_tabstop(const struct place *p, char *s) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
571 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
572 char *t; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
573 unsigned long val; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
574 |
7 | 575 (void)p; |
6 | 576 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
577 t = strchr(s, '='); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
578 if (t == NULL) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
579 /* should not happen */ |
143 | 580 complain(NULL, "Invalid tabstop"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
581 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
582 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
583 t++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
584 errno = 0; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
585 val = strtoul(t, &t, 10); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
586 if (errno || *t != '\0') { |
143 | 587 complain(NULL, "Invalid tabstop"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
588 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
589 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
590 if (val > 64) { |
143 | 591 complain(NULL, "Preposterously large tabstop"); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
592 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
593 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
594 mode.input_tabstop = val; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
597 /* |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
598 * macrolist |
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_dD(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 = false; |
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 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
611 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
612 commandline_dM(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
613 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
614 mode.do_macrolist = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
615 mode.macrolist_include_stddef = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
616 mode.macrolist_include_expansions = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
617 mode.do_output = 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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
621 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
622 commandline_dN(void) |
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 mode.do_macrolist = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
625 mode.macrolist_include_stddef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
626 mode.macrolist_include_expansions = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
629 /* |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
630 * include trace |
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_dI(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 = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
639 mode.trace_indented = false; |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
643 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
644 commandline_H(void) |
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 mode.do_trace = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
647 mode.trace_namesonly = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
648 mode.trace_indented = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
649 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
650 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
651 /* |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
652 * depend |
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(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 = false; |
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_setdependtarget_quoted(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_target = str; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
670 mode.depend_quote_target = true; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
673 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
674 void |
7 | 675 commandline_setdependoutput(const struct place *p, char *str) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
676 { |
7 | 677 (void)p; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
678 mode.depend_file = str; |
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_M(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 = true; |
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_MM(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 = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
696 mode.do_output = false; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
699 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
700 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
701 commandline_MD(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
702 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
703 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
704 mode.depend_report_system = true; |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
707 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
708 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
709 commandline_MMD(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
710 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
711 mode.do_depend = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
712 mode.depend_report_system = false; |
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_wall(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 = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
720 warns.undef = true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
721 warns.unused = true; |
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_wnoall(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.undef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
730 warns.unused = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
731 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
734 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
735 commandline_wnone(void) |
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 warns.nestcomment = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
738 warns.endiflabels = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
739 warns.undef = false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
740 warns.unused = false; |
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 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
744 // options |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
745 |
141 | 746 struct ignore_option { |
747 const char *string; | |
748 }; | |
749 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
750 struct flag_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
751 const char *string; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
752 bool *flag; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
753 bool setto; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
754 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
755 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
756 struct act_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
757 const char *string; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
758 void (*func)(void); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
759 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
760 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
761 struct prefix_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
762 const char *string; |
7 | 763 void (*func)(const struct place *, char *); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
764 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
765 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
766 struct arg_option { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
767 const char *string; |
7 | 768 void (*func)(const struct place *, char *); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
769 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
770 |
141 | 771 static const struct ignore_option ignore_options[] = { |
772 { "m32" }, | |
773 { "traditional" }, | |
774 }; | |
775 static const unsigned num_ignore_options = HOWMANY(ignore_options); | |
776 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
777 static const struct flag_option flag_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
778 { "C", &mode.output_retain_comments, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
779 { "CC", &mode.output_retain_comments, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
780 { "MG", &mode.depend_assume_generated, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
781 { "MP", &mode.depend_issue_fakerules, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
782 { "P", &mode.output_linenumbers, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
783 { "Wcomment", &warns.nestcomment, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
784 { "Wendif-labels", &warns.endiflabels, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
785 { "Werror", &mode.werror, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
786 { "Wno-comment", &warns.nestcomment, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
787 { "Wno-endif-labels", &warns.endiflabels, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
788 { "Wno-error", &mode.werror, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
789 { "Wno-undef", &warns.undef, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
790 { "Wno-unused-macros", &warns.unused, false }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
791 { "Wundef", &warns.undef, true }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
792 { "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
|
793 { "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
|
794 { "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
|
795 { "nostdinc", &mode.do_stdinc, false }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
796 { "undef", &mode.do_stddef, false }, |
4
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 unsigned num_flag_options = HOWMANY(flag_options); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
799 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
800 static const struct act_option act_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
801 { "H", commandline_H }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
802 { "M", commandline_M }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
803 { "MD", commandline_MD }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
804 { "MM", commandline_MM }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
805 { "MMD", commandline_MMD }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
806 { "Wall", commandline_wall }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
807 { "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
|
808 { "dD", commandline_dD }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
809 { "dI", commandline_dI }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
810 { "dM", commandline_dM }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
811 { "dN", commandline_dN }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
812 { "w", commandline_wnone }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
813 }; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
814 static const unsigned num_act_options = HOWMANY(act_options); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
815 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
816 static const struct prefix_option prefix_options[] = { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
817 { "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
|
818 { "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
|
819 { "U", commandline_undef }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
820 { "ftabstop=", commandline_tabstop }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
821 { "std=", commandline_setstd }, |
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_prefix_options = HOWMANY(prefix_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 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
|
826 { "MF", commandline_setdependoutput }, |
70902cac4170
Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents:
30
diff
changeset
|
827 { "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
|
828 { "MT", commandline_setdependtarget }, |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
829 { "idirafter", commandline_addincpath_late }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
830 { "imacros", commandline_addfile_nooutput }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
831 { "include", commandline_addfile_output }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
832 { "iprefix", commandline_setprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
833 { "iquote", commandline_addincpath_quote }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
834 { "iremap", commandline_iremap }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
835 { "isysroot", commandline_isysroot }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
836 { "isystem", commandline_addincpath_system }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
837 { "iwithprefix", commandline_addincpath_late_withprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
838 { "iwithprefixbefore", commandline_addincpath_user_withprefix }, |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
839 { "x", commandline_setlang }, |
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 static const unsigned num_arg_options = HOWMANY(arg_options); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
842 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
843 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
844 bool |
141 | 845 check_ignore_option(const char *opt) |
846 { | |
847 unsigned i; | |
848 int r; | |
849 | |
850 for (i=0; i<num_ignore_options; i++) { | |
851 r = strcmp(opt, ignore_options[i].string); | |
852 if (r == 0) { | |
853 return true; | |
854 } | |
855 if (r < 0) { | |
856 break; | |
857 } | |
858 } | |
859 return false; | |
860 } | |
861 | |
862 static | |
863 bool | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
864 check_flag_option(const char *opt) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
865 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
866 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
867 int r; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
868 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
869 for (i=0; i<num_flag_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
870 r = strcmp(opt, flag_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
871 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
872 *flag_options[i].flag = flag_options[i].setto; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
873 return true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
874 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
875 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
876 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
877 } |
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 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
880 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
883 bool |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
884 check_act_option(const char *opt) |
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 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
887 int r; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
888 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
889 for (i=0; i<num_act_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
890 r = strcmp(opt, act_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
891 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
892 act_options[i].func(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
893 return true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
894 } |
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 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
897 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
898 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
899 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
900 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
901 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
902 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
903 bool |
7 | 904 check_prefix_option(const struct place *p, char *opt) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
905 { |
44
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
906 unsigned i, len; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
907 int r; |
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 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
|
910 len = strlen(prefix_options[i].string); |
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
911 r = strncmp(opt, prefix_options[i].string, len); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
912 if (r == 0) { |
44
57e0c7a50b2d
Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents:
43
diff
changeset
|
913 prefix_options[i].func(p, opt + len); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
914 return true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
915 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
916 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
917 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
918 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
919 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
920 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
921 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
922 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
923 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
924 bool |
7 | 925 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
|
926 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
927 unsigned i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
928 int r; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
929 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
930 for (i=0; i<num_arg_options; i++) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
931 r = strcmp(opt, arg_options[i].string); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
932 if (r == 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
933 if (arg == NULL) { |
143 | 934 complain(NULL, |
935 "Option -%s requires an argument", | |
936 opt); | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
937 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
938 } |
7 | 939 arg_options[i].func(argplace, arg); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
940 return true; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
941 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
942 if (r < 0) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
943 break; |
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 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
946 return false; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
947 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
948 |
150 | 949 DEAD PF(2, 3) static |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
950 void |
142 | 951 usage(const char *progname, const char *fmt, ...) |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
952 { |
137 | 953 va_list ap; |
105
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
954 |
137 | 955 fprintf(stderr, "%s: ", progname); |
956 va_start(ap, fmt); | |
957 vfprintf(stderr, fmt, ap); | |
958 va_end(ap); | |
959 fprintf(stderr, "\n"); | |
960 | |
105
600f36cd7353
don't use getprogname() in the name of portability
David A. Holland
parents:
98
diff
changeset
|
961 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
962 fprintf(stderr, "Common options:\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
963 fprintf(stderr, " -C Retain comments\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
964 fprintf(stderr, " -Dmacro[=def] Predefine macro\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
965 fprintf(stderr, " -Idir Add to include path\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
966 fprintf(stderr, " -M Issue depend info\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
967 fprintf(stderr, " -MD Issue depend info and output\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
968 fprintf(stderr, " -MM -M w/o system headers\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
969 fprintf(stderr, " -MMD -MD w/o system headers\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
970 fprintf(stderr, " -nostdinc Drop default include path\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
971 fprintf(stderr, " -Umacro Undefine macro\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
972 fprintf(stderr, " -undef Undefine everything\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
973 fprintf(stderr, " -Wall Enable all warnings\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
974 fprintf(stderr, " -Werror Make warnings into errors\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
975 fprintf(stderr, " -w Disable all warnings\n"); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
976 die(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
977 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
978 |
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 // exit and cleanup |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
981 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
982 static struct stringarray freestrings; |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
985 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
986 init(void) |
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 stringarray_init(&freestrings); |
6 | 989 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
990 incpath_init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
991 commandline_macros_init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
992 commandline_files_init(); |
6 | 993 |
10 | 994 place_init(); |
6 | 995 files_init(); |
15 | 996 directive_init(); |
17 | 997 macros_init(); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
998 } |
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 static |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1001 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1002 cleanup(void) |
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 unsigned i, num; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1005 |
17 | 1006 macros_cleanup(); |
15 | 1007 directive_cleanup(); |
6 | 1008 files_cleanup(); |
10 | 1009 place_cleanup(); |
6 | 1010 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1011 commandline_files_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1012 commandline_macros_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1013 incpath_cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1014 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1015 num = stringarray_num(&freestrings); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1016 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
|
1017 dostrfree(stringarray_get(&freestrings, i)); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1018 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1019 stringarray_setsize(&freestrings, 0); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1020 stringarray_cleanup(&freestrings); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1023 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1024 die(void) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1025 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1026 cleanup(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1027 exit(EXIT_FAILURE); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1028 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1029 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1030 void |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1031 freestringlater(char *s) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1032 { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1033 stringarray_add(&freestrings, s, NULL); |
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 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1036 //////////////////////////////////////////////////////////// |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1037 // main |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1038 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1039 int |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1040 main(int argc, char *argv[]) |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1041 { |
142 | 1042 const char *progname; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1043 const char *inputfile = NULL; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1044 const char *outputfile = NULL; |
11 | 1045 struct place cmdplace; |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1046 unsigned builtin_counter; |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1047 int i; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1048 |
142 | 1049 progname = strrchr(argv[0], '/'); |
1050 progname = progname == NULL ? argv[0] : progname + 1; | |
1051 complain_init(progname); | |
1052 | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1053 init(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1054 |
7 | 1055 for (i=1; i<argc; i++) { |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1056 if (argv[i][0] != '-') { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1057 break; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1058 } |
14 | 1059 place_setcommandline(&cmdplace, i, 1); |
141 | 1060 if (check_ignore_option(argv[i]+1)) { |
1061 continue; | |
1062 } | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1063 if (check_flag_option(argv[i]+1)) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1064 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1065 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1066 if (check_act_option(argv[i]+1)) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1067 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1068 } |
11 | 1069 if (check_prefix_option(&cmdplace, argv[i]+1)) { |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1070 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1071 } |
14 | 1072 place_setcommandline(&cmdplace, i+1, 1); |
11 | 1073 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
|
1074 i++; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1075 continue; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1076 } |
142 | 1077 usage(progname, "Invalid option %s", argv[i]); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1078 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1079 if (i < argc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1080 inputfile = argv[i++]; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1081 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1082 if (i < argc) { |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1083 outputfile = argv[i++]; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1084 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1085 if (i < argc) { |
142 | 1086 usage(progname, "Extra non-option argument %s", argv[i]); |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1087 } |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1088 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1089 mode.output_file = outputfile; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1090 |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1091 loadincludepath(); |
159
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1092 |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1093 builtin_counter = 0; |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1094 apply_special_macros(&builtin_counter); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1095 apply_builtin_macros(&builtin_counter); |
8cef6d7227a8
Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents:
150
diff
changeset
|
1096 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1097 apply_commandline_macros(); |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1098 read_commandline_files(); |
11 | 1099 place_setnowhere(&cmdplace); |
1100 file_readabsolute(&cmdplace, inputfile); | |
7 | 1101 |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1102 cleanup(); |
6 | 1103 if (complain_failed()) { |
1104 return EXIT_FAILURE; | |
1105 } | |
4
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1106 return EXIT_SUCCESS; |
ee9a66b87c70
Initial version of toplevel and options handling.
David A. Holland
parents:
diff
changeset
|
1107 } |