aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2010-07-31 17:35:33 -0400
committerMichal Marek <mmarek@suse.cz>2010-08-03 07:49:32 -0400
commit49192f266ffa187bd7adaf5c2d881f85bd53e0ed (patch)
treec0187a389d50fd6a10e43bfd5dfb50c6393635b7 /scripts/kconfig
parentc252147de68cf58ba601278481e473dab432cee4 (diff)
kconfig: code refactoring in confdata.c
Add a a few local functions to avoid some code duplication No functional changes. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig')
-rw-r--r--scripts/kconfig/confdata.c137
1 files changed, 70 insertions, 67 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 8dce5862550d..583f6405f01d 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -399,15 +399,73 @@ int conf_read(const char *name)
399 return 0; 399 return 0;
400} 400}
401 401
402/* Write a S_STRING */
403static void conf_write_string(bool headerfile, const char *name,
404 const char *str, FILE *out)
405{
406 int l;
407 if (headerfile)
408 fprintf(out, "#define CONFIG_%s \"", name);
409 else
410 fprintf(out, "CONFIG_%s=\"", name);
411
412 while (1) {
413 l = strcspn(str, "\"\\");
414 if (l) {
415 fwrite(str, l, 1, out);
416 str += l;
417 }
418 if (!*str)
419 break;
420 fprintf(out, "\\%c", *str++);
421 }
422 fputs("\"\n", out);
423}
424
425static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
426 FILE *out, bool write_no)
427{
428 const char *str;
429
430 switch (type) {
431 case S_BOOLEAN:
432 case S_TRISTATE:
433 switch (sym_get_tristate_value(sym)) {
434 case no:
435 if (write_no)
436 fprintf(out, "# CONFIG_%s is not set\n", sym->name);
437 break;
438 case mod:
439 fprintf(out, "CONFIG_%s=m\n", sym->name);
440 break;
441 case yes:
442 fprintf(out, "CONFIG_%s=y\n", sym->name);
443 break;
444 }
445 break;
446 case S_STRING:
447 conf_write_string(false, sym->name, sym_get_string_value(sym), out);
448 break;
449 case S_HEX:
450 case S_INT:
451 str = sym_get_string_value(sym);
452 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
453 break;
454 case S_OTHER:
455 case S_UNKNOWN:
456 break;
457 }
458}
459
402int conf_write(const char *name) 460int conf_write(const char *name)
403{ 461{
404 FILE *out; 462 FILE *out;
405 struct symbol *sym; 463 struct symbol *sym;
406 struct menu *menu; 464 struct menu *menu;
407 const char *basename; 465 const char *basename;
408 char dirname[128], tmpname[128], newname[128];
409 int type, l;
410 const char *str; 466 const char *str;
467 char dirname[128], tmpname[128], newname[128];
468 enum symbol_type type;
411 time_t now; 469 time_t now;
412 int use_timestamp = 1; 470 int use_timestamp = 1;
413 char *env; 471 char *env;
@@ -487,50 +545,11 @@ int conf_write(const char *name)
487 if (modules_sym->curr.tri == no) 545 if (modules_sym->curr.tri == no)
488 type = S_BOOLEAN; 546 type = S_BOOLEAN;
489 } 547 }
490 switch (type) { 548 /* Write config symbol to file */
491 case S_BOOLEAN: 549 conf_write_symbol(sym, type, out, true);
492 case S_TRISTATE:
493 switch (sym_get_tristate_value(sym)) {
494 case no:
495 fprintf(out, "# CONFIG_%s is not set\n", sym->name);
496 break;
497 case mod:
498 fprintf(out, "CONFIG_%s=m\n", sym->name);
499 break;
500 case yes:
501 fprintf(out, "CONFIG_%s=y\n", sym->name);
502 break;
503 }
504 break;
505 case S_STRING:
506 str = sym_get_string_value(sym);
507 fprintf(out, "CONFIG_%s=\"", sym->name);
508 while (1) {
509 l = strcspn(str, "\"\\");
510 if (l) {
511 fwrite(str, l, 1, out);
512 str += l;
513 }
514 if (!*str)
515 break;
516 fprintf(out, "\\%c", *str++);
517 }
518 fputs("\"\n", out);
519 break;
520 case S_HEX:
521 str = sym_get_string_value(sym);
522 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
523 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
524 break;
525 }
526 case S_INT:
527 str = sym_get_string_value(sym);
528 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
529 break;
530 }
531 } 550 }
532 551
533 next: 552next:
534 if (menu->list) { 553 if (menu->list) {
535 menu = menu->list; 554 menu = menu->list;
536 continue; 555 continue;
@@ -682,7 +701,7 @@ int conf_write_autoconf(void)
682 const char *name; 701 const char *name;
683 FILE *out, *tristate, *out_h; 702 FILE *out, *tristate, *out_h;
684 time_t now; 703 time_t now;
685 int i, l; 704 int i;
686 705
687 sym_clear_all_valid(); 706 sym_clear_all_valid();
688 707
@@ -732,6 +751,11 @@ int conf_write_autoconf(void)
732 sym_calc_value(sym); 751 sym_calc_value(sym);
733 if (!(sym->flags & SYMBOL_WRITE) || !sym->name) 752 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
734 continue; 753 continue;
754
755 /* write symbol to config file */
756 conf_write_symbol(sym, sym->type, out, false);
757
758 /* update autoconf and tristate files */
735 switch (sym->type) { 759 switch (sym->type) {
736 case S_BOOLEAN: 760 case S_BOOLEAN:
737 case S_TRISTATE: 761 case S_TRISTATE:
@@ -739,12 +763,10 @@ int conf_write_autoconf(void)
739 case no: 763 case no:
740 break; 764 break;
741 case mod: 765 case mod:
742 fprintf(out, "CONFIG_%s=m\n", sym->name);
743 fprintf(tristate, "CONFIG_%s=M\n", sym->name); 766 fprintf(tristate, "CONFIG_%s=M\n", sym->name);
744 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); 767 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
745 break; 768 break;
746 case yes: 769 case yes:
747 fprintf(out, "CONFIG_%s=y\n", sym->name);
748 if (sym->type == S_TRISTATE) 770 if (sym->type == S_TRISTATE)
749 fprintf(tristate, "CONFIG_%s=Y\n", 771 fprintf(tristate, "CONFIG_%s=Y\n",
750 sym->name); 772 sym->name);
@@ -753,35 +775,16 @@ int conf_write_autoconf(void)
753 } 775 }
754 break; 776 break;
755 case S_STRING: 777 case S_STRING:
756 str = sym_get_string_value(sym); 778 conf_write_string(true, sym->name, sym_get_string_value(sym), out_h);
757 fprintf(out, "CONFIG_%s=\"", sym->name);
758 fprintf(out_h, "#define CONFIG_%s \"", sym->name);
759 while (1) {
760 l = strcspn(str, "\"\\");
761 if (l) {
762 fwrite(str, l, 1, out);
763 fwrite(str, l, 1, out_h);
764 str += l;
765 }
766 if (!*str)
767 break;
768 fprintf(out, "\\%c", *str);
769 fprintf(out_h, "\\%c", *str);
770 str++;
771 }
772 fputs("\"\n", out);
773 fputs("\"\n", out_h);
774 break; 779 break;
775 case S_HEX: 780 case S_HEX:
776 str = sym_get_string_value(sym); 781 str = sym_get_string_value(sym);
777 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { 782 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
778 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
779 fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str); 783 fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str);
780 break; 784 break;
781 } 785 }
782 case S_INT: 786 case S_INT:
783 str = sym_get_string_value(sym); 787 str = sym_get_string_value(sym);
784 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
785 fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str); 788 fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str);
786 break; 789 break;
787 default: 790 default: