annotate main.c @ 208:f6f2c7a9d7d8

also recognize __riscv128__, may as well.
author David A. Holland
date Mon, 21 Jan 2019 21:41:38 -0500
parents 3a25180d3a5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
1 /*-
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
2 * Copyright (c) 2010 The NetBSD Foundation, Inc.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
3 * All rights reserved.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
4 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
5 * This code is derived from software contributed to The NetBSD Foundation
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
6 * by David A. Holland.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
7 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
8 * Redistribution and use in source and binary forms, with or without
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
9 * modification, are permitted provided that the following conditions
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
10 * are met:
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
11 * 1. Redistributions of source code must retain the above copyright
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
12 * notice, this list of conditions and the following disclaimer.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
14 * notice, this list of conditions and the following disclaimer in the
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
15 * documentation and/or other materials provided with the distribution.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
16 *
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
27 * POSSIBILITY OF SUCH DAMAGE.
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
28 */
76c114899f63 copyrights
David A. Holland
parents: 18
diff changeset
29
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
30 #include <stdio.h>
140
904f7a9827e3 add missing stdarg.h.
David A. Holland
parents: 137
diff changeset
31 #include <stdarg.h>
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
32 #include <stdlib.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
33 #include <string.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
34 #include <errno.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
35
183
4c3375895c6e Don't use <stdbool.h> unless __STDC__ is large enough.
David A. Holland
parents: 182
diff changeset
36 #include "bool.h"
4
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
97243badae69 split place stuff to its own file
David A. Holland
parents: 7
diff changeset
42 #include "place.h"
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
43 #include "files.h"
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
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,
185
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 183
diff changeset
58 .output_cheaplinenumbers = false,
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
59 .output_retain_comments = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
60 .output_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
61
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
62 .do_depend = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
63 .depend_report_system = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
64 .depend_assume_generated = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
65 .depend_issue_fakerules = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
66 .depend_quote_target = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
67 .depend_target = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
68 .depend_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
69
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
70 .do_macrolist = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
71 .macrolist_include_stddef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
72 .macrolist_include_expansions = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
73
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
74 .do_trace = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
75 .trace_namesonly = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
76 .trace_indented = false,
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
79 struct warns warns = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
80 .endiflabels = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
81 .nestcomment = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
82 .undef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
83 .unused = false,
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 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
87 // commandline macros
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
88
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
89 struct commandline_macro {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
90 struct place where;
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
91 struct place where2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
92 const char *macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
93 const char *expansion;
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
96 static struct array commandline_macros;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
97
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
98 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
99 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
100 commandline_macros_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
101 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
102 array_init(&commandline_macros);
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
105 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
106 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
107 commandline_macros_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
108 {
135
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
109 unsigned i, num;
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
110 struct commandline_macro *cm;
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
111
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
112 num = array_num(&commandline_macros);
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
113 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
114 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
115 dofree(cm, sizeof(*cm));
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
116 }
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
117 array_setsize(&commandline_macros, 0);
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
118
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
119 array_cleanup(&commandline_macros);
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
122 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
123 void
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
124 commandline_macro_add(const struct place *p, const char *macro,
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
125 const struct place *p2, const char *expansion)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
126 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
127 struct commandline_macro *cm;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
128
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
129 cm = domalloc(sizeof(*cm));
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
130 cm->where = *p;
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
131 cm->where2 = *p2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
132 cm->macro = macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
133 cm->expansion = expansion;
86
70d7ebeb4523 Erm. Don't throw away -D args.
David A. Holland
parents: 71
diff changeset
134
70d7ebeb4523 Erm. Don't throw away -D args.
David A. Holland
parents: 71
diff changeset
135 array_add(&commandline_macros, cm, NULL);
4
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
138 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
139 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
140 commandline_def(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
141 {
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
142 struct place p2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
143 char *val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
144
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
145 if (*str == '\0') {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
146 complain(NULL, "-D: macro name expected");
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
147 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
148 }
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
149
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
150 val = strchr(str, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
151 if (val != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
152 *val = '\0';
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
153 val++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
154 }
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
155
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
156 if (val) {
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
157 p2 = *p;
203
3a25180d3a5c Abort on line numbering or column numbering overflow.
David A. Holland
parents: 199
diff changeset
158 place_addcolumns(&p2, strlen(str));
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
159 } else {
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
160 place_setbuiltin(&p2, 1);
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
161 }
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
162 commandline_macro_add(p, str, &p2, val ? val : "1");
4
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
165 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
166 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
167 commandline_undef(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
168 {
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
169 if (*str == '\0') {
197
f5981d0ee2b4 fix typo in error message; noted by Joerg
David A. Holland
parents: 193
diff changeset
170 complain(NULL, "-U: macro name expected");
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
171 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
172 }
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
173 commandline_macro_add(p, str, p, NULL);
4
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
176 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
177 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
178 apply_commandline_macros(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
179 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
180 struct commandline_macro *cm;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
181 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
182
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
183 num = array_num(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
184 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
185 cm = array_get(&commandline_macros, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
186 if (cm->expansion != NULL) {
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
187 macro_define_plain(&cm->where, cm->macro,
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
188 &cm->where2, cm->expansion);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
189 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
190 macro_undef(cm->macro);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
191 }
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
192 dofree(cm, sizeof(*cm));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
193 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
194 array_setsize(&commandline_macros, 0);
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
197 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
198 void
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
199 apply_magic_macro(unsigned num, const char *name)
159
8cef6d7227a8 Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents: 150
diff changeset
200 {
8cef6d7227a8 Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents: 150
diff changeset
201 struct place p;
8cef6d7227a8 Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents: 150
diff changeset
202
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
203 place_setbuiltin(&p, num);
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
204 macro_define_magic(&p, name);
159
8cef6d7227a8 Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents: 150
diff changeset
205 }
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 static
8cef6d7227a8 Expand __FILE__ and __LINE__.
Joerg Sonnenberger <joerg@bec.de>
parents: 150
diff changeset
208 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
209 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
210 {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
211 struct place p;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
212
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
213 place_setbuiltin(&p, num);
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
214 macro_define_plain(&p, name, &p, val);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
215 }
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
218 void
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
219 apply_builtin_macros(void)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
220 {
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
221 unsigned n = 1;
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
222
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
223 apply_magic_macro(n++, "__FILE__");
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
224 apply_magic_macro(n++, "__LINE__");
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
225
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
226 #ifdef CONFIG_OS
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
227 apply_builtin_macro(n++, CONFIG_OS, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
228 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
229 #ifdef CONFIG_OS_2
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
230 apply_builtin_macro(n++, CONFIG_OS_2, "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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
233 #ifdef CONFIG_CPU
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
234 apply_builtin_macro(n++, CONFIG_CPU, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
235 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
236 #ifdef CONFIG_CPU_2
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
237 apply_builtin_macro(n++, CONFIG_CPU_2, "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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
240 #ifdef CONFIG_SIZE
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
241 apply_builtin_macro(n++, CONFIG_SIZE, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
242 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
243 #ifdef CONFIG_BINFMT
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
244 apply_builtin_macro(n++, CONFIG_BINFMT, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
245 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
246
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
247 #ifdef CONFIG_COMPILER
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
248 apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR);
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
249 apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR);
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
250 apply_builtin_macro(n++, "__VERSION__", VERSION_LONG);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
251 #endif
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
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 // extra included files
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
256
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
257 struct commandline_file {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
258 struct place where;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
259 char *name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
260 bool suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
261 };
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 struct array commandline_files;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
264
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
265 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
266 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
267 commandline_files_init(void)
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 array_init(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
270 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
271
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
272 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
273 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
274 commandline_files_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
275 {
135
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
276 unsigned i, num;
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
277 struct commandline_file *cf;
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
278
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
279 num = array_num(&commandline_files);
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
280 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
281 cf = array_get(&commandline_files, i);
136
59680a727e9d Improve previous.
David A. Holland
parents: 135
diff changeset
282 if (cf != NULL) {
59680a727e9d Improve previous.
David A. Holland
parents: 135
diff changeset
283 dofree(cf, sizeof(*cf));
59680a727e9d Improve previous.
David A. Holland
parents: 135
diff changeset
284 }
135
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
285 }
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
286 array_setsize(&commandline_files, 0);
eaae8014a94a Don't assert and leak memory if failing during argument collection.
David A. Holland
parents: 122
diff changeset
287
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
288 array_cleanup(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
289 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
290
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
291 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
292 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
293 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
294 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
295 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
296
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
297 cf = domalloc(sizeof(*cf));
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
298 cf->where = *p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
299 cf->name = name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
300 cf->suppress_output = suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
301 array_add(&commandline_files, cf, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
302 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
303
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
304 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
305 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
306 commandline_addfile_output(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
307 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
308 commandline_addfile(p, name, false);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
309 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
310
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
311 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
312 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
313 commandline_addfile_nooutput(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
314 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
315 commandline_addfile(p, name, true);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
316 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
317
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
318 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
319 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
320 read_commandline_files(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
321 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
322 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
323 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
324 bool save = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
325
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
326 num = array_num(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
327 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
328 cf = array_get(&commandline_files, i);
136
59680a727e9d Improve previous.
David A. Holland
parents: 135
diff changeset
329 array_set(&commandline_files, i, NULL);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
330 if (cf->suppress_output) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
331 save = mode.do_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
332 mode.do_output = false;
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
333 file_readquote(&cf->where, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
334 mode.do_output = save;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
335 } else {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
336 file_readquote(&cf->where, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
337 }
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
338 dofree(cf, sizeof(*cf));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
339 }
5
7c489c73d62b Clear commandline_files after processing it.
David A. Holland
parents: 4
diff changeset
340 array_setsize(&commandline_files, 0);
4
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
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 // include path accumulation
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
345
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
346 static struct stringarray incpath_quote;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
347 static struct stringarray incpath_user;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
348 static struct stringarray incpath_system;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
349 static struct stringarray incpath_late;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
350 static const char *sysroot;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
351
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
352 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
353 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
354 incpath_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
355 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
356 stringarray_init(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
357 stringarray_init(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
358 stringarray_init(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
359 stringarray_init(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
360 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
361
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
362 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
363 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
364 incpath_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
365 {
37
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_quote, 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_user, 0);
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
368 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
369 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
370
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
371 stringarray_cleanup(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
372 stringarray_cleanup(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
373 stringarray_cleanup(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
374 stringarray_cleanup(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
375 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
376
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
377 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
378 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
379 commandline_isysroot(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
380 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
381 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
382 sysroot = dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
383 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
384
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
385 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
386 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
387 commandline_addincpath(struct stringarray *arr, char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
388 {
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
389 if (*s == '\0') {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
390 complain(NULL, "Empty include directory");
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
391 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
392 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
393 stringarray_add(arr, s, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
394 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
395
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
396 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
397 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
398 commandline_addincpath_quote(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
399 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
400 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
401 commandline_addincpath(&incpath_quote, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
402 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
403
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
404 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
405 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
406 commandline_addincpath_user(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
407 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
408 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
409 commandline_addincpath(&incpath_user, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
410 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
411
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
412 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
413 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
414 commandline_addincpath_system(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
415 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
416 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
417 commandline_addincpath(&incpath_system, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
418 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
419
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
420 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
421 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
422 commandline_addincpath_late(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
423 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
424 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
425 commandline_addincpath(&incpath_late, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
426 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
427
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
428 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
429 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
430 loadincludepath(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
431 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
432 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
433 const char *dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
434 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
435
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
436 num = stringarray_num(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
437 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
438 dir = stringarray_get(&incpath_quote, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
439 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
440 }
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 105
diff changeset
441 files_addquotepath(NULL, false);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
442
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
443 num = stringarray_num(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
444 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
445 dir = stringarray_get(&incpath_user, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
446 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
447 files_addbracketpath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
448 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
449
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
450 if (mode.do_stdinc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
451 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
452 t = dostrdup3(sysroot, "/", CONFIG_LOCALINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
453 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
454 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
455 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
456 dir = CONFIG_LOCALINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
457 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
458 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
459 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
460
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
461 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
462 t = dostrdup3(sysroot, "/", CONFIG_SYSTEMINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
463 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
464 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
465 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
466 dir = CONFIG_SYSTEMINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
467 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
468 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
469 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
470 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
471
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
472 num = stringarray_num(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
473 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
474 dir = stringarray_get(&incpath_system, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
475 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
476 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
477 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
478
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
479 num = stringarray_num(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
480 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
481 dir = stringarray_get(&incpath_late, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
482 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
483 files_addbracketpath(dir, false);
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
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 // silly commandline stuff
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 const char *commandline_prefix;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
491
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
492 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
493 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
494 commandline_setprefix(const struct place *p, char *prefix)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
495 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
496 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
497 commandline_prefix = prefix;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
498 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
499
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
500 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
501 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
502 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
503 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
504 char *s;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
505
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
506 if (commandline_prefix == NULL) {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
507 complain(NULL, "-iprefix needed");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
508 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
509 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
510 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
511 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
512 commandline_addincpath_user(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
513 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
514
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
515 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
516 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
517 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
518 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
519 char *s;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
520
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
521 if (commandline_prefix == NULL) {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
522 complain(NULL, "-iprefix needed");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
523 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
524 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
525 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
526 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
527 commandline_addincpath_late(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
528 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
529
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
530 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
531 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
532 commandline_setstd(const struct place *p, char *std)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
533 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
534 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
535
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
536 if (!strcmp(std, "krc")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
537 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
538 }
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
539 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
540 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
541 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
542
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
543 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
544 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
545 commandline_setlang(const struct place *p, char *lang)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
546 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
547 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
548
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
549 if (!strcmp(lang, "c") || !strcmp(lang, "assembler-with-cpp")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
550 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
551 }
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
552 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
553 die();
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
556 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
557 // complex modes
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
558
98
51848a7584e0 __dead -> DEAD
David A. Holland
parents: 86
diff changeset
559 DEAD static
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
560 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
561 commandline_iremap(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
562 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
563 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
564 /* XXX */
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
565 (void)str;
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
566 complain(NULL, "-iremap not supported");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
567 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
568 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
569
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
570 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
571 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
572 commandline_tabstop(const struct place *p, char *s)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
573 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
574 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
575 unsigned long val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
576
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
577 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
578
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
579 t = strchr(s, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
580 if (t == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
581 /* should not happen */
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
582 complain(NULL, "Invalid tabstop");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
583 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
584 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
585 t++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
586 errno = 0;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
587 val = strtoul(t, &t, 10);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
588 if (errno || *t != '\0') {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
589 complain(NULL, "Invalid tabstop");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
590 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
591 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
592 if (val > 64) {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
593 complain(NULL, "Preposterously large tabstop");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
594 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
595 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
596 mode.input_tabstop = val;
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
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 * macrolist
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
601 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
602
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
603 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
604 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
605 commandline_dD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
606 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
607 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
608 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
609 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
610 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
611
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
612 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
613 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
614 commandline_dM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
615 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
616 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
617 mode.macrolist_include_stddef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
618 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
619 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
620 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
621
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
622 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
623 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
624 commandline_dN(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
625 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
626 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
627 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
628 mode.macrolist_include_expansions = false;
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
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 * include trace
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
633 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
634
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
635 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
636 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
637 commandline_dI(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
638 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
639 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
640 mode.trace_namesonly = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
641 mode.trace_indented = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
642 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
643
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
644 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
645 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
646 commandline_H(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
647 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
648 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
649 mode.trace_namesonly = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
650 mode.trace_indented = true;
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
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 * depend
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
655 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
656
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
657 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
658 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
659 commandline_setdependtarget(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
660 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
661 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
662 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
663 mode.depend_quote_target = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
664 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
665
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
666 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
667 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
668 commandline_setdependtarget_quoted(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
669 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
670 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
671 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
672 mode.depend_quote_target = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
673 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
674
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
675 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
676 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
677 commandline_setdependoutput(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
678 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
679 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
680 mode.depend_file = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
681 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
682
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
683 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
684 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
685 commandline_M(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
686 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
687 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
688 mode.depend_report_system = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
689 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
690 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
691
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
692 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
693 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
694 commandline_MM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
695 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
696 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
697 mode.depend_report_system = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
698 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
699 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
700
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
701 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
702 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
703 commandline_MD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
704 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
705 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
706 mode.depend_report_system = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
707 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
708
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
709 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
710 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
711 commandline_MMD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
712 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
713 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
714 mode.depend_report_system = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
715 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
716
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
717 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
718 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
719 commandline_wall(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
720 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
721 warns.nestcomment = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
722 warns.undef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
723 warns.unused = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
724 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
725
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
726 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
727 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
728 commandline_wnoall(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
729 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
730 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
731 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
732 warns.unused = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
733 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
734
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
735 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
736 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
737 commandline_wnone(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
738 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
739 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
740 warns.endiflabels = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
741 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
742 warns.unused = false;
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
745 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
746 // options
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
747
141
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
748 struct ignore_option {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
749 const char *string;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
750 };
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
751
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
752 struct flag_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
753 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
754 bool *flag;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
755 bool setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
756 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
757
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
758 struct act_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
759 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
760 void (*func)(void);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
761 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
762
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
763 struct prefix_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
764 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
765 void (*func)(const struct place *, char *);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
766 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
767
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
768 struct arg_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
769 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
770 void (*func)(const struct place *, char *);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
771 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
772
141
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
773 static const struct ignore_option ignore_options[] = {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
774 { "m32" },
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
775 { "traditional" },
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
776 };
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
777 static const unsigned num_ignore_options = HOWMANY(ignore_options);
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
778
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
779 static const struct flag_option flag_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
780 { "C", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
781 { "CC", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
782 { "MG", &mode.depend_assume_generated, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
783 { "MP", &mode.depend_issue_fakerules, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
784 { "P", &mode.output_linenumbers, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
785 { "Wcomment", &warns.nestcomment, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
786 { "Wendif-labels", &warns.endiflabels, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
787 { "Werror", &mode.werror, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
788 { "Wno-comment", &warns.nestcomment, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
789 { "Wno-endif-labels", &warns.endiflabels, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
790 { "Wno-error", &mode.werror, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
791 { "Wno-undef", &warns.undef, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
792 { "Wno-unused-macros", &warns.unused, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
793 { "Wundef", &warns.undef, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
794 { "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
795 { "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
796 { "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
797 { "nostdinc", &mode.do_stdinc, false },
193
079304130850 the option lists need to stay sorted.
David A. Holland
parents: 185
diff changeset
798 { "p", &mode.output_cheaplinenumbers, true },
37
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
799 { "undef", &mode.do_stddef, false },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
800 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
801 static const unsigned num_flag_options = HOWMANY(flag_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
802
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
803 static const struct act_option act_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
804 { "H", commandline_H },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
805 { "M", commandline_M },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
806 { "MD", commandline_MD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
807 { "MM", commandline_MM },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
808 { "MMD", commandline_MMD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
809 { "Wall", commandline_wall },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
810 { "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
811 { "dD", commandline_dD },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
812 { "dI", commandline_dI },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
813 { "dM", commandline_dM },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
814 { "dN", commandline_dN },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
815 { "w", commandline_wnone },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
816 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
817 static const unsigned num_act_options = HOWMANY(act_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
818
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
819 static const struct prefix_option prefix_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
820 { "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
821 { "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
822 { "U", commandline_undef },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
823 { "ftabstop=", commandline_tabstop },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
824 { "std=", commandline_setstd },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
825 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
826 static const unsigned num_prefix_options = HOWMANY(prefix_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
827
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
828 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
829 { "MF", commandline_setdependoutput },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
830 { "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
831 { "MT", commandline_setdependtarget },
199
1d2bad7151f9 Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents: 197
diff changeset
832 { "debuglog", debuglog_open },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
833 { "idirafter", commandline_addincpath_late },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
834 { "imacros", commandline_addfile_nooutput },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
835 { "include", commandline_addfile_output },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
836 { "iprefix", commandline_setprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
837 { "iquote", commandline_addincpath_quote },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
838 { "iremap", commandline_iremap },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
839 { "isysroot", commandline_isysroot },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
840 { "isystem", commandline_addincpath_system },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
841 { "iwithprefix", commandline_addincpath_late_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
842 { "iwithprefixbefore", commandline_addincpath_user_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
843 { "x", commandline_setlang },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
844 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
845 static const unsigned num_arg_options = HOWMANY(arg_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
846
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
847 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
848 bool
141
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
849 check_ignore_option(const char *opt)
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
850 {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
851 unsigned i;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
852 int r;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
853
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
854 for (i=0; i<num_ignore_options; i++) {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
855 r = strcmp(opt, ignore_options[i].string);
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
856 if (r == 0) {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
857 return true;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
858 }
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
859 if (r < 0) {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
860 break;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
861 }
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
862 }
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
863 return false;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
864 }
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
865
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
866 static
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
867 bool
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
868 check_flag_option(const char *opt)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
869 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
870 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
871 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
872
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
873 for (i=0; i<num_flag_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
874 r = strcmp(opt, flag_options[i].string);
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 *flag_options[i].flag = flag_options[i].setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
877 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
878 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
879 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
880 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
881 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
882 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
883 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
884 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
885
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
886 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
887 bool
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
888 check_act_option(const char *opt)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
889 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
890 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
891 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
892
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
893 for (i=0; i<num_act_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
894 r = strcmp(opt, act_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
895 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
896 act_options[i].func();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
897 return true;
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 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
900 break;
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 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
903 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
904 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
905
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
906 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
907 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
908 check_prefix_option(const struct place *p, char *opt)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
909 {
44
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
910 unsigned i, len;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
911 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
912
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
913 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
914 len = strlen(prefix_options[i].string);
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
915 r = strncmp(opt, prefix_options[i].string, len);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
916 if (r == 0) {
44
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
917 prefix_options[i].func(p, opt + len);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
918 return true;
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 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
921 break;
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 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
924 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
925 }
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
928 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
929 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
930 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
931 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
932 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
933
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
934 for (i=0; i<num_arg_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
935 r = strcmp(opt, arg_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
936 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
937 if (arg == NULL) {
143
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
938 complain(NULL,
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
939 "Option -%s requires an argument",
ed45f2d8d3bc Don't use the <err.h> functions.
David A. Holland
parents: 142
diff changeset
940 opt);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
941 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
942 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
943 arg_options[i].func(argplace, arg);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
944 return true;
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 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
947 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
948 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
949 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
950 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
951 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
952
150
1a7de2c68290 declare usage() with PF(). from wiz
David A. Holland
parents: 143
diff changeset
953 DEAD PF(2, 3) static
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
954 void
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
955 usage(const char *progname, const char *fmt, ...)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
956 {
137
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
957 va_list ap;
105
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
958
137
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
959 fprintf(stderr, "%s: ", progname);
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
960 va_start(ap, fmt);
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
961 vfprintf(stderr, fmt, ap);
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
962 va_end(ap);
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
963 fprintf(stderr, "\n");
0816803b22d1 Improve usage reporting.
David A. Holland
parents: 136
diff changeset
964
182
f7814226906c very minor changes from openbsd
David A. Holland
parents: 181
diff changeset
965 fprintf(stderr, "usage: %s [options] [infile [outfile]]\n", progname);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
966 fprintf(stderr, "Common options:\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
967 fprintf(stderr, " -C Retain comments\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
968 fprintf(stderr, " -Dmacro[=def] Predefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
969 fprintf(stderr, " -Idir Add to include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
970 fprintf(stderr, " -M Issue depend info\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
971 fprintf(stderr, " -MD Issue depend info and output\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
972 fprintf(stderr, " -MM -M w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
973 fprintf(stderr, " -MMD -MD w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
974 fprintf(stderr, " -nostdinc Drop default include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
975 fprintf(stderr, " -Umacro Undefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
976 fprintf(stderr, " -undef Undefine everything\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
977 fprintf(stderr, " -Wall Enable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
978 fprintf(stderr, " -Werror Make warnings into errors\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
979 fprintf(stderr, " -w Disable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
980 die();
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
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 // exit and cleanup
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
985
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
986 static struct stringarray freestrings;
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
989 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
990 init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
991 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
992 stringarray_init(&freestrings);
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
993
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
994 incpath_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
995 commandline_macros_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
996 commandline_files_init();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
997
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
998 place_init();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
999 files_init();
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
1000 directive_init();
17
76da41da923f added macro table
David A. Holland
parents: 15
diff changeset
1001 macros_init();
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1002 }
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1005 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1006 cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1007 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1008 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1009
17
76da41da923f added macro table
David A. Holland
parents: 15
diff changeset
1010 macros_cleanup();
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
1011 directive_cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1012 files_cleanup();
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
1013 place_cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1014
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1015 commandline_files_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1016 commandline_macros_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1017 incpath_cleanup();
199
1d2bad7151f9 Add a -debuglog option to send an execution trace to a file.
David A. Holland
parents: 197
diff changeset
1018 debuglog_close();
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1019
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1020 num = stringarray_num(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1021 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
1022 dostrfree(stringarray_get(&freestrings, i));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1023 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1024 stringarray_setsize(&freestrings, 0);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1025 stringarray_cleanup(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1026 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1027
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1028 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1029 die(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1030 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1031 cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1032 exit(EXIT_FAILURE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1033 }
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 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1036 freestringlater(char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1037 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1038 stringarray_add(&freestrings, s, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1039 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1040
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1041 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1042 // main
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1043
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1044 int
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1045 main(int argc, char *argv[])
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1046 {
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1047 const char *progname;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1048 const char *inputfile = NULL;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1049 const char *outputfile = NULL;
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1050 struct place cmdplace;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1051 int i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1052
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1053 progname = strrchr(argv[0], '/');
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1054 progname = progname == NULL ? argv[0] : progname + 1;
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1055 complain_init(progname);
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1056
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1057 init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1058
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
1059 for (i=1; i<argc; i++) {
181
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1060 if (argv[i][0] != '-' || argv[i][1] == 0) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1061 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1062 }
14
David A. Holland
parents: 11
diff changeset
1063 place_setcommandline(&cmdplace, i, 1);
141
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
1064 if (check_ignore_option(argv[i]+1)) {
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
1065 continue;
63414cddf09c Accept and ignore -m32.
David A. Holland
parents: 140
diff changeset
1066 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1067 if (check_flag_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1068 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1069 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1070 if (check_act_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1071 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1072 }
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1073 if (check_prefix_option(&cmdplace, argv[i]+1)) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1074 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1075 }
14
David A. Holland
parents: 11
diff changeset
1076 place_setcommandline(&cmdplace, i+1, 1);
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1077 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
1078 i++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1079 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1080 }
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1081 usage(progname, "Invalid option %s", argv[i]);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1082 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1083 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1084 inputfile = argv[i++];
181
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1085 if (!strcmp(inputfile, "-")) {
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1086 inputfile = NULL;
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1087 }
4
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 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1090 outputfile = argv[i++];
181
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1091 if (!strcmp(outputfile, "-")) {
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1092 outputfile = NULL;
44ea61019069 Accept "-" as the input file, or as the output file.
David A. Holland
parents: 172
diff changeset
1093 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1094 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1095 if (i < argc) {
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 141
diff changeset
1096 usage(progname, "Extra non-option argument %s", argv[i]);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1097 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1098
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1099 mode.output_file = outputfile;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1100
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1101 loadincludepath();
172
3e7e696fe558 Clean up the mess Joerg made of apply_builtin_macros().
David A. Holland
parents: 159
diff changeset
1102 apply_builtin_macros();
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1103 apply_commandline_macros();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1104 read_commandline_files();
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1105 place_setnowhere(&cmdplace);
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1106 file_readabsolute(&cmdplace, inputfile);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
1107
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1108 cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1109 if (complain_failed()) {
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1110 return EXIT_FAILURE;
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1111 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1112 return EXIT_SUCCESS;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1113 }