Mercurial > hg > CbC > GCC_original
annotate gcc/opt-functions.awk @ 16:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
rev | line source |
---|---|
16 | 1 # Copyright (C) 2003-2017 Free Software Foundation, Inc. |
0 | 2 # Contributed by Kelley Cook, June 2004. |
3 # Original code from Neil Booth, May 2003. | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify it | |
6 # under the terms of the GNU General Public License as published by the | |
7 # Free Software Foundation; either version 3, or (at your option) any | |
8 # later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; see the file COPYING3. If not see | |
17 # <http://www.gnu.org/licenses/>. | |
18 | |
19 # Some common subroutines for use by opt[ch]-gen.awk. | |
20 | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
21 # Define some helpful character classes, for portability. |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
22 BEGIN { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
23 lower = "abcdefghijklmnopqrstuvwxyz" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
24 upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
25 digit = "0123456789" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
26 alnum = lower "" upper "" digit |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
27 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
28 |
0 | 29 # Return nonzero if FLAGS contains a flag matching REGEX. |
30 function flag_set_p(regex, flags) | |
31 { | |
16 | 32 # Ignore the arguments of flags with arguments. |
33 gsub ("\\([^)]+\\)", "", flags); | |
34 return (" " flags " ") ~ (" " regex " ") | |
0 | 35 } |
36 | |
37 # Return STRING if FLAGS contains a flag matching regexp REGEX, | |
38 # otherwise return the empty string. | |
39 function test_flag(regex, flags, string) | |
40 { | |
41 if (flag_set_p(regex, flags)) | |
42 return string | |
43 return "" | |
44 } | |
45 | |
16 | 46 # Return a field initializer, with trailing comma, for a field that is |
47 # 1 if FLAGS contains a flag matching REGEX and 0 otherwise. | |
48 function flag_init(regex, flags) | |
49 { | |
50 if (flag_set_p(regex, flags)) | |
51 return "1 /* " regex " */, " | |
52 else | |
53 return "0, " | |
54 } | |
55 | |
0 | 56 # If FLAGS contains a "NAME(...argument...)" flag, return the value |
57 # of the argument. Return the empty string otherwise. | |
58 function opt_args(name, flags) | |
59 { | |
60 flags = " " flags | |
61 if (flags !~ " " name "\\(") | |
62 return "" | |
63 sub(".* " name "\\(", "", flags) | |
16 | 64 if (flags ~ "^[{]") |
9
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
65 { |
16 | 66 sub ("^[{]", "", flags) |
67 sub ("}\\).*", "", flags) | |
9
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
68 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
69 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
70 sub("\\).*", "", flags) |
0 | 71 |
72 return flags | |
73 } | |
74 | |
75 # Return the Nth comma-separated element of S. Return the empty string | |
76 # if S does not contain N elements. | |
77 function nth_arg(n, s) | |
78 { | |
79 while (n-- > 0) { | |
80 if (s !~ ",") | |
81 return "" | |
82 sub("[^,]*, *", "", s) | |
83 } | |
84 sub(",.*", "", s) | |
85 return s | |
86 } | |
87 | |
88 # Return a bitmask of CL_* values for option flags FLAGS. | |
89 function switch_flags (flags) | |
90 { | |
91 result = "0" | |
92 for (j = 0; j < n_langs; j++) { | |
93 regex = langs[j] | |
94 gsub ( "\\+", "\\+", regex ) | |
95 result = result test_flag(regex, flags, " | " macros[j]) | |
96 } | |
97 result = result \ | |
98 test_flag("Common", flags, " | CL_COMMON") \ | |
99 test_flag("Target", flags, " | CL_TARGET") \ | |
16 | 100 test_flag("PchIgnore", flags, " | CL_PCH_IGNORE") \ |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
101 test_flag("Driver", flags, " | CL_DRIVER") \ |
0 | 102 test_flag("Joined", flags, " | CL_JOINED") \ |
16 | 103 test_flag("JoinedOrMissing", flags, " | CL_JOINED") \ |
0 | 104 test_flag("Separate", flags, " | CL_SEPARATE") \ |
105 test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \ | |
16 | 106 test_flag("NoDWARFRecord", flags, " | CL_NO_DWARF_RECORD") \ |
0 | 107 test_flag("Warning", flags, " | CL_WARNING") \ |
16 | 108 test_flag("(Optimization|PerFunction)", flags, " | CL_OPTIMIZATION") |
109 sub( "^0 \\| ", "", result ) | |
110 return result | |
111 } | |
112 | |
113 # Return bit-field initializers for option flags FLAGS. | |
114 function switch_bit_fields (flags) | |
115 { | |
116 vn = var_name(flags); | |
117 if (host_wide_int[vn] == "yes") | |
118 hwi = "Host_Wide_Int" | |
119 else | |
120 hwi = "" | |
121 result = "" | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
122 sep_args = opt_args("Args", flags) |
16 | 123 if (sep_args == "") |
124 sep_args = 0 | |
125 else | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
126 sep_args-- |
16 | 127 result = result sep_args ", " |
128 | |
129 result = result \ | |
130 flag_init("SeparateAlias", flags) \ | |
131 flag_init("NegativeAlias", flags) \ | |
132 flag_init("NoDriverArg", flags) \ | |
133 flag_init("RejectDriver", flags) \ | |
134 flag_init("RejectNegative", flags) \ | |
135 flag_init("JoinedOrMissing", flags) \ | |
136 flag_init("UInteger", flags) \ | |
137 flag_init("Host_Wide_Int", hwi) \ | |
138 flag_init("ToLower", flags) \ | |
139 flag_init("Report", flags) | |
140 | |
141 sub(", $", "", result) | |
0 | 142 return result |
143 } | |
144 | |
145 # If FLAGS includes a Var flag, return the name of the variable it specifies. | |
146 # Return the empty string otherwise. | |
147 function var_name(flags) | |
148 { | |
149 return nth_arg(0, opt_args("Var", flags)) | |
150 } | |
151 | |
16 | 152 # Return the name of the variable if FLAGS has a HOST_WIDE_INT variable. |
153 # Return the empty string otherwise. | |
154 function host_wide_int_var_name(flags) | |
155 { | |
156 split (flags, array, "[ \t]+") | |
157 if (array[1] == "HOST_WIDE_INT") | |
158 return array[2] | |
159 else | |
160 return "" | |
161 } | |
162 | |
0 | 163 # Return true if the option described by FLAGS has a globally-visible state. |
164 function global_state_p(flags) | |
165 { | |
166 return (var_name(flags) != "" \ | |
167 || opt_args("Mask", flags) != "" \ | |
168 || opt_args("InverseMask", flags) != "") | |
169 } | |
170 | |
171 # Return true if the option described by FLAGS must have some state | |
172 # associated with it. | |
173 function needs_state_p(flags) | |
174 { | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
175 return (flag_set_p("Target", flags) \ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
176 && !flag_set_p("Alias.*", flags) \ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
177 && !flag_set_p("Ignore", flags)) |
0 | 178 } |
179 | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
180 # If FLAGS describes an option that needs state without a public |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
181 # variable name, return the name of that field, minus the initial |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
182 # "x_", otherwise return "". NAME is the name of the option. |
0 | 183 function static_var(name, flags) |
184 { | |
185 if (global_state_p(flags) || !needs_state_p(flags)) | |
186 return "" | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
187 gsub ("[^" alnum "]", "_", name) |
0 | 188 return "VAR_" name |
189 } | |
190 | |
191 # Return the type of variable that should be associated with the given flags. | |
192 function var_type(flags) | |
193 { | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
194 if (flag_set_p("Defer", flags)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
195 return "void *" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
196 else if (flag_set_p("Enum.*", flags)) { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
197 en = opt_args("Enum", flags); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
198 return enum_type[en] " " |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
199 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
200 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) |
0 | 201 return "int " |
202 else if (flag_set_p("UInteger", flags)) | |
203 return "int " | |
204 else | |
205 return "const char *" | |
206 } | |
207 | |
208 # Return the type of variable that should be associated with the given flags | |
11
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
209 # for use within a structure. Simple variables are changed to signed char |
0 | 210 # type instead of int to save space. |
211 function var_type_struct(flags) | |
212 { | |
213 if (flag_set_p("UInteger", flags)) | |
214 return "int " | |
16 | 215 else if (flag_set_p("Enum.*", flags)) { |
216 en = opt_args("Enum", flags); | |
217 return enum_type[en] " " | |
218 } | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
219 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) { |
16 | 220 if (flag_set_p(".*Mask.*", flags)) { |
221 if (host_wide_int[var_name(flags)] == "yes") | |
222 return "HOST_WIDE_INT " | |
223 else | |
224 return "int " | |
225 } | |
0 | 226 else |
11
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
227 return "signed char " |
0 | 228 } |
229 else | |
230 return "const char *" | |
231 } | |
232 | |
233 # Given that an option has flags FLAGS, return an initializer for the | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
234 # "var_enum", "var_type" and "var_value" fields of its cl_options[] entry. |
0 | 235 function var_set(flags) |
236 { | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
237 if (flag_set_p("Defer", flags)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
238 return "0, CLVC_DEFER, 0" |
0 | 239 s = nth_arg(1, opt_args("Var", flags)) |
240 if (s != "") | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
241 return "0, CLVC_EQUAL, " s |
0 | 242 s = opt_args("Mask", flags); |
243 if (s != "") { | |
244 vn = var_name(flags); | |
245 if (vn) | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
246 return "0, CLVC_BIT_SET, OPTION_MASK_" s |
0 | 247 else |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
248 return "0, CLVC_BIT_SET, MASK_" s |
0 | 249 } |
250 s = nth_arg(0, opt_args("InverseMask", flags)); | |
251 if (s != "") { | |
252 vn = var_name(flags); | |
253 if (vn) | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
254 return "0, CLVC_BIT_CLEAR, OPTION_MASK_" s |
0 | 255 else |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
256 return "0, CLVC_BIT_CLEAR, MASK_" s |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
257 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
258 if (flag_set_p("Enum.*", flags)) { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
259 en = opt_args("Enum", flags); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
260 return enum_index[en] ", CLVC_ENUM, 0" |
0 | 261 } |
262 if (var_type(flags) == "const char *") | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
263 return "0, CLVC_STRING, 0" |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
264 return "0, CLVC_BOOLEAN, 0" |
0 | 265 } |
266 | |
267 # Given that an option called NAME has flags FLAGS, return an initializer | |
268 # for the "flag_var" field of its cl_options[] entry. | |
269 function var_ref(name, flags) | |
270 { | |
271 name = var_name(flags) static_var(name, flags) | |
272 if (name != "") | |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
273 return "offsetof (struct gcc_options, x_" name ")" |
0 | 274 if (opt_args("Mask", flags) != "") |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
275 return "offsetof (struct gcc_options, x_target_flags)" |
0 | 276 if (opt_args("InverseMask", flags) != "") |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
277 return "offsetof (struct gcc_options, x_target_flags)" |
16 | 278 return "(unsigned short) -1" |
0 | 279 } |
11
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
280 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
281 # Given the option called NAME return a sanitized version of its name. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
282 function opt_sanitized_name(name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
283 { |
14
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
284 gsub ("[^" alnum "]", "_", name) |
11
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
285 return name |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
286 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
287 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
288 # Given the option called NAME return the appropriate enum for it. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
289 function opt_enum(name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
290 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
291 return "OPT_" opt_sanitized_name(name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
292 } |
16 | 293 |
294 # Given the language called NAME return a sanitized version of its name. | |
295 function lang_sanitized_name(name) | |
296 { | |
297 gsub( "[^" alnum "_]", "X", name ) | |
298 return name | |
299 } | |
300 | |
301 # Search for a valid var_name among all OPTS equal to option NAME. | |
302 # If not found, return "". | |
303 function search_var_name(name, opt_numbers, opts, flags, n_opts) | |
304 { | |
305 opt_var_name = var_name(flags[opt_numbers[name]]); | |
306 if (opt_var_name != "") { | |
307 return opt_var_name; | |
308 } | |
309 for (k = 0; k < n_opts; k++) { | |
310 if (opts[k] == name && var_name(flags[k]) != "") { | |
311 return var_name(flags[k]); | |
312 } | |
313 } | |
314 return "" | |
315 } | |
316 | |
317 function integer_range_info(range_option, init, option) | |
318 { | |
319 if (range_option != "") { | |
320 start = nth_arg(0, range_option); | |
321 end = nth_arg(1, range_option); | |
322 if (init != "" && init != "-1" && (init < start || init > end)) | |
323 print "#error initial value " init " of '" option "' must be in range [" start "," end "]" | |
324 return start ", " end | |
325 } | |
326 else | |
327 return "-1, -1" | |
328 } | |
329 | |
330 # Handle LangEnabledBy(ENABLED_BY_LANGS, ENABLEDBY_NAME, ENABLEDBY_POSARG, | |
331 # ENABLEDBY_NEGARG). This function does not return anything. | |
332 function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg) | |
333 { | |
334 n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " "); | |
335 if (enabledby_posarg != "" && enabledby_negarg != "") { | |
336 with_args = "," enabledby_posarg "," enabledby_negarg | |
337 } else if (enabledby_posarg == "" && enabledby_negarg == "") { | |
338 with_args = "" | |
339 } else { | |
340 print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \ | |
341 enabledby_posarg", " enabledby_negargs \ | |
342 ") with three arguments, it should have either 2 or 4" | |
343 } | |
344 | |
345 n_enabledby_array = split(enabledby_name, enabledby_array, " \\|\\| "); | |
346 for (k = 1; k <= n_enabledby_array; k++) { | |
347 enabledby_index = opt_numbers[enabledby_array[k]]; | |
348 if (enabledby_index == "") { | |
349 print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \ | |
350 enabledby_posarg", " enabledby_negargs"), unknown option '" enabledby_name "'" | |
351 } else { | |
352 for (j = 1; j <= n_enabledby_arg_langs; j++) { | |
353 lang_name = lang_sanitized_name(enabledby_arg_langs[j]); | |
354 lang_index = lang_numbers[enabledby_arg_langs[j]]; | |
355 if (enables[lang_name,enabledby_array[k]] == "") { | |
356 enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k]; | |
357 n_enabledby_lang[lang_index]++; | |
358 } | |
359 enables[lang_name,enabledby_array[k]] \ | |
360 = enables[lang_name,enabledby_array[k]] opts[i] with_args ";"; | |
361 } | |
362 } | |
363 } | |
364 } |