From: Trent Huber Date: Sun, 6 Jul 2025 21:55:26 +0000 (-0400) Subject: Strings with escape sequences X-Git-Url: https://trenthuber.com/code?a=commitdiff_plain;h=5dc5ea6bb0e9b86282f170abb16260f760229720;p=thus.git Strings with escape sequences --- diff --git a/src/lex.c b/src/lex.c index 108084f..08a97d4 100644 --- a/src/lex.c +++ b/src/lex.c @@ -3,6 +3,7 @@ #include #include #include +#include #include // XXX #include "input.h" @@ -15,7 +16,7 @@ static struct cmd cmds[MAXCMDS + 1]; struct cmd empty = {0}; struct cmd *lex(char *b) { - char **t, *end; + char **t, *end, *p; struct cmd *c; long l; @@ -33,7 +34,7 @@ struct cmd *lex(char *b) { if (*(b - 1)) { if (c->args == --t) c->args = NULL; if ((l = strtol(*t, &end, 10)) < 0 || l > INT_MAX || end != b) { - warnx("Invalid file redirection operator"); + warnx("Invalid file redirection"); return ∅ } c->r->newfd = l; @@ -46,6 +47,37 @@ struct cmd *lex(char *b) { c->r++->oldname = b + 1; if (*(b + 1) == '&') ++b; break; + case '"': + for (end = ++b; *end && *end != '"'; ++end) if (*end == '\\') ++end; + if (!*end) { + warnx("Open-ended quote"); + return ∅ + } + *end++ = '\0'; + *t++ = p = b; + b = end; + while (p != end) if (*p++ == '\\') { + switch (*p) { + case 'n': + *p = '\n'; + break; + case 't': + *p = '\t'; + break; + case 'r': + *p = '\r'; + break; + case 'v': + *p = '\v'; + break; + } + memmove(p - 1, p, end-- - p); + } + break; + case '=': + break; + case '$': + break; case '&': case '|': case ';':