1 | /*␊ |
2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>␊ |
3 | * Released under the terms of the GNU GPL v2.0.␊ |
4 | */␊ |
5 | ␊ |
6 | #include <sys/stat.h>␊ |
7 | #include <ctype.h>␊ |
8 | #include <errno.h>␊ |
9 | #include <fcntl.h>␊ |
10 | #include <stdio.h>␊ |
11 | #include <stdlib.h>␊ |
12 | #include <string.h>␊ |
13 | #include <time.h>␊ |
14 | #include <unistd.h>␊ |
15 | ␊ |
16 | char *␊ |
17 | int_stpncpy (dst, src, len)␊ |
18 | char *dst;␊ |
19 | const char *src;␊ |
20 | size_t len;␊ |
21 | {␊ |
22 | ␉size_t n = strlen (src);␊ |
23 | ␉if (n > len)␊ |
24 | ␉␉n = len;␊ |
25 | ␉return strncpy (dst, src, len) + n;␊ |
26 | }␊ |
27 | ␊ |
28 | #define LKC_DIRECT_LINK␊ |
29 | #include "lkc.h"␊ |
30 | ␊ |
31 | #define max(a, b) ({\␊ |
32 | ␉␉typeof(a) _a = a;\␊ |
33 | ␉␉typeof(b) _b = b;\␊ |
34 | ␉␉_a > _b ? _a : _b; })␊ |
35 | ␊ |
36 | #define min(a, b) ({\␊ |
37 | ␉␉typeof(a) _a = a;\␊ |
38 | ␉␉typeof(b) _b = b;\␊ |
39 | ␉␉_a < _b ? _a : _b; })␊ |
40 | ␊ |
41 | static void conf_warning(const char *fmt, ...)␊ |
42 | ␉__attribute__ ((format (printf, 1, 2)));␊ |
43 | ␊ |
44 | static void conf_message(const char *fmt, ...)␊ |
45 | ␉__attribute__ ((format (printf, 1, 2)));␊ |
46 | ␊ |
47 | static const char *conf_filename;␊ |
48 | static int conf_lineno, conf_warnings, conf_unsaved;␊ |
49 | ␊ |
50 | const char conf_defname[] = "config/defconfig";␊ |
51 | ␊ |
52 | static void conf_warning(const char *fmt, ...)␊ |
53 | {␊ |
54 | ␉va_list ap;␊ |
55 | ␉va_start(ap, fmt);␊ |
56 | ␉fprintf(stderr, "%s:%d:warning: ", conf_filename, conf_lineno);␊ |
57 | ␉vfprintf(stderr, fmt, ap);␊ |
58 | ␉fprintf(stderr, "\n");␊ |
59 | ␉va_end(ap);␊ |
60 | ␉conf_warnings++;␊ |
61 | }␊ |
62 | ␊ |
63 | static void conf_default_message_callback(const char *fmt, va_list ap)␊ |
64 | {␊ |
65 | ␉printf("#\n# ");␊ |
66 | ␉vprintf(fmt, ap);␊ |
67 | ␉printf("\n#\n");␊ |
68 | }␊ |
69 | ␊ |
70 | static void (*conf_message_callback) (const char *fmt, va_list ap) =␊ |
71 | ␉conf_default_message_callback;␊ |
72 | void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))␊ |
73 | {␊ |
74 | ␉conf_message_callback = fn;␊ |
75 | }␊ |
76 | ␊ |
77 | static void conf_message(const char *fmt, ...)␊ |
78 | {␊ |
79 | ␉va_list ap;␊ |
80 | ␊ |
81 | ␉va_start(ap, fmt);␊ |
82 | ␉if (conf_message_callback)␊ |
83 | ␉␉conf_message_callback(fmt, ap);␊ |
84 | }␊ |
85 | ␊ |
86 | const char *conf_get_configname(void)␊ |
87 | {␊ |
88 | ␉char *name = getenv("KCONFIG_CONFIG");␊ |
89 | ␊ |
90 | ␉return name ? name : ".config";␊ |
91 | }␊ |
92 | ␊ |
93 | const char *conf_get_autoconfig_name(void)␊ |
94 | {␊ |
95 | ␉char *name = getenv("KCONFIG_AUTOCONFIG");␊ |
96 | ␊ |
97 | ␉return name ? name : "auto.conf";␊ |
98 | }␊ |
99 | ␊ |
100 | /* TODO: figure out if symbols are always null-terminated */␊ |
101 | static char *conf_expand_value(const char *in)␊ |
102 | {␊ |
103 | ␉static char res_value[SYMBOL_MAXLENGTH + 1];␊ |
104 | ␉char name[SYMBOL_MAXLENGTH];␊ |
105 | ␉size_t res_rem = SYMBOL_MAXLENGTH;␊ |
106 | ␉char *res_ptr = res_value;␊ |
107 | ␉const char *src;␊ |
108 | ␉*res_ptr = 0;␊ |
109 | ␉res_ptr[SYMBOL_MAXLENGTH] = 0;␊ |
110 | ␉while ((src = strchr(in, '$'))) {␊ |
111 | ␉␉struct symbol *sym;␊ |
112 | ␉␉const char *symval;␊ |
113 | ␉␉char *name_ptr = name;␊ |
114 | ␉␉size_t n = min(res_rem, src - in);␊ |
115 | ␊ |
116 | ␉␉res_ptr = int_stpncpy(res_ptr, in, n);␊ |
117 | ␉␉if (!(res_rem -= n))␊ |
118 | ␉␉{␊ |
119 | ␉␉␉return res_value; /* buffer full, quit now */␊ |
120 | ␉␉}␊ |
121 | ␉␉src++;␊ |
122 | ␊ |
123 | ␉␉*name_ptr = 0;␊ |
124 | ␉␉while (isalnum(*src) || *src == '_') {␊ |
125 | ␉␉␉*name_ptr++ = *src++;␊ |
126 | ␉␉}␊ |
127 | ␉␉*name_ptr = 0;␊ |
128 | ␊ |
129 | ␉␉sym = sym_lookup(name, 0);␊ |
130 | ␉␉sym_calc_value(sym);␊ |
131 | ␉␉symval = sym_get_string_value(sym);␊ |
132 | ␉␉n = min(res_rem, strlen(symval));␊ |
133 | ␊ |
134 | ␉␉res_ptr = int_stpncpy(res_ptr, symval, n);␊ |
135 | ␉␉if (!(res_rem -= n))␊ |
136 | ␉␉{␊ |
137 | ␉␉␉return res_value; /* buffer full, quit now */␊ |
138 | ␉␉}␊ |
139 | ␉␉in = src;␊ |
140 | ␉}␊ |
141 | ␊ |
142 | ␉strncpy(res_ptr, in, res_rem + 1);␊ |
143 | ␉return res_value;␊ |
144 | }␊ |
145 | ␊ |
146 | char *conf_get_default_confname(void)␊ |
147 | {␊ |
148 | ␉struct stat buf;␊ |
149 | ␉static char fullname[PATH_MAX+1];␊ |
150 | ␉char *env, *name;␊ |
151 | ␊ |
152 | ␉name = conf_expand_value(conf_defname);␊ |
153 | ␉env = getenv(SRCTREE);␊ |
154 | ␉if (env) {␊ |
155 | ␉␉snprintf(fullname, PATH_MAX+1, "%s/%s", env, name);␊ |
156 | ␉␉if (!stat(fullname, &buf))␊ |
157 | ␉␉␉return fullname;␊ |
158 | ␉}␊ |
159 | ␉return name;␊ |
160 | }␊ |
161 | ␊ |
162 | static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)␊ |
163 | {␊ |
164 | ␉char *p2;␊ |
165 | ␊ |
166 | ␉switch (sym->type) {␊ |
167 | ␉case S_TRISTATE:␊ |
168 | ␉␉if (p[0] == 'm') {␊ |
169 | ␉␉␉sym->def[def].tri = mod;␊ |
170 | ␉␉␉sym->flags |= def_flags;␊ |
171 | ␉␉␉break;␊ |
172 | ␉␉}␊ |
173 | ␉case S_BOOLEAN:␊ |
174 | ␉␉if (p[0] == 'y') {␊ |
175 | ␉␉␉sym->def[def].tri = yes;␊ |
176 | ␉␉␉sym->flags |= def_flags;␊ |
177 | ␉␉␉break;␊ |
178 | ␉␉}␊ |
179 | ␉␉if (p[0] == 'n') {␊ |
180 | ␉␉␉sym->def[def].tri = no;␊ |
181 | ␉␉␉sym->flags |= def_flags;␊ |
182 | ␉␉␉break;␊ |
183 | ␉␉}␊ |
184 | ␉␉conf_warning("symbol value '%s' invalid for %s", p, sym->name);␊ |
185 | ␉␉break;␊ |
186 | ␉case S_OTHER:␊ |
187 | ␉␉if (*p != '"') {␊ |
188 | ␉␉␉for (p2 = p; *p2 && !isspace(*p2); p2++)␊ |
189 | ␉␉␉␉;␊ |
190 | ␉␉␉sym->type = S_STRING;␊ |
191 | ␉␉␉goto done;␊ |
192 | ␉␉}␊ |
193 | ␉case S_STRING:␊ |
194 | ␉␉if (*p++ != '"')␊ |
195 | ␉␉␉break;␊ |
196 | ␉␉for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {␊ |
197 | ␉␉␉if (*p2 == '"') {␊ |
198 | ␉␉␉␉*p2 = 0;␊ |
199 | ␉␉␉␉break;␊ |
200 | ␉␉␉}␊ |
201 | ␉␉␉memmove(p2, p2 + 1, strlen(p2));␊ |
202 | ␉␉}␊ |
203 | ␉␉if (!p2) {␊ |
204 | ␉␉␉conf_warning("invalid string found");␊ |
205 | ␉␉␉return 1;␊ |
206 | ␉␉}␊ |
207 | ␉case S_INT:␊ |
208 | ␉case S_HEX:␊ |
209 | ␉done:␊ |
210 | ␉␉if (sym_string_valid(sym, p)) {␊ |
211 | ␉␉␉sym->def[def].val = strdup(p);␊ |
212 | ␉␉␉sym->flags |= def_flags;␊ |
213 | ␉␉} else {␊ |
214 | ␉␉␉conf_warning("symbol value '%s' invalid for %s", p, sym->name);␊ |
215 | ␉␉␉return 1;␊ |
216 | ␉␉}␊ |
217 | ␉␉break;␊ |
218 | ␉default:␊ |
219 | ␉␉;␊ |
220 | ␉}␊ |
221 | ␉return 0;␊ |
222 | }␊ |
223 | ␊ |
224 | int conf_read_simple(const char *name, int def)␊ |
225 | {␊ |
226 | ␉FILE *in = NULL;␊ |
227 | ␉char line[1024];␊ |
228 | ␉char *p, *p2;␊ |
229 | ␉struct symbol *sym;␊ |
230 | ␉int i, def_flags;␊ |
231 | ␊ |
232 | ␉if (name) {␊ |
233 | ␉␉in = zconf_fopen(name);␊ |
234 | ␉} else {␊ |
235 | ␉␉struct property *prop;␊ |
236 | ␊ |
237 | ␉␉name = conf_get_configname();␊ |
238 | ␉␉in = zconf_fopen(name);␊ |
239 | ␉␉if (in)␊ |
240 | ␉␉␉goto load;␊ |
241 | ␉␉sym_add_change_count(1);␊ |
242 | ␉␉if (!sym_defconfig_list) {␊ |
243 | ␉␉␉if (modules_sym)␊ |
244 | ␉␉␉␉sym_calc_value(modules_sym);␊ |
245 | ␉␉␉return 1;␊ |
246 | ␉␉}␊ |
247 | ␊ |
248 | ␉␉for_all_defaults(sym_defconfig_list, prop) {␊ |
249 | ␉␉␉if (expr_calc_value(prop->visible.expr) == no ||␊ |
250 | ␉␉␉ prop->expr->type != E_SYMBOL)␊ |
251 | ␉␉␉␉continue;␊ |
252 | ␉␉␉name = conf_expand_value(prop->expr->left.sym->name);␊ |
253 | ␉␉␉in = zconf_fopen(name);␊ |
254 | ␉␉␉if (in) {␊ |
255 | ␉␉␉␉conf_message(_("using defaults found in %s"),␊ |
256 | ␉␉␉␉␉ name);␊ |
257 | ␉␉␉␉goto load;␊ |
258 | ␉␉␉}␊ |
259 | ␉␉}␊ |
260 | ␉}␊ |
261 | ␉if (!in)␊ |
262 | ␉␉return 1;␊ |
263 | ␊ |
264 | load:␊ |
265 | ␉conf_filename = name;␊ |
266 | ␉conf_lineno = 0;␊ |
267 | ␉conf_warnings = 0;␊ |
268 | ␉conf_unsaved = 0;␊ |
269 | ␊ |
270 | ␉def_flags = SYMBOL_DEF << def;␊ |
271 | ␉for_all_symbols(i, sym) {␊ |
272 | ␉␉sym->flags |= SYMBOL_CHANGED;␊ |
273 | ␉␉sym->flags &= ~(def_flags|SYMBOL_VALID);␊ |
274 | ␉␉if (sym_is_choice(sym))␊ |
275 | ␉␉␉sym->flags |= def_flags;␊ |
276 | ␉␉switch (sym->type) {␊ |
277 | ␉␉case S_INT:␊ |
278 | ␉␉case S_HEX:␊ |
279 | ␉␉case S_STRING:␊ |
280 | ␉␉␉if (sym->def[def].val)␊ |
281 | ␉␉␉␉free(sym->def[def].val);␊ |
282 | ␉␉default:␊ |
283 | ␉␉␉sym->def[def].val = NULL;␊ |
284 | ␉␉␉sym->def[def].tri = no;␊ |
285 | ␉␉}␊ |
286 | ␉}␊ |
287 | ␊ |
288 | ␉while (fgets(line, sizeof(line), in)) {␊ |
289 | ␉␉conf_lineno++;␊ |
290 | ␉␉sym = NULL;␊ |
291 | ␉␉if (line[0] == '#') {␊ |
292 | ␉␉␉if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))␊ |
293 | ␉␉␉␉continue;␊ |
294 | ␉␉␉p = strchr(line + 2 + strlen(CONFIG_), ' ');␊ |
295 | ␉␉␉if (!p)␊ |
296 | ␉␉␉␉continue;␊ |
297 | ␉␉␉*p++ = 0;␊ |
298 | ␉␉␉if (strncmp(p, "is not set", 10))␊ |
299 | ␉␉␉␉continue;␊ |
300 | ␉␉␉if (def == S_DEF_USER) {␊ |
301 | ␉␉␉␉sym = sym_find(line + 2 + strlen(CONFIG_));␊ |
302 | ␉␉␉␉if (!sym) {␊ |
303 | ␉␉␉␉␉sym_add_change_count(1);␊ |
304 | ␉␉␉␉␉goto setsym;␊ |
305 | ␉␉␉␉}␊ |
306 | ␉␉␉} else {␊ |
307 | ␉␉␉␉sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);␊ |
308 | ␉␉␉␉if (sym->type == S_UNKNOWN)␊ |
309 | ␉␉␉␉␉sym->type = S_BOOLEAN;␊ |
310 | ␉␉␉}␊ |
311 | ␉␉␉if (sym->flags & def_flags) {␊ |
312 | ␉␉␉␉conf_warning("override: reassigning to symbol %s", sym->name);␊ |
313 | ␉␉␉}␊ |
314 | ␉␉␉switch (sym->type) {␊ |
315 | ␉␉␉case S_BOOLEAN:␊ |
316 | ␉␉␉case S_TRISTATE:␊ |
317 | ␉␉␉␉sym->def[def].tri = no;␊ |
318 | ␉␉␉␉sym->flags |= def_flags;␊ |
319 | ␉␉␉␉break;␊ |
320 | ␉␉␉default:␊ |
321 | ␉␉␉␉;␊ |
322 | ␉␉␉}␊ |
323 | ␉␉} else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {␊ |
324 | ␉␉␉p = strchr(line + strlen(CONFIG_), '=');␊ |
325 | ␉␉␉if (!p)␊ |
326 | ␉␉␉␉continue;␊ |
327 | ␉␉␉*p++ = 0;␊ |
328 | ␉␉␉p2 = strchr(p, '\n');␊ |
329 | ␉␉␉if (p2) {␊ |
330 | ␉␉␉␉*p2-- = 0;␊ |
331 | ␉␉␉␉if (*p2 == '\r')␊ |
332 | ␉␉␉␉␉*p2 = 0;␊ |
333 | ␉␉␉}␊ |
334 | ␉␉␉if (def == S_DEF_USER) {␊ |
335 | ␉␉␉␉sym = sym_find(line + strlen(CONFIG_));␊ |
336 | ␉␉␉␉if (!sym) {␊ |
337 | ␉␉␉␉␉sym_add_change_count(1);␊ |
338 | ␉␉␉␉␉goto setsym;␊ |
339 | ␉␉␉␉}␊ |
340 | ␉␉␉} else {␊ |
341 | ␉␉␉␉sym = sym_lookup(line + strlen(CONFIG_), 0);␊ |
342 | ␉␉␉␉if (sym->type == S_UNKNOWN)␊ |
343 | ␉␉␉␉␉sym->type = S_OTHER;␊ |
344 | ␉␉␉}␊ |
345 | ␉␉␉if (sym->flags & def_flags) {␊ |
346 | ␉␉␉␉conf_warning("override: reassigning to symbol %s", sym->name);␊ |
347 | ␉␉␉}␊ |
348 | ␉␉␉if (conf_set_sym_val(sym, def, def_flags, p))␊ |
349 | ␉␉␉␉continue;␊ |
350 | ␉␉} else {␊ |
351 | ␉␉␉if (line[0] != '\r' && line[0] != '\n')␊ |
352 | ␉␉␉␉conf_warning("unexpected data");␊ |
353 | ␉␉␉continue;␊ |
354 | ␉␉}␊ |
355 | setsym:␊ |
356 | ␉␉if (sym && sym_is_choice_value(sym)) {␊ |
357 | ␉␉␉struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));␊ |
358 | ␉␉␉switch (sym->def[def].tri) {␊ |
359 | ␉␉␉case no:␊ |
360 | ␉␉␉␉break;␊ |
361 | ␉␉␉case mod:␊ |
362 | ␉␉␉␉if (cs->def[def].tri == yes) {␊ |
363 | ␉␉␉␉␉conf_warning("%s creates inconsistent choice state", sym->name);␊ |
364 | ␉␉␉␉␉cs->flags &= ~def_flags;␊ |
365 | ␉␉␉␉}␊ |
366 | ␉␉␉␉break;␊ |
367 | ␉␉␉case yes:␊ |
368 | ␉␉␉␉if (cs->def[def].tri != no)␊ |
369 | ␉␉␉␉␉conf_warning("override: %s changes choice state", sym->name);␊ |
370 | ␉␉␉␉cs->def[def].val = sym;␊ |
371 | ␉␉␉␉break;␊ |
372 | ␉␉␉}␊ |
373 | ␉␉␉cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);␊ |
374 | ␉␉}␊ |
375 | ␉}␊ |
376 | ␉fclose(in);␊ |
377 | ␊ |
378 | ␉if (modules_sym)␊ |
379 | ␉␉sym_calc_value(modules_sym);␊ |
380 | ␉return 0;␊ |
381 | }␊ |
382 | ␊ |
383 | int conf_read(const char *name)␊ |
384 | {␊ |
385 | ␉struct symbol *sym, *choice_sym;␊ |
386 | ␉struct property *prop;␊ |
387 | ␉struct expr *e;␊ |
388 | ␉int i, flags;␊ |
389 | ␊ |
390 | ␉sym_set_change_count(0);␊ |
391 | ␊ |
392 | ␉if (conf_read_simple(name, S_DEF_USER))␊ |
393 | ␉␉return 1;␊ |
394 | ␊ |
395 | ␉for_all_symbols(i, sym) {␊ |
396 | ␉␉sym_calc_value(sym);␊ |
397 | ␉␉if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))␊ |
398 | ␉␉␉goto sym_ok;␊ |
399 | ␉␉if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {␊ |
400 | ␉␉␉/* check that calculated value agrees with saved value */␊ |
401 | ␉␉␉switch (sym->type) {␊ |
402 | ␉␉␉case S_BOOLEAN:␊ |
403 | ␉␉␉case S_TRISTATE:␊ |
404 | ␉␉␉␉if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))␊ |
405 | ␉␉␉␉␉break;␊ |
406 | ␉␉␉␉if (!sym_is_choice(sym))␊ |
407 | ␉␉␉␉␉goto sym_ok;␊ |
408 | ␉␉␉default:␊ |
409 | ␉␉␉␉if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))␊ |
410 | ␉␉␉␉␉goto sym_ok;␊ |
411 | ␉␉␉␉break;␊ |
412 | ␉␉␉}␊ |
413 | ␉␉} else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))␊ |
414 | ␉␉␉/* no previous value and not saved */␊ |
415 | ␉␉␉goto sym_ok;␊ |
416 | ␉␉conf_unsaved++;␊ |
417 | ␉␉/* maybe print value in verbose mode... */␊ |
418 | ␉sym_ok:␊ |
419 | ␉␉if (!sym_is_choice(sym))␊ |
420 | ␉␉␉continue;␊ |
421 | ␉␉/* The choice symbol only has a set value (and thus is not new)␊ |
422 | ␉␉ * if all its visible childs have values.␊ |
423 | ␉␉ */␊ |
424 | ␉␉prop = sym_get_choice_prop(sym);␊ |
425 | ␉␉flags = sym->flags;␊ |
426 | ␉␉expr_list_for_each_sym(prop->expr, e, choice_sym)␊ |
427 | ␉␉␉if (choice_sym->visible != no)␊ |
428 | ␉␉␉␉flags &= choice_sym->flags;␊ |
429 | ␉␉sym->flags &= flags | ~SYMBOL_DEF_USER;␊ |
430 | ␉}␊ |
431 | ␊ |
432 | ␉for_all_symbols(i, sym) {␊ |
433 | ␉␉if (sym_has_value(sym) && !sym_is_choice_value(sym)) {␊ |
434 | ␉␉␉/* Reset values of generates values, so they'll appear␊ |
435 | ␉␉␉ * as new, if they should become visible, but that␊ |
436 | ␉␉␉ * doesn't quite work if the Kconfig and the saved␊ |
437 | ␉␉␉ * configuration disagree.␊ |
438 | ␉␉␉ */␊ |
439 | ␉␉␉if (sym->visible == no && !conf_unsaved)␊ |
440 | ␉␉␉␉sym->flags &= ~SYMBOL_DEF_USER;␊ |
441 | ␉␉␉switch (sym->type) {␊ |
442 | ␉␉␉case S_STRING:␊ |
443 | ␉␉␉case S_INT:␊ |
444 | ␉␉␉case S_HEX:␊ |
445 | ␉␉␉␉/* Reset a string value if it's out of range */␊ |
446 | ␉␉␉␉if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))␊ |
447 | ␉␉␉␉␉break;␊ |
448 | ␉␉␉␉sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER);␊ |
449 | ␉␉␉␉conf_unsaved++;␊ |
450 | ␉␉␉␉break;␊ |
451 | ␉␉␉default:␊ |
452 | ␉␉␉␉break;␊ |
453 | ␉␉␉}␊ |
454 | ␉␉}␊ |
455 | ␉}␊ |
456 | ␊ |
457 | ␉sym_add_change_count(conf_warnings || conf_unsaved);␊ |
458 | ␊ |
459 | ␉return 0;␊ |
460 | }␊ |
461 | ␊ |
462 | /* Write a S_STRING */␊ |
463 | static void conf_write_string(bool headerfile, const char *name,␊ |
464 | const char *str, FILE *out)␊ |
465 | {␊ |
466 | ␉int l;␊ |
467 | ␉if (headerfile)␊ |
468 | ␉␉fprintf(out, "#define %s%s \"", CONFIG_, name);␊ |
469 | ␉else␊ |
470 | ␉␉fprintf(out, "%s%s=\"", CONFIG_, name);␊ |
471 | ␊ |
472 | ␉while (1) {␊ |
473 | ␉␉l = strcspn(str, "\"\\");␊ |
474 | ␉␉if (l) {␊ |
475 | ␉␉␉xfwrite(str, l, 1, out);␊ |
476 | ␉␉␉str += l;␊ |
477 | ␉␉}␊ |
478 | ␉␉if (!*str)␊ |
479 | ␉␉␉break;␊ |
480 | ␉␉fprintf(out, "\\%c", *str++);␊ |
481 | ␉}␊ |
482 | ␉fputs("\"\n", out);␊ |
483 | }␊ |
484 | ␊ |
485 | static void conf_write_symbol(struct symbol *sym, FILE *out, bool write_no)␊ |
486 | {␊ |
487 | ␉const char *str;␊ |
488 | ␊ |
489 | ␉switch (sym->type) {␊ |
490 | ␉case S_BOOLEAN:␊ |
491 | ␉case S_TRISTATE:␊ |
492 | ␉␉switch (sym_get_tristate_value(sym)) {␊ |
493 | ␉␉case no:␊ |
494 | ␉␉␉if (write_no)␊ |
495 | ␉␉␉␉fprintf(out, "# %s%s is not set\n",␊ |
496 | ␉␉␉␉ CONFIG_, sym->name);␊ |
497 | ␉␉␉break;␊ |
498 | ␉␉case mod:␊ |
499 | ␉␉␉fprintf(out, "%s%s=m\n", CONFIG_, sym->name);␊ |
500 | ␉␉␉break;␊ |
501 | ␉␉case yes:␊ |
502 | ␉␉␉fprintf(out, "%s%s=y\n", CONFIG_, sym->name);␊ |
503 | ␉␉␉break;␊ |
504 | ␉␉}␊ |
505 | ␉␉break;␊ |
506 | ␉case S_STRING:␊ |
507 | ␉␉conf_write_string(false, sym->name, sym_get_string_value(sym), out);␊ |
508 | ␉␉break;␊ |
509 | ␉case S_HEX:␊ |
510 | ␉case S_INT:␊ |
511 | ␉␉str = sym_get_string_value(sym);␊ |
512 | ␉␉fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str);␊ |
513 | ␉␉break;␊ |
514 | ␉case S_OTHER:␊ |
515 | ␉case S_UNKNOWN:␊ |
516 | ␉␉break;␊ |
517 | ␉}␊ |
518 | }␊ |
519 | ␊ |
520 | /*␊ |
521 | * Write out a minimal config.␊ |
522 | * All values that has default values are skipped as this is redundant.␊ |
523 | */␊ |
524 | int conf_write_defconfig(const char *filename)␊ |
525 | {␊ |
526 | ␉struct symbol *sym;␊ |
527 | ␉struct menu *menu;␊ |
528 | ␉FILE *out;␊ |
529 | ␊ |
530 | ␉out = fopen(filename, "w");␊ |
531 | ␉if (!out)␊ |
532 | ␉␉return 1;␊ |
533 | ␊ |
534 | ␉sym_clear_all_valid();␊ |
535 | ␊ |
536 | ␉/* Traverse all menus to find all relevant symbols */␊ |
537 | ␉menu = rootmenu.list;␊ |
538 | ␊ |
539 | ␉while (menu != NULL)␊ |
540 | ␉{␊ |
541 | ␉␉sym = menu->sym;␊ |
542 | ␉␉if (sym == NULL) {␊ |
543 | ␉␉␉if (!menu_is_visible(menu))␊ |
544 | ␉␉␉␉goto next_menu;␊ |
545 | ␉␉} else if (!sym_is_choice(sym)) {␊ |
546 | ␉␉␉sym_calc_value(sym);␊ |
547 | ␉␉␉if (!(sym->flags & SYMBOL_WRITE))␊ |
548 | ␉␉␉␉goto next_menu;␊ |
549 | ␉␉␉sym->flags &= ~SYMBOL_WRITE;␊ |
550 | ␉␉␉/* If we cannot change the symbol - skip */␊ |
551 | ␉␉␉if (!sym_is_changable(sym))␊ |
552 | ␉␉␉␉goto next_menu;␊ |
553 | ␉␉␉/* If symbol equals to default value - skip */␊ |
554 | ␉␉␉if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)␊ |
555 | ␉␉␉␉goto next_menu;␊ |
556 | ␊ |
557 | ␉␉␉/*␊ |
558 | ␉␉␉ * If symbol is a choice value and equals to the␊ |
559 | ␉␉␉ * default for a choice - skip.␊ |
560 | ␉␉␉ * But only if value is bool and equal to "y" and␊ |
561 | ␉␉␉ * choice is not "optional".␊ |
562 | ␉␉␉ * (If choice is "optional" then all values can be "n")␊ |
563 | ␉␉␉ */␊ |
564 | ␉␉␉if (sym_is_choice_value(sym)) {␊ |
565 | ␉␉␉␉struct symbol *cs;␊ |
566 | ␉␉␉␉struct symbol *ds;␊ |
567 | ␊ |
568 | ␉␉␉␉cs = prop_get_symbol(sym_get_choice_prop(sym));␊ |
569 | ␉␉␉␉ds = sym_choice_default(cs);␊ |
570 | ␉␉␉␉if (!sym_is_optional(cs) && sym == ds) {␊ |
571 | ␉␉␉␉␉if ((sym->type == S_BOOLEAN) &&␊ |
572 | ␉␉␉␉␉ sym_get_tristate_value(sym) == yes)␊ |
573 | ␉␉␉␉␉␉goto next_menu;␊ |
574 | ␉␉␉␉}␊ |
575 | ␉␉␉}␊ |
576 | ␉␉␉conf_write_symbol(sym, out, true);␊ |
577 | ␉␉}␊ |
578 | next_menu:␊ |
579 | ␉␉if (menu->list != NULL) {␊ |
580 | ␉␉␉menu = menu->list;␊ |
581 | ␉␉}␊ |
582 | ␉␉else if (menu->next != NULL) {␊ |
583 | ␉␉␉menu = menu->next;␊ |
584 | ␉␉} else {␊ |
585 | ␉␉␉while ((menu = menu->parent)) {␊ |
586 | ␉␉␉␉if (menu->next != NULL) {␊ |
587 | ␉␉␉␉␉menu = menu->next;␊ |
588 | ␉␉␉␉␉break;␊ |
589 | ␉␉␉␉}␊ |
590 | ␉␉␉}␊ |
591 | ␉␉}␊ |
592 | ␉}␊ |
593 | ␉fclose(out);␊ |
594 | ␉return 0;␊ |
595 | }␊ |
596 | ␊ |
597 | int conf_write(const char *name)␊ |
598 | {␊ |
599 | ␉FILE *out;␊ |
600 | ␉struct symbol *sym;␊ |
601 | ␉struct menu *menu;␊ |
602 | ␉const char *basename;␊ |
603 | ␉const char *str;␊ |
604 | ␉char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];␊ |
605 | ␉time_t now;␊ |
606 | ␉int use_timestamp = 1;␊ |
607 | ␉char *env;␊ |
608 | ␊ |
609 | ␉dirname[0] = 0;␊ |
610 | ␉if (name && name[0]) {␊ |
611 | ␉␉struct stat st;␊ |
612 | ␉␉char *slash;␊ |
613 | ␊ |
614 | ␉␉if (!stat(name, &st) && S_ISDIR(st.st_mode)) {␊ |
615 | ␉␉␉/* FIXME: add length check */␊ |
616 | ␉␉␉strcpy(stpcpy(dirname, name), "/");␊ |
617 | ␉␉␉basename = conf_get_configname();␊ |
618 | ␉␉} else if ((slash = strrchr(name, '/'))) {␊ |
619 | ␉␉␉size_t size = slash - name + 1;␊ |
620 | ␉␉␉memcpy(dirname, name, size);␊ |
621 | ␉␉␉dirname[size] = 0;␊ |
622 | ␉␉␉if (slash[1]) {␊ |
623 | ␉␉␉␉basename = slash + 1;␊ |
624 | ␉␉␉} else {␊ |
625 | ␉␉␉␉basename = conf_get_configname();␊ |
626 | ␉␉␉}␊ |
627 | ␉␉} else {␊ |
628 | ␉␉␉basename = name;␊ |
629 | ␉␉}␊ |
630 | ␉} else {␊ |
631 | ␉␉basename = conf_get_configname();␊ |
632 | ␉}␊ |
633 | ␉snprintf(newname, PATH_MAX+1, "%s%s", dirname, basename);␊ |
634 | ␉env = getenv("KCONFIG_OVERWRITECONFIG");␊ |
635 | ␉if (!env || !*env) {␊ |
636 | ␉␉snprintf(tmpname, PATH_MAX+1, "%s.tmpconfig.%d", dirname, (int)getpid());␊ |
637 | ␉␉out = fopen(tmpname, "w");␊ |
638 | ␉} else {␊ |
639 | ␉␉*tmpname = 0;␊ |
640 | ␉␉out = fopen(newname, "w");␊ |
641 | ␉}␊ |
642 | ␉if (!out) {␊ |
643 | ␉␉return 1;␊ |
644 | ␉}␊ |
645 | ␉time(&now);␊ |
646 | ␉env = getenv("KCONFIG_NOTIMESTAMP");␊ |
647 | ␉if (env && *env) {␊ |
648 | ␉␉use_timestamp = 0;␊ |
649 | ␉}␊ |
650 | ␊ |
651 | ␉fprintf(out, _("#\n"␊ |
652 | ␉␉ "# Automatically generated make config: don't edit\n"␊ |
653 | ␉␉ "# %s\n"␊ |
654 | ␉␉ "%s%s"␊ |
655 | ␉␉ "#\n"),␊ |
656 | ␉␉ rootmenu.prompt->text,␊ |
657 | ␉␉ use_timestamp ? "# " : "",␊ |
658 | ␉␉ use_timestamp ? ctime(&now) : "");␊ |
659 | ␊ |
660 | ␉if (!conf_get_changed())␊ |
661 | ␉␉sym_clear_all_valid();␊ |
662 | ␊ |
663 | ␉menu = rootmenu.list;␊ |
664 | ␉while (menu) {␊ |
665 | ␉␉sym = menu->sym;␊ |
666 | ␉␉if (!sym) {␊ |
667 | ␉␉␉if (!menu_is_visible(menu))␊ |
668 | ␉␉␉␉goto next;␊ |
669 | ␉␉␉str = menu_get_prompt(menu);␊ |
670 | ␉␉␉fprintf(out, "\n"␊ |
671 | ␉␉␉␉ "#\n"␊ |
672 | ␉␉␉␉ "# %s\n"␊ |
673 | ␉␉␉␉ "#\n", str);␊ |
674 | ␉␉} else if (!(sym->flags & SYMBOL_CHOICE)) {␊ |
675 | ␉␉␉sym_calc_value(sym);␊ |
676 | ␉␉␉if (!(sym->flags & SYMBOL_WRITE))␊ |
677 | ␉␉␉␉goto next;␊ |
678 | ␉␉␉sym->flags &= ~SYMBOL_WRITE;␊ |
679 | ␉␉␉/* Write config symbol to file */␊ |
680 | ␉␉␉conf_write_symbol(sym, out, true);␊ |
681 | ␉␉}␊ |
682 | ␊ |
683 | next:␊ |
684 | ␉␉if (menu->list) {␊ |
685 | ␉␉␉menu = menu->list;␊ |
686 | ␉␉␉continue;␊ |
687 | ␉␉}␊ |
688 | ␉␉if (menu->next) {␊ |
689 | ␉␉␉menu = menu->next;␊ |
690 | ␉␉} else while ((menu = menu->parent)) {␊ |
691 | ␉␉␉if (menu->next) {␊ |
692 | ␉␉␉␉menu = menu->next;␊ |
693 | ␉␉␉␉break;␊ |
694 | ␉␉␉}␊ |
695 | ␉␉}␊ |
696 | ␉}␊ |
697 | ␉fclose(out);␊ |
698 | ␊ |
699 | ␉if (*tmpname) {␊ |
700 | ␉␉strcat(dirname, basename);␊ |
701 | ␉␉strcat(dirname, ".old");␊ |
702 | ␉␉rename(newname, dirname);␊ |
703 | ␉␉if (rename(tmpname, newname)) {␊ |
704 | ␉␉␉return 1;␊ |
705 | ␉␉}␊ |
706 | ␉}␊ |
707 | ␊ |
708 | //␉conf_message(_("configuration written to %s"), newname);␊ |
709 | ␊ |
710 | ␉sym_set_change_count(0);␊ |
711 | ␊ |
712 | ␉return 0;␊ |
713 | }␊ |
714 | #if 0␊ |
715 | ␊ |
716 | static int conf_split_config(void)␊ |
717 | {␊ |
718 | ␉const char *name;␊ |
719 | ␉char path[PATH_MAX+1];␊ |
720 | ␉char *s, *d, c;␊ |
721 | ␉struct symbol *sym;␊ |
722 | ␉struct stat sb;␊ |
723 | ␉int res, i, fd;␊ |
724 | ␊ |
725 | ␉name = conf_get_autoconfig_name();␊ |
726 | ␉conf_read_simple(name, S_DEF_AUTO);␊ |
727 | ␊ |
728 | ␉//if (chdir("include/config"))␊ |
729 | ␉//␉return 1;␊ |
730 | ␊ |
731 | ␉res = 0;␊ |
732 | ␉for_all_symbols(i, sym) {␊ |
733 | ␉␉sym_calc_value(sym);␊ |
734 | ␉␉if ((sym->flags & SYMBOL_AUTO) || !sym->name)␊ |
735 | ␉␉␉continue;␊ |
736 | ␉␉if (sym->flags & SYMBOL_WRITE) {␊ |
737 | ␉␉␉if (sym->flags & SYMBOL_DEF_AUTO) {␊ |
738 | ␉␉␉␉/*␊ |
739 | ␉␉␉␉ * symbol has old and new value,␊ |
740 | ␉␉␉␉ * so compare them...␊ |
741 | ␉␉␉␉ */␊ |
742 | ␉␉␉␉switch (sym->type) {␊ |
743 | ␉␉␉␉case S_BOOLEAN:␊ |
744 | ␉␉␉␉case S_TRISTATE:␊ |
745 | ␉␉␉␉␉if (sym_get_tristate_value(sym) ==␊ |
746 | ␉␉␉␉␉ sym->def[S_DEF_AUTO].tri)␊ |
747 | ␉␉␉␉␉␉continue;␊ |
748 | ␉␉␉␉␉break;␊ |
749 | ␉␉␉␉case S_STRING:␊ |
750 | ␉␉␉␉case S_HEX:␊ |
751 | ␉␉␉␉case S_INT:␊ |
752 | ␉␉␉␉␉if (!strcmp(sym_get_string_value(sym),␊ |
753 | ␉␉␉␉␉␉ sym->def[S_DEF_AUTO].val))␊ |
754 | ␉␉␉␉␉␉continue;␊ |
755 | ␉␉␉␉␉break;␊ |
756 | ␉␉␉␉default:␊ |
757 | ␉␉␉␉␉break;␊ |
758 | ␉␉␉␉}␊ |
759 | ␉␉␉} else {␊ |
760 | ␉␉␉␉/*␊ |
761 | ␉␉␉␉ * If there is no old value, only 'no' (unset)␊ |
762 | ␉␉␉␉ * is allowed as new value.␊ |
763 | ␉␉␉␉ */␊ |
764 | ␉␉␉␉switch (sym->type) {␊ |
765 | ␉␉␉␉case S_BOOLEAN:␊ |
766 | ␉␉␉␉case S_TRISTATE:␊ |
767 | ␉␉␉␉␉if (sym_get_tristate_value(sym) == no)␊ |
768 | ␉␉␉␉␉␉continue;␊ |
769 | ␉␉␉␉␉break;␊ |
770 | ␉␉␉␉default:␊ |
771 | ␉␉␉␉␉break;␊ |
772 | ␉␉␉␉}␊ |
773 | ␉␉␉}␊ |
774 | ␉␉} else if (!(sym->flags & SYMBOL_DEF_AUTO))␊ |
775 | ␉␉␉/* There is neither an old nor a new value. */␊ |
776 | ␉␉␉continue;␊ |
777 | ␉␉/* else␊ |
778 | ␉␉ *␉There is an old value, but no new value ('no' (unset)␊ |
779 | ␉␉ *␉isn't saved in auto.conf, so the old value is always␊ |
780 | ␉␉ *␉different from 'no').␊ |
781 | ␉␉ */␊ |
782 | ␊ |
783 | ␉␉/* Replace all '_' and append ".h" */␊ |
784 | ␉␉s = sym->name;␊ |
785 | ␉␉d = path;␊ |
786 | ␉␉while ((c = *s++)) {␊ |
787 | ␉␉␉c = tolower(c);␊ |
788 | ␉␉␉*d++ = (c == '_') ? '/' : c;␊ |
789 | ␉␉}␊ |
790 | ␉␉strcpy(d, ".h");␊ |
791 | ␊ |
792 | ␉␉/* Assume directory path already exists. */␊ |
793 | ␉␉fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);␊ |
794 | ␉␉if (fd == -1) {␊ |
795 | ␉␉␉if (errno != ENOENT) {␊ |
796 | ␉␉␉␉res = 1;␊ |
797 | ␉␉␉␉break;␊ |
798 | ␉␉␉}␊ |
799 | ␉␉␉/*␊ |
800 | ␉␉␉ * Create directory components,␊ |
801 | ␉␉␉ * unless they exist already.␊ |
802 | ␉␉␉ */␊ |
803 | ␉␉␉d = path;␊ |
804 | ␉␉␉while ((d = strchr(d, '/'))) {␊ |
805 | ␉␉␉␉*d = 0;␊ |
806 | ␉␉␉␉if (stat(path, &sb) && mkdir(path, 0755)) {␊ |
807 | ␉␉␉␉␉res = 1;␊ |
808 | ␉␉␉␉␉goto out;␊ |
809 | ␉␉␉␉}␊ |
810 | ␉␉␉␉*d++ = '/';␊ |
811 | ␉␉␉}␊ |
812 | ␉␉␉/* Try it again. */␊ |
813 | ␉␉␉fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);␊ |
814 | ␉␉␉if (fd == -1) {␊ |
815 | ␉␉␉␉res = 1;␊ |
816 | ␉␉␉␉break;␊ |
817 | ␉␉␉}␊ |
818 | ␉␉}␊ |
819 | ␉␉close(fd);␊ |
820 | ␉}␊ |
821 | out:␊ |
822 | ␉if (chdir("../.."))␊ |
823 | ␉␉return 1;␊ |
824 | ␊ |
825 | ␉return res;␊ |
826 | }␊ |
827 | #endif␊ |
828 | int conf_write_autoconf(void)␊ |
829 | {␊ |
830 | ␉struct symbol *sym;␊ |
831 | ␉const char *str;␊ |
832 | ␉const char *name;␊ |
833 | ␉FILE *out, *out_h, *out_inc;␊ |
834 | ␉time_t now;␊ |
835 | ␉int i;␊ |
836 | ␊ |
837 | ␉sym_clear_all_valid();␊ |
838 | ␊ |
839 | ␉/*if (conf_split_config())␊ |
840 | ␉{␊ |
841 | printf("ERR: conf_split_config");␊ |
842 | return 1; ␊ |
843 | }*/␊ |
844 | ␊ |
845 | ␉out = fopen(".tmpconfig", "w");␊ |
846 | ␉if (!out)␊ |
847 | {␊ |
848 | printf("ERR: .tmpconfig");␊ |
849 | ␉␉return 1;␊ |
850 | }␊ |
851 | ␊ |
852 | ␉out_h = fopen(".tmpconfig.h", "w");␊ |
853 | ␉if (!out_h) {␊ |
854 | ␉␉fclose(out);␊ |
855 | ␉␉return 1;␊ |
856 | ␉}␊ |
857 | ␊ |
858 | out_inc = fopen(".tmpconfig.inc", "w");␊ |
859 | ␉if (!out_inc) {␊ |
860 | ␉␉fclose(out);␊ |
861 | fclose(out_h);␊ |
862 | ␉␉return 1;␊ |
863 | ␉}␊ |
864 | ␊ |
865 | ␊ |
866 | ␉time(&now);␊ |
867 | ␉fprintf(out, "#\n"␊ |
868 | ␉␉ "# Automatically generated make config: don't edit\n"␊ |
869 | ␉␉ "# %s\n"␊ |
870 | ␉␉ "# %s"␊ |
871 | ␉␉ "#\n",␊ |
872 | ␉␉ rootmenu.prompt->text, ctime(&now));␊ |
873 | ␊ |
874 | ␉fprintf(out_h, "//\n"␊ |
875 | "// Automatically generated make config: don't edit\n"␊ |
876 | "// %s\n"␊ |
877 | "// %s"␊ |
878 | "// \n",␊ |
879 | rootmenu.prompt->text, ctime(&now));␊ |
880 | ␊ |
881 | fprintf(out_inc, ";\n"␊ |
882 | "; Automatically generated make config: don't edit\n"␊ |
883 | "; %s\n"␊ |
884 | "; %s"␊ |
885 | ";\n",␊ |
886 | rootmenu.prompt->text, ctime(&now));␊ |
887 | ␊ |
888 | ␊ |
889 | fprintf(out_h, "#define CONFIG_IS_BUILTIN 1\n");␊ |
890 | fprintf(out_h, "#define CONFIG_IS_MODULE 2\n");␊ |
891 | ␊ |
892 | ␊ |
893 | ␉for_all_symbols(i, sym) {␊ |
894 | ␉␉sym_calc_value(sym);␊ |
895 | ␉␉if (!(sym->flags & SYMBOL_WRITE) || !sym->name)␊ |
896 | ␉␉␉continue;␊ |
897 | ␊ |
898 | ␉␉/* write symbol to config file */␊ |
899 | ␉␉conf_write_symbol(sym, out, false);␊ |
900 | ␊ |
901 | ␉␉/* update autoconf and tristate files */␊ |
902 | ␉␉switch (sym->type) {␊ |
903 | ␉␉case S_BOOLEAN:␊ |
904 | ␉␉case S_TRISTATE:␊ |
905 | ␉␉␉switch (sym_get_tristate_value(sym)) {␊ |
906 | ␉␉␉case no:␊ |
907 | fprintf(out_inc, "%s%s EQU 0\n",␊ |
908 | CONFIG_, sym->name);␊ |
909 | ␊ |
910 | ␉␉␉␉break;␊ |
911 | ␉␉␉case mod:␊ |
912 | ␉␉␉␉fprintf(out_inc, "%s%s EQU 1\n",␊ |
913 | ␉␉␉␉ CONFIG_, sym->name);␊ |
914 | fprintf(out_h, "#define %s%s CONFIG_IS_MODULE\n",␊ |
915 | CONFIG_, sym->name);␊ |
916 | ␊ |
917 | ␉␉␉␉break;␊ |
918 | ␉␉␉case yes:␊ |
919 | fprintf(out_inc, "%s%s EQU 1\n",␊ |
920 | CONFIG_, sym->name);␊ |
921 | ␉␉␉␉fprintf(out_h, "#define %s%s CONFIG_IS_BUILTIN\n",␊ |
922 | ␉␉␉␉ CONFIG_, sym->name);␊ |
923 | ␉␉␉␉break;␊ |
924 | ␉␉␉}␊ |
925 | ␉␉␉break;␊ |
926 | ␉␉case S_STRING:␊ |
927 | ␉␉␉conf_write_string(true, sym->name, sym_get_string_value(sym), out_h);␊ |
928 | ␉␉␉break;␊ |
929 | ␉␉case S_HEX:␊ |
930 | ␉␉␉str = sym_get_string_value(sym);␊ |
931 | ␉␉␉if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {␊ |
932 | fprintf(out_inc, "%s%s EQU 0x%s\n",␊ |
933 | CONFIG_, sym->name, str);␊ |
934 | ␉␉␉␉fprintf(out_h, "#define %s%s 0x%s\n",␊ |
935 | ␉␉␉␉ CONFIG_, sym->name, str);␊ |
936 | ␉␉␉␉break;␊ |
937 | ␉␉␉}␊ |
938 | ␉␉case S_INT:␊ |
939 | ␉␉␉str = sym_get_string_value(sym);␊ |
940 | fprintf(out_inc, "%s%s EQU %s\n",␊ |
941 | CONFIG_, sym->name, str);␊ |
942 | ␉␉␉fprintf(out_h, "#define %s%s %s\n",␊ |
943 | ␉␉␉ CONFIG_, sym->name, str);␊ |
944 | ␉␉␉break;␊ |
945 | ␉␉default:␊ |
946 | ␉␉␉break;␊ |
947 | ␉␉}␊ |
948 | ␉}␊ |
949 | ␉fclose(out);␊ |
950 | ␉fclose(out_h);␊ |
951 | ␉fclose(out_inc);␊ |
952 | ␊ |
953 | ␉name = getenv("CCONFIG_AUTOHEADER");␊ |
954 | ␉if (!name) name = "autoconf.h";␊ |
955 | ␉if (rename(".tmpconfig.h", name))␊ |
956 | ␉␉return 1;␊ |
957 | ␊ |
958 | name = getenv("CCONFIG_AUTOINC");␊ |
959 | ␉if (!name) name = "autoconf.inc";␊ |
960 | ␉if (rename(".tmpconfig.inc", name))␊ |
961 | ␉␉return 1;␊ |
962 | ␊ |
963 | ␊ |
964 | ␉name = conf_get_autoconfig_name();␊ |
965 | ␉/*␊ |
966 | ␉ * This must be the last step, kbuild has a dependency on auto.conf␊ |
967 | ␉ * and this marks the successful completion of the previous steps.␊ |
968 | ␉ */␊ |
969 | ␉if (rename(".tmpconfig", name))␊ |
970 | {␊ |
971 | printf("rename");␊ |
972 | ␉␉return 1;␊ |
973 | }␊ |
974 | ␉return 0;␊ |
975 | }␊ |
976 | ␊ |
977 | static int sym_change_count;␊ |
978 | static void (*conf_changed_callback)(void);␊ |
979 | ␊ |
980 | void sym_set_change_count(int count)␊ |
981 | {␊ |
982 | ␉int _sym_change_count = sym_change_count;␊ |
983 | ␉sym_change_count = count;␊ |
984 | ␉if (conf_changed_callback &&␊ |
985 | ␉ (bool)_sym_change_count != (bool)count)␊ |
986 | ␉␉conf_changed_callback();␊ |
987 | }␊ |
988 | ␊ |
989 | void sym_add_change_count(int count)␊ |
990 | {␊ |
991 | ␉sym_set_change_count(count + sym_change_count);␊ |
992 | }␊ |
993 | ␊ |
994 | bool conf_get_changed(void)␊ |
995 | {␊ |
996 | ␉return sym_change_count;␊ |
997 | }␊ |
998 | ␊ |
999 | void conf_set_changed_callback(void (*fn)(void))␊ |
1000 | {␊ |
1001 | ␉conf_changed_callback = fn;␊ |
1002 | }␊ |
1003 | ␊ |
1004 | static void randomize_choice_values(struct symbol *csym)␊ |
1005 | {␊ |
1006 | ␉struct property *prop;␊ |
1007 | ␉struct symbol *sym;␊ |
1008 | ␉struct expr *e;␊ |
1009 | ␉int cnt, def;␊ |
1010 | ␊ |
1011 | ␉/*␊ |
1012 | ␉ * If choice is mod then we may have more items selected␊ |
1013 | ␉ * and if no then no-one.␊ |
1014 | ␉ * In both cases stop.␊ |
1015 | ␉ */␊ |
1016 | ␉if (csym->curr.tri != yes)␊ |
1017 | ␉␉return;␊ |
1018 | ␊ |
1019 | ␉prop = sym_get_choice_prop(csym);␊ |
1020 | ␊ |
1021 | ␉/* count entries in choice block */␊ |
1022 | ␉cnt = 0;␊ |
1023 | ␉expr_list_for_each_sym(prop->expr, e, sym)␊ |
1024 | ␉␉cnt++;␊ |
1025 | ␊ |
1026 | ␉/*␊ |
1027 | ␉ * find a random value and set it to yes,␊ |
1028 | ␉ * set the rest to no so we have only one set␊ |
1029 | ␉ */␊ |
1030 | ␉def = (rand() % cnt);␊ |
1031 | ␊ |
1032 | ␉cnt = 0;␊ |
1033 | ␉expr_list_for_each_sym(prop->expr, e, sym) {␊ |
1034 | ␉␉if (def == cnt++) {␊ |
1035 | ␉␉␉sym->def[S_DEF_USER].tri = yes;␊ |
1036 | ␉␉␉csym->def[S_DEF_USER].val = sym;␊ |
1037 | ␉␉}␊ |
1038 | ␉␉else {␊ |
1039 | ␉␉␉sym->def[S_DEF_USER].tri = no;␊ |
1040 | ␉␉}␊ |
1041 | ␉}␊ |
1042 | ␉csym->flags |= SYMBOL_DEF_USER;␊ |
1043 | ␉/* clear VALID to get value calculated */␊ |
1044 | ␉csym->flags &= ~(SYMBOL_VALID);␊ |
1045 | }␊ |
1046 | ␊ |
1047 | static void set_all_choice_values(struct symbol *csym)␊ |
1048 | {␊ |
1049 | ␉struct property *prop;␊ |
1050 | ␉struct symbol *sym;␊ |
1051 | ␉struct expr *e;␊ |
1052 | ␊ |
1053 | ␉prop = sym_get_choice_prop(csym);␊ |
1054 | ␊ |
1055 | ␉/*␊ |
1056 | ␉ * Set all non-assinged choice values to no␊ |
1057 | ␉ */␊ |
1058 | ␉expr_list_for_each_sym(prop->expr, e, sym) {␊ |
1059 | ␉␉if (!sym_has_value(sym))␊ |
1060 | ␉␉␉sym->def[S_DEF_USER].tri = no;␊ |
1061 | ␉}␊ |
1062 | ␉csym->flags |= SYMBOL_DEF_USER;␊ |
1063 | ␉/* clear VALID to get value calculated */␊ |
1064 | ␉csym->flags &= ~(SYMBOL_VALID);␊ |
1065 | }␊ |
1066 | ␊ |
1067 | void conf_set_all_new_symbols(enum conf_def_mode mode)␊ |
1068 | {␊ |
1069 | ␉struct symbol *sym, *csym;␊ |
1070 | ␉int i, cnt;␊ |
1071 | ␊ |
1072 | ␉for_all_symbols(i, sym) {␊ |
1073 | ␉␉if (sym_has_value(sym))␊ |
1074 | ␉␉␉continue;␊ |
1075 | ␉␉switch (sym_get_type(sym)) {␊ |
1076 | ␉␉case S_BOOLEAN:␊ |
1077 | ␉␉case S_TRISTATE:␊ |
1078 | ␉␉␉switch (mode) {␊ |
1079 | ␉␉␉case def_yes:␊ |
1080 | ␉␉␉␉sym->def[S_DEF_USER].tri = yes;␊ |
1081 | ␉␉␉␉break;␊ |
1082 | ␉␉␉case def_mod:␊ |
1083 | ␉␉␉␉sym->def[S_DEF_USER].tri = mod;␊ |
1084 | ␉␉␉␉break;␊ |
1085 | ␉␉␉case def_no:␊ |
1086 | ␉␉␉␉sym->def[S_DEF_USER].tri = no;␊ |
1087 | ␉␉␉␉break;␊ |
1088 | ␉␉␉case def_random:␊ |
1089 | ␉␉␉␉cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;␊ |
1090 | ␉␉␉␉sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);␊ |
1091 | ␉␉␉␉break;␊ |
1092 | ␉␉␉default:␊ |
1093 | ␉␉␉␉continue;␊ |
1094 | ␉␉␉}␊ |
1095 | ␉␉␉if (!(sym_is_choice(sym) && mode == def_random))␊ |
1096 | ␉␉␉␉sym->flags |= SYMBOL_DEF_USER;␊ |
1097 | ␉␉␉break;␊ |
1098 | ␉␉default:␊ |
1099 | ␉␉␉break;␊ |
1100 | ␉␉}␊ |
1101 | ␊ |
1102 | ␉}␊ |
1103 | ␊ |
1104 | ␉sym_clear_all_valid();␊ |
1105 | ␊ |
1106 | ␉/*␊ |
1107 | ␉ * We have different type of choice blocks.␊ |
1108 | ␉ * If curr.tri equals to mod then we can select several␊ |
1109 | ␉ * choice symbols in one block.␊ |
1110 | ␉ * In this case we do nothing.␊ |
1111 | ␉ * If curr.tri equals yes then only one symbol can be␊ |
1112 | ␉ * selected in a choice block and we set it to yes,␊ |
1113 | ␉ * and the rest to no.␊ |
1114 | ␉ */␊ |
1115 | ␉for_all_symbols(i, csym) {␊ |
1116 | ␉␉if (sym_has_value(csym) || !sym_is_choice(csym))␊ |
1117 | ␉␉␉continue;␊ |
1118 | ␊ |
1119 | ␉␉sym_calc_value(csym);␊ |
1120 | ␉␉if (mode == def_random)␊ |
1121 | ␉␉␉randomize_choice_values(csym);␊ |
1122 | ␉␉else␊ |
1123 | ␉␉␉set_all_choice_values(csym);␊ |
1124 | ␉}␊ |
1125 | }␊ |
1126 | |