Shift-JIS patch for gcc 2.7.2 HOWTO: 1. patch this in gcc's top directory (where you can find `configure') 2. run `configure' 3. edit `makefile' and `cp/makefile' ex) CFLAGS = -O2 -DMULTIBYTE_CHARS -DUSE_SJIS CLIB=-lmb 4. make NOTE: This patch require some multibyte functions. You must get multibyte library before making. BUGREPORT: Daisuke Aoyama ### PATCH START HERE ### --- cp/lex-orig.c Thu Oct 12 02:30:14 1995 +++ cp/lex.c Sun Jul 14 19:25:14 1996 @@ -43,6 +43,10 @@ #include #include #endif +#ifdef USE_SJIS +#include +#include +#endif #ifndef errno extern int errno; /* needed for VAX. */ @@ -411,6 +415,11 @@ int i; +#ifdef MULTIBYTE_CHARS + /* Change to the native locale for multibyte conversions. */ + setlocale (LC_CTYPE, ""); +#endif + /* Initialize the lookahead machinery. */ init_spew (); @@ -3971,7 +3980,11 @@ if (c == '\'' || c == EOF) break; +#ifdef USE_SJIS + if (c == '\\' && _mbsbtype (token_buffer, num_chars) != _MBC_LEAD) +#else if (c == '\\') +#endif { int ignore = 0; c = readescape (&ignore); @@ -4024,7 +4037,11 @@ num_chars = max_chars; error ("character constant too long"); } +#ifdef MULTIBYTE_CHARS + else if (! wide_flag && num_chars != 1 && ! flag_traditional) +#else else if (num_chars != 1 && ! flag_traditional) +#endif warning ("multi-character character constant"); /* If char type is signed, sign-extend the constant. */ @@ -4087,7 +4104,15 @@ while (c != '"' && c >= 0) { /* ignore_escape_flag is set for reading the filename in #line. */ +#ifdef USE_SJIS + if (!ignore_escape_flag && c == '\\' + && (p == token_buffer+1 + || (p > token_buffer+1 + && _mbsbtype (token_buffer+1, + p-(token_buffer+1)-1) != _MBC_LEAD))) +#else if (!ignore_escape_flag && c == '\\') +#endif { int ignore = 0; c = readescape (&ignore); --- ./cccp-orig.c Thu Oct 26 22:07:26 1995 +++ ./cccp.c Sun Jul 14 19:16:58 1996 @@ -310,6 +310,14 @@ #define INCLUDE_LEN_FUDGE 0 #endif +#ifdef MULTIBYTE_CHARS +#include +#endif +#ifdef USE_SJIS +#include +#include +#endif + /* External declarations. */ extern char *version_string; @@ -1298,7 +1306,13 @@ /* Target-name to write with the dependency information. */ char *deps_target = 0; -#ifdef RLIMIT_STACK +#ifdef MULTIBYTE_CHARS + /* Change to the native locale for multibyte conversions. */ + setlocale (LC_CTYPE, ""); +#endif + +#ifdef RLIMIT_STACK + /* Get rid of any avoidable limit on stack size. */ { struct rlimit rlim; @@ -2951,6 +2965,10 @@ break; case '\\': +#ifdef USE_SJIS + if (_ismbblead (ibp[-2])) + break; +#endif if (ibp >= limit) break; if (*ibp == '\n') { @@ -3005,7 +3023,12 @@ while (++ibp < limit) { if (*ibp == '\n') { +#ifdef USE_SJIS + if (ibp[-1] != '\\' || + _mbsbtype (before_bp+1, ibp-(before_bp+1)-2) == _MBC_LEAD) { +#else if (ibp[-1] != '\\') { +#endif if (put_out_comments) { bcopy ((char *) before_bp, (char *) obp, ibp - before_bp); obp += ibp - before_bp; @@ -7807,7 +7830,11 @@ break; } c = *bp++; +#ifdef USE_SJIS + if (c == '\\' && ! _ismbblead (bp[-2])) { +#else if (c == '\\') { +#endif while (*bp == '\\' && bp[1] == '\n') { if (backslash_newlines_p) *backslash_newlines_p = 1; @@ -8248,7 +8275,15 @@ xbuf[totlen++] = '\"'; /* insert beginning quote */ for (; i < arglen; i++) { c = arg->raw[i]; - +#ifdef USE_SJIS + if (_ismbblead (c)) + { + escaped = 0; + xbuf[totlen++] = c; + xbuf[totlen++] = arg->raw[++i]; + continue; + } +#endif /* Special markers Newline Space generate nothing for a stringified argument. */ if (c == '\n' && arg->raw[i+1] != '\n') { --- ./cexp-orig.y Thu Jun 15 11:17:08 1995 +++ ./cexp.y Sun Jul 14 19:22:44 1996 @@ -33,6 +33,10 @@ #include #include #endif +#ifdef USE_SJIS +#include +#include +#endif #include @@ -604,7 +608,14 @@ if (c == '\'' || c == EOF) break; +#ifdef USE_SJIS + if (c == '\\' + && (num_chars == 0 + || (num_chars > 0 + && _mbsbtype (token_buffer, num_chars-1) != _MBC_LEAD))) +#else if (c == '\\') +#endif { c = parse_escape (&lexptr); if (width < HOST_BITS_PER_INT @@ -636,7 +647,11 @@ num_chars = max_chars; error ("character constant too long"); } +#ifdef MULTIBYTE_CHARS + else if (!wide_flag && num_chars != 1 && ! traditional) +#else else if (num_chars != 1 && ! traditional) +#endif warning ("multi-character character constant"); /* If char type is signed, sign-extend the constant. */ --- ./c-lex-orig.c Thu Jun 15 11:11:38 1995 +++ ./c-lex.c Sun Jul 14 19:24:08 1996 @@ -39,6 +39,10 @@ #include #include #endif +#ifdef USE_SJIS +#include +#include +#endif #ifndef errno extern int errno; @@ -1676,7 +1680,12 @@ if (c == '\'' || c == EOF) break; +#ifdef USE_SJIS + if (c == '\\' + && _mbsbtype (token_buffer, num_chars) != _MBC_LEAD) +#else if (c == '\\') +#endif { int ignore = 0; c = readescape (&ignore); @@ -1729,7 +1738,11 @@ num_chars = max_chars; error ("character constant too long"); } +#ifdef MULTIBYTE_CHARS + else if (! wide_flag && num_chars != 1 && ! flag_traditional) +#else else if (num_chars != 1 && ! flag_traditional) +#endif warning ("multi-character character constant"); /* If char type is signed, sign-extend the constant. */ @@ -1786,7 +1799,15 @@ while (c != '"' && c >= 0) { +#ifdef USE_SJIS + if (c == '\\' + && (p == token_buffer+1 + || (p > token_buffer+1 + && _mbsbtype (token_buffer+1, + p-(token_buffer+1)-1) != _MBC_LEAD))) +#else if (c == '\\') +#endif { int ignore = 0; c = readescape (&ignore); --- ./cppexp-orig.c Tue Nov 7 14:57:44 1995 +++ ./cppexp.c Tue Jun 25 23:00:30 1996 @@ -34,6 +34,10 @@ #include #include #endif +#ifdef USE_SJIS +#include +#include +#endif #include @@ -360,7 +364,15 @@ ++ptr; while (ptr < tok_end && ((c = *ptr++) != '\'')) { +#ifdef USE_SJIS + if (c == '\\' + && (num_chars == 0 + || (num_chars > 0 + && _mbsbtype (token_buffer, + num_chars-1) != _MBC_LEAD))) +#else if (c == '\\') +#endif { c = cpp_parse_escape (pfile, &ptr); if (width < HOST_BITS_PER_INT --- ./cpplib-orig.c Sat Nov 4 15:43:48 1995 +++ ./cpplib.c Tue Jun 25 22:46:20 1996 @@ -144,6 +144,11 @@ #define INCLUDE_LEN_FUDGE 0 #endif +#ifdef USE_SJIS +#include +#include +#endif + /* Symbols to predefine. */ #ifdef CPP_PREDEFINES @@ -924,6 +929,13 @@ for (;;) { c = GETC (); +#ifdef USE_SJIS + if (_ismbblead (c)) + { + c = GETC (); + continue; + } +#endif if (c == EOF) return ' '; /* Allow // to be terminated by EOF. */ while (c == '\\' && PEEKC() == '\n') @@ -2807,6 +2819,16 @@ for (; i < arglen; i++) { c = (ARG_BASE + arg->raw)[i]; +#ifdef USE_SJIS + if (_ismbblead (c)) + { + escaped = 0; + CPP_PUTC (pfile, c); + c = (ARG_BASE + arg->raw)[++i]; + CPP_PUTC (pfile, c); + continue; + } +#endif if (! in_string) { @@ -4768,6 +4790,15 @@ while (1) { int cc = GETC(); +#ifdef USE_SJIS + if (_ismbblead (cc)) + { + CPP_PUTC (pfile, cc); + cc = GETC (); + CPP_PUTC (pfile, cc); + continue; + } +#endif if (cc == EOF) { if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) --- ./cppmain-orig.c Sat Nov 4 15:31:26 1995 +++ ./cppmain.c Wed Jul 17 00:42:24 1996 @@ -27,6 +27,10 @@ #include "config.h" #endif /* not EMACS */ +#ifdef MULTIBYTE_CHARS +#include +#endif + extern char *getenv (); char *progname; @@ -53,6 +57,11 @@ int i; int argi = 1; /* Next argument to handle. */ struct cpp_options *opts = &options; + +#ifdef MULTIBYTE_CHARS + /* Change to the native locale for multibyte conversions. */ + setlocale (LC_CTYPE, ""); +#endif p = argv[0] + strlen (argv[0]); while (p != argv[0] && p[-1] != '/') --p;