aboutsummaryrefslogtreecommitdiff
path: root/src/symtab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/symtab.c')
-rw-r--r--src/symtab.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/symtab.c b/src/symtab.c
index c9c31194..cab45cc6 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -1,5 +1,5 @@
/* This file is part of mailfromd.
- Copyright (C) 2006, 2007 Sergey Poznyakoff
+ Copyright (C) 2006, 2007, 2008 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -172,7 +172,8 @@ static struct symtab *
lookup_or_install(int state, const char *name, int install)
{
unsigned i, pos;
-
+ struct symtab *foundp = NULL;
+
if (!symtable) {
if (install) {
if (rehash())
@@ -187,13 +188,21 @@ lookup_or_install(int state, const char *name, int install)
if ((state == SYM_UNDEF || symtable[i].state == state)
&& strcmp(symtable[i].vp->name, name) == 0)
return &symtable[i];
+ else if ((state & SYM_BITS)
+ && (SYM_MASK(symtable[i].state) & state)
+ && strcmp(symtable[i].vp->name, name) == 0)
+ foundp = &symtable[i];
+
if (++i >= hash_size[hash_num])
i = 0;
if (i == pos)
break;
}
+
+ if ((state & SYM_BITS) && foundp)
+ return foundp;
- if (!install || state == SYM_UNDEF)
+ if (!install || (state == SYM_UNDEF || (state & SYM_BITS)))
return NULL;
if (symtable[i].state == SYM_UNDEF) {
@@ -398,6 +407,18 @@ variable_lookup(const char *name)
return sp ? &sp->vp->variable : NULL;
}
+int
+variable_or_constant_lookup(const char *name, void **dptr)
+{
+ struct symtab *sp = lookup_or_install(
+ SYM_BITS|SYM_MASK(SYM_VARIABLE)|SYM_MASK(SYM_CONSTANT),
+ name, 0);
+ if (!sp)
+ return SYM_UNDEF;
+ *dptr = sp->vp;
+ return sp->state;
+}
+
struct function *
function_install(const char *name, size_t parmcnt, size_t optcnt,
@@ -467,11 +488,18 @@ define_constant(const char *name, struct value *value, struct locus *locus)
sp->vp->constant.value = *value;
}
-struct value *
+const struct constant *
constant_lookup(const char *name)
{
struct symtab *sp = lookup_or_install(SYM_CONSTANT, name, 0);
- return sp ? &sp->vp->constant.value : NULL;
+ return sp ? &sp->vp->constant : NULL;
+}
+
+const struct value *
+constant_lookup_value(const char *name)
+{
+ const struct constant *cptr = constant_lookup(name);
+ return cptr ? &cptr->value : NULL;
}

Return to:

Send suggestions and report system problems to the System administrator.