mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
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
This commit is contained in:
5
qio.c
5
qio.c
@@ -62,12 +62,13 @@ qprintf(char *fmt, ...)
|
|||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
ch = *fmt++;
|
ch = *fmt++;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
case 'a': ch = '\a'; break;
|
||||||
|
case 'b': ch = '\b'; break;
|
||||||
|
case 'f': ch = '\f'; break;
|
||||||
case 'n': ch = '\n'; break;
|
case 'n': ch = '\n'; break;
|
||||||
case 'r': ch = '\r'; break;
|
case 'r': ch = '\r'; break;
|
||||||
case 't': ch = '\t'; break;
|
case 't': ch = '\t'; break;
|
||||||
case 'f': ch = '\f'; break;
|
|
||||||
case 'v': ch = '\v'; break;
|
case 'v': ch = '\v'; break;
|
||||||
case 'b': ch = '\b'; break;
|
|
||||||
case 0:
|
case 0:
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return;
|
return;
|
||||||
|
19
str.c
19
str.c
@@ -1380,17 +1380,17 @@ printechar(char *c)
|
|||||||
math_chr('\\');
|
math_chr('\\');
|
||||||
ech = 0;
|
ech = 0;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
case '\a': ech = 'a'; break;
|
||||||
|
case '\b': ech = 'b'; break;
|
||||||
|
case '\f': ech = 'f'; break;
|
||||||
case '\n': ech = 'n'; break;
|
case '\n': ech = 'n'; break;
|
||||||
case '\r': ech = 'r'; break;
|
case '\r': ech = 'r'; break;
|
||||||
case '\t': ech = 't'; break;
|
case '\t': ech = 't'; break;
|
||||||
case '\b': ech = 'b'; break;
|
|
||||||
case '\f': ech = 'f'; break;
|
|
||||||
case '\v': ech = 'v'; break;
|
case '\v': ech = 'v'; break;
|
||||||
case '\\': ech = '\\'; break;
|
case '\\': ech = '\\'; break;
|
||||||
case '\"': ech = '\"'; break;
|
case '\"': ech = '\"'; break;
|
||||||
case '\'': ech = '\''; break;
|
case '\'': ech = '\''; break;
|
||||||
case 0: ech = '0'; break;
|
case 0: ech = '0'; break;
|
||||||
case 7: ech = 'a'; break;
|
|
||||||
case 27: ech = 'e'; break;
|
case 27: ech = 'e'; break;
|
||||||
}
|
}
|
||||||
if (ech == '0') {
|
if (ech == '0') {
|
||||||
@@ -1438,8 +1438,17 @@ fitstring(char *str, long len, long width)
|
|||||||
continue;
|
continue;
|
||||||
n++;
|
n++;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '\n': case '\r': case '\t': case '\b': case '\f':
|
case '\a':
|
||||||
case '\v': case '\\': case '\"': case 7: case 27:
|
case '\b':
|
||||||
|
case '\f':
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
case '\t':
|
||||||
|
case '\v':
|
||||||
|
case '\\':
|
||||||
|
case '\"':
|
||||||
|
case '\'':
|
||||||
|
case 27:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ch >= 64 || (nch >= '0' && nch <= '7')) {
|
if (ch >= 64 || (nch >= '0' && nch <= '7')) {
|
||||||
|
Reference in New Issue
Block a user