Skip to content

Commit 80f7bc7

Browse files
committed
kconfig: move sym_escape_string_value() to confdata.c
Now that sym_escape_string_value() is only used in confdata.c it can be a 'static' function. Rename it escape_string_value() because it is agnostic about (struct sym *). Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 51d792c commit 80f7bc7

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

scripts/kconfig/confdata.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,49 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs)
620620
fprintf(fp, "%s\n", cs->postfix);
621621
}
622622

623+
/* The returned pointer must be freed on the caller side */
624+
static char *escape_string_value(const char *in)
625+
{
626+
const char *p;
627+
char *out;
628+
size_t len;
629+
630+
len = strlen(in) + strlen("\"\"") + 1;
631+
632+
p = in;
633+
while (1) {
634+
p += strcspn(p, "\"\\");
635+
636+
if (p[0] == '\0')
637+
break;
638+
639+
len++;
640+
p++;
641+
}
642+
643+
out = xmalloc(len);
644+
out[0] = '\0';
645+
646+
strcat(out, "\"");
647+
648+
p = in;
649+
while (1) {
650+
len = strcspn(p, "\"\\");
651+
strncat(out, p, len);
652+
p += len;
653+
654+
if (p[0] == '\0')
655+
break;
656+
657+
strcat(out, "\\");
658+
strncat(out, p++, 1);
659+
}
660+
661+
strcat(out, "\"");
662+
663+
return out;
664+
}
665+
623666
/*
624667
* Kconfig configuration printer
625668
*
@@ -648,7 +691,7 @@ static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n,
648691
}
649692

650693
if (sym->type == S_STRING && escape_string) {
651-
escaped = sym_escape_string_value(val);
694+
escaped = escape_string_value(val);
652695
val = escaped;
653696
}
654697

@@ -702,7 +745,7 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym)
702745
val_prefix = "0x";
703746
break;
704747
case S_STRING:
705-
escaped = sym_escape_string_value(val);
748+
escaped = escape_string_value(val);
706749
val = escaped;
707750
default:
708751
break;

scripts/kconfig/lkc_proto.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
1818

1919
struct symbol * sym_lookup(const char *name, int flags);
2020
struct symbol * sym_find(const char *name);
21-
char *sym_escape_string_value(const char *in);
2221
void print_symbol_for_listconfig(struct symbol *sym);
2322
struct symbol ** sym_re_search(const char *pattern);
2423
const char * sym_type_name(enum symbol_type type);

scripts/kconfig/symbol.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -871,50 +871,6 @@ struct symbol *sym_find(const char *name)
871871
return symbol;
872872
}
873873

874-
/* The returned pointer must be freed on the caller side */
875-
char *sym_escape_string_value(const char *in)
876-
{
877-
const char *p;
878-
size_t reslen;
879-
char *res;
880-
size_t l;
881-
882-
reslen = strlen(in) + strlen("\"\"") + 1;
883-
884-
p = in;
885-
for (;;) {
886-
l = strcspn(p, "\"\\");
887-
p += l;
888-
889-
if (p[0] == '\0')
890-
break;
891-
892-
reslen++;
893-
p++;
894-
}
895-
896-
res = xmalloc(reslen);
897-
res[0] = '\0';
898-
899-
strcat(res, "\"");
900-
901-
p = in;
902-
for (;;) {
903-
l = strcspn(p, "\"\\");
904-
strncat(res, p, l);
905-
p += l;
906-
907-
if (p[0] == '\0')
908-
break;
909-
910-
strcat(res, "\\");
911-
strncat(res, p++, 1);
912-
}
913-
914-
strcat(res, "\"");
915-
return res;
916-
}
917-
918874
struct sym_match {
919875
struct symbol *sym;
920876
off_t so, eo;

0 commit comments

Comments
 (0)