summaryrefslogtreecommitdiff
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2021-10-01 14:32:48 +0900
committerMasahiro Yamada <masahiroy@kernel.org>2021-10-11 23:13:23 +0900
commit80f7bc7737630fb1b2c4f440fc7627337bd2f605 (patch)
tree52ade169fa4f653ca1c36f04590b4ae0337bbc75 /scripts/kconfig/confdata.c
parent51d792cb5de87fa8777b4769a33c302e4ad0580a (diff)
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 <masahiroy@kernel.org>
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f17a2a9562ee..26b39d34e2be 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -620,6 +620,49 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs)
fprintf(fp, "%s\n", cs->postfix);
}
+/* The returned pointer must be freed on the caller side */
+static char *escape_string_value(const char *in)
+{
+ const char *p;
+ char *out;
+ size_t len;
+
+ len = strlen(in) + strlen("\"\"") + 1;
+
+ p = in;
+ while (1) {
+ p += strcspn(p, "\"\\");
+
+ if (p[0] == '\0')
+ break;
+
+ len++;
+ p++;
+ }
+
+ out = xmalloc(len);
+ out[0] = '\0';
+
+ strcat(out, "\"");
+
+ p = in;
+ while (1) {
+ len = strcspn(p, "\"\\");
+ strncat(out, p, len);
+ p += len;
+
+ if (p[0] == '\0')
+ break;
+
+ strcat(out, "\\");
+ strncat(out, p++, 1);
+ }
+
+ strcat(out, "\"");
+
+ return out;
+}
+
/*
* Kconfig configuration printer
*
@@ -648,7 +691,7 @@ static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n,
}
if (sym->type == S_STRING && escape_string) {
- escaped = sym_escape_string_value(val);
+ escaped = escape_string_value(val);
val = escaped;
}
@@ -702,7 +745,7 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym)
val_prefix = "0x";
break;
case S_STRING:
- escaped = sym_escape_string_value(val);
+ escaped = escape_string_value(val);
val = escaped;
default:
break;