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