X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=src%2Fprint.c;h=5b828caedae1be2d72befbe5a2dd0d11f345a13d;hp=2616896b27adee236864f069ac27947327e29a5c;hb=46f51e794ddb493a8a76ec2f3be00b41e3b0be22;hpb=ea21eb75bbf90355514d65686bd53bea579f8e23 diff --git a/src/print.c b/src/print.c index 2616896..5b828ca 100644 --- a/src/print.c +++ b/src/print.c @@ -1106,7 +1106,9 @@ print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) case Lisp_Type_Int_Even: case Lisp_Type_Int_Odd: { - char buf[24]; + /* ASCII Decimal representation uses 2.4 times as many bits as + machine binary. */ + char buf[3 * sizeof (EMACS_INT) + 5]; long_to_string (buf, XINT (obj)); write_c_string (buf, printcharfun); break; @@ -1119,36 +1121,61 @@ print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) Emchar ch = XCHAR (obj); char *p = buf; *p++ = '?'; - if (ch == '\n') - *p++ = '\\', *p++ = 'n'; - else if (ch == '\r') - *p++ = '\\', *p++ = 'r'; - else if (ch == '\t') - *p++ = '\\', *p++ = 't'; - else if (ch < 32) + if (ch < 32) { - *p++ = '\\', *p++ = '^'; - *p++ = ch + 64; - if ((ch + 64) == '\\') - *p++ = '\\'; + *p++ = '\\'; + switch (ch) + { + case '\t': *p++ = 't'; break; + case '\n': *p++ = 'n'; break; + case '\r': *p++ = 'r'; break; + default: + *p++ = '^'; + *p++ = ch + 64; + if ((ch + 64) == '\\') + *p++ = '\\'; + break; + } + } + else if (ch < 127) + { + /* syntactically special characters should be escaped. */ + switch (ch) + { + case ' ': + case '"': + case '#': + case '\'': + case '(': + case ')': + case ',': + case '.': + case ';': + case '?': + case '[': + case '\\': + case ']': + case '`': + *p++ = '\\'; + } + *p++ = ch; } else if (ch == 127) - *p++ = '\\', *p++ = '^', *p++ = '?'; - else if (ch >= 128 && ch < 160) + { + *p++ = '\\', *p++ = '^', *p++ = '?'; + } + else if (ch < 160) { *p++ = '\\', *p++ = '^'; - p += set_charptr_emchar ((Bufbyte *)p, ch + 64); + p += set_charptr_emchar ((Bufbyte *) p, ch + 64); } - else if (ch < 127 - && !isdigit (ch) - && !isalpha (ch) - && ch != '^') /* must not backslash this or it will - be interpreted as the start of a - control char */ - *p++ = '\\', *p++ = ch; else - p += set_charptr_emchar ((Bufbyte *)p, ch); - output_string (printcharfun, (Bufbyte *)buf, Qnil, 0, p - buf); + { + p += set_charptr_emchar ((Bufbyte *) p, ch); + } + + output_string (printcharfun, (Bufbyte *) buf, Qnil, 0, p - buf); + break; }