diff options
Diffstat (limited to 'src/fmt.cff')
| -rw-r--r-- | src/fmt.cff | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/fmt.cff b/src/fmt.cff index 8212593..90fcd47 100644 --- a/src/fmt.cff +++ b/src/fmt.cff @@ -1,4 +1,5 @@ -import "all.hff"; +import "cffc.hff"; +import "common.hff"; extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list) void { defmacro p(x) [ proc(x, parg) ] @@ -10,14 +11,22 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list) defmacro pch(ch) [ { extern fn isprint(int) int; - let $ch = ch; - if isprint($ch) != 0 { + let $ch u8 = ch; + switch { + case $ch == '\''; + ps("\\'"); + case $ch == '\"'; + ps("\\\""); + case $ch == '\\'; + ps("\\\\"); + case isprint($ch) != 0; p($ch); - } else { - p('\\'); - p('0' + ($ch % 8)); - p('0' + (($ch / 8) % 8)); - p('0' + (($ch / 8 / 8) % 8)); + case $ch == '\n'; + ps("\\n"); + case else; + ps("\\x"); + p("0123456789ABCDEF"[($ch >> 4) & 15]); + p("0123456789ABCDEF"[$ch & 15]); } } ] |