2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 static void conf_warning(const char *fmt
, ...)
18 __attribute__ ((format (printf
, 1, 2)));
20 static const char *conf_filename
;
21 static int conf_lineno
, conf_warnings
, conf_unsaved
;
23 const char conf_def_filename
[] = ".config";
25 const char conf_defname
[] = "scripts/config/defconfig";
27 const char *conf_confnames
[] = {
33 static void conf_warning(const char *fmt
, ...)
37 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
38 vfprintf(stderr
, fmt
, ap
);
39 fprintf(stderr
, "\n");
44 static char *conf_expand_value(const char *in
)
48 static char res_value
[SYMBOL_MAXLENGTH
];
49 char *dst
, name
[SYMBOL_MAXLENGTH
];
53 while ((src
= strchr(in
, '$'))) {
54 strncat(res_value
, in
, src
- in
);
57 while (isalnum(*src
) || *src
== '_')
60 sym
= sym_lookup(name
, 0);
62 strcat(res_value
, sym_get_string_value(sym
));
65 strcat(res_value
, in
);
70 char *conf_get_default_confname(void)
73 static char fullname
[PATH_MAX
+1];
76 name
= conf_expand_value(conf_defname
);
77 env
= getenv(SRCTREE
);
79 sprintf(fullname
, "%s/%s", env
, name
);
80 if (!stat(fullname
, &buf
))
91 for_all_symbols(i
, sym
) {
92 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
93 if (sym_is_choice(sym
))
94 sym
->flags
&= ~SYMBOL_NEW
;
95 sym
->flags
&= ~SYMBOL_VALID
;
103 sym
->user
.val
= NULL
;
109 int conf_read_simple(const char *name
)
118 in
= zconf_fopen(name
);
120 const char **names
= conf_confnames
;
121 while ((name
= *names
++)) {
122 name
= conf_expand_value(name
);
123 in
= zconf_fopen(name
);
126 "# using defaults found in %s\n"
135 conf_filename
= name
;
140 for_all_symbols(i
, sym
) {
141 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
142 if (sym_is_choice(sym
))
143 sym
->flags
&= ~SYMBOL_NEW
;
144 sym
->flags
&= ~SYMBOL_VALID
;
152 sym
->user
.val
= NULL
;
157 while (fgets(line
, sizeof(line
), in
)) {
162 if (memcmp(line
+ 2, "CONFIG_", 7))
164 p
= strchr(line
+ 9, ' ');
168 if (strncmp(p
, "is not set", 10))
170 sym
= sym_find(line
+ 9);
172 conf_warning("trying to assign nonexistent symbol %s", line
+ 9);
174 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
175 conf_warning("trying to reassign symbol %s", sym
->name
);
182 sym
->flags
&= ~SYMBOL_NEW
;
189 if (memcmp(line
, "CONFIG_", 7)) {
190 conf_warning("unexpected data");
193 p
= strchr(line
+ 7, '=');
197 p2
= strchr(p
, '\n');
200 sym
= sym_find(line
+ 7);
202 conf_warning("trying to assign nonexistent symbol %s", line
+ 7);
204 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
205 conf_warning("trying to reassign symbol %s", sym
->name
);
212 sym
->flags
&= ~SYMBOL_NEW
;
218 sym
->flags
&= ~SYMBOL_NEW
;
223 sym
->flags
&= ~SYMBOL_NEW
;
226 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
231 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
236 memmove(p2
, p2
+ 1, strlen(p2
));
239 conf_warning("invalid string found");
244 if (sym_string_valid(sym
, p
)) {
245 sym
->user
.val
= strdup(p
);
246 sym
->flags
&= ~SYMBOL_NEW
;
248 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
259 conf_warning("unexpected data");
262 if (sym
&& sym_is_choice_value(sym
)) {
263 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
264 switch (sym
->user
.tri
) {
268 if (cs
->user
.tri
== yes
) {
269 conf_warning("%s creates inconsistent choice state", sym
->name
);
270 cs
->flags
|= SYMBOL_NEW
;
274 if (cs
->user
.tri
!= no
) {
275 conf_warning("%s creates inconsistent choice state", sym
->name
);
276 cs
->flags
|= SYMBOL_NEW
;
281 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
287 sym_calc_value(modules_sym
);
291 int conf_read(const char *name
)
294 struct property
*prop
;
298 if (conf_read_simple(name
))
301 for_all_symbols(i
, sym
) {
303 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
305 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
306 /* check that calculated value agrees with saved value */
310 if (sym
->user
.tri
!= sym_get_tristate_value(sym
))
312 if (!sym_is_choice(sym
))
315 if (!strcmp(sym
->curr
.val
, sym
->user
.val
))
319 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
320 /* no previous value and not saved */
323 /* maybe print value in verbose mode... */
325 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
326 if (sym
->visible
== no
)
327 sym
->flags
|= SYMBOL_NEW
;
332 if (!sym_string_within_range(sym
, sym
->user
.val
)) {
333 sym
->flags
|= SYMBOL_NEW
;
334 sym
->flags
&= ~SYMBOL_VALID
;
340 if (!sym_is_choice(sym
))
342 prop
= sym_get_choice_prop(sym
);
343 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
344 if (e
->right
.sym
->visible
!= no
)
345 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
348 sym_change_count
= conf_warnings
&& conf_unsaved
;
353 int conf_write(const char *name
)
358 const char *basename
;
359 char dirname
[128], tmpname
[128], newname
[128];
363 int use_timestamp
= 1;
367 if (name
&& name
[0]) {
371 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
372 strcpy(dirname
, name
);
373 strcat(dirname
, "/");
374 basename
= conf_def_filename
;
375 } else if ((slash
= strrchr(name
, '/'))) {
376 int size
= slash
- name
+ 1;
377 memcpy(dirname
, name
, size
);
380 basename
= slash
+ 1;
382 basename
= conf_def_filename
;
386 basename
= conf_def_filename
;
388 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
389 out
= fopen(newname
, "w");
392 sym
= sym_lookup("OPENWRTVERSION", 0);
395 env
= getenv("KCONFIG_NOTIMESTAMP");
400 "# Automatically generated make config: don't edit\n"
401 "# OpenWrt version: %s\n"
404 sym_get_string_value(sym
),
405 use_timestamp
? "# " : "",
406 use_timestamp
? ctime(&now
) : "");
408 if (!sym_change_count
)
409 sym_clear_all_valid();
411 menu
= rootmenu
.list
;
415 if (!menu_is_visible(menu
))
417 str
= menu_get_prompt(menu
);
422 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
424 if (!(sym
->flags
& SYMBOL_WRITE
))
426 sym
->flags
&= ~SYMBOL_WRITE
;
428 if (type
== S_TRISTATE
) {
429 sym_calc_value(modules_sym
);
430 /* tristate always enabled */
432 if (modules_sym
->curr
.tri
== no
)
439 switch (sym_get_tristate_value(sym
)) {
441 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
444 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
447 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
453 str
= sym_get_string_value(sym
);
454 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
456 l
= strcspn(str
, "\"\\");
458 fwrite(str
, l
, 1, out
);
461 while (*str
== '\\' || *str
== '"') {
462 fprintf(out
, "\\%c", *str
);
469 str
= sym_get_string_value(sym
);
470 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
471 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
475 str
= sym_get_string_value(sym
);
476 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
488 else while ((menu
= menu
->parent
)) {
496 if (!name
|| basename
!= conf_def_filename
) {
498 name
= conf_def_filename
;
499 sprintf(tmpname
, "%s.old", name
);
500 rename(name
, tmpname
);
502 sprintf(tmpname
, "%s%s", dirname
, basename
);
503 if (rename(newname
, tmpname
))
506 sym_change_count
= 0;
This page took 0.064859 seconds and 5 git commands to generate.