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