summaryrefslogtreecommitdiff
path: root/awkgram.y
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-08-02 21:41:40 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-08-02 21:41:40 +0300
commitedc2856a2ae2dc46037f85652440bd329b1a2c8a (patch)
treec7dc2821a1cea7d65cf8b6ed48d3494e98b98d09 /awkgram.y
parent4b00462246822209b642a4dd63491e59a4fab759 (diff)
downloadgawk-edc2856a2ae2dc46037f85652440bd329b1a2c8a.tar.gz
Rework zOS patches; keep separate from autotools.
Diffstat (limited to 'awkgram.y')
-rw-r--r--awkgram.y43
1 files changed, 41 insertions, 2 deletions
diff --git a/awkgram.y b/awkgram.y
index f311f29a..9bb747e4 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1823,7 +1823,7 @@ struct token {
NODE *(*ptr2)(int); /* alternate arbitrary-precision function */
};
-#if 'a' == 0x81 /* it's EBCDIC */
+#ifdef USE_EBCDIC
/* tokcompare --- lexicographically compare token names for sorting */
static int
@@ -2973,7 +2973,11 @@ static int newline_eof()
/* yylex --- Read the input and turn it into tokens. */
static int
+#ifdef USE_EBCDIC
+yylex_ebcdic(void)
+#else
yylex(void)
+#endif
{
int c;
bool seen_e = false; /* These are for numbers */
@@ -3799,6 +3803,41 @@ out:
#undef NEWLINE_EOF
}
+/* It's EBCDIC in a Bison grammar, run for the hills!
+
+ Or, 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 */
+
/* snode --- instructions for builtin functions. Checks for arg. count
and supplies defaults where possible. */
@@ -5556,7 +5595,7 @@ check_special(const char *name)
int low, high, mid;
int i;
int non_standard_flags = 0;
-#if 'a' == 0x81 /* it's EBCDIC */
+#ifdef USE_EBCDIC
static bool did_sort = false;
if (! did_sort) {