From 8944ce7878105d0b5c56b840db0a95a593e01244 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 6 Dec 2014 23:08:38 -0700 Subject: ext/SDBM_File/sdbm/dbu.c Generalize for EBCDIC platforms This also fixed a bug which hasn't shown up in the tests, in that it uses 'char' where it should be 'U8'. --- ext/SDBM_File/dbu.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'ext/SDBM_File') diff --git a/ext/SDBM_File/dbu.c b/ext/SDBM_File/dbu.c index d861c0f1b1..4631d40acd 100644 --- a/ext/SDBM_File/dbu.c +++ b/ext/SDBM_File/dbu.c @@ -224,19 +224,29 @@ static void prdatum(FILE *stream, datum d) { int c; - char *p = d.dptr; + U8 *p = (U8 *) d.dptr; int n = d.dsize; while (n--) { - c = *p++ & 0377; + c = *p++; +#ifndef EBCDIC /* Meta notation doesn't make sense on EBCDIC systems*/ if (c & 0200) { - fprintf(stream, "M-"); - c &= 0177; + fprintf(stream, "M-"); + c &= 0177; } - if (c == 0177 || c < ' ') - fprintf(stream, "^%c", (c == 0177) ? '?' : c + '@'); - else - putc(c, stream); +#endif + /* \c notation applies for \0 . \x1f, plus \c? */ + if (c <= 0x1F || c == QUESTION_MARK_CTRL) { + fprintf(stream, "^%c", toCTRL(c)); + } +#ifdef EBCDIC /* Instead of meta, use \x{} for non-printables */ + else if (! isPRINT_A(c)) { + fprintf(stream, "\\x{%02x}", c); + } +#endif + else { /* must be an ASCII printable */ + putc(c, stream); + } } } -- cgit v1.2.1