diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-11-22 14:51:07 +0100 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-11-22 14:55:15 +0100 |
commit | fc9cd6149b640ff8f62a6de9ccd0c6b009110407 (patch) | |
tree | 598115738b4e69a81b8ae4b7b16bb36d4a1a523f | |
parent | 1ff6f39c86b903499633ff13d7447fee4d81d1f6 (diff) | |
download | calcurse-fc9cd6149b640ff8f62a6de9ccd0c6b009110407.zip |
src/utils.c: Support escape sequences in format strings
We support all simple escape sequences listed in the ANSI C standard,
plus "\0" to allow for printing null characters.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/utils.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index fa4cefe..f7b500d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1006,6 +1006,55 @@ print_notefile (FILE *out, char *filename, int nbtab) } } +/* Print an escape sequence and return its length. */ +static int +print_escape (const char *s) +{ + switch (*(s + 1)) + { + case 'a': + putchar ('\a'); + return 1; + case 'b': + putchar ('\b'); + return 1; + case 'f': + putchar ('\f'); + return 1; + case 'n': + putchar ('\n'); + return 1; + case 'r': + putchar ('\r'); + return 1; + case 't': + putchar ('\t'); + return 1; + case 'v': + putchar ('\v'); + return 1; + case '0': + putchar ('\0'); + return 1; + case '\'': + putchar ('\''); + return 1; + case '"': + putchar ('"'); + return 1; + case '\?': + putchar ('?'); + return 1; + case '\\': + putchar ('\\'); + return 1; + case '\0': + return 0; + default: + return 1; + } +} + /* Print a formatted appointment to stdout. */ void print_apoint (const char *format, long day, struct apoint *apt) @@ -1056,6 +1105,8 @@ print_apoint (const char *format, long day, struct apoint *apt) break; } } + else if (*p == '\\') + p += print_escape (p); else putchar (*p); } @@ -1093,6 +1144,8 @@ print_event (const char *format, long day, struct event *ev) break; } } + else if (*p == '\\') + p += print_escape (p); else putchar (*p); } @@ -1160,6 +1213,8 @@ print_todo (const char *format, struct todo *todo) break; } } + else if (*p == '\\') + p += print_escape (p); else putchar (*p); } |