From 84ccb37bc34a30743065bcaf2c38ad4377237891 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Sun, 4 Nov 2018 17:08:11 -0800 Subject: [PATCH] Regualrize escape characters Regularized the case statements in qio.c, str.c, and token.c that relate to escape characters. The '\a' is now recognized in a printf format string as the single byte audible bell character (byte 0x07 in ASCII encoding). The following is a partial list of escape sequences recognized in strings and in printf formats: \a audible bell byte 0x07 in ASCII encoding \b backspace byte 0x08 in ASCII encoding \f form feed byte 0x0c in ASCII encoding \n newline byte 0x0b in ASCII encoding \r return byte 0x0a in ASCII encoding \t tab byte 0x0d in ASCII encoding \v vertical tab byte 0x09 in ASCII encoding --- qio.c | 5 +++-- str.c | 19 ++++++++++++++----- token.c | 8 +++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/qio.c b/qio.c index f17d9ee..ea1832e 100644 --- a/qio.c +++ b/qio.c @@ -62,12 +62,13 @@ qprintf(char *fmt, ...) if (ch == '\\') { ch = *fmt++; switch (ch) { + case 'a': ch = '\a'; break; + case 'b': ch = '\b'; break; + case 'f': ch = '\f'; break; case 'n': ch = '\n'; break; case 'r': ch = '\r'; break; case 't': ch = '\t'; break; - case 'f': ch = '\f'; break; case 'v': ch = '\v'; break; - case 'b': ch = '\b'; break; case 0: va_end(ap); return; diff --git a/str.c b/str.c index 2f5ac23..45f7e66 100644 --- a/str.c +++ b/str.c @@ -1380,17 +1380,17 @@ printechar(char *c) math_chr('\\'); ech = 0; switch (ch) { + case '\a': ech = 'a'; break; + case '\b': ech = 'b'; break; + case '\f': ech = 'f'; break; case '\n': ech = 'n'; break; case '\r': ech = 'r'; break; case '\t': ech = 't'; break; - case '\b': ech = 'b'; break; - case '\f': ech = 'f'; break; case '\v': ech = 'v'; break; case '\\': ech = '\\'; break; case '\"': ech = '\"'; break; case '\'': ech = '\''; break; case 0: ech = '0'; break; - case 7: ech = 'a'; break; case 27: ech = 'e'; break; } if (ech == '0') { @@ -1438,8 +1438,17 @@ fitstring(char *str, long len, long width) continue; n++; switch (ch) { - case '\n': case '\r': case '\t': case '\b': case '\f': - case '\v': case '\\': case '\"': case 7: case 27: + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + case '\\': + case '\"': + case '\'': + case 27: continue; } if (ch >= 64 || (nch >= '0' && nch <= '7')) { diff --git a/token.c b/token.c index 27468a9..3f0032f 100644 --- a/token.c +++ b/token.c @@ -183,10 +183,12 @@ gettoken(void) } switch (ch) { case ' ': - case '\t': - case '\r': - case '\v': + case '\a': + case '\b': case '\f': + case '\r': + case '\t': + case '\v': case '\0': break; case '\n':