summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>1999-11-11 11:42:20 +0000
committerMarc Espie <espie@cvs.openbsd.org>1999-11-11 11:42:20 +0000
commitcab6d5079d7fc44de8f9de73518101b11af6706e (patch)
treef57f06757f815e92d6b802506f3d8017fab4e7c3
parent43d7ae5708e1bec7e6339f73784b471d2d2c0215 (diff)
Communicate line numbers between parse.c and for.c.
Parse_String starts in the current line, but at a given line number. .for loops yield correct line numbers, much easier to debug !
-rw-r--r--usr.bin/make/extern.h5
-rw-r--r--usr.bin/make/for.c24
-rw-r--r--usr.bin/make/nonints.h5
-rw-r--r--usr.bin/make/parse.c26
4 files changed, 37 insertions, 23 deletions
diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h
index a4a0af111ea..b012b57fd6f 100644
--- a/usr.bin/make/extern.h
+++ b/usr.bin/make/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.9 1999/11/11 11:35:17 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.10 1999/11/11 11:42:19 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -100,8 +100,9 @@ void Parse_AddIncludeDir __P((char *));
void Parse_File __P((char *, FILE *));
void Parse_Init __P((void));
void Parse_End __P((void));
-void Parse_FromString __P((char *));
+void Parse_FromString __P((char *, unsigned long));
Lst Parse_MainName __P((void));
+unsigned long Parse_Getlineno __P((void));
/* str.c */
void str_init __P((void));
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c
index d90c0cf2561..eecfd7fe535 100644
--- a/usr.bin/make/for.c
+++ b/usr.bin/make/for.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: for.c,v 1.4 1998/12/05 00:06:27 espie Exp $ */
+/* $OpenBSD: for.c,v 1.5 1999/11/11 11:42:19 espie Exp $ */
/* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: for.c,v 1.4 1998/12/05 00:06:27 espie Exp $";
+static char rcsid[] = "$OpenBSD: for.c,v 1.5 1999/11/11 11:42:19 espie Exp $";
#endif
#endif /* not lint */
@@ -72,18 +72,20 @@ static char rcsid[] = "$OpenBSD: for.c,v 1.4 1998/12/05 00:06:27 espie Exp $";
* then we evaluate the for loop for each variable in the varlist.
*/
-static int forLevel = 0; /* Nesting level */
-static char *forVar; /* Iteration variable */
-static Buffer forBuf; /* Commands in loop */
-static Lst forLst; /* List of items */
+static int forLevel = 0; /* Nesting level */
+static char *forVar; /* Iteration variable */
+static Buffer forBuf; /* Commands in loop */
+static Lst forLst; /* List of items */
+static unsigned long forLineno; /* Line at beginning of loop */
/*
* State of a for loop.
*/
typedef struct _For {
- Buffer buf; /* Unexpanded buffer */
- char* var; /* Index name */
- Lst lst; /* List of variables */
+ Buffer buf; /* Unexpanded buffer */
+ char* var; /* Index name */
+ Lst lst; /* List of variables */
+ unsigned long lineno;
} For;
static int ForExec __P((ClientData, ClientData));
@@ -175,6 +177,7 @@ For_Eval (line)
* Make a list with the remaining words
*/
forLst = Lst_Init(FALSE);
+ forLineno = Parse_Getlineno();
buf = Buf_Init(0);
sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE);
@@ -264,7 +267,7 @@ ForExec(namep, argp)
if (DEBUG(FOR))
(void) fprintf(stderr, "--- %s = %s\n", arg->var, name);
Parse_FromString(Var_Subst(arg->var, (char *) Buf_GetAll(arg->buf, &len),
- VAR_GLOBAL, FALSE));
+ VAR_GLOBAL, FALSE), arg->lineno);
Var_Delete(arg->var, VAR_GLOBAL);
return 0;
@@ -294,6 +297,7 @@ For_Run()
arg.var = forVar;
arg.buf = forBuf;
arg.lst = forLst;
+ arg.lineno = forLineno;
forVar = NULL;
forBuf = NULL;
forLst = NULL;
diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h
index 5129247dc02..5d248d89ce8 100644
--- a/usr.bin/make/nonints.h
+++ b/usr.bin/make/nonints.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: nonints.h,v 1.9 1999/11/11 11:35:17 espie Exp $ */
+/* $OpenBSD: nonints.h,v 1.10 1999/11/11 11:42:19 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -100,8 +100,9 @@ void Parse_AddIncludeDir __P((char *));
void Parse_File __P((char *, FILE *));
void Parse_Init __P((void));
void Parse_End __P((void));
-void Parse_FromString __P((char *));
+void Parse_FromString __P((char *, unsigned long));
Lst Parse_MainName __P((void));
+unsigned long Parse_Getlineno __P((void));
/* str.c */
void str_init __P((void));
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index b606991f309..3731ba1a6d6 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.23 1999/11/11 11:40:09 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.24 1999/11/11 11:42:19 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.23 1999/11/11 11:40:09 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.24 1999/11/11 11:42:19 espie Exp $";
#endif
#endif /* not lint */
@@ -137,10 +137,10 @@ static GNode *mainNode; /* The main target to create. This is the
* Definitions for handling #include specifications
*/
typedef struct IFile {
- char *fname; /* name of previous file */
- unsigned long lineno; /* saved line number */
- FILE *F; /* the open stream */
- PTR *p; /* the char pointer */
+ char *fname; /* name of previous file */
+ unsigned long lineno; /* saved line number */
+ FILE *F; /* the open stream */
+ PTR *p; /* the char pointer */
} IFile;
static Lst includes; /* stack of IFiles generated by
@@ -1838,8 +1838,9 @@ ParseDoInclude (file)
*---------------------------------------------------------------------
*/
void
-Parse_FromString(str)
- char *str;
+Parse_FromString(str, newlineno)
+ char *str;
+ unsigned long newlineno;
{
IFile *oldFile; /* state associated with this file */
@@ -1857,7 +1858,7 @@ Parse_FromString(str)
curFILE = NULL;
curPTR = (PTR *) emalloc (sizeof (PTR));
curPTR->str = curPTR->ptr = str;
- lineno = 0;
+ lineno = newlineno;
fname = estrdup(fname);
}
@@ -2698,3 +2699,10 @@ Parse_MainName()
(void) Lst_AtEnd (listmain, (ClientData)mainNode);
return (listmain);
}
+
+unsigned long
+Parse_Getlineno()
+{
+ return lineno;
+}
+