1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-11-22 03:09:46 +01:00

cleanup normalize_line state machine

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-11-04 14:20:03 +01:00
parent acd09007a1
commit 1ffc240b3f

View file

@ -72,15 +72,17 @@ static int normalize_line(rdline_t *t)
while (isspace(*src)) while (isspace(*src))
++src; ++src;
while (*src != '\0' && (string || *src != '#')) { do {
c = *(src++); c = *(src++);
if (c == '"') { if (c == '"') {
string = !string; string = !string;
} else if (!string && c == '#') {
c = '\0';
} else if (!string && isspace(c)) { } else if (!string && isspace(c)) {
c = ' '; if (*src == '#' || *src == '\0' || isspace(*src))
if (dst > t->line && dst[-1] == ' ')
continue; continue;
c = ' ';
} else if (c == '%') { } else if (c == '%') {
*(dst++) = c; *(dst++) = c;
c = *(src++); c = *(src++);
@ -100,16 +102,12 @@ static int normalize_line(rdline_t *t)
} }
*(dst++) = c; *(dst++) = c;
} } while (c != '\0');
if (string) { if (string) {
errstr = "missing \""; errstr = "missing \"";
goto fail; goto fail;
} }
while (dst > t->line && dst[-1] == ' ')
--dst;
*dst = '\0';
return ret; return ret;
fail: fail:
fprintf(stderr, "%s: %zu: %s\n", t->filename, t->lineno, errstr); fprintf(stderr, "%s: %zu: %s\n", t->filename, t->lineno, errstr);
@ -123,9 +121,8 @@ static void substitute(rdline_t *t, char *dst, char *src)
while (*src != '\0') { while (*src != '\0') {
if (src[0] == '%' && isdigit(src[1])) { if (src[0] == '%' && isdigit(src[1])) {
strcpy(dst, t->argv[src[1] - '0']); strcpy(dst, t->argv[src[1] - '0']);
dst += strlen(dst);
src += 2; src += 2;
while (*dst != '\0')
++dst;
} else if (src[0] == '%' && src[1] == '%') { } else if (src[0] == '%' && src[1] == '%') {
*(dst++) = '%'; *(dst++) = '%';
src += 2; src += 2;