confdata.c (229d0cfae5b21bfc42525cf43b0b4279243acc4e) confdata.c (ca51b26b4a25b05c9b438ed85c4750bfb6f2d9ab)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 */
5
6#include <sys/mman.h>
7#include <sys/stat.h>
8#include <sys/types.h>

--- 147 unchanged lines hidden (view full) ---

156 }
157 close(fd);
158
159 return 0;
160}
161
162struct conf_printer {
163 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 */
5
6#include <sys/mman.h>
7#include <sys/stat.h>
8#include <sys/types.h>

--- 147 unchanged lines hidden (view full) ---

156 }
157 close(fd);
158
159 return 0;
160}
161
162struct conf_printer {
163 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
164 void (*print_comment)(FILE *, const char *, void *);
165};
166
167static void conf_warning(const char *fmt, ...)
168 __attribute__ ((format (printf, 1, 2)));
169
170static void conf_message(const char *fmt, ...)
171 __attribute__ ((format (printf, 1, 2)));
172

--- 416 unchanged lines hidden (view full) ---

589 }
590
591 if (conf_warnings || conf_unsaved)
592 conf_set_changed(true);
593
594 return 0;
595}
596
164};
165
166static void conf_warning(const char *fmt, ...)
167 __attribute__ ((format (printf, 1, 2)));
168
169static void conf_message(const char *fmt, ...)
170 __attribute__ ((format (printf, 1, 2)));
171

--- 416 unchanged lines hidden (view full) ---

588 }
589
590 if (conf_warnings || conf_unsaved)
591 conf_set_changed(true);
592
593 return 0;
594}
595
596struct comment_style {
597 const char *decoration;
598 const char *prefix;
599 const char *postfix;
600};
601
602static const struct comment_style comment_style_pound = {
603 .decoration = "#",
604 .prefix = "#",
605 .postfix = "#",
606};
607
608static const struct comment_style comment_style_c = {
609 .decoration = " *",
610 .prefix = "/*",
611 .postfix = " */",
612};
613
614static void conf_write_heading(FILE *fp, const struct comment_style *cs)
615{
616 fprintf(fp, "%s\n", cs->prefix);
617
618 fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n",
619 cs->decoration);
620
621 fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text);
622
623 fprintf(fp, "%s\n", cs->postfix);
624}
625
597/*
598 * Kconfig configuration printer
599 *
600 * This printer is used when generating the resulting configuration after
601 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
602 * passing a non-NULL argument to the printer.
603 *
604 */

--- 15 unchanged lines hidden (view full) ---

620 break;
621 default:
622 break;
623 }
624
625 fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
626}
627
626/*
627 * Kconfig configuration printer
628 *
629 * This printer is used when generating the resulting configuration after
630 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
631 * passing a non-NULL argument to the printer.
632 *
633 */

--- 15 unchanged lines hidden (view full) ---

649 break;
650 default:
651 break;
652 }
653
654 fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
655}
656
628static void
629kconfig_print_comment(FILE *fp, const char *value, void *arg)
630{
631 const char *p = value;
632 size_t l;
633
634 for (;;) {
635 l = strcspn(p, "\n");
636 fprintf(fp, "#");
637 if (l) {
638 fprintf(fp, " ");
639 xfwrite(p, l, 1, fp);
640 p += l;
641 }
642 fprintf(fp, "\n");
643 if (*p++ == '\0')
644 break;
645 }
646}
647
648static struct conf_printer kconfig_printer_cb =
649{
650 .print_symbol = kconfig_print_symbol,
657static struct conf_printer kconfig_printer_cb =
658{
659 .print_symbol = kconfig_print_symbol,
651 .print_comment = kconfig_print_comment,
652};
653
654/*
655 * Header printer
656 *
657 * This printer is used when generating the `include/generated/autoconf.h' file.
658 */
659static void

--- 32 unchanged lines hidden (view full) ---

692 CONFIG_, sym->name, value);
693 break;
694 default:
695 break;
696 }
697
698}
699
660};
661
662/*
663 * Header printer
664 *
665 * This printer is used when generating the `include/generated/autoconf.h' file.
666 */
667static void

--- 32 unchanged lines hidden (view full) ---

