diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-07-11 08:17:14 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-07-11 08:17:14 +0300 |
commit | 9e419cfbc401e9b9fd45c8e854fdf5ae799261d5 (patch) | |
tree | d73a710963075881315d841dd41dc01ed43a20dd /ext.c | |
parent | c8b9f5d5ac4e23a394dc79eccbfb824ddee531ef (diff) | |
download | egawk-9e419cfbc401e9b9fd45c8e854fdf5ae799261d5.tar.gz egawk-9e419cfbc401e9b9fd45c8e854fdf5ae799261d5.tar.bz2 egawk-9e419cfbc401e9b9fd45c8e854fdf5ae799261d5.zip |
Some cleanup about checking letters and identifiers.
Diffstat (limited to 'ext.c')
-rw-r--r-- | ext.c | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -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) { |