From f893e17ed98f655bddb85f1f264eb0c726c608f2 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 16 Aug 2016 05:15:38 -0300 Subject: [PATCH] eeshow/sch-parse.c (parse_field): accept escaped quotes (WIP) We should also remove the backslash. --- eeshow/sch-parse.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/eeshow/sch-parse.c b/eeshow/sch-parse.c index 3ae24e2..1b5b689 100644 --- a/eeshow/sch-parse.c +++ b/eeshow/sch-parse.c @@ -99,6 +99,9 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) char hv, hor, vert, italic, bold; struct comp_field *field; struct text *txt; + char *s; + const char *p; + int pos, len; field = alloc_type(struct comp_field); txt = &field->txt; @@ -110,10 +113,27 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) free(field); return 1; } - if (sscanf(line, "F %d \"%m[^\"]\" %c %d %d %u %u %c %c%c%c", - &n, &txt->s, &hv, &txt->x, &txt->y, &txt->size, &flags, - &hor, &vert, &italic, &bold) != 11) + + if (sscanf(line, "F %d \"%n", &n, &pos) != 1) return 0; + for (p = line + pos; *p && *p != '"'; p++) + if (*p == '\\' && p[1]) + p++; + if (*p != '"') + return 0; + + len = p - (line + pos); + s = alloc_size(len + 1); + memcpy(s, line + pos, len); + s[len] = 0; + + if (sscanf(p + 1, " %c %d %d %u %u %c %c%c%c", + &hv, &txt->x, &txt->y, &txt->size, &flags, + &hor, &vert, &italic, &bold) != 9) { + free(s); + return 0; + } + txt->s = s; if (flags) { /* @@ -128,9 +148,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) } if (n == 0 && comp->comp && comp->comp->units > 1) { - int len = strlen(txt->s); - char *s; - + len = strlen(txt->s); s = realloc((void *) txt->s, len + 3); if (!s) diag_pfatal("realloc");