2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
5 * Allow 'n' as a symbol value.
6 * 2002-11-05 Petr Baudis <pasky@ucw.cz>
15 #define LKC_DIRECT_LINK
18 const char conf_def_filename
[] = ".config";
20 const char conf_defname
[] = "extra/Configs/Config.$TARGET_ARCH.default";
22 const char *conf_confnames
[] = {
28 static char *conf_expand_value(const char *in
)
32 static char res_value
[SYMBOL_MAXLENGTH
];
33 char *dst
, name
[SYMBOL_MAXLENGTH
];
37 while ((src
= strchr(in
, '$'))) {
38 strncat(res_value
, in
, src
- in
);
41 while (isalnum((int)*src
) || *src
== '_')
44 sym
= sym_lookup(name
, 0);
46 strcat(res_value
, sym_get_string_value(sym
));
49 strcat(res_value
, in
);
54 char *conf_get_default_confname(void)
56 return conf_expand_value(conf_defname
);
59 int conf_read(const char *name
)
66 struct property
*prop
;
71 in
= fopen(name
, "r");
73 const char **names
= conf_confnames
;
74 while ((name
= *names
++)) {
75 name
= conf_expand_value(name
);
76 in
= fopen(name
, "r");
79 "# using defaults found in %s\n"
89 for_all_symbols(i
, sym
) {
90 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
91 sym
->flags
&= ~SYMBOL_VALID
;
97 free(S_VAL(sym
->def
));
99 S_VAL(sym
->def
) = NULL
;
100 S_TRI(sym
->def
) = no
;
105 while (fgets(line
, sizeof(line
), in
)) {
113 p
= strchr(line
, ' ');
121 if (strncmp(p
, "is not set", 10))
123 sym
= sym_lookup(line
+2, 0);
127 sym
->def
= symbol_no
.curr
;
128 sym
->flags
&= ~SYMBOL_NEW
;
135 p
= strchr(line
, '=');
139 p2
= strchr(p
, '\n');
142 sym
= sym_find(line
);
144 fprintf(stderr
, "%s:%d: trying to assign nonexistent symbol %s\n", name
, lineno
, line
);
150 S_TRI(sym
->def
) = mod
;
151 sym
->flags
&= ~SYMBOL_NEW
;
156 S_TRI(sym
->def
) = yes
;
157 sym
->flags
&= ~SYMBOL_NEW
;
161 S_TRI(sym
->def
) = no
;
162 sym
->flags
&= ~SYMBOL_NEW
;
169 if (sym_string_valid(sym
, p
)) {
170 S_VAL(sym
->def
) = strdup(p
);
171 sym
->flags
&= ~SYMBOL_NEW
;
173 fprintf(stderr
, "%s:%d:symbol value '%s' invalid for %s\n", name
, lineno
, p
, sym
->name
);
178 if (sym_is_choice_value(sym
)) {
179 prop
= sym_get_choice_prop(sym
);
180 switch (S_TRI(sym
->def
)) {
182 if (S_TRI(prop
->def
->def
) == yes
)
186 if (S_TRI(prop
->def
->def
) != no
)
188 S_VAL(prop
->def
->def
) = sym
;
193 S_TRI(prop
->def
->def
) = S_TRI(sym
->def
);
202 for_all_symbols(i
, sym
) {
203 if (!sym_is_choice(sym
))
205 prop
= sym_get_choice_prop(sym
);
206 for (e
= prop
->dep
; e
; e
= e
->left
.expr
)
207 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
208 sym
->flags
&= ~SYMBOL_NEW
;
211 sym_change_count
= 1;
216 int conf_write(const char *name
)
225 out
= fopen(".tmpconfig", "w");
228 out_h
= fopen(".tmpconfig.h", "w");
232 "# Automatically generated make config: don't edit\n"
234 fprintf(out_h
, "/*\n"
235 " * Automatically generated C config: don't edit\n"
239 if (!sym_change_count
)
240 sym_clear_all_valid();
242 menu
= rootmenu
.list
;
246 if (!menu_is_visible(menu
))
248 str
= menu_get_prompt(menu
);
257 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
259 if (!(sym
->flags
& SYMBOL_WRITE
))
261 sym
->flags
&= ~SYMBOL_WRITE
;
263 if (type
== S_TRISTATE
) {
264 sym_calc_value(modules_sym
);
265 if (S_TRI(modules_sym
->curr
) == no
)
271 switch (sym_get_tristate_value(sym
)) {
273 fprintf(out
, "# %s is not set\n", sym
->name
);
274 fprintf(out_h
, "#undef %s\n", sym
->name
);
275 fprintf(out_h
, " #define IF_%s(...)\n", sym
->name
);
276 fprintf(out_h
, " #define IF_NOT_%s(...) __VA_ARGS__\n", sym
->name
);
279 fprintf(out
, "%s=m\n", sym
->name
);
280 fprintf(out_h
, "#define %s__MODULE 1\n", sym
->name
);
281 fprintf(out_h
, " #define IF_%s__MODULE(...) __VA_ARGS__\n", sym
->name
);
282 fprintf(out_h
, " #define IF_%s(...) __VA_ARGS__\n", sym
->name
);
283 fprintf(out_h
, " #define IF_NOT_%s(...)\n", sym
->name
);
286 fprintf(out
, "%s=y\n", sym
->name
);
287 fprintf(out_h
, "#define %s 1\n", sym
->name
);
288 fprintf(out_h
, " #define IF_%s(...) __VA_ARGS__\n", sym
->name
);
289 fprintf(out_h
, " #define IF_NOT_%s(...)\n", sym
->name
);
295 str
= sym_get_string_value(sym
);
296 fprintf(out
, "%s=", sym
->name
);
297 fprintf(out_h
, "#define %s \"", sym
->name
);
299 l
= strcspn(str
, "\"\\");
301 fwrite(str
, l
, 1, out
);
302 fwrite(str
, l
, 1, out_h
);
305 while (*str
== '\\' || *str
== '"') {
306 fprintf(out
, "\\%c", *str
);
307 fprintf(out_h
, "\\%c", *str
);
312 fputs("\"\n", out_h
);
315 str
= sym_get_string_value(sym
);
316 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
317 fprintf(out
, "%s=%s\n", sym
->name
, str
);
318 fprintf(out_h
, "#define %s 0x%s\n", sym
->name
, str
);
322 str
= sym_get_string_value(sym
);
323 fprintf(out
, "%s=%s\n", sym
->name
, str
);
324 fprintf(out_h
, "#define %s %s\n", sym
->name
, str
);
336 else while ((menu
= menu
->parent
)) {
347 rename(".tmpconfig.h", "shared/tomato_config.h");
348 name
= conf_def_filename
;
349 file_write_dep(NULL
);
351 unlink(".tmpconfig.h");
353 sprintf(oldname
, "%s.old", name
);
354 rename(name
, oldname
);
355 if (rename(".tmpconfig", name
))
358 sym_change_count
= 0;