700 CONFIG_, sym->name, value);
701 break;
702 default:
703 break;
704 }
705
706}
707
700static void
701header_print_comment(FILE *fp, const char *value, void *arg)
702{
703 const char *p = value;
704 size_t l;
705
706 fprintf(fp, "/*\n");
707 for (;;) {
708 l = strcspn(p, "\n");
709 fprintf(fp, " *");
710 if (l) {
711 fprintf(fp, " ");
712 xfwrite(p, l, 1, fp);
713 p += l;
714 }
715 fprintf(fp, "\n");
716 if (*p++ == '\0')
717 break;
718 }
719 fprintf(fp, " */\n");
720}
721
722static struct conf_printer header_printer_cb =
723{
724 .print_symbol = header_print_symbol,
708static struct conf_printer header_printer_cb =
709{
710 .print_symbol = header_print_symbol,
725 .print_comment = header_print_comment,
726};
727
728static void conf_write_symbol(FILE *fp, struct symbol *sym,
729 struct conf_printer *printer, void *printer_arg)
730{
731 const char *val;
732 char *escaped = NULL;
733

--- 7 unchanged lines hidden (view full) ---

741 val = escaped;
742 }
743
744 printer->print_symbol(fp, sym, val, printer_arg);
745
746 free(escaped);
747}
748
711};
712
713static void conf_write_symbol(FILE *fp, struct symbol *sym,
714 struct conf_printer *printer, void *printer_arg)
715{
716 const char *val;
717 char *escaped = NULL;
718

--- 7 unchanged lines hidden (view full) ---

726 val = escaped;
727 }
728
729 printer->print_symbol(fp, sym, val, printer_arg);
730
731 free(escaped);
732}
733
749static void
750conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg)
751{
752 char buf[256];
753
754 snprintf(buf, sizeof(buf),
755 "\n"
756 "Automatically generated file; DO NOT EDIT.\n"
757 "%s\n",
758 rootmenu.prompt->text);
759
760 printer->print_comment(fp, buf, printer_arg);
761}
762
763/*
764 * Write out a minimal config.
765 * All values that has default values are skipped as this is redundant.
766 */
767int conf_write_defconfig(const char *filename)
768{
769 struct symbol *sym;
770 struct menu *menu;

--- 100 unchanged lines hidden (view full) ---

871 } else {
872 snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp",
873 name, (int)getpid());
874 out = fopen(tmpname, "w");
875 }
876 if (!out)
877 return 1;
878
734/*
735 * Write out a minimal config.
736 * All values that has default values are skipped as this is redundant.
737 */
738int conf_write_defconfig(const char *filename)
739{
740 struct symbol *sym;
741 struct menu *menu;

--- 100 unchanged lines hidden (view full) ---

842 } else {
843 snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp",
844 name, (int)getpid());
845 out = fopen(tmpname, "w");
846 }
847 if (!out)
848 return 1;
849
879 conf_write_heading(out, &kconfig_printer_cb, NULL);
850 conf_write_heading(out, &comment_style_pound);
880
881 if (!conf_get_changed())
882 sym_clear_all_valid();
883
884 menu = rootmenu.list;
885 while (menu) {
886 sym = menu->sym;
887 if (!sym) {

--- 187 unchanged lines hidden (view full) ---

1075 return 1;
1076
1077 out_h = fopen(".tmpconfig.h", "w");
1078 if (!out_h) {
1079 fclose(out);
1080 return 1;
1081 }
1082
851
852 if (!conf_get_changed())
853 sym_clear_all_valid();
854
855 menu = rootmenu.list;
856 while (menu) {
857 sym = menu->sym;
858 if (!sym) {

--- 187 unchanged lines hidden (view full) ---

1046 return 1;
1047
1048 out_h = fopen(".tmpconfig.h", "w");
1049 if (!out_h) {
1050 fclose(out);
1051 return 1;
1052 }
1053
1083 conf_write_heading(out, &kconfig_printer_cb, NULL);
1084 conf_write_heading(out_h, &header_printer_cb, NULL);
1054 conf_write_heading(out, &comment_style_pound);
1055 conf_write_heading(out_h, &comment_style_c);
1085
1086 for_all_symbols(i, sym) {
1087 sym_calc_value(sym);
1088 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
1089 continue;
1090
1091 /* write symbols to auto.conf and autoconf.h */
1092 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);

--- 65 unchanged lines hidden ---
1056
1057 for_all_symbols(i, sym) {
1058 sym_calc_value(sym);
1059 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
1060 continue;
1061
1062 /* write symbols to auto.conf and autoconf.h */
1063 conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);

--- 65 unchanged lines hidden ---