aboutsummaryrefslogtreecommitdiffstats
path: root/ext.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-07-11 08:17:14 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-07-11 08:17:14 +0300
commit9e419cfbc401e9b9fd45c8e854fdf5ae799261d5 (patch)
treed73a710963075881315d841dd41dc01ed43a20dd /ext.c
parentc8b9f5d5ac4e23a394dc79eccbfb824ddee531ef (diff)
downloadegawk-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.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/ext.c b/ext.c
index 609b3b2b..a2225d14 100644
--- a/ext.c
+++ b/ext.c
@@ -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) {