Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 3 | * Released under the terms of the GNU GPL v2.0. |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 6 | #include <sys/stat.h> |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 7 | #include <ctype.h> |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <unistd.h> |
| 12 | |
| 13 | #define LKC_DIRECT_LINK |
| 14 | #include "lkc.h" |
| 15 | |
| 16 | const char conf_def_filename[] = ".config"; |
| 17 | |
Rob Landley | 7a43bd0 | 2006-01-20 17:47:09 +0000 | [diff] [blame] | 18 | const char conf_defname[] = "defconfig"; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 19 | |
| 20 | const char *conf_confnames[] = { |
| 21 | ".config", |
| 22 | conf_defname, |
| 23 | NULL, |
| 24 | }; |
| 25 | |
Rob Landley | 9a1e25d | 2005-12-19 16:30:33 +0000 | [diff] [blame] | 26 | static char *conf_expand_value(const char *in) |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 27 | { |
| 28 | struct symbol *sym; |
Rob Landley | 9a1e25d | 2005-12-19 16:30:33 +0000 | [diff] [blame] | 29 | const char *src; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 30 | static char res_value[SYMBOL_MAXLENGTH]; |
| 31 | char *dst, name[SYMBOL_MAXLENGTH]; |
| 32 | |
| 33 | res_value[0] = 0; |
| 34 | dst = name; |
| 35 | while ((src = strchr(in, '$'))) { |
| 36 | strncat(res_value, in, src - in); |
| 37 | src++; |
| 38 | dst = name; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 39 | while (isalnum(*src) || *src == '_') |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 40 | *dst++ = *src++; |
| 41 | *dst = 0; |
| 42 | sym = sym_lookup(name, 0); |
| 43 | sym_calc_value(sym); |
| 44 | strcat(res_value, sym_get_string_value(sym)); |
| 45 | in = src; |
| 46 | } |
| 47 | strcat(res_value, in); |
| 48 | |
| 49 | return res_value; |
| 50 | } |
| 51 | |
| 52 | char *conf_get_default_confname(void) |
| 53 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 54 | struct stat buf; |
Eric Andersen | 16f94a6 | 2004-01-16 12:49:06 +0000 | [diff] [blame] | 55 | static char fullname[PATH_MAX+1]; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 56 | char *env, *name; |
| 57 | |
| 58 | name = conf_expand_value(conf_defname); |
| 59 | env = getenv(SRCTREE); |
| 60 | if (env) { |
| 61 | sprintf(fullname, "%s/%s", env, name); |
| 62 | if (!stat(fullname, &buf)) |
| 63 | return fullname; |
| 64 | } |
| 65 | return name; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | int conf_read(const char *name) |
| 69 | { |
| 70 | FILE *in = NULL; |
| 71 | char line[1024]; |
| 72 | char *p, *p2; |
| 73 | int lineno = 0; |
| 74 | struct symbol *sym; |
| 75 | struct property *prop; |
| 76 | struct expr *e; |
| 77 | int i; |
| 78 | |
| 79 | if (name) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 80 | in = zconf_fopen(name); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 81 | } else { |
| 82 | const char **names = conf_confnames; |
| 83 | while ((name = *names++)) { |
| 84 | name = conf_expand_value(name); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 85 | in = zconf_fopen(name); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 86 | if (in) { |
| 87 | printf("#\n" |
| 88 | "# using defaults found in %s\n" |
| 89 | "#\n", name); |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (!in) |
| 96 | return 1; |
| 97 | |
| 98 | for_all_symbols(i, sym) { |
| 99 | sym->flags |= SYMBOL_NEW | SYMBOL_CHANGED; |
| 100 | sym->flags &= ~SYMBOL_VALID; |
| 101 | switch (sym->type) { |
| 102 | case S_INT: |
| 103 | case S_HEX: |
| 104 | case S_STRING: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 105 | if (sym->user.val) |
| 106 | free(sym->user.val); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 107 | default: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 108 | sym->user.val = NULL; |
| 109 | sym->user.tri = no; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | while (fgets(line, sizeof(line), in)) { |
| 114 | lineno++; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 115 | sym = NULL; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 116 | switch (line[0]) { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 117 | case '#': |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 118 | if (line[1]!=' ') |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 119 | continue; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 120 | p = strchr(line + 2, ' '); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 121 | if (!p) |
| 122 | continue; |
| 123 | *p++ = 0; |
| 124 | if (strncmp(p, "is not set", 10)) |
| 125 | continue; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 126 | sym = sym_find(line + 2); |
| 127 | if (!sym) { |
| 128 | fprintf(stderr, "%s:%d: trying to assign nonexistent symbol %s\n", name, lineno, line + 2); |
| 129 | break; |
| 130 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 131 | switch (sym->type) { |
| 132 | case S_BOOLEAN: |
| 133 | case S_TRISTATE: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 134 | sym->user.tri = no; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 135 | sym->flags &= ~SYMBOL_NEW; |
| 136 | break; |
| 137 | default: |
| 138 | ; |
| 139 | } |
| 140 | break; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 141 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 142 | case 'A' ... 'Z': |
| 143 | p = strchr(line, '='); |
| 144 | if (!p) |
| 145 | continue; |
| 146 | *p++ = 0; |
| 147 | p2 = strchr(p, '\n'); |
| 148 | if (p2) |
| 149 | *p2 = 0; |
| 150 | sym = sym_find(line); |
| 151 | if (!sym) { |
| 152 | fprintf(stderr, "%s:%d: trying to assign nonexistent symbol %s\n", name, lineno, line); |
| 153 | break; |
| 154 | } |
| 155 | switch (sym->type) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 156 | case S_TRISTATE: |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 157 | if (p[0] == 'm') { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 158 | sym->user.tri = mod; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 159 | sym->flags &= ~SYMBOL_NEW; |
| 160 | break; |
| 161 | } |
| 162 | case S_BOOLEAN: |
| 163 | if (p[0] == 'y') { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 164 | sym->user.tri = yes; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 165 | sym->flags &= ~SYMBOL_NEW; |
| 166 | break; |
| 167 | } |
| 168 | if (p[0] == 'n') { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 169 | sym->user.tri = no; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 170 | sym->flags &= ~SYMBOL_NEW; |
| 171 | break; |
| 172 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 173 | break; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 174 | case S_STRING: |
| 175 | if (*p++ != '"') |
| 176 | break; |
| 177 | for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { |
| 178 | if (*p2 == '"') { |
| 179 | *p2 = 0; |
| 180 | break; |
| 181 | } |
| 182 | memmove(p2, p2 + 1, strlen(p2)); |
| 183 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 184 | if (!p2) { |
| 185 | fprintf(stderr, "%s:%d: invalid string found\n", name, lineno); |
| 186 | exit(1); |
| 187 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 188 | case S_INT: |
| 189 | case S_HEX: |
| 190 | if (sym_string_valid(sym, p)) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 191 | sym->user.val = strdup(p); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 192 | sym->flags &= ~SYMBOL_NEW; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 193 | } else { |
| 194 | fprintf(stderr, "%s:%d: symbol value '%s' invalid for %s\n", name, lineno, p, sym->name); |
| 195 | exit(1); |
| 196 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 197 | break; |
| 198 | default: |
| 199 | ; |
| 200 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 201 | break; |
| 202 | case '\n': |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 203 | break; |
| 204 | default: |
| 205 | continue; |
| 206 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 207 | if (sym && sym_is_choice_value(sym)) { |
| 208 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
| 209 | switch (sym->user.tri) { |
| 210 | case no: |
| 211 | break; |
| 212 | case mod: |
| 213 | if (cs->user.tri == yes) |
| 214 | /* warn? */; |
| 215 | break; |
| 216 | case yes: |
| 217 | if (cs->user.tri != no) |
| 218 | /* warn? */; |
| 219 | cs->user.val = sym; |
| 220 | break; |
| 221 | } |
| 222 | cs->user.tri = E_OR(cs->user.tri, sym->user.tri); |
| 223 | cs->flags &= ~SYMBOL_NEW; |
| 224 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 225 | } |
| 226 | fclose(in); |
| 227 | |
Eric Andersen | 837f058 | 2004-07-15 06:01:05 +0000 | [diff] [blame] | 228 | if (modules_sym) |
| 229 | sym_calc_value(modules_sym); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 230 | for_all_symbols(i, sym) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 231 | sym_calc_value(sym); |
| 232 | if (sym_has_value(sym) && !sym_is_choice_value(sym)) { |
| 233 | if (sym->visible == no) |
| 234 | sym->flags |= SYMBOL_NEW; |
| 235 | switch (sym->type) { |
| 236 | case S_STRING: |
| 237 | case S_INT: |
| 238 | case S_HEX: |
| 239 | if (!sym_string_within_range(sym, sym->user.val)) |
| 240 | sym->flags |= SYMBOL_NEW; |
| 241 | default: |
| 242 | break; |
| 243 | } |
| 244 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 245 | if (!sym_is_choice(sym)) |
| 246 | continue; |
| 247 | prop = sym_get_choice_prop(sym); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 248 | for (e = prop->expr; e; e = e->left.expr) |
| 249 | if (e->right.sym->visible != no) |
| 250 | sym->flags |= e->right.sym->flags & SYMBOL_NEW; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | sym_change_count = 1; |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 258 | struct menu *next_menu(struct menu *menu) |
| 259 | { |
| 260 | if (menu->list) return menu->list; |
| 261 | do { |
| 262 | if (menu->next) { |
| 263 | menu = menu->next; |
| 264 | break; |
| 265 | } |
| 266 | } while ((menu = menu->parent)); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 267 | |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 268 | return menu; |
| 269 | } |
| 270 | |
| 271 | #define SYMBOL_FORCEWRITE (1<<31) |
| 272 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 273 | int conf_write(const char *name) |
| 274 | { |
| 275 | FILE *out, *out_h; |
| 276 | struct symbol *sym; |
| 277 | struct menu *menu; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 278 | const char *basename; |
| 279 | char dirname[128], tmpname[128], newname[128]; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 280 | int type, l; |
| 281 | const char *str; |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 282 | const char *opt_name; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 283 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 284 | dirname[0] = 0; |
| 285 | if (name && name[0]) { |
Eric Andersen | 837f058 | 2004-07-15 06:01:05 +0000 | [diff] [blame] | 286 | struct stat st; |
| 287 | char *slash; |
| 288 | |
| 289 | if (!stat(name, &st) && S_ISDIR(st.st_mode)) { |
| 290 | strcpy(dirname, name); |
| 291 | strcat(dirname, "/"); |
| 292 | basename = conf_def_filename; |
| 293 | } else if ((slash = strrchr(name, '/'))) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 294 | int size = slash - name + 1; |
| 295 | memcpy(dirname, name, size); |
| 296 | dirname[size] = 0; |
| 297 | if (slash[1]) |
| 298 | basename = slash + 1; |
| 299 | else |
| 300 | basename = conf_def_filename; |
| 301 | } else |
| 302 | basename = name; |
| 303 | } else |
| 304 | basename = conf_def_filename; |
| 305 | |
Peter Kjellerstedt | bae38db | 2005-04-19 09:55:06 +0000 | [diff] [blame] | 306 | sprintf(newname, "%s.tmpconfig.%d", dirname, (int)getpid()); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 307 | out = fopen(newname, "w"); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 308 | if (!out) |
| 309 | return 1; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 310 | out_h = NULL; |
| 311 | if (!name) { |
| 312 | out_h = fopen(".tmpconfig.h", "w"); |
| 313 | if (!out_h) |
| 314 | return 1; |
| 315 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 316 | fprintf(out, "#\n" |
| 317 | "# Automatically generated make config: don't edit\n" |
| 318 | "#\n"); |
Glenn L McGrath | 7c87b67 | 2004-01-13 10:57:32 +0000 | [diff] [blame] | 319 | if (out_h) { |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 320 | fprintf(out_h, "#ifndef BB_CONFIG_H\n#define BB_CONFIG_H\n"); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 321 | fprintf(out_h, "/*\n" |
| 322 | " * Automatically generated header file: don't edit\n" |
| 323 | " */\n\n" |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 324 | "/* Version Number */\n" |
| 325 | "#define BB_VER \"%s\"\n" |
Glenn L McGrath | 7c87b67 | 2004-01-13 10:57:32 +0000 | [diff] [blame] | 326 | "#define BB_BT \"%s\"\n", |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 327 | getenv("VERSION"), |
| 328 | getenv("BUILDTIME")); |
Glenn L McGrath | 7c87b67 | 2004-01-13 10:57:32 +0000 | [diff] [blame] | 329 | if (getenv("EXTRA_VERSION")) |
| 330 | fprintf(out_h, "#define BB_EXTRA_VERSION \"%s\"\n", |
| 331 | getenv("EXTRA_VERSION")); |
| 332 | fprintf(out_h, "\n"); |
| 333 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 334 | |
| 335 | if (!sym_change_count) |
| 336 | sym_clear_all_valid(); |
| 337 | |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 338 | /* Force write of all non-duplicate symbols. */ |
| 339 | |
| 340 | /* Write out everything by default. */ |
| 341 | for(menu = rootmenu.list; menu; menu = next_menu(menu)) |
| 342 | if (menu->sym) menu->sym->flags |= SYMBOL_FORCEWRITE; |
| 343 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 344 | menu = rootmenu.list; |
| 345 | while (menu) { |
| 346 | sym = menu->sym; |
| 347 | if (!sym) { |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 348 | if (!menu_is_visible(menu)) |
| 349 | goto next; |
| 350 | str = menu_get_prompt(menu); |
| 351 | fprintf(out, "\n" |
| 352 | "#\n" |
| 353 | "# %s\n" |
| 354 | "#\n", str); |
| 355 | if (out_h) |
| 356 | fprintf(out_h, "\n" |
| 357 | "/*\n" |
| 358 | " * %s\n" |
| 359 | " */\n", str); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 360 | } else if (!(sym->flags & SYMBOL_CHOICE)) { |
| 361 | sym_calc_value(sym); |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 362 | if (!(sym->flags & SYMBOL_FORCEWRITE)) |
| 363 | goto next; |
| 364 | |
| 365 | sym->flags &= ~SYMBOL_FORCEWRITE; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 366 | type = sym->type; |
| 367 | if (type == S_TRISTATE) { |
| 368 | sym_calc_value(modules_sym); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 369 | if (modules_sym->curr.tri == no) |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 370 | type = S_BOOLEAN; |
| 371 | } |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 372 | opt_name = strchr(sym->name, '_'); |
| 373 | if(opt_name == NULL) |
| 374 | opt_name = sym->name; |
| 375 | else |
| 376 | opt_name++; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 377 | switch (type) { |
| 378 | case S_BOOLEAN: |
| 379 | case S_TRISTATE: |
| 380 | switch (sym_get_tristate_value(sym)) { |
| 381 | case no: |
| 382 | fprintf(out, "# %s is not set\n", sym->name); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 383 | if (out_h) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 384 | fprintf(out_h, "#undef %s\n", sym->name); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 385 | fprintf(out_h, "#define ENABLE_%s 0\n", opt_name); |
| 386 | fprintf(out_h, "#define USE_%s(...)\n", opt_name); |
| 387 | fprintf(out_h, "#define UNUSE_%s(...) __VA_ARGS__\n", opt_name); |
| 388 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 389 | break; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 390 | case mod: |
Glenn L McGrath | 8ac86e3 | 2003-10-03 08:28:59 +0000 | [diff] [blame] | 391 | #if 0 |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 392 | fprintf(out, "%s=m\n", sym->name); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 393 | if (out_h) |
| 394 | fprintf(out_h, "#define %s_MODULE 1\n", sym->name); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 395 | #endif |
Glenn L McGrath | 8ac86e3 | 2003-10-03 08:28:59 +0000 | [diff] [blame] | 396 | break; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 397 | case yes: |
| 398 | fprintf(out, "%s=y\n", sym->name); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 399 | if (out_h) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 400 | fprintf(out_h, "#define %s 1\n", sym->name); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 401 | fprintf(out_h, "#define ENABLE_%s 1\n", opt_name); |
| 402 | fprintf(out_h, "#define USE_%s(...) __VA_ARGS__\n", opt_name); |
| 403 | fprintf(out_h, "#define UNUSE_%s(...)\n", opt_name); |
| 404 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | break; |
| 408 | case S_STRING: |
| 409 | // fix me |
| 410 | str = sym_get_string_value(sym); |
| 411 | fprintf(out, "%s=\"", sym->name); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 412 | if (out_h) |
| 413 | fprintf(out_h, "#define %s \"", sym->name); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 414 | do { |
| 415 | l = strcspn(str, "\"\\"); |
| 416 | if (l) { |
| 417 | fwrite(str, l, 1, out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 418 | if (out_h) |
| 419 | fwrite(str, l, 1, out_h); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 420 | } |
| 421 | str += l; |
| 422 | while (*str == '\\' || *str == '"') { |
| 423 | fprintf(out, "\\%c", *str); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 424 | if (out_h) |
| 425 | fprintf(out_h, "\\%c", *str); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 426 | str++; |
| 427 | } |
| 428 | } while (*str); |
| 429 | fputs("\"\n", out); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 430 | if (out_h) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 431 | fputs("\"\n", out_h); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 432 | fprintf(out_h, "#define ENABLE_%s 1\n", opt_name); |
| 433 | fprintf(out_h, "#define USE_%s(...) __VA_ARGS__\n", opt_name); |
| 434 | fprintf(out_h, "#define UNUSE_%s(...)\n", opt_name); |
| 435 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 436 | break; |
| 437 | case S_HEX: |
| 438 | str = sym_get_string_value(sym); |
| 439 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { |
Rob Landley | 8f99104 | 2005-09-05 11:04:30 +0000 | [diff] [blame] | 440 | fprintf(out, "%s=%s\n", sym->name, *str ? str : "0"); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 441 | if (out_h) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 442 | fprintf(out_h, "#define %s 0x%s\n", sym->name, str); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 443 | fprintf(out_h, "#define ENABLE_%s 1\n", opt_name); |
| 444 | fprintf(out_h, "#define USE_%s(...) __VA_ARGS__\n", opt_name); |
| 445 | fprintf(out_h, "#define UNUSE_%s(...)\n", opt_name); |
| 446 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 447 | break; |
| 448 | } |
| 449 | case S_INT: |
| 450 | str = sym_get_string_value(sym); |
Rob Landley | 8f99104 | 2005-09-05 11:04:30 +0000 | [diff] [blame] | 451 | fprintf(out, "%s=%s\n", sym->name, *str ? str : "0"); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 452 | if (out_h) { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 453 | fprintf(out_h, "#define %s %s\n", sym->name, str); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 454 | fprintf(out_h, "#define ENABLE_%s 1\n", opt_name); |
| 455 | fprintf(out_h, "#define USE_%s(...) __VA_ARGS__\n", opt_name); |
| 456 | fprintf(out_h, "#define UNUSE_%s(...)\n", opt_name); |
| 457 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 458 | break; |
| 459 | } |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 460 | if (out_h) |
| 461 | fprintf(out_h, "\n"); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 462 | } |
Rob Landley | 2ee8272 | 2005-09-14 14:40:01 +0000 | [diff] [blame] | 463 | next: |
| 464 | menu = next_menu(menu); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 465 | } |
| 466 | fclose(out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 467 | if (out_h) { |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 468 | fprintf(out_h, "#endif /* BB_CONFIG_H */\n"); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 469 | fclose(out_h); |
"Vladimir N. Oleynik" | 6732af2 | 2006-02-15 12:29:37 +0000 | [diff] [blame] | 470 | rename(".tmpconfig.h", "include/bb_config.h"); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 471 | file_write_dep(NULL); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 472 | } |
| 473 | if (!name || basename != conf_def_filename) { |
| 474 | if (!name) |
| 475 | name = conf_def_filename; |
| 476 | sprintf(tmpname, "%s.old", name); |
| 477 | rename(name, tmpname); |
| 478 | } |
| 479 | sprintf(tmpname, "%s%s", dirname, basename); |
| 480 | if (rename(newname, tmpname)) |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 481 | return 1; |
| 482 | |
| 483 | sym_change_count = 0; |
| 484 | |
| 485 | return 0; |
| 486 | } |