Skip to content

Commit ca51b26

Browse files
committed
kconfig: refactor conf_write_heading()
All the call sites of conf_write_heading() pass NULL to the third argument, and it is not used in the function. Also, the print_comment hooks are doing much more complex than needed. Rewrite the code. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 229d0cf commit ca51b26

File tree

1 file changed

+33
-62
lines changed

1 file changed

+33
-62
lines changed

scripts/kconfig/confdata.c

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ static int conf_touch_dep(const char *name)
161161

162162
struct conf_printer {
163163
void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
164-
void (*print_comment)(FILE *, const char *, void *);
165164
};
166165

167166
static void conf_warning(const char *fmt, ...)
@@ -594,6 +593,36 @@ int conf_read(const char *name)
594593
return 0;
595594
}
596595

596+
struct comment_style {
597+
const char *decoration;
598+
const char *prefix;
599+
const char *postfix;
600+
};
601+
602+
static const struct comment_style comment_style_pound = {
603+
.decoration = "#",
604+
.prefix = "#",
605+
.postfix = "#",
606+
};
607+
608+
static const struct comment_style comment_style_c = {
609+
.decoration = " *",
610+
.prefix = "/*",
611+
.postfix = " */",
612+
};
613+
614+
static 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+
597626
/*
598627
* Kconfig configuration printer
599628
*
@@ -625,30 +654,9 @@ kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
625654
fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
626655
}
627656

628-
static void
629-
kconfig_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-
648657
static struct conf_printer kconfig_printer_cb =
649658
{
650659
.print_symbol = kconfig_print_symbol,
651-
.print_comment = kconfig_print_comment,
652660
};
653661

654662
/*
@@ -697,32 +705,9 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
697705

698706
}
699707

700-
static void
701-
header_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-
722708
static struct conf_printer header_printer_cb =
723709
{
724710
.print_symbol = header_print_symbol,
725-
.print_comment = header_print_comment,
726711
};
727712

728713
static void conf_write_symbol(FILE *fp, struct symbol *sym,
@@ -746,20 +731,6 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
746731
free(escaped);
747732
}
748733

749-
static void
750-
conf_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-
763734
/*
764735
* Write out a minimal config.
765736
* All values that has default values are skipped as this is redundant.
@@ -876,7 +847,7 @@ int conf_write(const char *name)
876847
if (!out)
877848
return 1;
878849

879-
conf_write_heading(out, &kconfig_printer_cb, NULL);
850+
conf_write_heading(out, &comment_style_pound);
880851

881852
if (!conf_get_changed())
882853
sym_clear_all_valid();
@@ -1080,8 +1051,8 @@ int conf_write_autoconf(int overwrite)
10801051
return 1;
10811052
}
10821053

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);
10851056

10861057
for_all_symbols(i, sym) {
10871058
sym_calc_value(sym);

0 commit comments

Comments
 (0)