version 1.38, 2000/06/23 16:27:29 |
version 1.39, 2000/07/17 22:55:12 |
|
|
GSymT *VAR_CMD; /* variables defined on the command-line */ |
GSymT *VAR_CMD; /* variables defined on the command-line */ |
static GSymT *VAR_ENV; /* variables read from env */ |
static GSymT *VAR_ENV; /* variables read from env */ |
|
|
#define FIND_CMD 0x1 /* look in VAR_CMD when searching */ |
#define FIND_MINE 0x1 /* look in CTXT_CMD and CTXT_GLOBAL */ |
#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */ |
#define FIND_ENV 0x2 /* look in the environment */ |
#define FIND_ENV 0x4 /* look in the environment also */ |
|
|
|
typedef struct Var_ { |
typedef struct Var_ { |
BUFFER val; /* its value */ |
BUFFER val; /* its value */ |
|
|
static int quick_lookup __P((const char *, const char **, u_int32_t *)); |
static int quick_lookup __P((const char *, const char **, u_int32_t *)); |
#define VarValue(v) Buf_Retrieve(&((v)->val)) |
#define VarValue(v) Buf_Retrieve(&((v)->val)) |
static int VarCmp __P((void *, void *)); |
static int VarCmp __P((void *, void *)); |
static Var *VarFind __P((char *, SymTable *, int)); |
static Var *varfind __P((const char *, const char *, SymTable *, int, int, u_int32_t)); |
static Var *VarAdd __P((char *, char *, GSymT *)); |
static Var *VarFind_interval __P((const char *, const char *, SymTable *, int)); |
|
#define VarFind(n, ctxt, flags) VarFind_interval(n, NULL, ctxt, flags) |
|
static Var *VarAdd __P((const char *, const char *, GSymT *)); |
static void VarDelete __P((void *)); |
static void VarDelete __P((void *)); |
static Boolean VarHead __P((char *, Boolean, Buffer, void *)); |
static Boolean VarHead __P((char *, Boolean, Buffer, void *)); |
static Boolean VarTail __P((char *, Boolean, Buffer, void *)); |
static Boolean VarTail __P((char *, Boolean, Buffer, void *)); |
|
|
static Boolean VarUppercase __P((char *, Boolean, Buffer, void *)); |
static Boolean VarUppercase __P((char *, Boolean, Buffer, void *)); |
static Boolean VarLowercase __P((char *, Boolean, Buffer, void *)); |
static Boolean VarLowercase __P((char *, Boolean, Buffer, void *)); |
static const char *context_name __P((GSymT *)); |
static const char *context_name __P((GSymT *)); |
static Var *new_var __P((char *, char *)); |
static Var *new_var __P((const char *, const char *)); |
static Var *getvar __P((GSymT *, char *, const char *, u_int32_t)); |
static Var *getvar __P((GSymT *, const char *, const char *, u_int32_t)); |
|
|
void |
void |
SymTable_Init(ctxt) |
SymTable_Init(ctxt) |
|
|
/* Create a variable, to pass to VarAdd. */ |
/* Create a variable, to pass to VarAdd. */ |
static Var * |
static Var * |
new_var(name, val) |
new_var(name, val) |
char *name; |
const char *name; |
char *val; |
const char *val; |
{ |
{ |
Var *v; |
Var *v; |
const char *end = NULL; |
const char *end = NULL; |
|
|
static Var * |
static Var * |
getvar(ctxt, name, end, k) |
getvar(ctxt, name, end, k) |
GSymT *ctxt; |
GSymT *ctxt; |
char *name; |
const char *name; |
const char *end; |
const char *end; |
u_int32_t k; |
u_int32_t k; |
{ |
{ |
|
|
|
|
/*- |
/*- |
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
* VarFind -- |
* VarFind_interval -- |
* Find the given variable in the given context and any other contexts |
* Find the given variable in the given context and any other contexts |
* indicated. |
* indicated. if end is NULL, name is a string, otherwise, only |
|
* the interval name - end is concerned. |
* |
* |
* Results: |
* Results: |
* A pointer to the structure describing the desired variable or |
* A pointer to the structure describing the desired variable or |
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Var * |
static Var * |
VarFind(name, ctxt, flags) |
VarFind_interval(name, end, ctxt, flags) |
char *name; /* name to find */ |
const char *name; /* name to find */ |
|
const char *end; /* end of name */ |
SymTable *ctxt; /* context in which to find it */ |
SymTable *ctxt; /* context in which to find it */ |
int flags; /* FIND_GLOBAL set means to look in the |
int flags; /* FIND_MINE set means to look in the |
* VAR_GLOBAL context as well. |
* CTXT_GLOBAL and CTXT_CMD contexts also. |
* FIND_CMD set means to look in the VAR_CMD |
|
* context also. |
|
* FIND_ENV set means to look in the |
* FIND_ENV set means to look in the |
* environment/VAR_ENV context. */ |
* environment */ |
{ |
{ |
Var *v; |
|
const char *end = NULL; |
|
int idx; |
int idx; |
u_int32_t k; |
u_int32_t k; |
|
|
idx = quick_lookup(name, &end, &k); |
idx = quick_lookup(name, &end, &k); |
|
return varfind(name, end, ctxt, flags, idx, k); |
|
} |
|
|
|
static Var * |
|
varfind(name, end, ctxt, flags, idx, k) |
|
const char *name; |
|
const char *end; |
|
SymTable *ctxt; |
|
int flags; |
|
int idx; |
|
u_int32_t k; |
|
{ |
|
Var *v; |
|
|
/* |
/* |
* First look for the variable in the given context. If it's not there, |
* First look for the variable in the given context. If it's not there, |
* look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, |
* look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, |
|
|
if (v != NULL) |
if (v != NULL) |
return v; |
return v; |
|
|
if ((flags & FIND_CMD) && ctxt != CTXT_CMD) |
if ((flags & FIND_MINE) && ctxt != CTXT_CMD) |
v = getvar(VAR_CMD, name, end, k); |
v = getvar(VAR_CMD, name, end, k); |
if (v != NULL) |
if (v != NULL) |
return v; |
return v; |
|
|
if (!checkEnvFirst && (flags & FIND_GLOBAL) && ctxt != CTXT_GLOBAL) |
if (!checkEnvFirst && (flags & FIND_MINE) && ctxt != CTXT_GLOBAL) |
v = getvar(VAR_GLOBAL, name, end, k); |
v = getvar(VAR_GLOBAL, name, end, k); |
if (v != NULL) |
if (v != NULL) |
return v; |
return v; |
|
|
return VarAdd(name, env, VAR_ENV); |
return VarAdd(name, env, VAR_ENV); |
} |
} |
|
|
if (checkEnvFirst && (flags & FIND_GLOBAL) && ctxt != CTXT_GLOBAL) |
if (checkEnvFirst && (flags & FIND_MINE) && ctxt != CTXT_GLOBAL) |
v = getvar(VAR_GLOBAL, name, end, k); |
v = getvar(VAR_GLOBAL, name, end, k); |
return v; |
return v; |
} |
} |
|
|
*/ |
*/ |
static Var * |
static Var * |
VarAdd(name, val, ctxt) |
VarAdd(name, val, ctxt) |
char *name; /* name of variable to add */ |
const char *name; /* name of variable to add */ |
char *val; /* value to set it to */ |
const char *val; /* value to set it to */ |
GSymT *ctxt; /* context in which to set it */ |
GSymT *ctxt; /* context in which to set it */ |
{ |
{ |
Var *v; |
Var *v; |
|
|
{ |
{ |
Var *v; |
Var *v; |
|
|
v = VarFind(name, (SymTable *)ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV); |
v = VarFind(name, (SymTable *)ctxt, FIND_MINE|FIND_ENV); |
|
|
if (v == NULL) |
if (v == NULL) |
return FALSE; |
return FALSE; |
|
|
{ |
{ |
Var *v; |
Var *v; |
|
|
v = VarFind(name, (SymTable *)ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); |
v = VarFind(name, (SymTable *)ctxt, FIND_ENV | FIND_MINE); |
if (v != NULL) |
if (v != NULL) |
return VarValue(v); |
return VarValue(v); |
else |
else |
|
|
* We just need to check for the first character and return the |
* We just need to check for the first character and return the |
* value if it exists. |
* value if it exists. |
*/ |
*/ |
char name[2]; |
v = VarFind_interval(str+1, str+2, ctxt, FIND_ENV | FIND_MINE); |
|
|
name[0] = str[1]; |
|
name[1] = '\0'; |
|
|
|
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); |
|
if (v == NULL) { |
if (v == NULL) { |
*lengthPtr = 2; |
*lengthPtr = 2; |
|
|
|
|
} |
} |
*tstr = '\0'; |
*tstr = '\0'; |
|
|
v = VarFind (str + 2, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); |
v = VarFind_interval(str + 2, tstr, ctxt, FIND_ENV | FIND_MINE); |
if (v == NULL && ctxt != CTXT_CMD && ctxt != CTXT_GLOBAL && |
if (v == NULL && ctxt != CTXT_CMD && ctxt != CTXT_GLOBAL && |
ctxt != NULL && |
ctxt != NULL && |
(tstr-str) == 4 && (str[3] == 'F' || str[3] == 'D')) |
(tstr-str) == 4 && (str[3] == 'F' || str[3] == 'D')) |
|
|
case '>': |
case '>': |
case '<': |
case '<': |
{ |
{ |
char vname[2]; |
|
char *val; |
char *val; |
|
|
/* |
/* Well, it's local -- go look for it. */ |
* Well, it's local -- go look for it. |
v = VarFind_interval(str+2, str+3, ctxt, 0); |
*/ |
|
vname[0] = str[2]; |
|
vname[1] = '\0'; |
|
v = VarFind(vname, ctxt, 0); |
|
|
|
if (v != NULL) { |
if (v != NULL) { |
/* |
/* |