aboutsummaryrefslogtreecommitdiffstats
path: root/awkgram.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-07-10 15:34:40 -0700
committerArnold D. Robbins <arnold@skeeve.com>2014-07-10 15:34:40 -0700
commitbd29e4330190f4ce26dc1f734229357b6f248a1a (patch)
tree813ad6fd7826dc56099b0679e6238d8126f7b0ae /awkgram.c
parentf6e8ca91a0046536ed5ffef60bb818d674fadf54 (diff)
downloadegawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.tar.gz
egawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.tar.bz2
egawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.zip
Make source code character checking smarter.
Diffstat (limited to 'awkgram.c')
-rw-r--r--awkgram.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/awkgram.c b/awkgram.c
index 94ca1313..711c2e37 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -5130,6 +5130,34 @@ tokexpand()
return tok;
}
+/* check_bad_char --- fatal if c isn't allowed in gawk source code */
+
+/*
+ * The error message was inspired by someone who decided to put
+ * a physical \0 byte into the source code to see what would
+ * happen and then filed a bug report about it. Sigh.
+ */
+
+static void
+check_bad_char(int c)
+{
+ /* allow escapes. needed for autoconf. bleah. */
+ switch (c) {
+ case '\a':
+ case '\b':
+ case '\f':
+ case '\n':
+ case '\r':
+ case '\t':
+ return;
+ default:
+ break;
+ }
+
+ if (iscntrl(c) && ! isspace(c))
+ fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c);
+}
+
/* nextc --- get the next input character */
#if MBS_SUPPORT
@@ -5186,8 +5214,8 @@ again:
0 : work_ring_idx + 1;
cur_char_ring[work_ring_idx] = 0;
}
- if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr))
- fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr);
+ if (check_for_bad)
+ check_bad_char(*lexptr);
return (int) (unsigned char) *lexptr++;
} else {
@@ -5195,8 +5223,8 @@ again:
if (lexeof)
return END_FILE;
if (lexptr && lexptr < lexend) {
- if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr))
- fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr);
+ if (check_for_bad)
+ check_bad_char(*lexptr);
return ((int) (unsigned char) *lexptr++);
}
} while (get_src_buf());
@@ -5213,8 +5241,8 @@ nextc(bool check_for_bad)
if (lexeof)
return END_FILE;
if (lexptr && lexptr < lexend) {
- if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr))
- fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr);
+ if (check_for_bad)
+ check_bad_char(*lexptr);
return ((int) (unsigned char) *lexptr++);
}
} while (get_src_buf());