annotate main.c @ 6:0601b6e8e53d

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