diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | awk.h | 1 | ||||
-rw-r--r-- | awkgram.c | 14 | ||||
-rw-r--r-- | awkgram.y | 14 | ||||
-rw-r--r-- | command.c | 2 | ||||
-rw-r--r-- | command.y | 4 | ||||
-rw-r--r-- | ext.c | 43 | ||||
-rw-r--r-- | main.c | 2 |
8 files changed, 63 insertions, 28 deletions
@@ -1,3 +1,14 @@ +2017-07-11 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (is_letter): Add declaration. + * ext.c (is_valid_identifier): New function. + (make_builtin): Use is_valid_identifier instead of inline code. + (is_letter): Moved from here ... + * awkgram.y (is_letter): ... to here. + (yylex): Use is_letter instead of a test. + * command.y (yylex): Ditto. + * main.c (arg_assign): Ditto. + 2017-07-07 Arnold D. Robbins <arnold@skeeve.com> Remove warnings from GCC 7.1 compilation. @@ -1418,6 +1418,7 @@ extern builtin_func_t lookup_builtin(const char *name); extern void install_builtins(void); extern bool is_alpha(int c); extern bool is_alnum(int c); +extern bool is_letter(int c); extern bool is_identchar(int c); extern NODE *make_regnode(int type, NODE *exp); /* builtin.c */ @@ -6506,7 +6506,7 @@ retry: } } - if (c != '_' && ! is_alpha(c)) { + if (! is_letter(c)) { yyerror(_("invalid char '%c' in expression"), c); return lasttok = LEX_EOF; } @@ -8728,6 +8728,18 @@ is_alnum(int c) } +/* + * is_letter --- function to check letters + * isalpha() isn't good enough since it can look at the locale. + * Underscore counts as a letter in awk identifiers + */ + +bool +is_letter(int c) +{ + return (is_alpha(c) || c == '_'); +} + /* is_identchar --- return true if c can be in an identifier */ bool @@ -4086,7 +4086,7 @@ retry: } } - if (c != '_' && ! is_alpha(c)) { + if (! is_letter(c)) { yyerror(_("invalid char '%c' in expression"), c); return lasttok = LEX_EOF; } @@ -6308,6 +6308,18 @@ is_alnum(int c) } +/* + * is_letter --- function to check letters + * isalpha() isn't good enough since it can look at the locale. + * Underscore counts as a letter in awk identifiers + */ + +bool +is_letter(int c) +{ + return (is_alpha(c) || c == '_'); +} + /* is_identchar --- return true if c can be in an identifier */ bool @@ -3038,7 +3038,7 @@ err: || c == ',' || c == '=') return *lexptr++; - if (c != '_' && ! is_alpha(c)) { + if (! is_letter(c)) { yyerror(_("invalid character")); return '\n'; } @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2004, 2010, 2011, 2014, 2016 + * Copyright (C) 2004, 2010, 2011, 2014, 2016, 2017 * the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the @@ -1288,7 +1288,7 @@ err: || c == ',' || c == '=') return *lexptr++; - if (c != '_' && ! is_alpha(c)) { + if (! is_letter(c)) { yyerror(_("invalid character")); return '\n'; } @@ -35,18 +35,6 @@ extern SRCFILE *srcfiles; #include <dlfcn.h> -/* - * is_letter --- function to check letters - * isalpha() isn't good enough since it can look at the locale. - * Underscore counts as a letter in awk identifiers - */ - -static bool -is_letter(unsigned char c) -{ - return (is_alpha(c) || c == '_'); -} - #define INIT_FUNC "dl_load" /* load_ext --- load an external library */ @@ -89,6 +77,25 @@ load_ext(const char *lib_name) lib_name, INIT_FUNC); } +/* is_valid_identifier --- return true if name is a valid simple identifier */ + +static bool +is_valid_identifier(const char *name) +{ + const char *sp = name; + int c; + + if (! is_letter(*sp)) + return false; + + for (sp++; (c = *sp++) != '\0';) { + if (! is_identchar(c)) + return false; + } + + return true; +} + /* make_builtin --- register name to be called as func with a builtin body */ awk_bool_t @@ -96,23 +103,15 @@ make_builtin(const awk_ext_func_t *funcinfo) { NODE *symbol, *f; INSTRUCTION *b; - const char *sp; - char c; const char *name = funcinfo->name; int count = funcinfo->max_expected_args; - sp = name; - if (sp == NULL || *sp == '\0') + if (name == NULL || *name == '\0') fatal(_("make_builtin: missing function name")); - if (! is_letter(*sp)) + if (! is_valid_identifier(name)) return awk_false; - for (sp++; (c = *sp++) != '\0';) { - if (! is_identchar(c)) - return awk_false; - } - f = lookup(name); if (f != NULL) { @@ -1125,7 +1125,7 @@ arg_assign(char *arg, bool initing) /* first check that the variable name has valid syntax */ badvar = false; - if (! is_alpha((unsigned char) arg[0]) && arg[0] != '_') + if (! is_letter((unsigned char) arg[0])) badvar = true; else for (cp2 = arg+1; *cp2; cp2++) |