summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-06-23 16:20:02 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-06-23 16:20:02 +0000
commit9dec3f73c83665e70d33f9ae6b9638739eea07ce (patch)
treef72f0893d30167b21a6df37d6f88637add64d50a /usr.bin
parentdec90b2d5ea86b10e997457c6dca338aba4d1cc7 (diff)
Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *' in prevision of things to come. Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL, VAR_ENV, which become simple Lsts... This is not a problem, except when getting to a context's name for debugging (handled very nicely by offsetof). Again, this is a preparatory patch, which does not gain anything except for cleaning up issues... Reviewed by millert@ and miod@, like the previous patch
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/arch.c8
-rw-r--r--usr.bin/make/compat.c10
-rw-r--r--usr.bin/make/extern.h25
-rw-r--r--usr.bin/make/job.c8
-rw-r--r--usr.bin/make/make.h10
-rw-r--r--usr.bin/make/parse.c6
-rw-r--r--usr.bin/make/suff.c12
-rw-r--r--usr.bin/make/targ.c8
-rw-r--r--usr.bin/make/var.c124
9 files changed, 120 insertions, 91 deletions
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c
index 045d20d979b..ab5eb6971ce 100644
--- a/usr.bin/make/arch.c
+++ b/usr.bin/make/arch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arch.c,v 1.30 2000/06/23 16:18:08 espie Exp $ */
+/* $OpenBSD: arch.c,v 1.31 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
#else
-static char rcsid[] = "$OpenBSD: arch.c,v 1.30 2000/06/23 16:18:08 espie Exp $";
+static char rcsid[] = "$OpenBSD: arch.c,v 1.31 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -197,10 +197,10 @@ ArchFree(ap)
*-----------------------------------------------------------------------
*/
ReturnStatus
-Arch_ParseArchive (linePtr, nodeLst, ctxt)
+Arch_ParseArchive(linePtr, nodeLst, ctxt)
char **linePtr; /* Pointer to start of specification */
Lst nodeLst; /* Lst on which to place the nodes */
- GNode *ctxt; /* Context in which to expand variables */
+ SymTable *ctxt; /* Context in which to expand variables */
{
register char *cp; /* Pointer into line */
GNode *gn; /* New node */
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c
index 1515c3d59e7..c90ca26cca7 100644
--- a/usr.bin/make/compat.c
+++ b/usr.bin/make/compat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compat.c,v 1.29 2000/06/23 16:18:08 espie Exp $ */
+/* $OpenBSD: compat.c,v 1.30 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: compat.c,v 1.29 2000/06/23 16:18:08 espie Exp $";
+static char rcsid[] = "$OpenBSD: compat.c,v 1.30 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -233,7 +233,7 @@ CompatRunCommand (cmdp, gnp)
errCheck = !(gn->type & OP_IGNORE);
cmdNode = Lst_Member(&gn->commands, cmd);
- cmdStart = Var_Subst(cmd, gn, FALSE);
+ cmdStart = Var_Subst(cmd, &gn->context, FALSE);
/*
* brk_string will return an argv with a NULL in av[0], thus causing
@@ -601,11 +601,11 @@ CompatMake(gnp, pgnp)
} else {
if (gn->lineno)
printf("\n\nStop in %s (line %lu of %s).\n",
- Var_Value(".CURDIR", gn),
+ Var_Value(".CURDIR", &gn->context),
(unsigned long)gn->lineno,
gn->fname);
else
- printf("\n\nStop in %s.\n", Var_Value(".CURDIR", gn));
+ printf("\n\nStop in %s.\n", Var_Value(".CURDIR", &gn->context));
exit (1);
}
} else if (gn->made == ERROR) {
diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h
index c70ca7435fa..3f041ff215c 100644
--- a/usr.bin/make/extern.h
+++ b/usr.bin/make/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.24 2000/06/23 16:18:09 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.25 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -42,7 +42,7 @@
*/
/* arch.c */
-ReturnStatus Arch_ParseArchive __P((char **, Lst, GNode *));
+ReturnStatus Arch_ParseArchive __P((char **, Lst, SymTable *));
void Arch_Touch __P((GNode *));
void Arch_TouchLib __P((GNode *));
Boolean Arch_MTime __P((GNode *));
@@ -90,7 +90,7 @@ Boolean Make_Run __P((Lst));
void Parse_Error __P((int, char *, ...));
Boolean Parse_AnyExport __P((void));
Boolean Parse_IsVar __P((char *));
-void Parse_DoVar __P((char *, GNode *));
+void Parse_DoVar __P((char *, SymTable *));
void Parse_AddIncludeDir __P((char *));
void Parse_File __P((char *, FILE *));
void Parse_Init __P((void));
@@ -142,20 +142,21 @@ void Targ_PrintType __P((int));
void Targ_PrintGraph __P((int));
/* var.c */
-void Var_Delete __P((char *, GNode *));
-void Var_Set __P((char *, char *, GNode *));
+void Var_Delete __P((char *, SymTable *));
+void Var_Set __P((char *, char *, SymTable *));
void Varq_Set __P((int, char *, GNode *));
-void Var_Append __P((char *, char *, GNode *));
+void Var_Append __P((char *, char *, SymTable *));
void Varq_Append __P((int, char *, GNode *));
-Boolean Var_Exists __P((char *, GNode *));
+Boolean Var_Exists __P((char *, SymTable *));
Boolean Varq_Exists __P((int, GNode *));
-char *Var_Value __P((char *, GNode *));
+char *Var_Value __P((char *, SymTable *));
char *Varq_Value __P((int, GNode *));
-char *Var_Parse __P((char *, GNode *, Boolean, size_t *, Boolean *));
-char *Var_Subst __P((char *, GNode *, Boolean));
-void Var_SubstVar __P((Buffer, char *, const char *, GNode *));
+char *Var_Parse __P((char *, SymTable *, Boolean, size_t *, Boolean *));
+char *Var_Subst __P((char *, SymTable *, Boolean));
+void Var_SubstVar __P((Buffer, char *, const char *, SymTable *));
char *Var_GetTail __P((char *));
char *Var_GetHead __P((char *));
void Var_Init __P((void));
void Var_End __P((void));
-void Var_Dump __P((GNode *));
+void Var_Dump __P((SymTable *));
+void SymTable_Init __P((SymTable *));
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 32f78d14495..534176c84a2 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.31 2000/06/23 16:18:09 espie Exp $ */
+/* $OpenBSD: job.c,v 1.32 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: job.c,v 1.31 2000/06/23 16:18:09 espie Exp $";
+static char rcsid[] = "$OpenBSD: job.c,v 1.32 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -551,7 +551,7 @@ JobPrintCommand(cmdp, jobp)
* the variables in the command.
*/
cmdNode = Lst_Member(&job->node->commands, cmd);
- cmdStart = cmd = Var_Subst(cmd, job->node, FALSE);
+ cmdStart = cmd = Var_Subst(cmd, &job->node->context, FALSE);
Lst_Replace(cmdNode, cmdStart);
cmdTemplate = "%s\n";
@@ -670,7 +670,7 @@ JobSaveCommand(cmd, gn)
{
char *result;
- result = Var_Subst((char *)cmd, (GNode *)gn, FALSE);
+ result = Var_Subst((char *)cmd, &((GNode *)gn)->context, FALSE);
Lst_AtEnd(&postCommands->commands, result);
}
diff --git a/usr.bin/make/make.h b/usr.bin/make/make.h
index fa92abfc339..2383cd6db80 100644
--- a/usr.bin/make/make.h
+++ b/usr.bin/make/make.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: make.h,v 1.21 2000/06/23 16:18:09 espie Exp $ */
+/* $OpenBSD: make.h,v 1.22 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: make.h,v 1.15 1997/03/10 21:20:00 christos Exp $ */
/*
@@ -122,6 +122,8 @@
* 17) a Lst of strings that are commands to be given to a shell
* to create this target.
*/
+typedef LIST SymTable;
+
typedef struct GNode {
char *name; /* The target's name */
char *path; /* The full pathname of the file */
@@ -168,7 +170,7 @@ typedef struct GNode {
LIST successors; /* Nodes that must be made after this one */
LIST preds; /* Nodes that must be made before this one */
- LIST context; /* The local variables */
+ SymTable context; /* The local variables */
unsigned long lineno; /* First line number of commands. */
const char * fname; /* File name of commands. */
LIST commands; /* Creation commands */
@@ -343,9 +345,9 @@ extern Boolean checkEnvFirst; /* TRUE if environment should be searched for
extern GNode *DEFAULT; /* .DEFAULT rule */
-extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g
+extern SymTable *VAR_GLOBAL; /* Variables defined in a global context, e.g
* in the Makefile itself */
-extern GNode *VAR_CMD; /* Variables defined on the command line */
+extern SymTable *VAR_CMD; /* Variables defined on the command line */
extern char var_Error[]; /* Value returned by Var_Parse when an error
* is encountered. It actually points to
* an empty string, so naive callers needn't
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 469d2d9bbad..eed3277a5d4 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.46 2000/06/23 16:15:50 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.47 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: parse.c,v 1.46 2000/06/23 16:15:50 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.47 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -1407,7 +1407,7 @@ void
Parse_DoVar (line, ctxt)
char *line; /* a line guaranteed to be a variable
* assignment. This reduces error checks */
- GNode *ctxt; /* Context in which to do the assignment */
+ SymTable *ctxt; /* Context in which to do the assignment */
{
char *cp; /* pointer into line */
enum {
diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c
index bc75abc23f6..b642ac3c367 100644
--- a/usr.bin/make/suff.c
+++ b/usr.bin/make/suff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: suff.c,v 1.32 2000/06/23 16:18:09 espie Exp $ */
+/* $OpenBSD: suff.c,v 1.33 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
-static char rcsid[] = "$OpenBSD: suff.c,v 1.32 2000/06/23 16:18:09 espie Exp $";
+static char rcsid[] = "$OpenBSD: suff.c,v 1.33 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -1293,7 +1293,7 @@ SuffExpandChildren(cgnp, pgnp)
if (strchr(cgn->name, '$') != NULL) {
if (DEBUG(SUFF))
printf("Expanding \"%s\"...", cgn->name);
- cp = Var_Subst(cgn->name, pgn, TRUE);
+ cp = Var_Subst(cgn->name, &pgn->context, TRUE);
if (cp != NULL) {
LIST members;
@@ -1307,7 +1307,7 @@ SuffExpandChildren(cgnp, pgnp)
*/
char *sacrifice = cp;
- (void)Arch_ParseArchive(&sacrifice, &members, pgn);
+ (void)Arch_ParseArchive(&sacrifice, &members, &pgn->context);
} else {
/*
* Break the result into a vector of strings whose nodes
@@ -1347,7 +1347,7 @@ SuffExpandChildren(cgnp, pgnp)
size_t len;
Boolean doFree;
- junk = Var_Parse(cp, pgn, TRUE, &len, &doFree);
+ junk = Var_Parse(cp, &pgn->context, TRUE, &len, &doFree);
if (junk != var_Error)
cp += len - 1;
@@ -1640,7 +1640,7 @@ SuffFindArchiveDeps(gn, slst)
* Copy in the variables from the member node to this one.
*/
for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
- Var_Set(copy[i], Var_Value(copy[i], mem), gn);
+ Var_Set(copy[i], Var_Value(copy[i], &mem->context), &gn->context);
}
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index ad7bb023f32..21dd8fc0c77 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: targ.c,v 1.22 2000/06/23 16:15:50 espie Exp $ */
+/* $OpenBSD: targ.c,v 1.23 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */
/*
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
-static char *rcsid = "$OpenBSD: targ.c,v 1.22 2000/06/23 16:15:50 espie Exp $";
+static char *rcsid = "$OpenBSD: targ.c,v 1.23 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -617,9 +617,9 @@ Targ_PrintGraph (pass)
printf("#\n# Files that are only sources:\n");
Lst_Every(&allTargets, TargPrintOnlySrc);
printf("#*** Global Variables:\n");
- Var_Dump (VAR_GLOBAL);
+ Var_Dump(VAR_GLOBAL);
printf("#*** Command-line Variables:\n");
- Var_Dump (VAR_CMD);
+ Var_Dump(VAR_CMD);
printf("\n");
Dir_PrintDirectories();
printf("\n");
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 5042e22224c..a81660b71eb 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.34 2000/06/23 16:18:09 espie Exp $ */
+/* $OpenBSD: var.c,v 1.35 2000/06/23 16:20:01 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: var.c,v 1.34 2000/06/23 16:18:09 espie Exp $";
+static char rcsid[] = "$OpenBSD: var.c,v 1.35 2000/06/23 16:20:01 espie Exp $";
#endif
#endif /* not lint */
@@ -122,6 +122,7 @@ static char rcsid[] = "$OpenBSD: var.c,v 1.34 2000/06/23 16:18:09 espie Exp $";
#include <regex.h>
#endif
#include <stdlib.h>
+#include <stddef.h>
#include "make.h"
#include "buf.h"
@@ -143,7 +144,7 @@ Varq_Set(idx, val, gn)
char *val;
GNode *gn;
{
- Var_Set(varnames[idx], val, gn);
+ Var_Set(varnames[idx], val, &gn->context);
}
void
@@ -152,7 +153,7 @@ Varq_Append(idx, val, gn)
char *val;
GNode *gn;
{
- Var_Append(varnames[idx], val, gn);
+ Var_Append(varnames[idx], val, &gn->context);
}
char *
@@ -160,7 +161,7 @@ Varq_Value(idx, gn)
int idx;
GNode *gn;
{
- return Var_Value(varnames[idx], gn);
+ return Var_Value(varnames[idx], &gn->context);
}
Boolean
@@ -168,7 +169,7 @@ Varq_Exists(idx, gn)
int idx;
GNode *gn;
{
- return Var_Exists(varnames[idx], gn);
+ return Var_Exists(varnames[idx], &gn->context);
}
/*
@@ -201,9 +202,9 @@ static char varNoError[] = "";
* The four contexts are searched in the reverse order from which they are
* listed.
*/
-GNode *VAR_GLOBAL; /* variables from the makefile */
-GNode *VAR_CMD; /* variables defined on the command-line */
-static GNode *VAR_ENV; /* variables read from env */
+SymTable *VAR_GLOBAL; /* variables from the makefile */
+SymTable *VAR_CMD; /* variables defined on the command-line */
+static SymTable *VAR_ENV; /* variables read from env */
static LIST allVars; /* List of all variables */
@@ -250,8 +251,8 @@ typedef struct {
#define VarValue(v) Buf_Retrieve(&((v)->val))
static int VarCmp __P((void *, void *));
-static Var *VarFind __P((char *, GNode *, int));
-static Var *VarAdd __P((char *, char *, GNode *));
+static Var *VarFind __P((char *, SymTable *, int));
+static Var *VarAdd __P((char *, char *, SymTable *));
static void VarDelete __P((void *));
static Boolean VarHead __P((char *, Boolean, Buffer, void *));
static Boolean VarTail __P((char *, Boolean, Buffer, void *));
@@ -267,14 +268,34 @@ static void VarREError __P((int, regex_t *, const char *));
static Boolean VarRESubstitute __P((char *, Boolean, Buffer, void *));
#endif
static Boolean VarSubstitute __P((char *, Boolean, Buffer, void *));
-static char *VarGetPattern __P((GNode *, int, char **, int, int *, size_t *,
+static char *VarGetPattern __P((SymTable *, int, char **, int, int *, size_t *,
VarPattern *));
static char *VarQuote __P((char *));
static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer, void *), void *));
static void VarPrintVar __P((void *));
static Boolean VarUppercase __P((char *word, Boolean addSpace, Buffer buf, void *dummy));
static Boolean VarLowercase __P((char *word, Boolean addSpace, Buffer buf, void *dummy));
+static char *context_name __P((SymTable *));
+
+static char *
+context_name(ctxt)
+ SymTable *ctxt;
+{
+ GNode *g;
+
+ /* specific handling for GLOBAL, CMD, ENV contexts, which are not
+ owned by a GNode */
+ if (ctxt == VAR_GLOBAL)
+ return "Global";
+ if (ctxt == VAR_CMD)
+ return "Command";
+ if (ctxt == VAR_ENV)
+ return "Environment";
+ g = (GNode *)((char *)ctxt - offsetof(GNode, context));
+ return g->name;
+}
+
/*-
*-----------------------------------------------------------------------
* VarCmp --
@@ -311,9 +332,9 @@ VarCmp(v, name)
*-----------------------------------------------------------------------
*/
static Var *
-VarFind (name, ctxt, flags)
+VarFind(name, ctxt, flags)
char *name; /* name to find */
- GNode *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
* VAR_GLOBAL context as well.
* FIND_CMD set means to look in the VAR_CMD
@@ -364,16 +385,16 @@ VarFind (name, ctxt, flags)
* look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order,
* depending on the FIND_* flags in 'flags'
*/
- var = Lst_Find(&ctxt->context, VarCmp, name);
+ var = Lst_Find(ctxt, VarCmp, name);
if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD))
- var = Lst_Find(&VAR_CMD->context, VarCmp, name);
+ var = Lst_Find(VAR_CMD, VarCmp, name);
if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) &&
(ctxt != VAR_GLOBAL)) {
- var = Lst_Find(&VAR_GLOBAL->context, VarCmp, name);
+ var = Lst_Find(VAR_GLOBAL, VarCmp, name);
}
if ((var == NULL) && (flags & FIND_ENV)) {
- var = Lst_Find(&VAR_ENV->context, VarCmp, name);
+ var = Lst_Find(VAR_ENV, VarCmp, name);
if (var == NULL) {
char *env;
@@ -383,7 +404,7 @@ VarFind (name, ctxt, flags)
}
if (var == NULL && checkEnvFirst && (flags & FIND_GLOBAL) &&
(ctxt != VAR_GLOBAL))
- var = Lst_Find(&VAR_GLOBAL->context, VarCmp, name);
+ var = Lst_Find(VAR_GLOBAL, VarCmp, name);
if (var == NULL)
return NULL;
else
@@ -408,14 +429,14 @@ static Var *
VarAdd(name, val, ctxt)
char *name; /* name of variable to add */
char *val; /* value to set it to */
- GNode *ctxt; /* context in which to set it */
+ SymTable *ctxt; /* context in which to set it */
{
register Var *v;
int len;
- v = (Var *) emalloc (sizeof (Var));
+ v = (Var *) emalloc(sizeof(Var));
- v->name = estrdup (name);
+ v->name = estrdup(name);
len = val ? strlen(val) : 0;
Buf_Init(&(v->val), len+1);
@@ -423,10 +444,10 @@ VarAdd(name, val, ctxt)
v->flags = 0;
- Lst_AtFront(&ctxt->context, v);
+ Lst_AtFront(ctxt, v);
Lst_AtEnd(&allVars, v);
if (DEBUG(VAR)) {
- printf("%s:%s = %s\n", ctxt->name, name, val);
+ printf("%s:%s = %s\n", context_name(ctxt), name, val);
}
return v;
}
@@ -472,19 +493,19 @@ VarDelete(vp)
void
Var_Delete(name, ctxt)
char *name;
- GNode *ctxt;
+ SymTable *ctxt;
{
LstNode ln;
if (DEBUG(VAR)) {
- printf("%s:delete %s\n", ctxt->name, name);
+ printf("%s:delete %s\n", context_name(ctxt), name);
}
- ln = Lst_Find(&ctxt->context, VarCmp, name);
+ ln = Lst_Find(ctxt, VarCmp, name);
if (ln != NULL) {
register Var *v;
v = (Var *)Lst_Datum(ln);
- Lst_Remove(&ctxt->context, ln);
+ Lst_Remove(ctxt, ln);
ln = Lst_Member(&allVars, v);
Lst_Remove(&allVars, ln);
VarDelete(v);
@@ -513,10 +534,10 @@ Var_Delete(name, ctxt)
*-----------------------------------------------------------------------
*/
void
-Var_Set (name, val, ctxt)
+Var_Set(name, val, ctxt)
char *name; /* name of variable to set */
char *val; /* value to give to the variable */
- GNode *ctxt; /* context in which to set it */
+ SymTable *ctxt; /* context in which to set it */
{
register Var *v;
@@ -525,7 +546,7 @@ Var_Set (name, val, ctxt)
* here will override anything in a lower context, so there's not much
* point in searching them all just to save a bit of memory...
*/
- v = VarFind (name, ctxt, 0);
+ v = VarFind(name, ctxt, 0);
if (v == NULL) {
(void)VarAdd(name, val, ctxt);
} else {
@@ -533,7 +554,7 @@ Var_Set (name, val, ctxt)
Buf_AddString(&(v->val), val);
if (DEBUG(VAR)) {
- printf("%s:%s = %s\n", ctxt->name, name, val);
+ printf("%s:%s = %s\n", context_name(ctxt), name, val);
}
}
/*
@@ -572,14 +593,14 @@ Var_Set (name, val, ctxt)
*-----------------------------------------------------------------------
*/
void
-Var_Append (name, val, ctxt)
+Var_Append(name, val, ctxt)
char *name; /* Name of variable to modify */
char *val; /* String to append to it */
- GNode *ctxt; /* Context in which this should occur */
+ SymTable *ctxt; /* Context in which this should occur */
{
register Var *v;
- v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
+ v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
if (v == NULL) {
(void)VarAdd(name, val, ctxt);
@@ -588,7 +609,7 @@ Var_Append (name, val, ctxt)
Buf_AddString(&(v->val), val);
if (DEBUG(VAR)) {
- printf("%s:%s = %s\n", ctxt->name, name, VarValue(v));
+ printf("%s:%s = %s\n", context_name(ctxt), name, VarValue(v));
}
}
@@ -610,7 +631,7 @@ Var_Append (name, val, ctxt)
Boolean
Var_Exists(name, ctxt)
char *name; /* Variable to find */
- GNode *ctxt; /* Context in which to start search */
+ SymTable *ctxt; /* Context in which to start search */
{
Var *v;
@@ -637,7 +658,7 @@ Var_Exists(name, ctxt)
char *
Var_Value(name, ctxt)
char *name; /* name to find */
- GNode *ctxt; /* context in which to search for it */
+ SymTable *ctxt; /* context in which to search for it */
{
Var *v;
@@ -1348,7 +1369,7 @@ VarModify (str, modProc, datum)
*/
static char *
VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
- GNode *ctxt;
+ SymTable *ctxt;
int err;
char **tstr;
int delim;
@@ -1476,9 +1497,9 @@ VarQuote(str)
*-----------------------------------------------------------------------
*/
char *
-Var_Parse (str, ctxt, err, lengthPtr, freePtr)
+Var_Parse(str, ctxt, err, lengthPtr, freePtr)
char *str; /* The string to parse */
- GNode *ctxt; /* The context for the variable */
+ SymTable *ctxt; /* The context for the variable */
Boolean err; /* TRUE if undefined variables are an error */
size_t *lengthPtr; /* OUT: The length of the specification */
Boolean *freePtr; /* OUT: TRUE if caller should free result */
@@ -2145,7 +2166,7 @@ cleanup:
char *
Var_Subst(str, ctxt, undefErr)
char *str; /* the string in which to substitute */
- GNode *ctxt; /* the context wherein to find variables */
+ SymTable *ctxt; /* the context wherein to find variables */
Boolean undefErr; /* TRUE if undefineds are an error */
{
BUFFER buf; /* Buffer for forming things */
@@ -2231,7 +2252,7 @@ Var_SubstVar(buf, str, var, ctxt)
Buffer buf; /* Where to store the result */
char *str; /* The string in which to substitute */
const char *var; /* Named variable */
- GNode *ctxt; /* The context wherein to find variables */
+ SymTable *ctxt; /* The context wherein to find variables */
{
char *val; /* Value substituted for a variable */
size_t length; /* Length of the variable invocation */
@@ -2355,9 +2376,14 @@ Var_GetHead(file)
void
Var_Init()
{
- VAR_GLOBAL = Targ_NewGN("Global");
- VAR_CMD = Targ_NewGN("Command");
- VAR_ENV = Targ_NewGN("Environment");
+ static SymTable global_vars, cmd_vars, env_vars;
+
+ VAR_GLOBAL = &global_vars;
+ VAR_CMD = &cmd_vars;
+ VAR_ENV = &env_vars;
+ Lst_Init(VAR_GLOBAL);
+ Lst_Init(VAR_CMD);
+ Lst_Init(VAR_ENV);
Lst_Init(&allVars);
}
@@ -2387,8 +2413,8 @@ VarPrintVar(vp)
*-----------------------------------------------------------------------
*/
void
-Var_Dump (ctxt)
- GNode *ctxt;
+Var_Dump(ctxt)
+ SymTable *ctxt;
{
- Lst_Every(&ctxt->context, VarPrintVar);
+ Lst_Every(ctxt, VarPrintVar);
}