diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-04 13:09:59 -0400 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-04 13:09:59 -0400 |
commit | 38cc76cf9fbaa6bc7ff4af803f6a10da70cc769e (patch) | |
tree | 5fe6dea63a8f49a547f19a7fbb42bb589fd8d962 /awkgram.c | |
parent | 577ece63770a6c4b5ad00d6998127fb7e85b86b9 (diff) | |
parent | f6e8ca91a0046536ed5ffef60bb818d674fadf54 (diff) | |
download | egawk-38cc76cf9fbaa6bc7ff4af803f6a10da70cc769e.tar.gz egawk-38cc76cf9fbaa6bc7ff4af803f6a10da70cc769e.tar.bz2 egawk-38cc76cf9fbaa6bc7ff4af803f6a10da70cc769e.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 90 |
1 files changed, 49 insertions, 41 deletions
@@ -5135,7 +5135,7 @@ tokexpand() #if MBS_SUPPORT static int -nextc(void) +nextc(bool check_for_bad) { if (gawk_mb_cur_max > 1) { again: @@ -5186,14 +5186,19 @@ 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); return (int) (unsigned char) *lexptr++; } else { do { if (lexeof) return END_FILE; - if (lexptr && lexptr < lexend) - return ((int) (unsigned char) *lexptr++); + if (lexptr && lexptr < lexend) { + if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + return ((int) (unsigned char) *lexptr++); + } } while (get_src_buf()); return END_SRC; } @@ -5202,13 +5207,16 @@ again: #else /* MBS_SUPPORT */ int -nextc() +nextc(bool check_for_bad) { do { if (lexeof) return END_FILE; - if (lexptr && lexptr < lexend) + if (lexptr && lexptr < lexend) { + if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); return ((int) (unsigned char) *lexptr++); + } } while (get_src_buf()); return END_SRC; } @@ -5237,13 +5245,13 @@ allow_newline(void) int c; for (;;) { - c = nextc(); + c = nextc(true); if (c == END_FILE) { pushback(); break; } if (c == '#') { - while ((c = nextc()) != '\n' && c != END_FILE) + while ((c = nextc(false)) != '\n' && c != END_FILE) continue; if (c == END_FILE) { pushback(); @@ -5315,7 +5323,7 @@ yylex(void) if (lasttok == LEX_EOF) /* error earlier in current source, must give up !! */ return 0; - c = nextc(); + c = nextc(true); if (c == END_SRC) return 0; if (c == END_FILE) @@ -5357,12 +5365,12 @@ yylex(void) want_regexp = false; tok = tokstart; for (;;) { - c = nextc(); + c = nextc(true); if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) { case '[': /* one day check for `.' and `=' too */ - if (nextc() == ':' || in_brack == 0) + if (nextc(true) == ':' || in_brack == 0) in_brack++; pushback(); break; @@ -5376,7 +5384,7 @@ yylex(void) in_brack--; break; case '\\': - if ((c = nextc()) == END_FILE) { + if ((c = nextc(true)) == END_FILE) { pushback(); yyerror(_("unterminated regexp ends with `\\' at end of file")); goto end_regexp; /* kludge */ @@ -5396,7 +5404,7 @@ end_regexp: yylval = GET_INSTRUCTION(Op_token); yylval->lextok = estrdup(tokstart, tok - tokstart); if (do_lint) { - int peek = nextc(); + int peek = nextc(true); pushback(); if (peek == 'i' || peek == 's') { @@ -5426,7 +5434,7 @@ end_regexp: retry: /* skipping \r is a hack, but windows is just too pervasive. sigh. */ - while ((c = nextc()) == ' ' || c == '\t' || c == '\r') + while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r') continue; lexeme = lexptr ? lexptr - 1 : lexptr; @@ -5448,7 +5456,7 @@ retry: return lasttok = NEWLINE; case '#': /* it's a comment */ - while ((c = nextc()) != '\n') { + while ((c = nextc(false)) != '\n') { if (c == END_FILE) return lasttok = NEWLINE_EOF; } @@ -5468,7 +5476,7 @@ retry: */ if (! do_traditional) { /* strip trailing white-space and/or comment */ - while ((c = nextc()) == ' ' || c == '\t' || c == '\r') + while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r') continue; if (c == '#') { static bool warned = false; @@ -5478,16 +5486,16 @@ retry: lintwarn( _("use of `\\ #...' line continuation is not portable")); } - while ((c = nextc()) != '\n') + while ((c = nextc(false)) != '\n') if (c == END_FILE) break; } pushback(); } #endif /* RELAXED_CONTINUATION */ - c = nextc(); + c = nextc(true); if (c == '\r') /* allow MS-DOS files. bleah */ - c = nextc(); + c = nextc(true); if (c == '\n') { sourceline++; goto retry; @@ -5526,7 +5534,7 @@ retry: case '[': return lasttok = c; case ']': - c = nextc(); + c = nextc(true); pushback(); if (c == '[') { yylval = GET_INSTRUCTION(Op_sub_array); @@ -5538,7 +5546,7 @@ retry: return ']'; case '*': - if ((c = nextc()) == '=') { + if ((c = nextc(true)) == '=') { yylval = GET_INSTRUCTION(Op_assign_times); return lasttok = ASSIGNOP; } else if (do_posix) { @@ -5549,7 +5557,7 @@ retry: /* make ** and **= aliases for ^ and ^= */ static bool did_warn_op = false, did_warn_assgn = false; - if (nextc() == '=') { + if (nextc(true) == '=') { if (! did_warn_assgn) { did_warn_assgn = true; if (do_lint) @@ -5577,7 +5585,7 @@ retry: return lasttok = '*'; case '/': - if (nextc() == '=') { + if (nextc(true) == '=') { pushback(); return lasttok = SLASH_BEFORE_EQUAL; } @@ -5586,7 +5594,7 @@ retry: return lasttok = '/'; case '%': - if (nextc() == '=') { + if (nextc(true) == '=') { yylval = GET_INSTRUCTION(Op_assign_mod); return lasttok = ASSIGNOP; } @@ -5598,7 +5606,7 @@ retry: { static bool did_warn_op = false, did_warn_assgn = false; - if (nextc() == '=') { + if (nextc(true) == '=') { if (do_lint_old && ! did_warn_assgn) { did_warn_assgn = true; warning(_("operator `^=' is not supported in old awk")); @@ -5616,7 +5624,7 @@ retry: } case '+': - if ((c = nextc()) == '=') { + if ((c = nextc(true)) == '=') { yylval = GET_INSTRUCTION(Op_assign_plus); return lasttok = ASSIGNOP; } @@ -5629,7 +5637,7 @@ retry: return lasttok = '+'; case '!': - if ((c = nextc()) == '=') { + if ((c = nextc(true)) == '=') { yylval = GET_INSTRUCTION(Op_notequal); return lasttok = RELOP; } @@ -5642,7 +5650,7 @@ retry: return lasttok = '!'; case '<': - if (nextc() == '=') { + if (nextc(true) == '=') { yylval = GET_INSTRUCTION(Op_leq); return lasttok = RELOP; } @@ -5651,7 +5659,7 @@ retry: return lasttok = '<'; case '=': - if (nextc() == '=') { + if (nextc(true) == '=') { yylval = GET_INSTRUCTION(Op_equal); return lasttok = RELOP; } @@ -5660,7 +5668,7 @@ retry: return lasttok = ASSIGN; case '>': - if ((c = nextc()) == '=') { + if ((c = nextc(true)) == '=') { yylval = GET_INSTRUCTION(Op_geq); return lasttok = RELOP; } else if (c == '>') { @@ -5699,7 +5707,7 @@ retry: case '"': string: esc_seen = false; - while ((c = nextc()) != '"') { + while ((c = nextc(true)) != '"') { if (c == '\n') { pushback(); yyerror(_("unterminated string")); @@ -5707,7 +5715,7 @@ retry: } if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) && c == '\\') { - c = nextc(); + c = nextc(true); if (c == '\n') { sourceline++; continue; @@ -5741,7 +5749,7 @@ retry: return lasttok = YSTRING; case '-': - if ((c = nextc()) == '=') { + if ((c = nextc(true)) == '=') { yylval = GET_INSTRUCTION(Op_assign_minus); return lasttok = ASSIGNOP; } @@ -5754,7 +5762,7 @@ retry: return lasttok = '-'; case '.': - c = nextc(); + c = nextc(true); pushback(); if (! isdigit(c)) return lasttok = '.'; @@ -5782,7 +5790,7 @@ retry: if (do_traditional) goto done; if (tok == tokstart + 2) { - int peek = nextc(); + int peek = nextc(true); if (isxdigit(peek)) { inhex = true; @@ -5810,8 +5818,8 @@ retry: break; } seen_e = true; - if ((c = nextc()) == '-' || c == '+') { - int c2 = nextc(); + if ((c = nextc(true)) == '-' || c == '+') { + int c2 = nextc(true); if (isdigit(c2)) { tokadd(c); @@ -5858,7 +5866,7 @@ retry: } if (gotnumber) break; - c = nextc(); + c = nextc(true); } pushback(); @@ -5907,7 +5915,7 @@ retry: return lasttok = YNUMBER; case '&': - if ((c = nextc()) == '&') { + if ((c = nextc(true)) == '&') { yylval = GET_INSTRUCTION(Op_and); allow_newline(); return lasttok = LEX_AND; @@ -5917,7 +5925,7 @@ retry: return lasttok = '&'; case '|': - if ((c = nextc()) == '|') { + if ((c = nextc(true)) == '|') { yylval = GET_INSTRUCTION(Op_or); allow_newline(); return lasttok = LEX_OR; @@ -5958,7 +5966,7 @@ retry: * occasions where the interactions are funny. */ if (! do_traditional && c == '_' && lasttok != '$') { - if ((c = nextc()) == '"') { + if ((c = nextc(true)) == '"') { intlstr = true; goto string; } @@ -5970,7 +5978,7 @@ retry: tok = tokstart; while (c != END_FILE && is_identchar(c)) { tokadd(c); - c = nextc(); + c = nextc(true); } tokadd('\0'); pushback(); |