From edc2856a2ae2dc46037f85652440bd329b1a2c8a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 2 Aug 2015 21:41:40 +0300 Subject: Rework zOS patches; keep separate from autotools. --- command.y | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'command.y') diff --git a/command.y b/command.y index 08893743..43aae8d2 100644 --- a/command.y +++ b/command.y @@ -1022,7 +1022,11 @@ yyerror(const char *mesg, ...) /* yylex --- read a command and turn it into tokens */ static int +#ifdef USE_EBCDIC +yylex_ebcdic(void) +#else yylex(void) +#endif { static char *lexptr = NULL; static char *lexend; @@ -1298,6 +1302,39 @@ err: return D_VARIABLE; } +/* Convert single-character tokens coming out of yylex() from EBCDIC to + ASCII values on-the-fly so that the parse tables need not be regenerated + for EBCDIC systems. */ +#ifdef USE_EBCDIC +static int +yylex(void) +{ + static char etoa_xlate[256]; + static int do_etoa_init = 1; + int tok; + + if (do_etoa_init) + { + for (tok = 0; tok < 256; tok++) + etoa_xlate[tok] = (char) tok; +#ifdef HAVE___ETOA_L + /* IBM helpfully provides this function. */ + __etoa_l(etoa_xlate, sizeof(etoa_xlate)); +#else +# error "An EBCDIC-to-ASCII translation function is needed for this system" +#endif + do_etoa_init = 0; + } + + tok = yylex_ebcdic(); + + if (tok >= 0 && tok <= 0xFF) + tok = etoa_xlate[tok]; + + return tok; +} +#endif /* USE_EBCDIC */ + /* find_argument --- find index in 'argtab' for a command option */ static int -- cgit v1.2.3