annotate main.c @ 122:64c4de3709de

Complain if -[DIU] is given an empty argument. (Like many compilers over the years, we don't accept the argument appearing in the next argv word.) Warn about this in the man page too.
author David A. Holland
date Tue, 11 Jun 2013 18:32:41 -0400
parents 2b0b61fd1a36
children eaae8014a94a
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 <stdbool.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
31 #include <stdio.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
32 #include <stdlib.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
33 #include <string.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
34 #include <errno.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
35 #include <err.h>
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
36
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
37 #include "version.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
38 #include "config.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
39 #include "utils.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
40 #include "array.h"
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
41 #include "mode.h"
8
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,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
58 .output_retain_comments = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
59 .output_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
60
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
61 .do_depend = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
62 .depend_report_system = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
63 .depend_assume_generated = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
64 .depend_issue_fakerules = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
65 .depend_quote_target = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
66 .depend_target = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
67 .depend_file = NULL,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
68
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
69 .do_macrolist = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
70 .macrolist_include_stddef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
71 .macrolist_include_expansions = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
72
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
73 .do_trace = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
74 .trace_namesonly = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
75 .trace_indented = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
76 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
77
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
78 struct warns warns = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
79 .endiflabels = true,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
80 .nestcomment = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
81 .undef = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
82 .unused = false,
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
83 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
84
71
dc63e70e425d Accept and ignore -traditional.
David A. Holland
parents: 44
diff changeset
85 /* this is always true, but can be set explicitly with -traditional */
dc63e70e425d Accept and ignore -traditional.
David A. Holland
parents: 44
diff changeset
86 static bool traditional = true;
dc63e70e425d Accept and ignore -traditional.
David A. Holland
parents: 44
diff changeset
87
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
88 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
89 // commandline macros
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
90
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
91 struct commandline_macro {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
92 struct place where;
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
93 struct place where2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
94 const char *macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
95 const char *expansion;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
96 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
97
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
98 static struct array commandline_macros;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
99
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
100 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
101 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
102 commandline_macros_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
103 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
104 array_init(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
105 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
106
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
107 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
108 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
109 commandline_macros_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
110 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
111 array_cleanup(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
112 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
113
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
114 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
115 void
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
116 commandline_macro_add(const struct place *p, const char *macro,
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
117 const struct place *p2, const char *expansion)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
118 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
119 struct commandline_macro *cm;
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 cm = domalloc(sizeof(*cm));
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
122 cm->where = *p;
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
123 cm->where2 = *p2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
124 cm->macro = macro;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
125 cm->expansion = expansion;
86
70d7ebeb4523 Erm. Don't throw away -D args.
David A. Holland
parents: 71
diff changeset
126
70d7ebeb4523 Erm. Don't throw away -D args.
David A. Holland
parents: 71
diff changeset
127 array_add(&commandline_macros, cm, NULL);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
128 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
129
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
130 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
131 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
132 commandline_def(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
133 {
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
134 struct place p2;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
135 char *val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
136
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
137 if (*str == '\0') {
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
138 warnx("-D: macro name expected");
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
139 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
140 }
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
141
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
142 val = strchr(str, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
143 if (val != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
144 *val = '\0';
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
145 val++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
146 }
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
147
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
148 if (val) {
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
149 p2 = *p;
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
150 p2.column += strlen(str);
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
151 } else {
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
152 place_setbuiltin(&p2, 1);
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
153 }
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
154 commandline_macro_add(p, str, &p2, val ? val : "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
155 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
156
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
157 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
158 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
159 commandline_undef(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
160 {
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
161 if (*str == '\0') {
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
162 warnx("-D: macro name expected");
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
163 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
164 }
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
165 commandline_macro_add(p, str, p, NULL);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
166 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
167
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
168 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
169 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
170 apply_commandline_macros(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
171 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
172 struct commandline_macro *cm;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
173 unsigned i, num;
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 num = array_num(&commandline_macros);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
176 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
177 cm = array_get(&commandline_macros, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
178 if (cm->expansion != NULL) {
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
179 macro_define_plain(&cm->where, cm->macro,
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
180 &cm->where2, cm->expansion);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
181 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
182 macro_undef(cm->macro);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
183 }
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
184 dofree(cm, sizeof(*cm));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
185 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
186 array_setsize(&commandline_macros, 0);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
187 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
188
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
189 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
190 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
191 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
192 {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
193 struct place p;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
194
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
195 place_setbuiltin(&p, num);
18
c08a947d8f30 deal with macro parameters
David A. Holland
parents: 17
diff changeset
196 macro_define_plain(&p, name, &p, val);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
197 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
198
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
199 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
200 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
201 apply_builtin_macros(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
202 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
203 unsigned n = 1;
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
204
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
205 #ifdef CONFIG_OS
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
206 apply_builtin_macro(n++, CONFIG_OS, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
207 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
208 #ifdef CONFIG_OS_2
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
209 apply_builtin_macro(n++, CONFIG_OS_2, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
210 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
211
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
212 #ifdef CONFIG_CPU
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
213 apply_builtin_macro(n++, CONFIG_CPU, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
214 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
215 #ifdef CONFIG_CPU_2
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
216 apply_builtin_macro(n++, CONFIG_CPU_2, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
217 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
218
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
219 #ifdef CONFIG_SIZE
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
220 apply_builtin_macro(n++, CONFIG_SIZE, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
221 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
222 #ifdef CONFIG_BINFMT
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
223 apply_builtin_macro(n++, CONFIG_BINFMT, "1");
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
224 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
225
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
226 #ifdef CONFIG_COMPILER
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
227 apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
228 apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR);
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
229 apply_builtin_macro(n++, "__VERSION__", VERSION_LONG);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
230 #endif
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
231 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
232
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
233 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
234 // extra included files
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
235
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
236 struct commandline_file {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
237 struct place where;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
238 char *name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
239 bool suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
240 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
241
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
242 static struct array commandline_files;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
243
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
244 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
245 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
246 commandline_files_init(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
247 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
248 array_init(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
249 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
250
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
251 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
252 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
253 commandline_files_cleanup(void)
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 array_cleanup(&commandline_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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
258 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
259 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
260 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
261 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
262 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
263
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
264 cf = domalloc(sizeof(*cf));
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
265 cf->where = *p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
266 cf->name = name;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
267 cf->suppress_output = suppress_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
268 array_add(&commandline_files, cf, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
269 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
270
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
271 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
272 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
273 commandline_addfile_output(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
274 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
275 commandline_addfile(p, name, false);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
276 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
277
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
278 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
279 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
280 commandline_addfile_nooutput(const struct place *p, char *name)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
281 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
282 commandline_addfile(p, name, true);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
283 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
284
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
285 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
286 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
287 read_commandline_files(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
288 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
289 struct commandline_file *cf;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
290 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
291 bool save = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
292
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
293 num = array_num(&commandline_files);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
294 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
295 cf = array_get(&commandline_files, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
296 if (cf->suppress_output) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
297 save = mode.do_output;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
298 mode.do_output = false;
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
299 file_readquote(&cf->where, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
300 mode.do_output = save;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
301 } else {
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
302 file_readquote(&cf->where, cf->name);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
303 }
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
304 dofree(cf, sizeof(*cf));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
305 }
5
7c489c73d62b Clear commandline_files after processing it.
David A. Holland
parents: 4
diff changeset
306 array_setsize(&commandline_files, 0);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
307 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
308
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
309 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
310 // include path accumulation
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
311
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
312 static struct stringarray incpath_quote;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
313 static struct stringarray incpath_user;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
314 static struct stringarray incpath_system;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
315 static struct stringarray incpath_late;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
316 static const char *sysroot;
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 incpath_init(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 stringarray_init(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
323 stringarray_init(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
324 stringarray_init(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
325 stringarray_init(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
326 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
327
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
328 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
329 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
330 incpath_cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
331 {
37
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
332 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
333 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
334 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
335 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
336
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
337 stringarray_cleanup(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
338 stringarray_cleanup(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
339 stringarray_cleanup(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
340 stringarray_cleanup(&incpath_late);
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
344 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
345 commandline_isysroot(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
346 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
347 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
348 sysroot = dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
349 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
350
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
351 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
352 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
353 commandline_addincpath(struct stringarray *arr, char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
354 {
122
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
355 if (*s == '\0') {
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
356 warnx("Empty include path");
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
357 die();
64c4de3709de Complain if -[DIU] is given an empty argument.
David A. Holland
parents: 112
diff changeset
358 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
359 stringarray_add(arr, s, NULL);
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
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
364 commandline_addincpath_quote(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
365 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
366 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
367 commandline_addincpath(&incpath_quote, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
368 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
369
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
370 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
371 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
372 commandline_addincpath_user(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
373 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
374 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
375 commandline_addincpath(&incpath_user, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
376 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
377
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
378 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
379 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
380 commandline_addincpath_system(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
381 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
382 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
383 commandline_addincpath(&incpath_system, dir);
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
386 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
387 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
388 commandline_addincpath_late(const struct place *p, char *dir)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
389 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
390 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
391 commandline_addincpath(&incpath_late, dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
392 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
393
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
394 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
395 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
396 loadincludepath(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
397 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
398 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
399 const char *dir;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
400 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
401
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
402 num = stringarray_num(&incpath_quote);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
403 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
404 dir = stringarray_get(&incpath_quote, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
405 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
406 }
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 105
diff changeset
407 files_addquotepath(NULL, false);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
408
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
409 num = stringarray_num(&incpath_user);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
410 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
411 dir = stringarray_get(&incpath_user, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
412 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
413 files_addbracketpath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
414 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
415
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
416 if (mode.do_stdinc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
417 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
418 t = dostrdup3(sysroot, "/", CONFIG_LOCALINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
419 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
420 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
421 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
422 dir = CONFIG_LOCALINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
423 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
424 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
425 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
426
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
427 if (sysroot != NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
428 t = dostrdup3(sysroot, "/", CONFIG_SYSTEMINCLUDE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
429 freestringlater(t);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
430 dir = t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
431 } else {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
432 dir = CONFIG_SYSTEMINCLUDE;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
433 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
434 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
435 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
436 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
437
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
438 num = stringarray_num(&incpath_system);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
439 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
440 dir = stringarray_get(&incpath_system, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
441 files_addquotepath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
442 files_addbracketpath(dir, true);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
443 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
444
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
445 num = stringarray_num(&incpath_late);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
446 for (i=0; i<num; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
447 dir = stringarray_get(&incpath_late, i);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
448 files_addquotepath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
449 files_addbracketpath(dir, false);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
450 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
451 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
452
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
453 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
454 // silly commandline stuff
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
455
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
456 static const char *commandline_prefix;
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 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
459 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
460 commandline_setprefix(const struct place *p, char *prefix)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
461 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
462 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
463 commandline_prefix = prefix;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
464 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
465
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
466 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
467 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
468 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
469 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
470 char *s;
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 if (commandline_prefix == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
473 warnx("-iprefix needed");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
474 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
475 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
476 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
477 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
478 commandline_addincpath_user(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
479 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
480
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
481 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
482 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
483 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
484 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
485 char *s;
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 if (commandline_prefix == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
488 warnx("-iprefix needed");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
489 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
490 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
491 s = dostrdup3(commandline_prefix, "/", dir);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
492 freestringlater(s);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
493 commandline_addincpath_late(p, s);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
494 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
495
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
496 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
497 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
498 commandline_setstd(const struct place *p, char *std)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
499 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
500 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
501
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
502 if (!strcmp(std, "krc")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
503 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
504 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
505 warnx("Standard %s not supported by this preprocessor", std);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
506 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
507 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
508
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
509 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
510 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
511 commandline_setlang(const struct place *p, char *lang)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
512 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
513 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
514
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
515 if (!strcmp(lang, "c") || !strcmp(lang, "assembler-with-cpp")) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
516 return;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
517 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
518 warnx("Language %s not supported by this preprocessor", lang);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
519 die();
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
522 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
523 // complex modes
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
524
98
51848a7584e0 __dead -> DEAD
David A. Holland
parents: 86
diff changeset
525 DEAD static
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
526 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
527 commandline_iremap(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
528 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
529 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
530 /* XXX */
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
531 (void)str;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
532 warnx("-iremap not supported");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
533 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
534 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
535
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
536 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
537 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
538 commandline_tabstop(const struct place *p, char *s)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
539 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
540 char *t;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
541 unsigned long val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
542
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
543 (void)p;
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
544
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
545 t = strchr(s, '=');
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
546 if (t == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
547 /* should not happen */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
548 warnx("Invalid tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
549 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
550 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
551 t++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
552 errno = 0;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
553 val = strtoul(t, &t, 10);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
554 if (errno || *t != '\0') {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
555 warnx("Invalid tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
556 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
557 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
558 if (val > 64) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
559 warnx("Preposterously large tabstop");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
560 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
561 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
562 mode.input_tabstop = val;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
563 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
564
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
565 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
566 * macrolist
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
567 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
568
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
569 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
570 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
571 commandline_dD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
572 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
573 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
574 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
575 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
576 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
577
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
578 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
579 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
580 commandline_dM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
581 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
582 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
583 mode.macrolist_include_stddef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
584 mode.macrolist_include_expansions = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
585 mode.do_output = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
586 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
587
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
588 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
589 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
590 commandline_dN(void)
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 mode.do_macrolist = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
593 mode.macrolist_include_stddef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
594 mode.macrolist_include_expansions = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
595 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
596
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
597 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
598 * include trace
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
599 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
600
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
601 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
602 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
603 commandline_dI(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
604 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
605 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
606 mode.trace_namesonly = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
607 mode.trace_indented = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
608 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
609
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
610 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
611 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
612 commandline_H(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
613 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
614 mode.do_trace = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
615 mode.trace_namesonly = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
616 mode.trace_indented = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
617 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
618
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
619 /*
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
620 * depend
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
621 */
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
622
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
623 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
624 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
625 commandline_setdependtarget(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
626 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
627 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
628 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
629 mode.depend_quote_target = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
630 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
631
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
632 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
633 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
634 commandline_setdependtarget_quoted(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
635 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
636 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
637 mode.depend_target = str;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
638 mode.depend_quote_target = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
639 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
640
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
641 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
642 void
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
643 commandline_setdependoutput(const struct place *p, char *str)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
644 {
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
645 (void)p;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
646 mode.depend_file = str;
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
649 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
650 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
651 commandline_M(void)
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 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
654 mode.depend_report_system = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
655 mode.do_output = false;
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
658 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
659 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
660 commandline_MM(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
661 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
662 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
663 mode.depend_report_system = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
664 mode.do_output = false;
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
667 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
668 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
669 commandline_MD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
670 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
671 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
672 mode.depend_report_system = 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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
677 commandline_MMD(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
678 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
679 mode.do_depend = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
680 mode.depend_report_system = false;
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_wall(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 warns.nestcomment = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
688 warns.undef = true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
689 warns.unused = true;
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_wnoall(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 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
697 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
698 warns.unused = 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_wnone(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 warns.nestcomment = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
706 warns.endiflabels = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
707 warns.undef = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
708 warns.unused = false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
709 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
710
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
711 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
712 // options
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
713
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
714 struct flag_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
715 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
716 bool *flag;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
717 bool setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
718 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
719
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
720 struct act_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
721 const char *string;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
722 void (*func)(void);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
723 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
724
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
725 struct prefix_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
726 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
727 void (*func)(const struct place *, char *);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
728 };
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 struct arg_option {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
731 const char *string;
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
732 void (*func)(const struct place *, char *);
4
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 const struct flag_option flag_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
736 { "C", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
737 { "CC", &mode.output_retain_comments, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
738 { "MG", &mode.depend_assume_generated, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
739 { "MP", &mode.depend_issue_fakerules, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
740 { "P", &mode.output_linenumbers, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
741 { "Wcomment", &warns.nestcomment, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
742 { "Wendif-labels", &warns.endiflabels, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
743 { "Werror", &mode.werror, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
744 { "Wno-comment", &warns.nestcomment, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
745 { "Wno-endif-labels", &warns.endiflabels, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
746 { "Wno-error", &mode.werror, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
747 { "Wno-undef", &warns.undef, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
748 { "Wno-unused-macros", &warns.unused, false },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
749 { "Wundef", &warns.undef, true },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
750 { "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
751 { "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
752 { "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
753 { "nostdinc", &mode.do_stdinc, false },
71
dc63e70e425d Accept and ignore -traditional.
David A. Holland
parents: 44
diff changeset
754 { "traditional", &traditional, true },
37
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
755 { "undef", &mode.do_stddef, false },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
756 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
757 static const unsigned num_flag_options = HOWMANY(flag_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
758
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
759 static const struct act_option act_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
760 { "H", commandline_H },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
761 { "M", commandline_M },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
762 { "MD", commandline_MD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
763 { "MM", commandline_MM },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
764 { "MMD", commandline_MMD },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
765 { "Wall", commandline_wall },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
766 { "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
767 { "dD", commandline_dD },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
768 { "dI", commandline_dI },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
769 { "dM", commandline_dM },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
770 { "dN", commandline_dN },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
771 { "w", commandline_wnone },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
772 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
773 static const unsigned num_act_options = HOWMANY(act_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
774
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
775 static const struct prefix_option prefix_options[] = {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
776 { "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
777 { "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
778 { "U", commandline_undef },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
779 { "ftabstop=", commandline_tabstop },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
780 { "std=", commandline_setstd },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
781 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
782 static const unsigned num_prefix_options = HOWMANY(prefix_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
783
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
784 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
785 { "MF", commandline_setdependoutput },
70902cac4170 Sort the option lists to match the comparison used to search them. duh.
David A. Holland
parents: 30
diff changeset
786 { "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
787 { "MT", commandline_setdependtarget },
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
788 { "idirafter", commandline_addincpath_late },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
789 { "imacros", commandline_addfile_nooutput },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
790 { "include", commandline_addfile_output },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
791 { "iprefix", commandline_setprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
792 { "iquote", commandline_addincpath_quote },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
793 { "iremap", commandline_iremap },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
794 { "isysroot", commandline_isysroot },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
795 { "isystem", commandline_addincpath_system },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
796 { "iwithprefix", commandline_addincpath_late_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
797 { "iwithprefixbefore", commandline_addincpath_user_withprefix },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
798 { "x", commandline_setlang },
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
799 };
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
800 static const unsigned num_arg_options = HOWMANY(arg_options);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
801
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
802 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
803 bool
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
804 check_flag_option(const char *opt)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
805 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
806 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
807 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
808
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
809 for (i=0; i<num_flag_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
810 r = strcmp(opt, flag_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
811 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
812 *flag_options[i].flag = flag_options[i].setto;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
813 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
814 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
815 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
816 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
817 }
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 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
820 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
821
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
822 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
823 bool
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
824 check_act_option(const char *opt)
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 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
827 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
828
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
829 for (i=0; i<num_act_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
830 r = strcmp(opt, act_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
831 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
832 act_options[i].func();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
833 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
834 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
835 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
836 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
837 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
838 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
839 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
840 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
841
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
842 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
843 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
844 check_prefix_option(const struct place *p, char *opt)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
845 {
44
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
846 unsigned i, len;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
847 int r;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
848
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
849 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
850 len = strlen(prefix_options[i].string);
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
851 r = strncmp(opt, prefix_options[i].string, len);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
852 if (r == 0) {
44
57e0c7a50b2d Skip option itself, before passing down to handler.
Joerg Sonnenberger <joerg@bec.de>
parents: 43
diff changeset
853 prefix_options[i].func(p, opt + len);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
854 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
855 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
856 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
857 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
858 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
859 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
860 return false;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
861 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
862
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
863 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
864 bool
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
865 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
866 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
867 unsigned i;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
868 int r;
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 for (i=0; i<num_arg_options; i++) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
871 r = strcmp(opt, arg_options[i].string);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
872 if (r == 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
873 if (arg == NULL) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
874 warnx("Option -%s requires an argument", opt);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
875 die();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
876 }
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
877 arg_options[i].func(argplace, arg);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
878 return true;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
879 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
880 if (r < 0) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
881 break;
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 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
884 return false;
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
98
51848a7584e0 __dead -> DEAD
David A. Holland
parents: 86
diff changeset
887 DEAD static
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
888 void
105
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
889 usage(const char *argv0)
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
890 {
105
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
891 const char *progname;
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
892
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
893 progname = strrchr(argv0, '/');
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
894 progname = progname == NULL ? argv0 : progname + 1;
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
895
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
896 fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
897 fprintf(stderr, "Common options:\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
898 fprintf(stderr, " -C Retain comments\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
899 fprintf(stderr, " -Dmacro[=def] Predefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
900 fprintf(stderr, " -Idir Add to include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
901 fprintf(stderr, " -M Issue depend info\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
902 fprintf(stderr, " -MD Issue depend info and output\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
903 fprintf(stderr, " -MM -M w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
904 fprintf(stderr, " -MMD -MD w/o system headers\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
905 fprintf(stderr, " -nostdinc Drop default include path\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
906 fprintf(stderr, " -Umacro Undefine macro\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
907 fprintf(stderr, " -undef Undefine everything\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
908 fprintf(stderr, " -Wall Enable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
909 fprintf(stderr, " -Werror Make warnings into errors\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
910 fprintf(stderr, " -w Disable all warnings\n");
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
911 die();
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
914 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
915 // exit and cleanup
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
916
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
917 static struct stringarray freestrings;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
918
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
919 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
920 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
921 init(void)
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 stringarray_init(&freestrings);
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
924
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
925 incpath_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
926 commandline_macros_init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
927 commandline_files_init();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
928
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
929 place_init();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
930 files_init();
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
931 directive_init();
17
76da41da923f added macro table
David A. Holland
parents: 15
diff changeset
932 macros_init();
4
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
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
935 static
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
936 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
937 cleanup(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
938 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
939 unsigned i, num;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
940
17
76da41da923f added macro table
David A. Holland
parents: 15
diff changeset
941 macros_cleanup();
15
f6177d3ed5c2 handle directives
David A. Holland
parents: 14
diff changeset
942 directive_cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
943 files_cleanup();
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
944 place_cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
945
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
946 commandline_files_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
947 commandline_macros_cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
948 incpath_cleanup();
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 num = stringarray_num(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
951 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
952 dostrfree(stringarray_get(&freestrings, i));
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
953 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
954 stringarray_setsize(&freestrings, 0);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
955 stringarray_cleanup(&freestrings);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
956 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
957
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
958 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
959 die(void)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
960 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
961 cleanup();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
962 exit(EXIT_FAILURE);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
963 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
964
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
965 void
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
966 freestringlater(char *s)
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
967 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
968 stringarray_add(&freestrings, s, NULL);
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
969 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
970
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
971 ////////////////////////////////////////////////////////////
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
972 // main
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
973
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
974 int
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
975 main(int argc, char *argv[])
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
976 {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
977 const char *inputfile = NULL;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
978 const char *outputfile = NULL;
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
979 struct place cmdplace;
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
980 int i;
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 init();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
983
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
984 for (i=1; i<argc; i++) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
985 if (argv[i][0] != '-') {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
986 break;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
987 }
14
David A. Holland
parents: 11
diff changeset
988 place_setcommandline(&cmdplace, i, 1);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
989 if (check_flag_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
990 continue;
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 if (check_act_option(argv[i]+1)) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
993 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
994 }
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
995 if (check_prefix_option(&cmdplace, argv[i]+1)) {
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
996 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
997 }
14
David A. Holland
parents: 11
diff changeset
998 place_setcommandline(&cmdplace, i+1, 1);
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
999 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
1000 i++;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1001 continue;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1002 }
105
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
1003 usage(argv[0]);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1004 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1005 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1006 inputfile = argv[i++];
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 if (i < argc) {
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1009 outputfile = argv[i++];
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1010 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1011 if (i < argc) {
105
600f36cd7353 don't use getprogname() in the name of portability
David A. Holland
parents: 98
diff changeset
1012 usage(argv[0]);
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1013 }
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1014
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1015 mode.output_file = outputfile;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1016
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1017 loadincludepath();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1018 apply_builtin_macros();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1019 apply_commandline_macros();
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1020 read_commandline_files();
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1021 place_setnowhere(&cmdplace);
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
1022 file_readabsolute(&cmdplace, inputfile);
7
b8167949474a make places work better
David A. Holland
parents: 6
diff changeset
1023
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1024 cleanup();
6
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1025 if (complain_failed()) {
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1026 return EXIT_FAILURE;
0601b6e8e53d checkpoint - can find files
David A. Holland
parents: 5
diff changeset
1027 }
4
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1028 return EXIT_SUCCESS;
ee9a66b87c70 Initial version of toplevel and options handling.
David A. Holland
parents:
diff changeset
1029 }