Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
This commit is contained in:
parent
b3857f73f0
commit
26a8972fd7
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)arch.c 5.7 (Berkeley) 12/28/90";*/
|
||||
static char rcsid[] = "$Id: arch.c,v 1.6 1994/03/18 11:32:09 pk Exp $";
|
||||
static char rcsid[] = "$Id: arch.c,v 1.7 1994/06/06 22:45:17 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -85,6 +85,8 @@ static char rcsid[] = "$Id: arch.c,v 1.6 1994/03/18 11:32:09 pk Exp $";
|
||||
* is out-of-date.
|
||||
*
|
||||
* Arch_Init Initialize this module.
|
||||
*
|
||||
* Arch_End Cleanup this module.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -109,10 +111,45 @@ typedef struct Arch {
|
||||
* by <name, struct ar_hdr *> key/value pairs */
|
||||
} Arch;
|
||||
|
||||
static int ArchFindArchive __P((Arch *, char *));
|
||||
static int ArchFindArchive __P((ClientData, ClientData));
|
||||
static void ArchFree __P((ClientData));
|
||||
static struct ar_hdr *ArchStatMember __P((char *, char *, Boolean));
|
||||
static FILE *ArchFindMember __P((char *, char *, struct ar_hdr *, char *));
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* ArchFree --
|
||||
* Free memory used by an archive
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
*
|
||||
* Side Effects:
|
||||
* None.
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
ArchFree(ap)
|
||||
ClientData ap;
|
||||
{
|
||||
Arch *a = (Arch *) ap;
|
||||
Hash_Search search;
|
||||
Hash_Entry *entry;
|
||||
|
||||
/* Free memory from hash entries */
|
||||
for (entry = Hash_EnumFirst(&a->members, &search);
|
||||
entry != (Hash_Entry *)NULL;
|
||||
entry = Hash_EnumNext(&search))
|
||||
free((Address) Hash_GetValue (entry));
|
||||
|
||||
free(a->name);
|
||||
Hash_DeleteTable(&a->members);
|
||||
free((Address) a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Arch_ParseArchive --
|
||||
@ -378,10 +415,10 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
|
||||
*/
|
||||
static int
|
||||
ArchFindArchive (ar, archName)
|
||||
Arch *ar; /* Current list element */
|
||||
char *archName; /* Name we want */
|
||||
ClientData ar; /* Current list element */
|
||||
ClientData archName; /* Name we want */
|
||||
{
|
||||
return (strcmp (archName, ar->name));
|
||||
return (strcmp ((char *) archName, ((Arch *) ar)->name));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -547,8 +584,7 @@ ArchStatMember (archive, member, hash)
|
||||
}
|
||||
#endif
|
||||
|
||||
he = Hash_CreateEntry (&ar->members, strdup (memName),
|
||||
(Boolean *)NULL);
|
||||
he = Hash_CreateEntry (&ar->members, memName, (Boolean *)NULL);
|
||||
Hash_SetValue (he, (ClientData)emalloc (sizeof (struct ar_hdr)));
|
||||
memcpy ((Address)Hash_GetValue (he), (Address)&arh,
|
||||
sizeof (struct ar_hdr));
|
||||
@ -560,7 +596,10 @@ ArchStatMember (archive, member, hash)
|
||||
* 'size' field of the header and round it up during the seek.
|
||||
*/
|
||||
arh.ar_size[sizeof(arh.ar_size)-1] = '\0';
|
||||
size = (int) strtol(arh.ar_size, NULL, 10);
|
||||
#if 0
|
||||
(void) sscanf (arh.ar_size, "%10d", &size);
|
||||
#endif
|
||||
fseek (arch, (size + 1) & ~1, 1);
|
||||
}
|
||||
|
||||
@ -715,7 +754,10 @@ skip:
|
||||
* header and round it up during the seek.
|
||||
*/
|
||||
arhPtr->ar_size[sizeof(arhPtr->ar_size)-1] = '\0';
|
||||
size = (int) strtol(arhPtr->ar_size, NULL, 10);
|
||||
#if 0
|
||||
(void)sscanf (arhPtr->ar_size, "%10d", &size);
|
||||
#endif
|
||||
fseek (arch, (size + 1) & ~1, 1);
|
||||
}
|
||||
}
|
||||
@ -749,10 +791,15 @@ Arch_Touch (gn)
|
||||
{
|
||||
FILE * arch; /* Stream open to archive, positioned properly */
|
||||
struct ar_hdr arh; /* Current header describing member */
|
||||
char *p1, *p2;
|
||||
|
||||
arch = ArchFindMember(Var_Value (ARCHIVE, gn),
|
||||
Var_Value (TARGET, gn),
|
||||
arch = ArchFindMember(Var_Value (ARCHIVE, gn, &p1),
|
||||
Var_Value (TARGET, gn, &p2),
|
||||
&arh, "r+");
|
||||
if (p1)
|
||||
free(p1);
|
||||
if (p2)
|
||||
free(p2);
|
||||
sprintf(arh.ar_date, "%-12ld", (long) now);
|
||||
|
||||
if (arch != (FILE *) NULL) {
|
||||
@ -817,12 +864,21 @@ Arch_MTime (gn)
|
||||
{
|
||||
struct ar_hdr *arhPtr; /* Header of desired member */
|
||||
int modTime; /* Modification time as an integer */
|
||||
char *p1, *p2;
|
||||
|
||||
arhPtr = ArchStatMember (Var_Value (ARCHIVE, gn),
|
||||
Var_Value (TARGET, gn),
|
||||
arhPtr = ArchStatMember (Var_Value (ARCHIVE, gn, &p1),
|
||||
Var_Value (TARGET, gn, &p2),
|
||||
TRUE);
|
||||
if (p1)
|
||||
free(p1);
|
||||
if (p2)
|
||||
free(p2);
|
||||
|
||||
if (arhPtr != (struct ar_hdr *) NULL) {
|
||||
modTime = (int) strtol(arhPtr->ar_date, NULL, 10);
|
||||
#if 0
|
||||
(void)sscanf (arhPtr->ar_date, "%12d", &modTime);
|
||||
#endif
|
||||
} else {
|
||||
modTime = 0;
|
||||
}
|
||||
@ -981,7 +1037,10 @@ Arch_LibOODate (gn)
|
||||
arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
|
||||
|
||||
if (arhPtr != (struct ar_hdr *)NULL) {
|
||||
modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10);
|
||||
#if 0
|
||||
(void)sscanf (arhPtr->ar_date, "%12d", &modTimeTOC);
|
||||
#endif
|
||||
|
||||
if (DEBUG(ARCH) || DEBUG(MAKE)) {
|
||||
printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
|
||||
@ -1018,3 +1077,24 @@ Arch_Init ()
|
||||
{
|
||||
archives = Lst_Init (FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Arch_End --
|
||||
* Cleanup things for this module.
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
*
|
||||
* Side Effects:
|
||||
* The 'archives' list is freed
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Arch_End ()
|
||||
{
|
||||
Lst_Destroy(archives, ArchFree);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)buf.c 5.5 (Berkeley) 12/28/90"; */
|
||||
static char *rcsid = "$Id: buf.c,v 1.4 1994/03/05 00:34:34 cgd Exp $";
|
||||
static char *rcsid = "$Id: buf.c,v 1.5 1994/06/06 22:45:19 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -95,9 +95,9 @@ Buf_OvAddByte (bp, byte)
|
||||
register Buffer bp;
|
||||
int byte;
|
||||
{
|
||||
|
||||
int nbytes = 1;
|
||||
bp->left = 0;
|
||||
BufExpand (bp, 1);
|
||||
BufExpand (bp, nbytes);
|
||||
|
||||
*bp->inPtr++ = byte;
|
||||
bp->left--;
|
||||
|
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)buf.h 5.4 (Berkeley) 12/28/90
|
||||
* $Id: buf.h,v 1.3 1994/03/05 00:34:36 cgd Exp $
|
||||
* $Id: buf.h,v 1.4 1994/06/06 22:45:20 jtc Exp $
|
||||
*/
|
||||
|
||||
/*-
|
||||
@ -49,7 +49,7 @@
|
||||
|
||||
#include "sprite.h"
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef char Byte;
|
||||
|
||||
typedef struct Buffer {
|
||||
int size; /* Current size of the buffer */
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)compat.c 5.7 (Berkeley) 3/1/91"; */
|
||||
static char *rcsid = "$Id: compat.c,v 1.6 1994/03/07 22:22:01 cgd Exp $";
|
||||
static char *rcsid = "$Id: compat.c,v 1.7 1994/06/06 22:45:21 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -79,8 +79,8 @@ static char meta[256];
|
||||
static GNode *curTarg = NILGNODE;
|
||||
static GNode *ENDNode;
|
||||
static void CompatInterrupt __P((int));
|
||||
static int CompatRunCommand __P((char *, GNode *));
|
||||
static int CompatMake __P((GNode *, GNode *));
|
||||
static int CompatRunCommand __P((ClientData, ClientData));
|
||||
static int CompatMake __P((ClientData, ClientData));
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
@ -104,13 +104,16 @@ CompatInterrupt (signo)
|
||||
GNode *gn;
|
||||
|
||||
if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
|
||||
char *file = Var_Value (TARGET, curTarg);
|
||||
char *p1;
|
||||
char *file = Var_Value (TARGET, curTarg, &p1);
|
||||
struct stat st;
|
||||
|
||||
if (lstat(file, &st) != -1 && !S_ISDIR(st.st_mode) &&
|
||||
unlink(file) != -1) {
|
||||
printf ("*** %s removed\n", file);
|
||||
}
|
||||
if (p1)
|
||||
free(p1);
|
||||
|
||||
/*
|
||||
* Run .INTERRUPT only if hit with interrupt signal
|
||||
@ -121,8 +124,9 @@ CompatInterrupt (signo)
|
||||
Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
exit (0);
|
||||
exit (signo);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -140,9 +144,9 @@ CompatInterrupt (signo)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
CompatRunCommand (cmd, gn)
|
||||
char *cmd; /* Command to execute */
|
||||
GNode *gn; /* Node from which the command came */
|
||||
CompatRunCommand (cmdp, gnp)
|
||||
ClientData cmdp; /* Command to execute */
|
||||
ClientData gnp; /* Node from which the command came */
|
||||
{
|
||||
char *cmdStart; /* Start of expanded command */
|
||||
register char *cp;
|
||||
@ -158,6 +162,8 @@ CompatRunCommand (cmd, gn)
|
||||
* dynamically allocated */
|
||||
Boolean local; /* TRUE if command should be executed
|
||||
* locally */
|
||||
char *cmd = (char *) cmdp;
|
||||
GNode *gn = (GNode *) gnp;
|
||||
|
||||
/*
|
||||
* Avoid clobbered variable warnings by forcing the compiler
|
||||
@ -181,6 +187,7 @@ CompatRunCommand (cmd, gn)
|
||||
*/
|
||||
|
||||
if (*cmdStart == '\0') {
|
||||
free(cmdStart);
|
||||
Error("%s expands to empty string", cmd);
|
||||
return(0);
|
||||
} else {
|
||||
@ -278,16 +285,13 @@ CompatRunCommand (cmd, gn)
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
free(cmdStart);
|
||||
Lst_Replace (cmdNode, (ClientData) NULL);
|
||||
|
||||
/*
|
||||
* The child is off and running. Now all we can do is wait...
|
||||
*/
|
||||
while (1) {
|
||||
int id;
|
||||
|
||||
if (!local) {
|
||||
id = 0;
|
||||
}
|
||||
|
||||
while ((stat = wait((int *)&reason)) != cpid) {
|
||||
if (stat == -1 && errno != EINTR) {
|
||||
@ -352,10 +356,12 @@ CompatRunCommand (cmd, gn)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
CompatMake (gn, pgn)
|
||||
GNode *gn; /* The node to make */
|
||||
GNode *pgn; /* Parent to abort if necessary */
|
||||
CompatMake (gnp, pgnp)
|
||||
ClientData gnp; /* The node to make */
|
||||
ClientData pgnp; /* Parent to abort if necessary */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
GNode *pgn = (GNode *) pgnp;
|
||||
if (gn->type & OP_USE) {
|
||||
Make_HandleUse(gn, pgn);
|
||||
} else if (gn->made == UNMADE) {
|
||||
@ -378,7 +384,10 @@ CompatMake (gn, pgn)
|
||||
}
|
||||
|
||||
if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
|
||||
Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
|
||||
char *p1;
|
||||
Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
||||
if (p1)
|
||||
free(p1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -526,7 +535,10 @@ CompatMake (gn, pgn)
|
||||
pgn->make = FALSE;
|
||||
} else {
|
||||
if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
|
||||
Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
|
||||
char *p1;
|
||||
Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
||||
if (p1)
|
||||
free(p1);
|
||||
}
|
||||
switch(gn->made) {
|
||||
case BEINGMADE:
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)cond.c 5.6 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: cond.c,v 1.4 1994/03/05 00:34:39 cgd Exp $";
|
||||
static char *rcsid = "$Id: cond.c,v 1.5 1994/06/06 22:45:23 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -97,7 +97,7 @@ typedef enum {
|
||||
*/
|
||||
static int CondGetArg __P((char **, char **, char *, Boolean));
|
||||
static Boolean CondDoDefined __P((int, char *));
|
||||
static int CondStrMatch __P((char *, char *));
|
||||
static int CondStrMatch __P((ClientData, ClientData));
|
||||
static Boolean CondDoMake __P((int, char *));
|
||||
static Boolean CondDoExists __P((int, char *));
|
||||
static Boolean CondDoTarget __P((int, char *));
|
||||
@ -278,14 +278,17 @@ CondDoDefined (argLen, arg)
|
||||
char *arg;
|
||||
{
|
||||
char savec = arg[argLen];
|
||||
char *p1;
|
||||
Boolean result;
|
||||
|
||||
arg[argLen] = '\0';
|
||||
if (Var_Value (arg, VAR_CMD) != (char *)NULL) {
|
||||
if (Var_Value (arg, VAR_CMD, &p1) != (char *)NULL) {
|
||||
result = TRUE;
|
||||
} else {
|
||||
result = FALSE;
|
||||
}
|
||||
if (p1)
|
||||
free(p1);
|
||||
arg[argLen] = savec;
|
||||
return (result);
|
||||
}
|
||||
@ -306,10 +309,10 @@ CondDoDefined (argLen, arg)
|
||||
*/
|
||||
static int
|
||||
CondStrMatch(string, pattern)
|
||||
char *string;
|
||||
char *pattern;
|
||||
ClientData string;
|
||||
ClientData pattern;
|
||||
{
|
||||
return(!Str_Match(string,pattern));
|
||||
return(!Str_Match((char *) string,(char *) pattern));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -533,7 +536,8 @@ CondToken(doEval)
|
||||
}
|
||||
condExpr += varSpecLen;
|
||||
|
||||
if (!isspace(*condExpr) && strchr("!=><", *condExpr) == NULL) {
|
||||
if (!isspace((unsigned char) *condExpr) &&
|
||||
strchr("!=><", *condExpr) == NULL) {
|
||||
Buffer buf;
|
||||
char *cp;
|
||||
|
||||
@ -545,7 +549,8 @@ CondToken(doEval)
|
||||
if (doFree)
|
||||
free(lhs);
|
||||
|
||||
for (;*condExpr && !isspace(*condExpr); condExpr++)
|
||||
for (;*condExpr && !isspace((unsigned char) *condExpr);
|
||||
condExpr++)
|
||||
Buf_AddByte(buf, (Byte)*condExpr);
|
||||
|
||||
Buf_AddByte(buf, (Byte)'\0');
|
||||
@ -558,7 +563,7 @@ CondToken(doEval)
|
||||
/*
|
||||
* Skip whitespace to get to the operator
|
||||
*/
|
||||
while (isspace(*condExpr))
|
||||
while (isspace((unsigned char) *condExpr))
|
||||
condExpr++;
|
||||
|
||||
/*
|
||||
@ -584,7 +589,7 @@ CondToken(doEval)
|
||||
|
||||
goto do_compare;
|
||||
}
|
||||
while (isspace(*condExpr)) {
|
||||
while (isspace((unsigned char) *condExpr)) {
|
||||
condExpr++;
|
||||
}
|
||||
if (*condExpr == '\0') {
|
||||
@ -704,7 +709,8 @@ do_string_compare:
|
||||
/*
|
||||
* Skip over the right-hand side
|
||||
*/
|
||||
while(!isspace(*condExpr) && (*condExpr != '\0')) {
|
||||
while(!isspace((unsigned char) *condExpr) &&
|
||||
(*condExpr != '\0')) {
|
||||
condExpr++;
|
||||
}
|
||||
}
|
||||
@ -811,9 +817,8 @@ error:
|
||||
for (arglen = 0;
|
||||
condExpr[arglen] != '(' && condExpr[arglen] != '\0';
|
||||
arglen += 1)
|
||||
{
|
||||
/* void */ ;
|
||||
}
|
||||
continue;
|
||||
|
||||
if (condExpr[arglen] != '\0') {
|
||||
val = Var_Parse(&condExpr[arglen - 1], VAR_CMD,
|
||||
doEval, &length, &doFree);
|
||||
@ -825,7 +830,7 @@ error:
|
||||
* spaces... 4/15/92, christos
|
||||
*/
|
||||
char *p;
|
||||
for (p = val; *p && isspace(*p); p++)
|
||||
for (p = val; *p && isspace((unsigned char)*p); p++)
|
||||
continue;
|
||||
t = (*p == '\0') ? True : False;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)dir.c 5.6 (Berkeley) 12/28/90"; */
|
||||
static char *rcsid = "$Id: dir.c,v 1.5 1994/03/05 00:34:41 cgd Exp $";
|
||||
static char *rcsid = "$Id: dir.c,v 1.6 1994/06/06 22:45:25 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -50,6 +50,8 @@ static char *rcsid = "$Id: dir.c,v 1.5 1994/03/05 00:34:41 cgd Exp $";
|
||||
* The interface for this module is:
|
||||
* Dir_Init Initialize the module.
|
||||
*
|
||||
* Dir_End Cleanup the module.
|
||||
*
|
||||
* Dir_HasWildcards Returns TRUE if the name given it needs to
|
||||
* be wildcard-expanded.
|
||||
*
|
||||
@ -185,12 +187,12 @@ static Hash_Table mtimes; /* Results of doing a last-resort stat in
|
||||
* should be ok, but... */
|
||||
|
||||
|
||||
static int DirFindName __P((Path *, char *));
|
||||
static int DirFindName __P((ClientData, ClientData));
|
||||
static int DirMatchFiles __P((char *, Path *, Lst));
|
||||
static void DirExpandCurly __P((char *, char *, Lst, Lst));
|
||||
static void DirExpandInt __P((char *, Lst, Lst));
|
||||
static int DirPrintWord __P((char *));
|
||||
static int DirPrintDir __P((Path *));
|
||||
static int DirPrintWord __P((ClientData, ClientData));
|
||||
static int DirPrintDir __P((ClientData, ClientData));
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
@ -227,6 +229,30 @@ Dir_Init ()
|
||||
dot->refCount += 1;
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Dir_End --
|
||||
* cleanup things for this module
|
||||
*
|
||||
* Results:
|
||||
* none
|
||||
*
|
||||
* Side Effects:
|
||||
* none
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Dir_End()
|
||||
{
|
||||
dot->refCount -= 1;
|
||||
Dir_Destroy((ClientData) dot);
|
||||
Dir_ClearPath(dirSearchPath);
|
||||
Lst_Destroy(dirSearchPath, NOFREE);
|
||||
Dir_ClearPath(openDirectories);
|
||||
Lst_Destroy(openDirectories, NOFREE);
|
||||
Hash_DeleteTable(&mtimes);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* DirFindName --
|
||||
@ -243,10 +269,10 @@ Dir_Init ()
|
||||
*/
|
||||
static int
|
||||
DirFindName (p, dname)
|
||||
Path *p; /* Current name */
|
||||
char *dname; /* Desired name */
|
||||
ClientData p; /* Current name */
|
||||
ClientData dname; /* Desired name */
|
||||
{
|
||||
return (strcmp (p->name, dname));
|
||||
return (strcmp (((Path *)p)->name, (char *) dname));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -491,12 +517,13 @@ DirExpandInt(word, path, expansions)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
DirPrintWord(word)
|
||||
char *word;
|
||||
DirPrintWord(word, dummy)
|
||||
ClientData word;
|
||||
ClientData dummy;
|
||||
{
|
||||
printf("%s ", word);
|
||||
printf("%s ", (char *) word);
|
||||
|
||||
return(0);
|
||||
return(dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -607,7 +634,7 @@ Dir_Expand (word, path, expansions)
|
||||
}
|
||||
}
|
||||
if (DEBUG(DIR)) {
|
||||
Lst_ForEach(expansions, DirPrintWord, NULL);
|
||||
Lst_ForEach(expansions, DirPrintWord, (ClientData) 0);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
}
|
||||
@ -713,7 +740,7 @@ Dir_FindFile (name, path)
|
||||
*/
|
||||
p1 = p->name + strlen (p->name) - 1;
|
||||
p2 = cp - 2;
|
||||
while (p2 >= name && *p1 == *p2) {
|
||||
while (p2 >= name && p1 >= p->name && *p1 == *p2) {
|
||||
p1 -= 1; p2 -= 1;
|
||||
}
|
||||
if (p2 >= name || (p1 >= p->name && *p1 != '/')) {
|
||||
@ -947,7 +974,7 @@ Dir_MTime (gn)
|
||||
}
|
||||
|
||||
if (fullName == (char *)NULL) {
|
||||
fullName = gn->name;
|
||||
fullName = strdup(gn->name);
|
||||
}
|
||||
|
||||
entry = Hash_FindEntry(&mtimes, fullName);
|
||||
@ -965,6 +992,8 @@ Dir_MTime (gn)
|
||||
Hash_DeleteEntry(&mtimes, entry);
|
||||
} else if (stat (fullName, &stb) < 0) {
|
||||
if (gn->type & OP_MEMBER) {
|
||||
if (fullName != gn->path)
|
||||
free(fullName);
|
||||
return Arch_MemMTime (gn);
|
||||
} else {
|
||||
stb.st_mtime = 0;
|
||||
@ -1040,7 +1069,7 @@ Dir_AddDir (path, name)
|
||||
if (dp->d_fileno == 0) {
|
||||
continue;
|
||||
}
|
||||
#endif sun
|
||||
#endif /* sun */
|
||||
(void)Hash_CreateEntry(&p->files, dp->d_name, (Boolean *)NULL);
|
||||
}
|
||||
(void) closedir (d);
|
||||
@ -1069,9 +1098,9 @@ Dir_AddDir (path, name)
|
||||
*/
|
||||
ClientData
|
||||
Dir_CopyDir(p)
|
||||
Path *p; /* Directory descriptor to copy */
|
||||
ClientData p;
|
||||
{
|
||||
p->refCount += 1;
|
||||
((Path *) p)->refCount += 1;
|
||||
|
||||
return ((ClientData)p);
|
||||
}
|
||||
@ -1133,9 +1162,10 @@ Dir_MakeFlags (flag, path)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Dir_Destroy (p)
|
||||
Path *p; /* The directory descriptor to nuke */
|
||||
Dir_Destroy (pp)
|
||||
ClientData pp; /* The directory descriptor to nuke */
|
||||
{
|
||||
Path *p = (Path *) pp;
|
||||
p->refCount -= 1;
|
||||
|
||||
if (p->refCount == 0) {
|
||||
@ -1171,7 +1201,7 @@ Dir_ClearPath(path)
|
||||
Path *p;
|
||||
while (!Lst_IsEmpty(path)) {
|
||||
p = (Path *)Lst_DeQueue(path);
|
||||
Dir_Destroy(p);
|
||||
Dir_Destroy((ClientData) p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1229,7 +1259,13 @@ Dir_PrintDirectories()
|
||||
}
|
||||
}
|
||||
|
||||
static int DirPrintDir (p) Path *p; { printf ("%s ", p->name); return (0); }
|
||||
static int DirPrintDir (p, dummy)
|
||||
ClientData p;
|
||||
ClientData dummy;
|
||||
{
|
||||
printf ("%s ", ((Path *) p)->name);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
void
|
||||
Dir_PrintPath (path)
|
||||
|
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)dir.h 5.4 (Berkeley) 12/28/90
|
||||
* $Id: dir.h,v 1.1 1994/03/05 00:34:43 cgd Exp $
|
||||
* $Id: dir.h,v 1.2 1994/06/06 22:45:27 jtc Exp $
|
||||
*/
|
||||
|
||||
/* dir.h --
|
||||
@ -54,6 +54,7 @@ typedef struct Path {
|
||||
} Path;
|
||||
|
||||
void Dir_Init __P((void));
|
||||
void Dir_End __P((void));
|
||||
Boolean Dir_HasWildcards __P((char *));
|
||||
void Dir_Expand __P((char *, Lst, Lst));
|
||||
char *Dir_FindFile __P((char *, Lst));
|
||||
@ -64,7 +65,7 @@ void Dir_ClearPath __P((Lst));
|
||||
void Dir_Concat __P((Lst, Lst));
|
||||
void Dir_PrintDirectories __P((void));
|
||||
void Dir_PrintPath __P((Lst));
|
||||
void Dir_Destroy __P((Path *));
|
||||
ClientData Dir_CopyDir __P((Path *));
|
||||
void Dir_Destroy __P((ClientData));
|
||||
ClientData Dir_CopyDir __P((ClientData));
|
||||
|
||||
#endif /* _DIR */
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)for.c 5.6 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: for.c,v 1.1 1994/03/05 00:34:44 cgd Exp $";
|
||||
static char *rcsid = "$Id: for.c,v 1.2 1994/06/06 22:45:28 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -74,13 +74,13 @@ static Lst forLst; /* List of items */
|
||||
/*
|
||||
* State of a for loop.
|
||||
*/
|
||||
struct For {
|
||||
typedef struct _For {
|
||||
Buffer buf; /* Unexpanded buffer */
|
||||
char* var; /* Index name */
|
||||
Lst lst; /* List of variables */
|
||||
};
|
||||
} For;
|
||||
|
||||
static int ForExec __P((char *, struct For *));
|
||||
static int ForExec __P((ClientData, ClientData));
|
||||
|
||||
|
||||
|
||||
@ -116,27 +116,28 @@ For_Eval (line)
|
||||
Buffer buf;
|
||||
int varlen;
|
||||
|
||||
for (ptr++; *ptr && isspace(*ptr); ptr++)
|
||||
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
|
||||
continue;
|
||||
/*
|
||||
* If we are not in a for loop quickly determine if the statement is
|
||||
* a for.
|
||||
*/
|
||||
if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' || !isspace(ptr[3]))
|
||||
if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' ||
|
||||
!isspace((unsigned char) ptr[3]))
|
||||
return FALSE;
|
||||
ptr += 3;
|
||||
|
||||
/*
|
||||
* we found a for loop, and now we are going to parse it.
|
||||
*/
|
||||
while (*ptr && isspace(*ptr))
|
||||
while (*ptr && isspace((unsigned char) *ptr))
|
||||
ptr++;
|
||||
|
||||
/*
|
||||
* Grab the variable
|
||||
*/
|
||||
buf = Buf_Init(0);
|
||||
for (wrd = ptr; *ptr && !isspace(*ptr); ptr++)
|
||||
for (wrd = ptr; *ptr && !isspace((unsigned char) *ptr); ptr++)
|
||||
continue;
|
||||
Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd);
|
||||
|
||||
@ -147,20 +148,21 @@ For_Eval (line)
|
||||
}
|
||||
Buf_Destroy(buf, FALSE);
|
||||
|
||||
while (*ptr && isspace(*ptr))
|
||||
while (*ptr && isspace((unsigned char) *ptr))
|
||||
ptr++;
|
||||
|
||||
/*
|
||||
* Grab the `in'
|
||||
*/
|
||||
if (ptr[0] != 'i' || ptr[1] != 'n' || !isspace(ptr[2])) {
|
||||
if (ptr[0] != 'i' || ptr[1] != 'n' ||
|
||||
!isspace((unsigned char) ptr[2])) {
|
||||
Parse_Error (level, "missing `in' in for");
|
||||
printf("%s\n", ptr);
|
||||
return 0;
|
||||
}
|
||||
ptr += 3;
|
||||
|
||||
while (*ptr && isspace(*ptr))
|
||||
while (*ptr && isspace((unsigned char) *ptr))
|
||||
ptr++;
|
||||
|
||||
/*
|
||||
@ -176,14 +178,14 @@ For_Eval (line)
|
||||
Lst_AtEnd(forLst, (ClientData) Buf_GetAll(buf, &varlen)), \
|
||||
Buf_Destroy(buf, FALSE)
|
||||
|
||||
for (ptr = sub; *ptr && isspace(*ptr); ptr++)
|
||||
for (ptr = sub; *ptr && isspace((unsigned char) *ptr); ptr++)
|
||||
continue;
|
||||
|
||||
for (wrd = ptr; *ptr; ptr++)
|
||||
if (isspace(*ptr)) {
|
||||
if (isspace((unsigned char) *ptr)) {
|
||||
ADDWORD();
|
||||
buf = Buf_Init(0);
|
||||
while (*ptr && isspace(*ptr))
|
||||
while (*ptr && isspace((unsigned char) *ptr))
|
||||
ptr++;
|
||||
wrd = ptr--;
|
||||
}
|
||||
@ -201,10 +203,11 @@ For_Eval (line)
|
||||
}
|
||||
else if (*ptr == '.') {
|
||||
|
||||
for (ptr++; *ptr && isspace(*ptr); ptr++)
|
||||
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
|
||||
continue;
|
||||
|
||||
if (strncmp(ptr, "endfor", 6) == 0 && (isspace(ptr[6]) || !ptr[6])) {
|
||||
if (strncmp(ptr, "endfor", 6) == 0 &&
|
||||
(isspace((unsigned char) ptr[6]) || !ptr[6])) {
|
||||
if (DEBUG(FOR))
|
||||
(void) fprintf(stderr, "For: end for %d\n", forLevel);
|
||||
if (--forLevel < 0) {
|
||||
@ -212,7 +215,8 @@ For_Eval (line)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (strncmp(ptr, "for", 3) == 0 && isspace(ptr[3])) {
|
||||
else if (strncmp(ptr, "for", 3) == 0 &&
|
||||
isspace((unsigned char) ptr[3])) {
|
||||
forLevel++;
|
||||
if (DEBUG(FOR))
|
||||
(void) fprintf(stderr, "For: new loop %d\n", forLevel);
|
||||
@ -243,10 +247,12 @@ For_Eval (line)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ForExec(name, arg)
|
||||
char *name;
|
||||
struct For *arg;
|
||||
ForExec(namep, argp)
|
||||
ClientData namep;
|
||||
ClientData argp;
|
||||
{
|
||||
char *name = (char *) namep;
|
||||
For *arg = (For *) argp;
|
||||
int len;
|
||||
Var_Set(arg->var, name, VAR_GLOBAL);
|
||||
if (DEBUG(FOR))
|
||||
@ -275,7 +281,7 @@ ForExec(name, arg)
|
||||
void
|
||||
For_Run()
|
||||
{
|
||||
struct For arg;
|
||||
For arg;
|
||||
|
||||
if (forVar == NULL || forBuf == NULL || forLst == NULL)
|
||||
return;
|
||||
@ -289,6 +295,6 @@ For_Run()
|
||||
Lst_ForEach(arg.lst, ForExec, (ClientData) &arg);
|
||||
|
||||
free((Address)arg.var);
|
||||
Lst_Destroy(arg.lst, free);
|
||||
Lst_Destroy(arg.lst, (void (*) __P((ClientData))) free);
|
||||
Buf_Destroy(arg.buf, TRUE);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)job.c 5.15 (Berkeley) 3/1/91"; */
|
||||
static char *rcsid = "$Id: job.c,v 1.5 1994/03/05 00:34:48 cgd Exp $";
|
||||
static char *rcsid = "$Id: job.c,v 1.6 1994/06/06 22:45:29 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -243,11 +243,11 @@ Lst stoppedJobs; /* Lst of Job structures describing
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static int JobCondPassSig __P((Job *, int));
|
||||
static int JobCondPassSig __P((ClientData, ClientData));
|
||||
static void JobPassSig __P((int));
|
||||
static int JobCmpPid __P((Job *, int));
|
||||
static int JobPrintCommand __P((char *, Job *));
|
||||
static int JobSaveCommand __P((char *, GNode *));
|
||||
static int JobCmpPid __P((ClientData, ClientData));
|
||||
static int JobPrintCommand __P((ClientData, ClientData));
|
||||
static int JobSaveCommand __P((ClientData, ClientData));
|
||||
static void JobFinish __P((Job *, union wait));
|
||||
static void JobExec __P((Job *, char **));
|
||||
static void JobMakeArgv __P((Job *, char **));
|
||||
@ -272,10 +272,12 @@ static void JobInterrupt __P((int));
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
JobCondPassSig(job, signo)
|
||||
Job *job; /* Job to biff */
|
||||
int signo; /* Signal to send it */
|
||||
JobCondPassSig(jobp, signop)
|
||||
ClientData jobp; /* Job to biff */
|
||||
ClientData signop; /* Signal to send it */
|
||||
{
|
||||
Job *job = (Job *) jobp;
|
||||
int signo = *(int *) signop;
|
||||
#ifdef RMT_WANTS_SIGNALS
|
||||
if (job->flags & JOB_REMOTE) {
|
||||
(void)Rmt_Signal(job, signo);
|
||||
@ -344,7 +346,8 @@ JobPassSig(signo)
|
||||
|
||||
kill(getpid(), signo);
|
||||
|
||||
Lst_ForEach(jobs, JobCondPassSig, (ClientData)SIGCONT);
|
||||
signo = SIGCONT;
|
||||
Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
|
||||
|
||||
sigsetmask(mask);
|
||||
signal(signo, JobPassSig);
|
||||
@ -367,10 +370,10 @@ JobPassSig(signo)
|
||||
*/
|
||||
static int
|
||||
JobCmpPid (job, pid)
|
||||
int pid; /* process id desired */
|
||||
Job *job; /* job to examine */
|
||||
ClientData job; /* job to examine */
|
||||
ClientData pid; /* process id desired */
|
||||
{
|
||||
return (pid - job->pid);
|
||||
return ( *(int *) pid - ((Job *) job)->pid);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -401,9 +404,9 @@ JobCmpPid (job, pid)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
JobPrintCommand (cmd, job)
|
||||
char *cmd; /* command string to print */
|
||||
Job *job; /* job for which to print it */
|
||||
JobPrintCommand (cmdp, jobp)
|
||||
ClientData cmdp; /* command string to print */
|
||||
ClientData jobp; /* job for which to print it */
|
||||
{
|
||||
Boolean noSpecials; /* true if we shouldn't worry about
|
||||
* inserting special commands into
|
||||
@ -417,6 +420,8 @@ JobPrintCommand (cmd, job)
|
||||
* command */
|
||||
char *cmdStart; /* Start of expanded command */
|
||||
LstNode cmdNode; /* Node for replacing the command */
|
||||
char *cmd = (char *) cmdp;
|
||||
Job *job = (Job *) jobp;
|
||||
|
||||
noSpecials = (noExecute && ! (job->node->type & OP_MAKE));
|
||||
|
||||
@ -556,11 +561,11 @@ JobPrintCommand (cmd, job)
|
||||
*/
|
||||
static int
|
||||
JobSaveCommand (cmd, gn)
|
||||
char *cmd;
|
||||
GNode *gn;
|
||||
ClientData cmd;
|
||||
ClientData gn;
|
||||
{
|
||||
cmd = Var_Subst (NULL, cmd, gn, FALSE);
|
||||
(void)Lst_AtEnd (postCommands->commands, (ClientData)cmd);
|
||||
cmd = (ClientData) Var_Subst (NULL, (char *) cmd, (GNode *) gn, FALSE);
|
||||
(void)Lst_AtEnd (postCommands->commands, cmd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -914,6 +919,7 @@ Job_CheckCommands (gn, abortProc)
|
||||
* commands
|
||||
*/
|
||||
if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands)) {
|
||||
char *p1;
|
||||
/*
|
||||
* Make only looks for a .DEFAULT if the node was never the
|
||||
* target of an operator, so that's what we do too. If
|
||||
@ -924,7 +930,9 @@ Job_CheckCommands (gn, abortProc)
|
||||
* .DEFAULT itself.
|
||||
*/
|
||||
Make_HandleUse(DEFAULT, gn);
|
||||
Var_Set (IMPSRC, Var_Value (TARGET, gn), gn);
|
||||
Var_Set (IMPSRC, Var_Value (TARGET, gn, &p1), gn);
|
||||
if (p1)
|
||||
free(p1);
|
||||
} else if (Dir_MTime (gn) == 0) {
|
||||
/*
|
||||
* The node wasn't the target of an operator we have no .DEFAULT
|
||||
@ -1361,7 +1369,7 @@ JobRestart(job)
|
||||
static int
|
||||
JobStart (gn, flags, previous)
|
||||
GNode *gn; /* target to create */
|
||||
short flags; /* flags for the job to override normal ones.
|
||||
int flags; /* flags for the job to override normal ones.
|
||||
* e.g. JOB_SPECIAL or JOB_IGNDOTS */
|
||||
Job *previous; /* The previous Job structure for this node,
|
||||
* if any. */
|
||||
@ -1949,11 +1957,11 @@ Job_CatchChildren (block)
|
||||
printf("Process %d exited or stopped.\n", pid);
|
||||
|
||||
|
||||
jnode = Lst_Find (jobs, (ClientData)pid, JobCmpPid);
|
||||
jnode = Lst_Find (jobs, (ClientData)&pid, JobCmpPid);
|
||||
|
||||
if (jnode == NILLNODE) {
|
||||
if (WIFSIGNALED(status) && (status.w_termsig == SIGCONT)) {
|
||||
jnode = Lst_Find(stoppedJobs, (ClientData)pid, JobCmpPid);
|
||||
jnode = Lst_Find(stoppedJobs, (ClientData) &pid, JobCmpPid);
|
||||
if (jnode == NILLNODE) {
|
||||
Error("Resumed child (%d) not in table", pid);
|
||||
continue;
|
||||
|
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)lst.h 5.3 (Berkeley) 6/1/90
|
||||
* $Id: lst.h,v 1.3 1994/03/05 00:34:52 cgd Exp $
|
||||
* $Id: lst.h,v 1.4 1994/06/06 22:45:32 jtc Exp $
|
||||
*/
|
||||
|
||||
/*-
|
||||
@ -47,6 +47,7 @@
|
||||
#define _LST_H_
|
||||
|
||||
#include <sprite.h>
|
||||
#include <sys/cdefs.h>
|
||||
#if __STDC__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
@ -66,8 +67,8 @@ typedef struct LstNode *LstNode;
|
||||
* not to be freed.
|
||||
* NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
|
||||
*/
|
||||
#define NOFREE ((void (*)()) 0)
|
||||
#define NOCOPY ((ClientData (*)()) 0)
|
||||
#define NOFREE ((void (*) __P((ClientData))) 0)
|
||||
#define NOCOPY ((ClientData (*) __P((ClientData))) 0)
|
||||
|
||||
#define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */
|
||||
#define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */
|
||||
@ -75,72 +76,90 @@ typedef struct LstNode *LstNode;
|
||||
/*
|
||||
* Creation/destruction functions
|
||||
*/
|
||||
Lst Lst_Init(); /* Create a new list */
|
||||
Lst Lst_Duplicate(); /* Duplicate an existing list */
|
||||
void Lst_Destroy(); /* Destroy an old one */
|
||||
|
||||
int Lst_Length(); /* Find the length of a list */
|
||||
Boolean Lst_IsEmpty(); /* True if list is empty */
|
||||
/* Create a new list */
|
||||
Lst Lst_Init __P((Boolean));
|
||||
/* Duplicate an existing list */
|
||||
Lst Lst_Duplicate __P((Lst, ClientData (*)(ClientData)));
|
||||
/* Destroy an old one */
|
||||
void Lst_Destroy __P((Lst, void (*)(ClientData)));
|
||||
/* True if list is empty */
|
||||
Boolean Lst_IsEmpty __P((Lst));
|
||||
|
||||
/*
|
||||
* Functions to modify a list
|
||||
*/
|
||||
ReturnStatus Lst_Insert(); /* Insert an element before another */
|
||||
ReturnStatus Lst_Append(); /* Insert an element after another */
|
||||
ReturnStatus Lst_AtFront(); /* Place an element at the front of
|
||||
* a lst. */
|
||||
ReturnStatus Lst_AtEnd(); /* Place an element at the end of a
|
||||
* lst. */
|
||||
ReturnStatus Lst_Remove(); /* Remove an element */
|
||||
ReturnStatus Lst_Replace(); /* Replace a node with a new value */
|
||||
ReturnStatus Lst_Move(); /* Move an element to another place */
|
||||
ReturnStatus Lst_Concat(); /* Concatenate two lists */
|
||||
/* Insert an element before another */
|
||||
ReturnStatus Lst_Insert __P((Lst, LstNode, ClientData));
|
||||
/* Insert an element after another */
|
||||
ReturnStatus Lst_Append __P((Lst, LstNode, ClientData));
|
||||
/* Place an element at the front of a lst. */
|
||||
ReturnStatus Lst_AtFront __P((Lst, ClientData));
|
||||
/* Place an element at the end of a lst. */
|
||||
ReturnStatus Lst_AtEnd __P((Lst, ClientData));
|
||||
/* Remove an element */
|
||||
ReturnStatus Lst_Remove __P((Lst, LstNode));
|
||||
/* Replace a node with a new value */
|
||||
ReturnStatus Lst_Replace __P((LstNode, ClientData));
|
||||
/* Concatenate two lists */
|
||||
ReturnStatus Lst_Concat __P((Lst, Lst, int));
|
||||
|
||||
/*
|
||||
* Node-specific functions
|
||||
*/
|
||||
LstNode Lst_First(); /* Return first element in list */
|
||||
LstNode Lst_Last(); /* Return last element in list */
|
||||
LstNode Lst_Succ(); /* Return successor to given element */
|
||||
LstNode Lst_Pred(); /* Return predecessor to given
|
||||
* element */
|
||||
ClientData Lst_Datum(); /* Get datum from LstNode */
|
||||
/* Return first element in list */
|
||||
LstNode Lst_First __P((Lst));
|
||||
/* Return last element in list */
|
||||
LstNode Lst_Last __P((Lst));
|
||||
/* Return successor to given element */
|
||||
LstNode Lst_Succ __P((LstNode));
|
||||
/* Get datum from LstNode */
|
||||
ClientData Lst_Datum __P((LstNode));
|
||||
|
||||
/*
|
||||
* Functions for entire lists
|
||||
*/
|
||||
LstNode Lst_Find(); /* Find an element in a list */
|
||||
LstNode Lst_FindFrom(); /* Find an element starting from
|
||||
* somewhere */
|
||||
LstNode Lst_Member(); /* See if the given datum is on the
|
||||
* list. Returns the LstNode containing
|
||||
* the datum */
|
||||
int Lst_Index(); /* Returns the index of a datum in the
|
||||
* list, starting from 0 */
|
||||
void Lst_ForEach(); /* Apply a function to all elements of
|
||||
* a lst */
|
||||
void Lst_ForEachFrom(); /* Apply a function to all elements of
|
||||
* a lst starting from a certain point.
|
||||
* If the list is circular, the
|
||||
* application will wrap around to the
|
||||
* beginning of the list again. */
|
||||
/* Find an element in a list */
|
||||
LstNode Lst_Find __P((Lst, ClientData,
|
||||
int (*)(ClientData, ClientData)));
|
||||
/* Find an element starting from somewhere */
|
||||
LstNode Lst_FindFrom __P((Lst, LstNode, ClientData,
|
||||
int (*cProc)(ClientData, ClientData)));
|
||||
/*
|
||||
* See if the given datum is on the list. Returns the LstNode containing
|
||||
* the datum
|
||||
*/
|
||||
LstNode Lst_Member __P((Lst, ClientData));
|
||||
/* Apply a function to all elements of a lst */
|
||||
void Lst_ForEach __P((Lst, int (*)(ClientData, ClientData),
|
||||
ClientData));
|
||||
/*
|
||||
* Apply a function to all elements of a lst starting from a certain point.
|
||||
* If the list is circular, the application will wrap around to the
|
||||
* beginning of the list again.
|
||||
*/
|
||||
void Lst_ForEachFrom __P((Lst, LstNode,
|
||||
int (*)(ClientData, ClientData),
|
||||
ClientData));
|
||||
/*
|
||||
* these functions are for dealing with a list as a table, of sorts.
|
||||
* An idea of the "current element" is kept and used by all the functions
|
||||
* between Lst_Open() and Lst_Close().
|
||||
*/
|
||||
ReturnStatus Lst_Open(); /* Open the list */
|
||||
LstNode Lst_Prev(); /* Previous element */
|
||||
LstNode Lst_Cur(); /* The current element, please */
|
||||
LstNode Lst_Next(); /* Next element please */
|
||||
Boolean Lst_IsAtEnd(); /* Done yet? */
|
||||
void Lst_Close(); /* Finish table access */
|
||||
/* Open the list */
|
||||
ReturnStatus Lst_Open __P((Lst));
|
||||
/* Next element please */
|
||||
LstNode Lst_Next __P((Lst));
|
||||
/* Done yet? */
|
||||
Boolean Lst_IsAtEnd __P((Lst));
|
||||
/* Finish table access */
|
||||
void Lst_Close __P((Lst));
|
||||
|
||||
/*
|
||||
* for using the list as a queue
|
||||
*/
|
||||
ReturnStatus Lst_EnQueue(); /* Place an element at tail of queue */
|
||||
ClientData Lst_DeQueue(); /* Remove an element from head of
|
||||
* queue */
|
||||
/* Place an element at tail of queue */
|
||||
ReturnStatus Lst_EnQueue __P((Lst, ClientData));
|
||||
/* Remove an element from head of queue */
|
||||
ClientData Lst_DeQueue __P((Lst));
|
||||
|
||||
#endif _LST_H_
|
||||
#endif /* _LST_H_ */
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstConcat.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstConcat.c,v 1.3 1994/03/05 00:35:35 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstConcat.c,v 1.4 1994/06/06 22:45:57 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -103,6 +103,8 @@ Lst_Concat (l1, l2, flags)
|
||||
list2->firstPtr->prevPtr = list1->lastPtr;
|
||||
if (list1->lastPtr != NilListNode) {
|
||||
list1->lastPtr->nextPtr = list2->firstPtr;
|
||||
} else {
|
||||
list1->firstPtr = list2->firstPtr;
|
||||
}
|
||||
list1->lastPtr = list2->lastPtr;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstDestroy.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstDestroy.c,v 1.3 1994/03/05 00:35:38 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstDestroy.c,v 1.4 1994/06/06 22:45:59 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -64,7 +64,7 @@ static char *rcsid = "$Id: lstDestroy.c,v 1.3 1994/03/05 00:35:38 cgd Exp $";
|
||||
void
|
||||
Lst_Destroy (l, freeProc)
|
||||
Lst l;
|
||||
register void (*freeProc)();
|
||||
register void (*freeProc) __P((ClientData));
|
||||
{
|
||||
register ListNode ln;
|
||||
register ListNode tln = NilListNode;
|
||||
@ -77,21 +77,25 @@ Lst_Destroy (l, freeProc)
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* To ease scanning */
|
||||
if (list->lastPtr != NilListNode)
|
||||
list->lastPtr->nextPtr = NilListNode;
|
||||
else {
|
||||
free ((Address)l);
|
||||
return;
|
||||
}
|
||||
|
||||
if (freeProc) {
|
||||
for (ln = list->firstPtr;
|
||||
ln != NilListNode && tln != list->firstPtr;
|
||||
ln = tln) {
|
||||
tln = ln->nextPtr;
|
||||
(*freeProc) (ln->datum);
|
||||
free ((Address)ln);
|
||||
for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
|
||||
tln = ln->nextPtr;
|
||||
(*freeProc) (ln->datum);
|
||||
free ((Address)ln);
|
||||
}
|
||||
} else {
|
||||
for (ln = list->firstPtr;
|
||||
ln != NilListNode && tln != list->firstPtr;
|
||||
ln = tln) {
|
||||
tln = ln->nextPtr;
|
||||
free ((Address)ln);
|
||||
for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
|
||||
tln = ln->nextPtr;
|
||||
free ((Address)ln);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstDupl.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstDupl.c,v 1.3 1994/03/05 00:35:39 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstDupl.c,v 1.4 1994/06/06 22:46:00 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -63,7 +63,8 @@ static char *rcsid = "$Id: lstDupl.c,v 1.3 1994/03/05 00:35:39 cgd Exp $";
|
||||
Lst
|
||||
Lst_Duplicate (l, copyProc)
|
||||
Lst l; /* the list to duplicate */
|
||||
ClientData (*copyProc)(); /* A function to duplicate each ClientData */
|
||||
/* A function to duplicate each ClientData */
|
||||
ClientData (*copyProc) __P((ClientData));
|
||||
{
|
||||
register Lst nl;
|
||||
register ListNode ln;
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstFind.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstFind.c,v 1.3 1994/03/05 00:35:41 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstFind.c,v 1.4 1994/06/06 22:46:01 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -64,7 +64,7 @@ LstNode
|
||||
Lst_Find (l, d, cProc)
|
||||
Lst l;
|
||||
ClientData d;
|
||||
int (*cProc)();
|
||||
int (*cProc) __P((ClientData, ClientData));
|
||||
{
|
||||
return (Lst_FindFrom (l, Lst_First(l), d, cProc));
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstFindFrom.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstFindFrom.c,v 1.3 1994/03/05 00:35:42 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstFindFrom.c,v 1.4 1994/06/06 22:46:02 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -66,7 +66,7 @@ Lst_FindFrom (l, ln, d, cProc)
|
||||
Lst l;
|
||||
register LstNode ln;
|
||||
register ClientData d;
|
||||
register int (*cProc)();
|
||||
register int (*cProc) __P((ClientData, ClientData));
|
||||
{
|
||||
register ListNode tln;
|
||||
Boolean found = FALSE;
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)lstForEach.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: lstForEach.c,v 1.3 1994/03/05 00:35:44 cgd Exp $";
|
||||
static char *rcsid = "$Id: lstForEach.c,v 1.4 1994/06/06 22:46:03 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -65,7 +65,7 @@ static char *rcsid = "$Id: lstForEach.c,v 1.3 1994/03/05 00:35:44 cgd Exp $";
|
||||
void
|
||||
Lst_ForEach (l, proc, d)
|
||||
Lst l;
|
||||
register int (*proc)();
|
||||
register int (*proc) __P((ClientData, ClientData));
|
||||
register ClientData d;
|
||||
{
|
||||
Lst_ForEachFrom(l, Lst_First(l), proc, d);
|
||||
|
@ -44,7 +44,7 @@ char copyright[] =
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91"; */
|
||||
static char *rcsid = "$Id: main.c,v 1.13 1994/03/05 00:34:53 cgd Exp $";
|
||||
static char *rcsid = "$Id: main.c,v 1.14 1994/06/06 22:45:33 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -309,7 +309,7 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
|
||||
optind = 1; /* - */
|
||||
goto rearg;
|
||||
}
|
||||
(void)Lst_AtEnd(create, (ClientData)*argv);
|
||||
(void)Lst_AtEnd(create, (ClientData)strdup(*argv));
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,6 +334,7 @@ Main_ParseArgLine(line)
|
||||
{
|
||||
char **argv; /* Manufactured argument vector */
|
||||
int argc; /* Number of arguments in argv */
|
||||
char *p1;
|
||||
|
||||
if (line == NULL)
|
||||
return;
|
||||
@ -371,7 +372,7 @@ main(argc, argv)
|
||||
Lst targs; /* target nodes to create -- passed to Make_Init */
|
||||
Boolean outOfDate = TRUE; /* FALSE if all targets up to date */
|
||||
struct stat sb, sa;
|
||||
char *p, *path, *pwd, *getenv(), *getwd();
|
||||
char *p, *p1, *path, *pwd, *getenv(), *getwd();
|
||||
char mdpath[MAXPATHLEN + 1];
|
||||
char obpath[MAXPATHLEN + 1];
|
||||
char cdpath[MAXPATHLEN + 1];
|
||||
@ -488,6 +489,7 @@ main(argc, argv)
|
||||
* directories */
|
||||
Var_Init(); /* As well as the lists of variables for
|
||||
* parsing arguments */
|
||||
str_init();
|
||||
if (objdir != curdir)
|
||||
Dir_AddDir(dirSearchPath, curdir);
|
||||
Var_Set(".CURDIR", curdir, VAR_GLOBAL);
|
||||
@ -569,15 +571,19 @@ main(argc, argv)
|
||||
|
||||
(void)ReadMakefile(".depend");
|
||||
|
||||
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL), VAR_GLOBAL);
|
||||
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
|
||||
if (p1)
|
||||
free(p1);
|
||||
|
||||
/* Install all the flags into the MAKE envariable. */
|
||||
if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL)) != NULL) && *p)
|
||||
if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p)
|
||||
#ifdef POSIX
|
||||
setenv("MAKEFLAGS", p, 1);
|
||||
#else
|
||||
setenv("MAKE", p, 1);
|
||||
#endif
|
||||
if (p1)
|
||||
free(p1);
|
||||
|
||||
/*
|
||||
* For compatibility, look at the directories in the VPATH variable
|
||||
@ -658,10 +664,22 @@ main(argc, argv)
|
||||
*/
|
||||
Compat_Run(targs);
|
||||
|
||||
Lst_Destroy(targs, NOFREE);
|
||||
Lst_Destroy(makefiles, NOFREE);
|
||||
Lst_Destroy(create, (void (*) __P((ClientData))) free);
|
||||
|
||||
/* print the graph now it's been processed if the user requested it */
|
||||
if (DEBUG(GRAPH2))
|
||||
Targ_PrintGraph(2);
|
||||
|
||||
Suff_End();
|
||||
Targ_End();
|
||||
Arch_End();
|
||||
str_end();
|
||||
Var_End();
|
||||
Parse_End();
|
||||
Dir_End();
|
||||
|
||||
if (queryFlag && outOfDate)
|
||||
return(1);
|
||||
else
|
||||
@ -878,11 +896,11 @@ Finish(errors)
|
||||
*/
|
||||
char *
|
||||
emalloc(len)
|
||||
u_int len;
|
||||
size_t len;
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (!(p = malloc(len)))
|
||||
if ((p = (char *) malloc(len)) == NULL)
|
||||
enomem();
|
||||
return(p);
|
||||
}
|
||||
@ -910,3 +928,13 @@ usage()
|
||||
[-I directory] [-j max_jobs] [variable=value]\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
PrintAddr(a, b)
|
||||
ClientData a;
|
||||
ClientData b;
|
||||
{
|
||||
printf("%lx ", (unsigned long) a);
|
||||
return b ? 0 : 0;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)make.c 5.3 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: make.c,v 1.4 1994/03/05 00:34:58 cgd Exp $";
|
||||
static char *rcsid = "$Id: make.c,v 1.5 1994/06/06 22:45:34 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -87,10 +87,12 @@ static int numNodes; /* Number of nodes to be processed. If this
|
||||
* is non-zero when Job_Empty() returns
|
||||
* TRUE, there's a cycle in the graph */
|
||||
|
||||
static int MakeAddChild __P((GNode *, Lst));
|
||||
static int MakeAddAllSrc __P((GNode *, GNode *));
|
||||
static int MakeAddChild __P((ClientData, ClientData));
|
||||
static int MakeAddAllSrc __P((ClientData, ClientData));
|
||||
static int MakeTimeStamp __P((ClientData, ClientData));
|
||||
static int MakeHandleUse __P((ClientData, ClientData));
|
||||
static Boolean MakeStartJobs __P((void));
|
||||
static int MakePrintStatus __P((GNode *, Boolean));
|
||||
static int MakePrintStatus __P((ClientData, ClientData));
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Make_TimeStamp --
|
||||
@ -107,14 +109,22 @@ static int MakePrintStatus __P((GNode *, Boolean));
|
||||
*/
|
||||
int
|
||||
Make_TimeStamp (pgn, cgn)
|
||||
register GNode *pgn; /* the current parent */
|
||||
register GNode *cgn; /* the child we've just examined */
|
||||
GNode *pgn; /* the current parent */
|
||||
GNode *cgn; /* the child we've just examined */
|
||||
{
|
||||
if (cgn->mtime > pgn->cmtime) {
|
||||
pgn->cmtime = cgn->mtime;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
MakeTimeStamp (pgn, cgn)
|
||||
ClientData pgn; /* the current parent */
|
||||
ClientData cgn; /* the child we've just examined */
|
||||
{
|
||||
return Make_TimeStamp((GNode *) pgn, (GNode *) cgn);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
@ -246,7 +256,7 @@ Make_OODate (gn)
|
||||
* thinking they're out-of-date.
|
||||
*/
|
||||
if (!oodate) {
|
||||
Lst_ForEach (gn->parents, Make_TimeStamp, (ClientData)gn);
|
||||
Lst_ForEach (gn->parents, MakeTimeStamp, (ClientData)gn);
|
||||
}
|
||||
|
||||
return (oodate);
|
||||
@ -266,10 +276,12 @@ Make_OODate (gn)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
MakeAddChild (gn, l)
|
||||
GNode *gn; /* the node to add */
|
||||
Lst l; /* the list to which to add it */
|
||||
MakeAddChild (gnp, lp)
|
||||
ClientData gnp; /* the node to add */
|
||||
ClientData lp; /* the list to which to add it */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
Lst l = (Lst) lp;
|
||||
if (!gn->make && !(gn->type & OP_USE)) {
|
||||
(void)Lst_EnQueue (l, (ClientData)gn);
|
||||
}
|
||||
@ -344,6 +356,13 @@ Make_HandleUse (cgn, pgn)
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
static int
|
||||
MakeHandleUse (pgn, cgn)
|
||||
ClientData pgn; /* the current parent */
|
||||
ClientData cgn; /* the child we've just examined */
|
||||
{
|
||||
return Make_HandleUse((GNode *) pgn, (GNode *) cgn);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
@ -377,8 +396,11 @@ Make_Update (cgn)
|
||||
register GNode *pgn; /* the parent node */
|
||||
register char *cname; /* the child's name */
|
||||
register LstNode ln; /* Element in parents and iParents lists */
|
||||
char *p1;
|
||||
|
||||
cname = Var_Value (TARGET, cgn);
|
||||
cname = Var_Value (TARGET, cgn, &p1);
|
||||
if (p1)
|
||||
free(p1);
|
||||
|
||||
/*
|
||||
* If the child was actually made, see what its modification time is
|
||||
@ -497,7 +519,8 @@ Make_Update (cgn)
|
||||
* of this node.
|
||||
*/
|
||||
if (Lst_Open (cgn->iParents) == SUCCESS) {
|
||||
char *cpref = Var_Value(PREFIX, cgn);
|
||||
char *p1;
|
||||
char *cpref = Var_Value(PREFIX, cgn, &p1);
|
||||
|
||||
while ((ln = Lst_Next (cgn->iParents)) != NILLNODE) {
|
||||
pgn = (GNode *)Lst_Datum (ln);
|
||||
@ -506,6 +529,8 @@ Make_Update (cgn)
|
||||
Var_Set (PREFIX, cpref, pgn);
|
||||
}
|
||||
}
|
||||
if (p1)
|
||||
free(p1);
|
||||
Lst_Close (cgn->iParents);
|
||||
}
|
||||
}
|
||||
@ -531,15 +556,18 @@ Make_Update (cgn)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
MakeAddAllSrc (cgn, pgn)
|
||||
GNode *cgn; /* The child to add */
|
||||
GNode *pgn; /* The parent to whose ALLSRC variable it should be */
|
||||
MakeAddAllSrc (cgnp, pgnp)
|
||||
ClientData cgnp; /* The child to add */
|
||||
ClientData pgnp; /* The parent to whose ALLSRC variable it should be */
|
||||
/* added */
|
||||
{
|
||||
GNode *cgn = (GNode *) cgnp;
|
||||
GNode *pgn = (GNode *) pgnp;
|
||||
if ((cgn->type & (OP_EXEC|OP_USE|OP_INVISIBLE)) == 0) {
|
||||
register char *child;
|
||||
char *child;
|
||||
char *p1;
|
||||
|
||||
child = Var_Value(TARGET, cgn);
|
||||
child = Var_Value(TARGET, cgn, &p1);
|
||||
Var_Append (ALLSRC, child, pgn);
|
||||
if (pgn->type & OP_JOIN) {
|
||||
if (cgn->made == MADE) {
|
||||
@ -566,6 +594,8 @@ MakeAddAllSrc (cgn, pgn)
|
||||
*/
|
||||
Var_Append(OODATE, child, pgn);
|
||||
}
|
||||
if (p1)
|
||||
free(p1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@ -596,7 +626,7 @@ void
|
||||
Make_DoAllVar (gn)
|
||||
GNode *gn;
|
||||
{
|
||||
Lst_ForEach (gn->children, MakeAddAllSrc, gn);
|
||||
Lst_ForEach (gn->children, MakeAddAllSrc, (ClientData) gn);
|
||||
|
||||
if (!Var_Exists (OODATE, gn)) {
|
||||
Var_Set (OODATE, "", gn);
|
||||
@ -606,7 +636,10 @@ Make_DoAllVar (gn)
|
||||
}
|
||||
|
||||
if (gn->type & OP_JOIN) {
|
||||
Var_Set (TARGET, Var_Value (ALLSRC, gn), gn);
|
||||
char *p1;
|
||||
Var_Set (TARGET, Var_Value (ALLSRC, gn, &p1), gn);
|
||||
if (p1)
|
||||
free(p1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -711,16 +744,19 @@ MakeStartJobs ()
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
MakePrintStatus(gn, cycle)
|
||||
GNode *gn; /* Node to examine */
|
||||
Boolean cycle; /* True if gn->unmade being non-zero implies
|
||||
MakePrintStatus(gnp, cyclep)
|
||||
ClientData gnp; /* Node to examine */
|
||||
ClientData cyclep; /* True if gn->unmade being non-zero implies
|
||||
* a cycle in the graph, not an error in an
|
||||
* inferior */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
Boolean cycle = *(Boolean *) cyclep;
|
||||
if (gn->made == UPTODATE) {
|
||||
printf ("`%s' is up to date.\n", gn->name);
|
||||
} else if (gn->unmade != 0) {
|
||||
if (cycle) {
|
||||
Boolean t = TRUE;
|
||||
/*
|
||||
* If printing cycles and came to one that has unmade children,
|
||||
* print out the cycle by recursing on its children. Note a
|
||||
@ -734,11 +770,11 @@ MakePrintStatus(gn, cycle)
|
||||
if (gn->made == CYCLE) {
|
||||
Error("Graph cycles through `%s'", gn->name);
|
||||
gn->made = ENDCYCLE;
|
||||
Lst_ForEach(gn->children, MakePrintStatus, (ClientData)TRUE);
|
||||
Lst_ForEach(gn->children, MakePrintStatus, (ClientData) &t);
|
||||
gn->made = UNMADE;
|
||||
} else if (gn->made != ENDCYCLE) {
|
||||
gn->made = CYCLE;
|
||||
Lst_ForEach(gn->children, MakePrintStatus, (ClientData)TRUE);
|
||||
Lst_ForEach(gn->children, MakePrintStatus, (ClientData) &t);
|
||||
}
|
||||
} else {
|
||||
printf ("`%s' not remade because of errors.\n", gn->name);
|
||||
@ -800,7 +836,7 @@ Make_Run (targs)
|
||||
* Apply any .USE rules before looking for implicit dependencies
|
||||
* to make sure everything has commands that should...
|
||||
*/
|
||||
Lst_ForEach (gn->children, Make_HandleUse, (ClientData)gn);
|
||||
Lst_ForEach (gn->children, MakeHandleUse, (ClientData)gn);
|
||||
Suff_FindDeps (gn);
|
||||
|
||||
if (gn->unmade != 0) {
|
||||
@ -853,8 +889,8 @@ Make_Run (targs)
|
||||
* Print the final status of each target. E.g. if it wasn't made
|
||||
* because some inferior reported an error.
|
||||
*/
|
||||
Lst_ForEach(targs, MakePrintStatus,
|
||||
(ClientData)((errors == 0) && (numNodes != 0)));
|
||||
errors = ((errors == 0) && (numNodes != 0));
|
||||
Lst_ForEach(targs, MakePrintStatus, (ClientData) &errors);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)nonints.h 5.6 (Berkeley) 4/18/91
|
||||
* $Id: nonints.h,v 1.3 1994/03/05 00:35:02 cgd Exp $
|
||||
* $Id: nonints.h,v 1.4 1994/06/06 22:45:37 jtc Exp $
|
||||
*/
|
||||
|
||||
/* arch.c */
|
||||
@ -48,6 +48,7 @@ int Arch_MemMTime __P((GNode *));
|
||||
void Arch_FindLib __P((GNode *, Lst));
|
||||
Boolean Arch_LibOODate __P((GNode *));
|
||||
void Arch_Init __P((void));
|
||||
void Arch_End __P((void));
|
||||
|
||||
/* compat.c */
|
||||
void Compat_Run __P((Lst));
|
||||
@ -67,8 +68,9 @@ void Error __P((char *, ...));
|
||||
void Fatal __P((char *, ...));
|
||||
void Punt __P((char *, ...));
|
||||
void DieHorribly __P((void));
|
||||
int PrintAddr __P((ClientData, ClientData));
|
||||
void Finish __P((int));
|
||||
char *emalloc __P((u_int));
|
||||
char *emalloc __P((size_t));
|
||||
void enomem __P((void));
|
||||
|
||||
/* parse.c */
|
||||
@ -79,10 +81,13 @@ void Parse_DoVar __P((char *, GNode *));
|
||||
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 *));
|
||||
Lst Parse_MainName __P((void));
|
||||
|
||||
/* str.c */
|
||||
void str_init __P((void));
|
||||
void str_end __P((void));
|
||||
char *str_concat __P((char *, char *, int));
|
||||
char **brk_string __P((char *, int *));
|
||||
char *Str_FindSubstring __P((char *, char *));
|
||||
@ -94,7 +99,7 @@ void Str_SYSVSubst __P((Buffer, char *, char *, int));
|
||||
void Suff_ClearSuffixes __P((void));
|
||||
Boolean Suff_IsTransform __P((char *));
|
||||
GNode *Suff_AddTransform __P((char *));
|
||||
int Suff_EndTransform __P((GNode *));
|
||||
int Suff_EndTransform __P((ClientData, ClientData));
|
||||
void Suff_AddSuffix __P((char *));
|
||||
Lst Suff_GetPath __P((char *));
|
||||
void Suff_DoPaths __P((void));
|
||||
@ -103,10 +108,12 @@ void Suff_AddLib __P((char *));
|
||||
void Suff_FindDeps __P((GNode *));
|
||||
void Suff_SetNull __P((char *));
|
||||
void Suff_Init __P((void));
|
||||
void Suff_End __P((void));
|
||||
void Suff_PrintAll __P((void));
|
||||
|
||||
/* targ.c */
|
||||
void Targ_Init __P((void));
|
||||
void Targ_End __P((void));
|
||||
GNode *Targ_NewGN __P((char *));
|
||||
GNode *Targ_FindNode __P((char *, int));
|
||||
Lst Targ_FindList __P((Lst, int));
|
||||
@ -114,7 +121,7 @@ Boolean Targ_Ignore __P((GNode *));
|
||||
Boolean Targ_Silent __P((GNode *));
|
||||
Boolean Targ_Precious __P((GNode *));
|
||||
void Targ_SetMain __P((GNode *));
|
||||
int Targ_PrintCmd __P((char *));
|
||||
int Targ_PrintCmd __P((ClientData, ClientData));
|
||||
char *Targ_FmtTime __P((time_t));
|
||||
void Targ_PrintType __P((int));
|
||||
void Targ_PrintGraph __P((int));
|
||||
@ -124,10 +131,11 @@ void Var_Delete __P((char *, GNode *));
|
||||
void Var_Set __P((char *, char *, GNode *));
|
||||
void Var_Append __P((char *, char *, GNode *));
|
||||
Boolean Var_Exists __P((char *, GNode *));
|
||||
char *Var_Value __P((char *, GNode *));
|
||||
char *Var_Value __P((char *, GNode *, char **));
|
||||
char *Var_Parse __P((char *, GNode *, Boolean, int *, Boolean *));
|
||||
char *Var_Subst __P((char *, char *, GNode *, Boolean));
|
||||
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 *));
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)parse.c 5.18 (Berkeley) 2/19/91"; */
|
||||
static char *rcsid = "$Id: parse.c,v 1.8 1994/05/21 16:36:01 jtc Exp $";
|
||||
static char *rcsid = "$Id: parse.c,v 1.9 1994/06/06 22:45:39 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -64,6 +64,8 @@ static char *rcsid = "$Id: parse.c,v 1.8 1994/05/21 16:36:01 jtc Exp $";
|
||||
* called before anything else in this module
|
||||
* is used.
|
||||
*
|
||||
* Parse_End Cleanup the module
|
||||
*
|
||||
* Parse_File Function used to parse a makefile. It must
|
||||
* be given the name of the file, which should
|
||||
* already have been opened, and a function
|
||||
@ -105,6 +107,7 @@ static char *rcsid = "$Id: parse.c,v 1.8 1994/05/21 16:36:01 jtc Exp $";
|
||||
#define CONTINUE 1
|
||||
#define DONE 0
|
||||
static Lst targets; /* targets we're working on */
|
||||
static Lst targCmds; /* command lines for targets */
|
||||
static Boolean inLine; /* true if currently in a dependency
|
||||
* line or its commands */
|
||||
typedef struct {
|
||||
@ -219,17 +222,17 @@ static struct {
|
||||
};
|
||||
|
||||
static int ParseFindKeyword __P((char *));
|
||||
static int ParseLinkSrc __P((GNode *, GNode *));
|
||||
static int ParseDoOp __P((GNode *, int));
|
||||
static int ParseLinkSrc __P((ClientData, ClientData));
|
||||
static int ParseDoOp __P((ClientData, ClientData));
|
||||
static void ParseDoSrc __P((int, char *));
|
||||
static int ParseFindMain __P((GNode *));
|
||||
static int ParseAddDir __P((Lst, char *));
|
||||
static int ParseClearPath __P((Lst));
|
||||
static int ParseFindMain __P((ClientData, ClientData));
|
||||
static int ParseAddDir __P((ClientData, ClientData));
|
||||
static int ParseClearPath __P((ClientData, ClientData));
|
||||
static void ParseDoDependency __P((char *));
|
||||
static int ParseAddCmd __P((GNode *, char *));
|
||||
static int ParseAddCmd __P((ClientData, ClientData));
|
||||
static int ParseReadc __P((void));
|
||||
static void ParseUnreadc __P((int));
|
||||
static int ParseHasCommands __P((GNode *));
|
||||
static void ParseHasCommands __P((ClientData));
|
||||
static void ParseDoInclude __P((char *));
|
||||
#ifdef SYSVINCLUDE
|
||||
static void ParseTraditionalInclude __P((char *));
|
||||
@ -339,10 +342,12 @@ Parse_Error(va_alist)
|
||||
*---------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ParseLinkSrc (pgn, cgn)
|
||||
GNode *pgn; /* The parent node */
|
||||
GNode *cgn; /* The child node */
|
||||
ParseLinkSrc (pgnp, cgnp)
|
||||
ClientData pgnp; /* The parent node */
|
||||
ClientData cgnp; /* The child node */
|
||||
{
|
||||
GNode *pgn = (GNode *) pgnp;
|
||||
GNode *cgn = (GNode *) cgnp;
|
||||
if (Lst_Member (pgn->children, (ClientData)cgn) == NILLNODE) {
|
||||
(void)Lst_AtEnd (pgn->children, (ClientData)cgn);
|
||||
if (specType == Not) {
|
||||
@ -370,11 +375,13 @@ ParseLinkSrc (pgn, cgn)
|
||||
*---------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ParseDoOp (gn, op)
|
||||
GNode *gn; /* The node to which the operator is to be
|
||||
ParseDoOp (gnp, opp)
|
||||
ClientData gnp; /* The node to which the operator is to be
|
||||
* applied */
|
||||
int op; /* The operator to apply */
|
||||
ClientData opp; /* The operator to apply */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
int op = *(int *) opp;
|
||||
/*
|
||||
* If the dependency mask of the operator and the node don't match and
|
||||
* the node has actually had an operator applied to it before, and
|
||||
@ -462,7 +469,7 @@ ParseDoSrc (tOp, src)
|
||||
}
|
||||
}
|
||||
if (op != 0) {
|
||||
Lst_ForEach (targets, ParseDoOp, (ClientData)op);
|
||||
Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
|
||||
} else if (specType == Main) {
|
||||
/*
|
||||
* If we have noted the existence of a .MAIN, it means we need
|
||||
@ -542,15 +549,17 @@ ParseDoSrc (tOp, src)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ParseFindMain(gn)
|
||||
GNode *gn; /* Node to examine */
|
||||
ParseFindMain(gnp, dummy)
|
||||
ClientData gnp; /* Node to examine */
|
||||
ClientData dummy;
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
if ((gn->type & (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)) == 0) {
|
||||
mainNode = gn;
|
||||
Targ_SetMain(gn);
|
||||
return (1);
|
||||
return (dummy ? 1 : 1);
|
||||
} else {
|
||||
return (0);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,10 +578,10 @@ ParseFindMain(gn)
|
||||
*/
|
||||
static int
|
||||
ParseAddDir(path, name)
|
||||
Lst path;
|
||||
char *name;
|
||||
ClientData path;
|
||||
ClientData name;
|
||||
{
|
||||
Dir_AddDir(path, name);
|
||||
Dir_AddDir((Lst) path, (char *) name);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -590,11 +599,12 @@ ParseAddDir(path, name)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ParseClearPath(path)
|
||||
Lst path;
|
||||
ParseClearPath(path, dummy)
|
||||
ClientData path;
|
||||
ClientData dummy;
|
||||
{
|
||||
Dir_ClearPath(path);
|
||||
return(0);
|
||||
Dir_ClearPath((Lst) path);
|
||||
return(dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -635,9 +645,9 @@ static void
|
||||
ParseDoDependency (line)
|
||||
char *line; /* the line to parse */
|
||||
{
|
||||
register char *cp; /* our current position */
|
||||
register GNode *gn; /* a general purpose temporary node */
|
||||
register int op; /* the operator on the line */
|
||||
char *cp; /* our current position */
|
||||
GNode *gn; /* a general purpose temporary node */
|
||||
int op; /* the operator on the line */
|
||||
char savec; /* a place to save a character */
|
||||
Lst paths; /* List of search paths to alter when parsing
|
||||
* a list of .PATH targets */
|
||||
@ -932,7 +942,7 @@ ParseDoDependency (line)
|
||||
|
||||
cp++; /* Advance beyond operator */
|
||||
|
||||
Lst_ForEach (targets, ParseDoOp, (ClientData)op);
|
||||
Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
|
||||
|
||||
/*
|
||||
* Get to the first source
|
||||
@ -1404,7 +1414,7 @@ Parse_DoVar (line, ctxt)
|
||||
char result[BUFSIZ];
|
||||
cc = read(fds[0], result, sizeof(result));
|
||||
if (cc > 0)
|
||||
Buf_AddBytes(buf, cc, (unsigned char *) result);
|
||||
Buf_AddBytes(buf, cc, (Byte *) result);
|
||||
}
|
||||
while (cc > 0 || (cc == -1 && errno == EINTR));
|
||||
|
||||
@ -1483,14 +1493,15 @@ Parse_DoVar (line, ctxt)
|
||||
* A new element is added to the commands list of the node.
|
||||
*/
|
||||
static int
|
||||
ParseAddCmd(gn, cmd)
|
||||
GNode *gn; /* the node to which the command is to be added */
|
||||
char *cmd; /* the command to add */
|
||||
ParseAddCmd(gnp, cmd)
|
||||
ClientData gnp; /* the node to which the command is to be added */
|
||||
ClientData cmd; /* the command to add */
|
||||
{
|
||||
/* if target already supplied, ignore commands */
|
||||
if (!(gn->type & OP_HAS_COMMANDS))
|
||||
(void)Lst_AtEnd(gn->commands, (ClientData)cmd);
|
||||
return(0);
|
||||
GNode *gn = (GNode *) gnp;
|
||||
/* if target already supplied, ignore commands */
|
||||
if (!(gn->type & OP_HAS_COMMANDS))
|
||||
(void)Lst_AtEnd(gn->commands, cmd);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -1502,21 +1513,21 @@ ParseAddCmd(gn, cmd)
|
||||
* on multiple dependency lines.
|
||||
*
|
||||
* Results:
|
||||
* Always 0.
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* OP_HAS_COMMANDS may be set for the target.
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
ParseHasCommands(gn)
|
||||
GNode *gn; /* Node to examine */
|
||||
static void
|
||||
ParseHasCommands(gnp)
|
||||
ClientData gnp; /* Node to examine */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
if (!Lst_IsEmpty(gn->commands)) {
|
||||
gn->type |= OP_HAS_COMMANDS;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -1635,7 +1646,10 @@ ParseDoInclude (file)
|
||||
char *newName;
|
||||
|
||||
*prefEnd = '\0';
|
||||
newName = str_concat (fname, file, STR_ADDSLASH);
|
||||
if (file[0] == '/')
|
||||
newName = strdup(file);
|
||||
else
|
||||
newName = str_concat (fname, file, STR_ADDSLASH);
|
||||
fullname = Dir_FindFile (newName, parseIncPath);
|
||||
if (fullname == (char *)NULL) {
|
||||
fullname = Dir_FindFile(newName, dirSearchPath);
|
||||
@ -1676,6 +1690,8 @@ ParseDoInclude (file)
|
||||
return;
|
||||
}
|
||||
|
||||
free(file);
|
||||
|
||||
/*
|
||||
* Once we find the absolute path to the file, we get to save all the
|
||||
* state from the current file before we can start reading this
|
||||
@ -2073,7 +2089,7 @@ ParseReadLine ()
|
||||
* for the purposes of setting semiNL */
|
||||
Boolean ignComment; /* TRUE if should ignore comments (in a
|
||||
* shell command */
|
||||
char *line; /* Result */
|
||||
char *line; /* Result */
|
||||
int lineLength; /* Length of result */
|
||||
|
||||
semiNL = FALSE;
|
||||
@ -2304,11 +2320,10 @@ test_char:
|
||||
static void
|
||||
ParseFinishLine()
|
||||
{
|
||||
extern int Suff_EndTransform();
|
||||
|
||||
if (inLine) {
|
||||
Lst_ForEach(targets, Suff_EndTransform, (ClientData)NULL);
|
||||
Lst_Destroy (targets, ParseHasCommands);
|
||||
targets = NULL;
|
||||
inLine = FALSE;
|
||||
}
|
||||
}
|
||||
@ -2358,11 +2373,12 @@ Parse_File(name, stream)
|
||||
goto nextLine;
|
||||
} else if (strncmp(cp, "undef", 5) == 0) {
|
||||
char *cp2;
|
||||
for (cp += 5; isspace(*cp); cp++) {
|
||||
for (cp += 5; isspace((unsigned char) *cp); cp++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (cp2 = cp; !isspace(*cp2) && (*cp2 != '\0'); cp2++) {
|
||||
for (cp2 = cp; !isspace((unsigned char) *cp2) &&
|
||||
(*cp2 != '\0'); cp2++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2395,7 +2411,8 @@ Parse_File(name, stream)
|
||||
* in a dependency spec, add the command to the list of
|
||||
* commands of all targets in the dependency spec
|
||||
*/
|
||||
Lst_ForEach (targets, ParseAddCmd, (ClientData)cp);
|
||||
Lst_ForEach (targets, ParseAddCmd, cp);
|
||||
Lst_AtEnd(targCmds, (ClientData) line);
|
||||
continue;
|
||||
} else {
|
||||
Parse_Error (PARSE_FATAL,
|
||||
@ -2438,7 +2455,7 @@ Parse_File(name, stream)
|
||||
#ifndef POSIX
|
||||
if (line[0] == ' ') {
|
||||
while ((*cp != ':') && (*cp != '!') && (*cp != '\0')) {
|
||||
if (!isspace(*cp)) {
|
||||
if (!isspace((unsigned char) *cp)) {
|
||||
nonSpace = TRUE;
|
||||
}
|
||||
cp++;
|
||||
@ -2464,6 +2481,9 @@ Parse_File(name, stream)
|
||||
/*
|
||||
* Need a non-circular list for the target nodes
|
||||
*/
|
||||
if (targets)
|
||||
Lst_Destroy(targets, NOFREE);
|
||||
|
||||
targets = Lst_Init (FALSE);
|
||||
inLine = TRUE;
|
||||
|
||||
@ -2516,6 +2536,7 @@ Parse_Init ()
|
||||
parseIncPath = Lst_Init (FALSE);
|
||||
sysIncPath = Lst_Init (FALSE);
|
||||
includes = Lst_Init (FALSE);
|
||||
targCmds = Lst_Init (FALSE);
|
||||
|
||||
/*
|
||||
* Add the directories from the DEFSYSPATH (more than one may be given
|
||||
@ -2533,6 +2554,18 @@ Parse_Init ()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Parse_End()
|
||||
{
|
||||
Lst_Destroy(targCmds, (void (*) __P((ClientData))) free);
|
||||
if (targets)
|
||||
Lst_Destroy(targets, NOFREE);
|
||||
Lst_Destroy(sysIncPath, Dir_Destroy);
|
||||
Lst_Destroy(parseIncPath, Dir_Destroy);
|
||||
Lst_Destroy(includes, NOFREE); /* Should be empty now */
|
||||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Parse_MainName --
|
||||
|
@ -36,7 +36,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)sprite.h 5.3 (Berkeley) 6/1/90
|
||||
* $Id: sprite.h,v 1.3 1994/03/05 00:35:07 cgd Exp $
|
||||
* $Id: sprite.h,v 1.4 1994/06/06 22:45:41 jtc Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -104,12 +104,9 @@ typedef char *Address;
|
||||
* ClientData is an uninterpreted word. It is defined as an int so that
|
||||
* kdbx will not interpret client data as a string. Unlike an "Address",
|
||||
* client data will generally not be used in arithmetic.
|
||||
* But we don't have kdbx anymore so we define it as void (christos)
|
||||
*/
|
||||
|
||||
typedef int *ClientData;
|
||||
typedef void *ClientData;
|
||||
|
||||
#ifdef notdef
|
||||
#include "status.h"
|
||||
#endif
|
||||
|
||||
#endif _SPRITE
|
||||
#endif /* _SPRITE */
|
||||
|
@ -38,11 +38,42 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: str.c,v 1.6 1994/05/17 15:55:42 jtc Exp $";
|
||||
static char *rcsid = "$Id: str.c,v 1.7 1994/06/06 22:45:43 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "make.h"
|
||||
|
||||
static char **argv, *buffer;
|
||||
static int argmax, curlen;
|
||||
|
||||
/*
|
||||
* str_init --
|
||||
* Initialize the strings package
|
||||
*
|
||||
*/
|
||||
void
|
||||
str_init()
|
||||
{
|
||||
char *p1;
|
||||
argv = (char **)emalloc((argmax = 50) * sizeof(char *));
|
||||
argv[0] = Var_Value(".MAKE", VAR_GLOBAL, &p1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* str_end --
|
||||
* Cleanup the strings package
|
||||
*
|
||||
*/
|
||||
void
|
||||
str_end()
|
||||
{
|
||||
free(argv[0]);
|
||||
free((Address) argv);
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
/*-
|
||||
* str_concat --
|
||||
* concatenate the two strings, inserting a space or slash between them,
|
||||
@ -104,25 +135,20 @@ brk_string(str, store_argc)
|
||||
register char *str;
|
||||
int *store_argc;
|
||||
{
|
||||
static int argmax, curlen;
|
||||
static char **argv, *buf;
|
||||
register int argc, ch;
|
||||
register char inquote, *p, *start, *t;
|
||||
int len;
|
||||
|
||||
/* save off pmake variable */
|
||||
if (!argv) {
|
||||
argv = (char **)emalloc((argmax = 50) * sizeof(char *));
|
||||
argv[0] = Var_Value(".MAKE", VAR_GLOBAL);
|
||||
}
|
||||
|
||||
/* skip leading space chars. */
|
||||
for (; *str == ' ' || *str == '\t'; ++str)
|
||||
continue;
|
||||
|
||||
/* allocate room for a copy of the string */
|
||||
if ((len = strlen(str) + 1) > curlen)
|
||||
buf = emalloc(curlen = len);
|
||||
if ((len = strlen(str) + 1) > curlen) {
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
buffer = emalloc(curlen = len);
|
||||
}
|
||||
|
||||
/*
|
||||
* copy the string; at the same time, parse backslashes,
|
||||
@ -130,7 +156,7 @@ brk_string(str, store_argc)
|
||||
*/
|
||||
argc = 1;
|
||||
inquote = '\0';
|
||||
for (p = str, start = t = buf;; ++p) {
|
||||
for (p = str, start = t = buffer;; ++p) {
|
||||
switch(ch = *p) {
|
||||
case '"':
|
||||
case '\'':
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)suff.c 5.6 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: suff.c,v 1.5 1994/03/23 00:52:14 jtc Exp $";
|
||||
static char *rcsid = "$Id: suff.c,v 1.6 1994/06/06 22:45:44 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -49,6 +49,8 @@ static char *rcsid = "$Id: suff.c,v 1.5 1994/03/23 00:52:14 jtc Exp $";
|
||||
* Interface:
|
||||
* Suff_Init Initialize all things to do with suffixes.
|
||||
*
|
||||
* Suff_End Cleanup the module
|
||||
*
|
||||
* Suff_DoPaths This function is used to make life easier
|
||||
* when searching for a file according to its
|
||||
* suffix. It takes the global search path,
|
||||
@ -97,6 +99,8 @@ static char *rcsid = "$Id: suff.c,v 1.5 1994/03/23 00:52:14 jtc Exp $";
|
||||
#include "bit.h"
|
||||
|
||||
static Lst sufflist; /* Lst of suffixes */
|
||||
static Lst suffClean; /* Lst of suffixes to be cleaned */
|
||||
static Lst srclist; /* Lst of sources */
|
||||
static Lst transforms; /* Lst of transformation rules */
|
||||
|
||||
static int sNum = 0; /* Counter for assigning suffix numbers */
|
||||
@ -114,8 +118,10 @@ typedef struct _Suff {
|
||||
Lst searchPath; /* The path along which files of this suffix
|
||||
* may be found */
|
||||
int sNum; /* The suffix number */
|
||||
int refCount; /* Reference count of list membership */
|
||||
Lst parents; /* Suffixes we have a transformation to */
|
||||
Lst children; /* Suffixes we have a transformation from */
|
||||
Lst ref; /* List of lists this suffix is referenced */
|
||||
} Suff;
|
||||
|
||||
/*
|
||||
@ -129,6 +135,9 @@ typedef struct _Src {
|
||||
GNode *node; /* The node describing the file */
|
||||
int children; /* Count of existing children (so we don't free
|
||||
* this thing too early or never nuke it) */
|
||||
#ifdef DEBUG_SRC
|
||||
Lst cp; /* Debug; children list */
|
||||
#endif
|
||||
} Src;
|
||||
|
||||
/*
|
||||
@ -147,27 +156,28 @@ static Suff *emptySuff; /* The empty suffix required for POSIX
|
||||
|
||||
static char *SuffStrIsPrefix __P((char *, char *));
|
||||
static char *SuffSuffIsSuffix __P((Suff *, char *));
|
||||
static int SuffSuffIsSuffixP __P((Suff *, char *));
|
||||
static int SuffSuffHasNameP __P((Suff *, char *));
|
||||
static int SuffSuffIsPrefix __P((Suff *, char *));
|
||||
static int SuffGNHasNameP __P((GNode *, char *));
|
||||
static void SuffFree __P((Suff *));
|
||||
static Suff* SuffCopy __P((Suff *));
|
||||
static int SuffSuffIsSuffixP __P((ClientData, ClientData));
|
||||
static int SuffSuffHasNameP __P((ClientData, ClientData));
|
||||
static int SuffSuffIsPrefix __P((ClientData, ClientData));
|
||||
static int SuffGNHasNameP __P((ClientData, ClientData));
|
||||
static void SuffFree __P((ClientData));
|
||||
static void SuffInsert __P((Lst, Suff *));
|
||||
static void SuffRemove __P((Lst, Suff *));
|
||||
static Boolean SuffParseTransform __P((char *, Suff **, Suff **));
|
||||
static int SuffRebuildGraph __P((GNode *, Suff *));
|
||||
static int SuffAddSrc __P((Suff *, LstSrc *));
|
||||
static int SuffRebuildGraph __P((ClientData, ClientData));
|
||||
static int SuffAddSrc __P((ClientData, ClientData));
|
||||
static int SuffRemoveSrc __P((Lst));
|
||||
static void SuffAddLevel __P((Lst, Src *));
|
||||
static void SuffFreeSrc __P((Src *));
|
||||
static Src *SuffFindThem __P((Lst));
|
||||
static Src *SuffFindCmds __P((Src *));
|
||||
static int SuffExpandChildren __P((GNode *, GNode *));
|
||||
static Src *SuffFindThem __P((Lst, Lst));
|
||||
static Src *SuffFindCmds __P((Src *, Lst));
|
||||
static int SuffExpandChildren __P((ClientData, ClientData));
|
||||
static Boolean SuffApplyTransform __P((GNode *, GNode *, Suff *, Suff *));
|
||||
static void SuffFindArchiveDeps __P((GNode *));
|
||||
static void SuffFindNormalDeps __P((GNode *));
|
||||
static int SuffPrintName __P((Suff *));
|
||||
static int SuffPrintSuff __P((Suff *));
|
||||
static int SuffPrintTrans __P((GNode *));
|
||||
static void SuffFindDeps __P((GNode *, Lst));
|
||||
static void SuffFindArchiveDeps __P((GNode *, Lst));
|
||||
static void SuffFindNormalDeps __P((GNode *, Lst));
|
||||
static int SuffPrintName __P((ClientData, ClientData));
|
||||
static int SuffPrintSuff __P((ClientData, ClientData));
|
||||
static int SuffPrintTrans __P((ClientData, ClientData));
|
||||
|
||||
/*************** Lst Predicates ****************/
|
||||
/*-
|
||||
@ -244,10 +254,10 @@ SuffSuffIsSuffix (s, str)
|
||||
*/
|
||||
static int
|
||||
SuffSuffIsSuffixP(s, str)
|
||||
Suff *s;
|
||||
char *str;
|
||||
ClientData s;
|
||||
ClientData str;
|
||||
{
|
||||
return(!SuffSuffIsSuffix(s, str));
|
||||
return(!SuffSuffIsSuffix((Suff *) s, (char *) str));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -265,10 +275,10 @@ SuffSuffIsSuffixP(s, str)
|
||||
*/
|
||||
static int
|
||||
SuffSuffHasNameP (s, sname)
|
||||
Suff *s; /* Suffix to check */
|
||||
char *sname; /* Desired name */
|
||||
ClientData s; /* Suffix to check */
|
||||
ClientData sname; /* Desired name */
|
||||
{
|
||||
return (strcmp (sname, s->name));
|
||||
return (strcmp ((char *) sname, ((Suff *) s)->name));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -288,10 +298,10 @@ SuffSuffHasNameP (s, sname)
|
||||
*/
|
||||
static int
|
||||
SuffSuffIsPrefix (s, str)
|
||||
Suff *s; /* suffix to compare */
|
||||
char *str; /* string to examine */
|
||||
ClientData s; /* suffix to compare */
|
||||
ClientData str; /* string to examine */
|
||||
{
|
||||
return (SuffStrIsPrefix (s->name, str) == NULL ? 1 : 0);
|
||||
return (SuffStrIsPrefix (((Suff *) s)->name, (char *) str) == NULL ? 1 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -308,13 +318,28 @@ SuffSuffIsPrefix (s, str)
|
||||
*/
|
||||
static int
|
||||
SuffGNHasNameP (gn, name)
|
||||
GNode *gn; /* current node we're looking at */
|
||||
char *name; /* name we're looking for */
|
||||
ClientData gn; /* current node we're looking at */
|
||||
ClientData name; /* name we're looking for */
|
||||
{
|
||||
return (strcmp (name, gn->name));
|
||||
return (strcmp ((char *) name, ((GNode *) gn)->name));
|
||||
}
|
||||
|
||||
/*********** Maintenance Functions ************/
|
||||
|
||||
static void
|
||||
SuffUnRef(lp, sp)
|
||||
ClientData lp;
|
||||
ClientData sp;
|
||||
{
|
||||
Lst l = (Lst) lp;
|
||||
|
||||
LstNode ln = Lst_Member(l, sp);
|
||||
if (ln != NILLNODE) {
|
||||
Lst_Remove(l, ln);
|
||||
((Suff *) sp)->refCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* SuffFree --
|
||||
@ -328,16 +353,49 @@ SuffGNHasNameP (gn, name)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
SuffFree (s)
|
||||
Suff *s;
|
||||
SuffFree (sp)
|
||||
ClientData sp;
|
||||
{
|
||||
Suff *s = (Suff *) sp;
|
||||
|
||||
if (s == suffNull)
|
||||
suffNull = NULL;
|
||||
|
||||
if (s == emptySuff)
|
||||
emptySuff = NULL;
|
||||
|
||||
Lst_Destroy (s->ref, NOFREE);
|
||||
Lst_Destroy (s->children, NOFREE);
|
||||
Lst_Destroy (s->parents, NOFREE);
|
||||
Lst_Destroy (s->searchPath, Dir_Destroy);
|
||||
|
||||
free ((Address)s->name);
|
||||
free ((Address)s);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* SuffRemove --
|
||||
* Remove the suffix into the list
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* The reference count for the suffix is decremented and the
|
||||
* suffix is possibly freed
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
SuffRemove(l, s)
|
||||
Lst l;
|
||||
Suff *s;
|
||||
{
|
||||
SuffUnRef((ClientData) l, (ClientData) s);
|
||||
if (s->refCount == 0)
|
||||
SuffFree((ClientData) s);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* SuffInsert --
|
||||
@ -348,7 +406,7 @@ SuffFree (s)
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* Not really
|
||||
* The reference count of the suffix is incremented
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
@ -378,11 +436,15 @@ SuffInsert (l, s)
|
||||
printf("at end of list\n");
|
||||
}
|
||||
(void)Lst_AtEnd (l, (ClientData)s);
|
||||
s->refCount++;
|
||||
(void)Lst_AtEnd(s->ref, (ClientData) l);
|
||||
} else if (s2->sNum != s->sNum) {
|
||||
if (DEBUG(SUFF)) {
|
||||
printf("before %s(%d)\n", s2->name, s2->sNum);
|
||||
}
|
||||
(void)Lst_Insert (l, ln, (ClientData)s);
|
||||
s->refCount++;
|
||||
(void)Lst_AtEnd(s->ref, (ClientData) l);
|
||||
} else if (DEBUG(SUFF)) {
|
||||
printf("already there\n");
|
||||
}
|
||||
@ -408,8 +470,7 @@ SuffInsert (l, s)
|
||||
void
|
||||
Suff_ClearSuffixes ()
|
||||
{
|
||||
Lst_Destroy (sufflist, SuffFree);
|
||||
|
||||
Lst_Concat (suffClean, sufflist, LST_CONCLINK);
|
||||
sufflist = Lst_Init(FALSE);
|
||||
sNum = 0;
|
||||
suffNull = emptySuff;
|
||||
@ -474,7 +535,7 @@ SuffParseTransform(str, srcPtr, targPtr)
|
||||
* XXX: Use emptySuff over suffNull?
|
||||
*/
|
||||
*srcPtr = single;
|
||||
*targPtr = SuffCopy(suffNull);
|
||||
*targPtr = suffNull;
|
||||
return(TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
@ -598,14 +659,16 @@ Suff_AddTransform (line)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
int
|
||||
Suff_EndTransform(gn)
|
||||
GNode *gn; /* Node for transformation */
|
||||
Suff_EndTransform(gnp, dummy)
|
||||
ClientData gnp; /* Node for transformation */
|
||||
ClientData dummy; /* Node for transformation */
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
|
||||
if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) &&
|
||||
Lst_IsEmpty(gn->children))
|
||||
{
|
||||
Suff *s, *t;
|
||||
LstNode ln;
|
||||
|
||||
(void)SuffParseTransform(gn->name, &s, &t);
|
||||
|
||||
@ -622,23 +685,17 @@ Suff_EndTransform(gn)
|
||||
* We'll be called twice when the next target is seen, but .c and .o
|
||||
* are only linked once...
|
||||
*/
|
||||
ln = Lst_Member(t->children, (ClientData)s);
|
||||
if (ln != NILLNODE) {
|
||||
(void)Lst_Remove(t->children, ln);
|
||||
}
|
||||
SuffRemove(t->children, s);
|
||||
|
||||
/*
|
||||
* Remove the target from the source's parents list
|
||||
*/
|
||||
ln = Lst_Member(s->parents, (ClientData)t);
|
||||
if (ln != NILLNODE) {
|
||||
(void)Lst_Remove(s->parents, ln);
|
||||
}
|
||||
SuffRemove(s->parents, t);
|
||||
} else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
|
||||
printf("transformation %s complete\n", gn->name);
|
||||
}
|
||||
|
||||
return(0);
|
||||
return(dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -661,13 +718,15 @@ Suff_EndTransform(gn)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
SuffRebuildGraph(transform, s)
|
||||
GNode *transform; /* Transformation to test */
|
||||
Suff *s; /* Suffix to rebuild */
|
||||
SuffRebuildGraph(transformp, sp)
|
||||
ClientData transformp; /* Transformation to test */
|
||||
ClientData sp; /* Suffix to rebuild */
|
||||
{
|
||||
register char *cp;
|
||||
register LstNode ln;
|
||||
register Suff *s2;
|
||||
GNode *transform = (GNode *) transformp;
|
||||
Suff *s = (Suff *) sp;
|
||||
char *cp;
|
||||
LstNode ln;
|
||||
Suff *s2;
|
||||
|
||||
/*
|
||||
* First see if it is a transformation from this suffix.
|
||||
@ -743,8 +802,10 @@ Suff_AddSuffix (str)
|
||||
s->searchPath = Lst_Init (FALSE);
|
||||
s->children = Lst_Init (FALSE);
|
||||
s->parents = Lst_Init (FALSE);
|
||||
s->ref = Lst_Init (FALSE);
|
||||
s->sNum = sNum++;
|
||||
s->flags = 0;
|
||||
s->refCount = 0;
|
||||
|
||||
(void)Lst_AtEnd (sufflist, (ClientData)s);
|
||||
/*
|
||||
@ -807,6 +868,7 @@ Suff_DoPaths()
|
||||
{
|
||||
register Suff *s;
|
||||
register LstNode ln;
|
||||
char *ptr;
|
||||
Lst inIncludes; /* Cumulative .INCLUDES path */
|
||||
Lst inLibs; /* Cumulative .LIBS path */
|
||||
|
||||
@ -837,8 +899,10 @@ Suff_DoPaths()
|
||||
}
|
||||
}
|
||||
|
||||
Var_Set(".INCLUDES", Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
|
||||
Var_Set(".LIBS", Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
|
||||
Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
|
||||
free(ptr);
|
||||
Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
|
||||
free(ptr);
|
||||
|
||||
Lst_Destroy(inIncludes, Dir_Destroy);
|
||||
Lst_Destroy(inLibs, Dir_Destroy);
|
||||
@ -922,10 +986,12 @@ Suff_AddLib (sname)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
SuffAddSrc (s, ls)
|
||||
Suff *s; /* suffix for which to create a Src structure */
|
||||
LstSrc *ls; /* list and parent for the new Src */
|
||||
SuffAddSrc (sp, lsp)
|
||||
ClientData sp; /* suffix for which to create a Src structure */
|
||||
ClientData lsp; /* list and parent for the new Src */
|
||||
{
|
||||
Suff *s = (Suff *) sp;
|
||||
LstSrc *ls = (LstSrc *) lsp;
|
||||
Src *s2; /* new Src structure */
|
||||
Src *targ; /* Target structure */
|
||||
|
||||
@ -943,9 +1009,17 @@ SuffAddSrc (s, ls)
|
||||
s2->parent = targ;
|
||||
s2->node = NILGNODE;
|
||||
s2->suff = s;
|
||||
s->refCount++;
|
||||
s2->children = 0;
|
||||
targ->children += 1;
|
||||
(void)Lst_AtEnd (ls->l, (ClientData)s2);
|
||||
#ifdef DEBUG_SRC
|
||||
s2->cp = Lst_Init(FALSE);
|
||||
Lst_AtEnd(targ->cp, (ClientData) s2);
|
||||
printf("1 add %x %x to %x:", targ, s2, ls->l);
|
||||
Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
s2 = (Src *) emalloc (sizeof (Src));
|
||||
s2->file = str_concat (targ->pref, s->name, 0);
|
||||
@ -953,9 +1027,17 @@ SuffAddSrc (s, ls)
|
||||
s2->parent = targ;
|
||||
s2->node = NILGNODE;
|
||||
s2->suff = s;
|
||||
s->refCount++;
|
||||
s2->children = 0;
|
||||
targ->children += 1;
|
||||
(void)Lst_AtEnd (ls->l, (ClientData)s2);
|
||||
#ifdef DEBUG_SRC
|
||||
s2->cp = Lst_Init(FALSE);
|
||||
Lst_AtEnd(targ->cp, (ClientData) s2);
|
||||
printf("2 add %x %x to %x:", targ, s2, ls->l);
|
||||
Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
return(0);
|
||||
}
|
||||
@ -987,31 +1069,70 @@ SuffAddLevel (l, targ)
|
||||
|
||||
/*-
|
||||
*----------------------------------------------------------------------
|
||||
* SuffFreeSrc --
|
||||
* Free all memory associated with a Src structure
|
||||
* SuffRemoveSrc --
|
||||
* Free all src structures in list that don't have a reference count
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
* Ture if an src was removed
|
||||
*
|
||||
* Side Effects:
|
||||
* The memory is free'd.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
SuffFreeSrc (s)
|
||||
Src *s;
|
||||
static int
|
||||
SuffRemoveSrc (l)
|
||||
Lst l;
|
||||
{
|
||||
free ((Address)s->file);
|
||||
if (!s->parent) {
|
||||
free((Address)s->pref);
|
||||
} else if (--s->parent->children == 0 && s->parent->parent) {
|
||||
/*
|
||||
* Parent has no more children, now we're gone, and it's not
|
||||
* at the top of the tree, so blow it away too.
|
||||
*/
|
||||
SuffFreeSrc(s->parent);
|
||||
LstNode ln;
|
||||
Src *s;
|
||||
int t = 0;
|
||||
|
||||
if (Lst_Open (l) == FAILURE) {
|
||||
return 0;
|
||||
}
|
||||
free ((Address)s);
|
||||
#ifdef DEBUG_SRC
|
||||
printf("cleaning %lx: ", (unsigned long) l);
|
||||
Lst_ForEach(l, PrintAddr, (ClientData) 0);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
|
||||
while ((ln = Lst_Next (l)) != NILLNODE) {
|
||||
s = (Src *) Lst_Datum (ln);
|
||||
if (s->children == 0) {
|
||||
free ((Address)s->file);
|
||||
if (!s->parent)
|
||||
free((Address)s->pref);
|
||||
else {
|
||||
#ifdef DEBUG_SRC
|
||||
LstNode ln = Lst_Member(s->parent->cp, (ClientData)s);
|
||||
if (ln != NILLNODE)
|
||||
Lst_Remove(s->parent->cp, ln);
|
||||
#endif
|
||||
--s->parent->children;
|
||||
}
|
||||
#ifdef DEBUG_SRC
|
||||
printf("free: [l=%x] p=%x %d\n", l, s, s->children);
|
||||
Lst_Destroy(s->cp, NOFREE);
|
||||
#endif
|
||||
Lst_Remove(l, ln);
|
||||
free ((Address)s);
|
||||
t |= 1;
|
||||
Lst_Close(l);
|
||||
return TRUE;
|
||||
}
|
||||
#ifdef DEBUG_SRC
|
||||
else {
|
||||
printf("keep: [l=%x] p=%x %d: ", l, s, s->children);
|
||||
Lst_ForEach(s->cp, PrintAddr, (ClientData) 0);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Lst_Close(l);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -1027,11 +1148,13 @@ SuffFreeSrc (s)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Src *
|
||||
SuffFindThem (srcs)
|
||||
SuffFindThem (srcs, slst)
|
||||
Lst srcs; /* list of Src structures to search through */
|
||||
Lst slst;
|
||||
{
|
||||
Src *s; /* current Src */
|
||||
Src *rs; /* returned Src */
|
||||
char *ptr;
|
||||
|
||||
rs = (Src *) NULL;
|
||||
|
||||
@ -1041,24 +1164,38 @@ SuffFindThem (srcs)
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("\ttrying %s...", s->file);
|
||||
}
|
||||
|
||||
/*
|
||||
* A file is considered to exist if either a node exists in the
|
||||
* graph for it or the file actually exists.
|
||||
*/
|
||||
if ((Targ_FindNode(s->file, TARG_NOCREATE) != NILGNODE) ||
|
||||
(Dir_FindFile (s->file, s->suff->searchPath) != (char *) NULL))
|
||||
{
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("got it\n");
|
||||
}
|
||||
if (Targ_FindNode(s->file, TARG_NOCREATE) != NILGNODE) {
|
||||
#ifdef DEBUG_SRC
|
||||
printf("remove %x from %x\n", s, srcs);
|
||||
#endif
|
||||
rs = s;
|
||||
break;
|
||||
} else {
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("not there\n");
|
||||
}
|
||||
SuffAddLevel (srcs, s);
|
||||
}
|
||||
|
||||
if ((ptr = Dir_FindFile (s->file, s->suff->searchPath)) != NULL) {
|
||||
rs = s;
|
||||
#ifdef DEBUG_SRC
|
||||
printf("remove %x from %x\n", s, srcs);
|
||||
#endif
|
||||
free(ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("not there\n");
|
||||
}
|
||||
|
||||
SuffAddLevel (srcs, s);
|
||||
Lst_AtEnd(slst, (ClientData) s);
|
||||
}
|
||||
|
||||
if (DEBUG(SUFF) && rs) {
|
||||
printf ("got it\n");
|
||||
}
|
||||
return (rs);
|
||||
}
|
||||
@ -1079,8 +1216,9 @@ SuffFindThem (srcs)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Src *
|
||||
SuffFindCmds (targ)
|
||||
Src *targ; /* Src structure to play with */
|
||||
SuffFindCmds (targ, slst)
|
||||
Src *targ; /* Src structure to play with */
|
||||
Lst slst;
|
||||
{
|
||||
LstNode ln; /* General-purpose list node */
|
||||
register GNode *t, /* Target GNode */
|
||||
@ -1128,14 +1266,21 @@ SuffFindCmds (targ)
|
||||
* source node's name so Suff_FindDeps can free it
|
||||
* again (ick)), and return the new structure.
|
||||
*/
|
||||
ret = (Src *)emalloc (sizeof(Src));
|
||||
ret = (Src *)emalloc (sizeof (Src));
|
||||
ret->file = strdup(s->name);
|
||||
ret->pref = targ->pref;
|
||||
ret->suff = suff;
|
||||
suff->refCount++;
|
||||
ret->parent = targ;
|
||||
ret->node = s;
|
||||
ret->children = 0;
|
||||
targ->children += 1;
|
||||
#ifdef DEBUG_SRC
|
||||
ret->cp = Lst_Init(FALSE);
|
||||
printf("3 add %x %x\n", targ, ret);
|
||||
Lst_AtEnd(targ->cp, (ClientData) ret);
|
||||
#endif
|
||||
Lst_AtEnd(slst, (ClientData) ret);
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("\tusing existing source %s\n", s->name);
|
||||
}
|
||||
@ -1165,10 +1310,12 @@ SuffFindCmds (targ)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
SuffExpandChildren(cgn, pgn)
|
||||
GNode *cgn; /* Child to examine */
|
||||
GNode *pgn; /* Parent node being processed */
|
||||
SuffExpandChildren(cgnp, pgnp)
|
||||
ClientData cgnp; /* Child to examine */
|
||||
ClientData pgnp; /* Parent node being processed */
|
||||
{
|
||||
GNode *cgn = (GNode *) cgnp;
|
||||
GNode *pgn = (GNode *) pgnp;
|
||||
GNode *gn; /* New source 8) */
|
||||
LstNode prevLN; /* Node after which new source should be put */
|
||||
LstNode ln; /* List element for old source */
|
||||
@ -1511,8 +1658,9 @@ SuffApplyTransform(tGn, sGn, t, s)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
SuffFindArchiveDeps(gn)
|
||||
SuffFindArchiveDeps(gn, slst)
|
||||
GNode *gn; /* Node for which to locate dependencies */
|
||||
Lst slst;
|
||||
{
|
||||
char *eoarch; /* End of archive portion */
|
||||
char *eoname; /* End of member portion */
|
||||
@ -1521,7 +1669,6 @@ SuffFindArchiveDeps(gn)
|
||||
TARGET, /* Must be first */
|
||||
PREFIX, /* Must be second */
|
||||
};
|
||||
char *vals[sizeof(copy)/sizeof(copy[0])];
|
||||
int i; /* Index into copy and vals */
|
||||
Suff *ms; /* Suffix descriptor for member */
|
||||
char *name; /* Start of member's name */
|
||||
@ -1546,7 +1693,7 @@ SuffFindArchiveDeps(gn)
|
||||
* suffix list, backtracking for each one...
|
||||
*/
|
||||
mem = Targ_FindNode(name, TARG_CREATE);
|
||||
Suff_FindDeps(mem);
|
||||
SuffFindDeps(mem, slst);
|
||||
|
||||
/*
|
||||
* Create the link between the two nodes right off
|
||||
@ -1561,8 +1708,11 @@ SuffFindArchiveDeps(gn)
|
||||
* Copy in the variables from the member node to this one.
|
||||
*/
|
||||
for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
|
||||
vals[i] = Var_Value(copy[i], mem);
|
||||
Var_Set(copy[i], vals[i], gn);
|
||||
char *p1;
|
||||
Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn);
|
||||
if (p1)
|
||||
free(p1);
|
||||
|
||||
}
|
||||
|
||||
ms = mem->suffix;
|
||||
@ -1646,8 +1796,9 @@ SuffFindArchiveDeps(gn)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
SuffFindNormalDeps(gn)
|
||||
SuffFindNormalDeps(gn, slst)
|
||||
GNode *gn; /* Node for which to find sources */
|
||||
Lst slst;
|
||||
{
|
||||
char *eoname; /* End of name */
|
||||
char *sopref; /* Start of prefix */
|
||||
@ -1704,12 +1855,16 @@ SuffFindNormalDeps(gn)
|
||||
/*
|
||||
* Allocate a Src structure to which things can be transformed
|
||||
*/
|
||||
targ = (Src *)emalloc(sizeof(Src));
|
||||
targ = (Src *)emalloc(sizeof (Src));
|
||||
targ->file = strdup(gn->name);
|
||||
targ->suff = (Suff *)Lst_Datum(ln);
|
||||
targ->suff->refCount++;
|
||||
targ->node = gn;
|
||||
targ->parent = (Src *)NULL;
|
||||
targ->children = 0;
|
||||
#ifdef DEBUG_SRC
|
||||
targ->cp = Lst_Init(FALSE);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allocate room for the prefix, whose end is found by subtracting
|
||||
@ -1745,13 +1900,17 @@ SuffFindNormalDeps(gn)
|
||||
printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
|
||||
}
|
||||
|
||||
targ = (Src *)emalloc(sizeof(Src));
|
||||
targ = (Src *)emalloc(sizeof (Src));
|
||||
targ->file = strdup(gn->name);
|
||||
targ->suff = suffNull;
|
||||
targ->suff->refCount++;
|
||||
targ->node = gn;
|
||||
targ->parent = (Src *)NULL;
|
||||
targ->children = 0;
|
||||
targ->pref = strdup(sopref);
|
||||
#ifdef DEBUG_SRC
|
||||
targ->cp = Lst_Init(FALSE);
|
||||
#endif
|
||||
|
||||
SuffAddLevel(srcs, targ);
|
||||
(void)Lst_AtEnd(targs, (ClientData)targ);
|
||||
@ -1761,7 +1920,7 @@ SuffFindNormalDeps(gn)
|
||||
* Using the list of possible sources built up from the target suffix(es),
|
||||
* try and find an existing file/target that matches.
|
||||
*/
|
||||
bottom = SuffFindThem(srcs);
|
||||
bottom = SuffFindThem(srcs, slst);
|
||||
|
||||
if (bottom == (Src *)NULL) {
|
||||
/*
|
||||
@ -1827,7 +1986,10 @@ sfnd_abort:
|
||||
int len = strlen(gn->path);
|
||||
char savec;
|
||||
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount--;
|
||||
gn->suffix = targ->suff;
|
||||
gn->suffix->refCount++;
|
||||
|
||||
savec = gn->path[len-targ->suff->nameLen];
|
||||
gn->path[len-targ->suff->nameLen] = '\0';
|
||||
@ -1840,6 +2002,8 @@ sfnd_abort:
|
||||
* The .PREFIX gets the full path if the target has
|
||||
* no known suffix.
|
||||
*/
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount--;
|
||||
gn->suffix = NULL;
|
||||
|
||||
Var_Set(PREFIX, gn->path, gn);
|
||||
@ -1851,8 +2015,14 @@ sfnd_abort:
|
||||
* path to be the name so Dir_MTime won't go grovelling for
|
||||
* it.
|
||||
*/
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount--;
|
||||
gn->suffix = (targ == NULL) ? NULL : targ->suff;
|
||||
gn->path = gn->name;
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount++;
|
||||
if (gn->path != NULL)
|
||||
free(gn->path);
|
||||
gn->path = strdup(gn->name);
|
||||
}
|
||||
|
||||
goto sfnd_return;
|
||||
@ -1870,7 +2040,7 @@ sfnd_abort:
|
||||
* Check for overriding transformation rule implied by sources
|
||||
*/
|
||||
if (!Lst_IsEmpty(gn->children)) {
|
||||
src = SuffFindCmds(targ);
|
||||
src = SuffFindCmds(targ, slst);
|
||||
|
||||
if (src != (Src *)NULL) {
|
||||
/*
|
||||
@ -1878,10 +2048,10 @@ sfnd_abort:
|
||||
* up to, but not including, the parent node.
|
||||
*/
|
||||
while (bottom && bottom->parent != NULL) {
|
||||
Src *p = bottom->parent;
|
||||
|
||||
SuffFreeSrc(bottom);
|
||||
bottom = p;
|
||||
if (Lst_Member(slst, (ClientData) bottom) == NILLNODE) {
|
||||
Lst_AtEnd(slst, (ClientData) bottom);
|
||||
}
|
||||
bottom = bottom->parent;
|
||||
}
|
||||
bottom = src;
|
||||
}
|
||||
@ -1913,7 +2083,10 @@ sfnd_abort:
|
||||
for (src = bottom; src->parent != (Src *)NULL; src = src->parent) {
|
||||
targ = src->parent;
|
||||
|
||||
if (src->node->suffix)
|
||||
src->node->suffix->refCount--;
|
||||
src->node->suffix = src->suff;
|
||||
src->node->suffix->refCount++;
|
||||
|
||||
if (targ->node == NILGNODE) {
|
||||
targ->node = Targ_FindNode(targ->file, TARG_CREATE);
|
||||
@ -1940,28 +2113,35 @@ sfnd_abort:
|
||||
}
|
||||
}
|
||||
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount--;
|
||||
gn->suffix = src->suff;
|
||||
gn->suffix->refCount++;
|
||||
|
||||
/*
|
||||
* So Dir_MTime doesn't go questing for it...
|
||||
*/
|
||||
gn->path = gn->name;
|
||||
if (gn->path)
|
||||
free(gn->path);
|
||||
gn->path = strdup(gn->name);
|
||||
|
||||
/*
|
||||
* Nuke the transformation path and the Src structures left over in the
|
||||
* two lists.
|
||||
*/
|
||||
SuffFreeSrc(bottom);
|
||||
|
||||
sfnd_return:
|
||||
Lst_Destroy(srcs, SuffFreeSrc);
|
||||
Lst_Destroy(targs, SuffFreeSrc);
|
||||
if (bottom)
|
||||
if (Lst_Member(slst, (ClientData) bottom) == NILLNODE)
|
||||
Lst_AtEnd(slst, (ClientData) bottom);
|
||||
|
||||
while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
|
||||
continue;
|
||||
|
||||
Lst_Concat(slst, srcs, LST_CONCLINK);
|
||||
Lst_Concat(slst, targs, LST_CONCLINK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Suff_FindDeps --
|
||||
@ -1989,9 +2169,22 @@ sfnd_return:
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void
|
||||
Suff_FindDeps (gn)
|
||||
Suff_FindDeps(gn)
|
||||
GNode *gn;
|
||||
{
|
||||
|
||||
SuffFindDeps(gn, srclist);
|
||||
while (SuffRemoveSrc(srclist))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SuffFindDeps (gn, slst)
|
||||
GNode *gn; /* node we're dealing with */
|
||||
Lst slst;
|
||||
{
|
||||
if (gn->type & OP_DEPS_FOUND) {
|
||||
/*
|
||||
@ -2003,11 +2196,11 @@ Suff_FindDeps (gn)
|
||||
}
|
||||
|
||||
if (DEBUG(SUFF)) {
|
||||
printf ("Suff_FindDeps (%s)\n", gn->name);
|
||||
printf ("SuffFindDeps (%s)\n", gn->name);
|
||||
}
|
||||
|
||||
if (gn->type & OP_ARCHV) {
|
||||
SuffFindArchiveDeps(gn);
|
||||
SuffFindArchiveDeps(gn, slst);
|
||||
} else if (gn->type & OP_LIB) {
|
||||
/*
|
||||
* If the node is a library, it is the arch module's job to find it
|
||||
@ -2021,8 +2214,11 @@ Suff_FindDeps (gn)
|
||||
Suff *s;
|
||||
|
||||
ln = Lst_Find (sufflist, (ClientData)LIBSUFF, SuffSuffHasNameP);
|
||||
if (gn->suffix)
|
||||
gn->suffix->refCount--;
|
||||
if (ln != NILLNODE) {
|
||||
gn->suffix = s = (Suff *) Lst_Datum (ln);
|
||||
gn->suffix->refCount++;
|
||||
Arch_FindLib (gn, s->searchPath);
|
||||
} else {
|
||||
gn->suffix = NULL;
|
||||
@ -2035,7 +2231,7 @@ Suff_FindDeps (gn)
|
||||
*/
|
||||
Var_Set(PREFIX, "", gn);
|
||||
} else {
|
||||
SuffFindNormalDeps(gn);
|
||||
SuffFindNormalDeps(gn, slst);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2096,6 +2292,8 @@ void
|
||||
Suff_Init ()
|
||||
{
|
||||
sufflist = Lst_Init (FALSE);
|
||||
suffClean = Lst_Init(FALSE);
|
||||
srclist = Lst_Init (FALSE);
|
||||
transforms = Lst_Init (FALSE);
|
||||
|
||||
sNum = 0;
|
||||
@ -2112,54 +2310,59 @@ Suff_Init ()
|
||||
Dir_Concat(suffNull->searchPath, dirSearchPath);
|
||||
suffNull->children = Lst_Init (FALSE);
|
||||
suffNull->parents = Lst_Init (FALSE);
|
||||
suffNull->ref = Lst_Init (FALSE);
|
||||
suffNull->sNum = sNum++;
|
||||
suffNull->flags = SUFF_NULL;
|
||||
suffNull->refCount = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* SuffCopy --
|
||||
* Create a copy of the source suffix.
|
||||
* Currently does not copy children or parents
|
||||
*----------------------------------------------------------------------
|
||||
* Suff_End --
|
||||
* Cleanup the this module
|
||||
*
|
||||
* Results:
|
||||
* a new suffix is returned
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* none
|
||||
*-----------------------------------------------------------------------
|
||||
* The memory is free'd.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
static Suff *
|
||||
SuffCopy(s)
|
||||
Suff *s;
|
||||
|
||||
void
|
||||
Suff_End()
|
||||
{
|
||||
Suff *n = (Suff *) emalloc (sizeof (Suff));
|
||||
n->name = strdup (s->name);
|
||||
n->nameLen = s->nameLen;
|
||||
n->searchPath = Lst_Init (FALSE);
|
||||
Dir_Concat(suffNull->searchPath, s->searchPath);
|
||||
n->children = Lst_Init (FALSE);
|
||||
n->parents = Lst_Init (FALSE);
|
||||
n->sNum = s->sNum;
|
||||
n->flags = s->flags;
|
||||
return n;
|
||||
Lst_Destroy(sufflist, SuffFree);
|
||||
Lst_Destroy(suffClean, SuffFree);
|
||||
if (suffNull)
|
||||
SuffFree(suffNull);
|
||||
Lst_Destroy(srclist, NOFREE);
|
||||
Lst_Destroy(transforms, NOFREE);
|
||||
}
|
||||
|
||||
|
||||
/********************* DEBUGGING FUNCTIONS **********************/
|
||||
|
||||
static int SuffPrintName(s) Suff *s; {printf ("%s ", s->name); return (0);}
|
||||
static int SuffPrintName(s, dummy)
|
||||
ClientData s;
|
||||
ClientData dummy;
|
||||
{
|
||||
printf ("%s ", ((Suff *) s)->name);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
static int
|
||||
SuffPrintSuff (s)
|
||||
Suff *s;
|
||||
SuffPrintSuff (sp, dummy)
|
||||
ClientData sp;
|
||||
ClientData dummy;
|
||||
{
|
||||
Suff *s = (Suff *) sp;
|
||||
int flags;
|
||||
int flag;
|
||||
|
||||
printf ("# `%s'", s->name);
|
||||
printf ("# `%s' [%d] ", s->name, s->refCount);
|
||||
|
||||
flags = s->flags;
|
||||
if (flags) {
|
||||
@ -2191,21 +2394,22 @@ SuffPrintSuff (s)
|
||||
printf ("#\tSearch Path: ");
|
||||
Dir_PrintPath (s->searchPath);
|
||||
fputc ('\n', stdout);
|
||||
return (0);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
static int
|
||||
SuffPrintTrans (t)
|
||||
GNode *t;
|
||||
SuffPrintTrans (tp, dummy)
|
||||
ClientData tp;
|
||||
ClientData dummy;
|
||||
{
|
||||
extern int Targ_PrintCmd();
|
||||
GNode *t = (GNode *) tp;
|
||||
|
||||
printf ("%-16s: ", t->name);
|
||||
Targ_PrintType (t->type);
|
||||
fputc ('\n', stdout);
|
||||
Lst_ForEach (t->commands, Targ_PrintCmd, (ClientData)0);
|
||||
fputc ('\n', stdout);
|
||||
return(0);
|
||||
return(dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2217,4 +2421,3 @@ Suff_PrintAll()
|
||||
printf ("#*** Transformations:\n");
|
||||
Lst_ForEach (transforms, SuffPrintTrans, (ClientData)0);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)targ.c 5.9 (Berkeley) 3/1/91"; */
|
||||
static char *rcsid = "$Id: targ.c,v 1.3 1994/03/05 00:35:13 cgd Exp $";
|
||||
static char *rcsid = "$Id: targ.c,v 1.4 1994/06/06 22:45:47 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -50,6 +50,8 @@ static char *rcsid = "$Id: targ.c,v 1.3 1994/03/05 00:35:13 cgd Exp $";
|
||||
* Interface:
|
||||
* Targ_Init Initialization procedure.
|
||||
*
|
||||
* Targ_End Cleanup the module
|
||||
*
|
||||
* Targ_NewGN Create a new GNode for the passed target
|
||||
* (string). The node is *not* placed in the
|
||||
* hash table, though all its fields are
|
||||
@ -87,10 +89,16 @@ static char *rcsid = "$Id: targ.c,v 1.3 1994/03/05 00:35:13 cgd Exp $";
|
||||
#include "dir.h"
|
||||
|
||||
static Lst allTargets; /* the list of all targets found so far */
|
||||
static Lst allGNs; /* List of all the GNodes */
|
||||
static Hash_Table targets; /* a hash table of same */
|
||||
|
||||
#define HTSIZE 191 /* initial size of hash table */
|
||||
|
||||
static int TargPrintOnlySrc __P((ClientData, ClientData));
|
||||
static int TargPrintName __P((ClientData, ClientData));
|
||||
static int TargPrintNode __P((ClientData, ClientData));
|
||||
static void TargFreeGN __P((ClientData));
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Targ_Init --
|
||||
@ -110,6 +118,27 @@ Targ_Init ()
|
||||
Hash_InitTable (&targets, HTSIZE);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Targ_End --
|
||||
* Finalize this module
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* All lists and gnodes are cleared
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Targ_End ()
|
||||
{
|
||||
Lst_Destroy(allTargets, NOFREE);
|
||||
if (allGNs)
|
||||
Lst_Destroy(allGNs, TargFreeGN);
|
||||
Hash_DeleteTable(&targets);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Targ_NewGN --
|
||||
@ -120,7 +149,7 @@ Targ_Init ()
|
||||
* of the passed name
|
||||
*
|
||||
* Side Effects:
|
||||
* None.
|
||||
* The gnode is added to the list of all gnodes.
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
GNode *
|
||||
@ -146,15 +175,54 @@ Targ_NewGN (name)
|
||||
gn->cohorts = Lst_Init (FALSE);
|
||||
gn->parents = Lst_Init (FALSE);
|
||||
gn->children = Lst_Init (FALSE);
|
||||
gn->successors = Lst_Init(FALSE);
|
||||
gn->preds = Lst_Init(FALSE);
|
||||
gn->successors = Lst_Init (FALSE);
|
||||
gn->preds = Lst_Init (FALSE);
|
||||
gn->context = Lst_Init (FALSE);
|
||||
gn->commands = Lst_Init (FALSE);
|
||||
gn->suffix = NULL;
|
||||
|
||||
if (allGNs == NULL)
|
||||
allGNs = Lst_Init(FALSE);
|
||||
Lst_AtEnd(allGNs, (ClientData) gn);
|
||||
|
||||
return (gn);
|
||||
}
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* TargFreeGN --
|
||||
* Destroy a GNode
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
*
|
||||
* Side Effects:
|
||||
* None.
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
TargFreeGN (gnp)
|
||||
ClientData gnp;
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
|
||||
|
||||
free(gn->name);
|
||||
if (gn->path)
|
||||
free(gn->path);
|
||||
|
||||
Lst_Destroy(gn->iParents, NOFREE);
|
||||
Lst_Destroy(gn->cohorts, NOFREE);
|
||||
Lst_Destroy(gn->parents, NOFREE);
|
||||
Lst_Destroy(gn->children, NOFREE);
|
||||
Lst_Destroy(gn->successors, NOFREE);
|
||||
Lst_Destroy(gn->preds, NOFREE);
|
||||
Lst_Destroy(gn->context, NOFREE);
|
||||
Lst_Destroy(gn->commands, NOFREE);
|
||||
free((Address)gn);
|
||||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Targ_FindNode --
|
||||
@ -344,11 +412,11 @@ Targ_SetMain (gn)
|
||||
}
|
||||
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
TargPrintName (gn, ppath)
|
||||
GNode *gn;
|
||||
int ppath;
|
||||
TargPrintName (gnp, ppath)
|
||||
ClientData gnp;
|
||||
ClientData ppath;
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
printf ("%s ", gn->name);
|
||||
#ifdef notdef
|
||||
if (ppath) {
|
||||
@ -360,16 +428,17 @@ TargPrintName (gn, ppath)
|
||||
}
|
||||
}
|
||||
#endif /* notdef */
|
||||
return (0);
|
||||
return (ppath ? 0 : 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Targ_PrintCmd (cmd)
|
||||
char *cmd;
|
||||
Targ_PrintCmd (cmd, dummy)
|
||||
ClientData cmd;
|
||||
ClientData dummy;
|
||||
{
|
||||
printf ("\t%s\n", cmd);
|
||||
return (0);
|
||||
printf ("\t%s\n", (char *) cmd);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -463,10 +532,12 @@ Targ_PrintType (type)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
TargPrintNode (gn, pass)
|
||||
GNode *gn;
|
||||
int pass;
|
||||
TargPrintNode (gnp, passp)
|
||||
ClientData gnp;
|
||||
ClientData passp;
|
||||
{
|
||||
GNode *gn = (GNode *) gnp;
|
||||
int pass = *(int *) passp;
|
||||
if (!OP_NOP(gn->type)) {
|
||||
printf("#\n");
|
||||
if (gn == mainTarg) {
|
||||
@ -523,7 +594,7 @@ TargPrintNode (gn, pass)
|
||||
Lst_ForEach (gn->commands, Targ_PrintCmd, (ClientData)0);
|
||||
printf("\n\n");
|
||||
if (gn->type & OP_DOUBLEDEP) {
|
||||
Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)pass);
|
||||
Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)&pass);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
@ -543,14 +614,15 @@ TargPrintNode (gn, pass)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
TargPrintOnlySrc(gn)
|
||||
GNode *gn;
|
||||
TargPrintOnlySrc(gnp, dummy)
|
||||
ClientData gnp;
|
||||
ClientData dummy;
|
||||
{
|
||||
if (OP_NOP(gn->type)) {
|
||||
printf("#\t%s [%s]\n", gn->name,
|
||||
gn->path ? gn->path : gn->name);
|
||||
}
|
||||
return (0);
|
||||
GNode *gn = (GNode *) gnp;
|
||||
if (OP_NOP(gn->type))
|
||||
printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name);
|
||||
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -571,10 +643,10 @@ Targ_PrintGraph (pass)
|
||||
* 2 => processing done */
|
||||
{
|
||||
printf("#*** Input graph:\n");
|
||||
Lst_ForEach (allTargets, TargPrintNode, (ClientData)pass);
|
||||
Lst_ForEach (allTargets, TargPrintNode, (ClientData)&pass);
|
||||
printf("\n\n");
|
||||
printf("#\n# Files that are only sources:\n");
|
||||
Lst_ForEach (allTargets, TargPrintOnlySrc);
|
||||
Lst_ForEach (allTargets, TargPrintOnlySrc, (ClientData) 0);
|
||||
printf("#*** Global Variables:\n");
|
||||
Var_Dump (VAR_GLOBAL);
|
||||
printf("#*** Command-line Variables:\n");
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)var.c 5.7 (Berkeley) 6/1/90"; */
|
||||
static char *rcsid = "$Id: var.c,v 1.5 1994/03/05 00:35:17 cgd Exp $";
|
||||
static char *rcsid = "$Id: var.c,v 1.6 1994/06/06 22:45:49 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -120,6 +120,8 @@ static char varNoError[] = "";
|
||||
GNode *VAR_GLOBAL; /* variables from the makefile */
|
||||
GNode *VAR_CMD; /* variables defined on the command-line */
|
||||
|
||||
static Lst allVars; /* List of all variables */
|
||||
|
||||
#define FIND_CMD 0x1 /* look in VAR_CMD when searching */
|
||||
#define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */
|
||||
#define FIND_ENV 0x4 /* look in the environment also */
|
||||
@ -149,19 +151,22 @@ typedef struct {
|
||||
#define VAR_NO_SUB 8 /* Substitution is non-global and already done */
|
||||
} VarPattern;
|
||||
|
||||
static int VarCmp __P((Var *, char *));
|
||||
static int VarCmp __P((ClientData, ClientData));
|
||||
static Var *VarFind __P((char *, GNode *, int));
|
||||
static void VarAdd __P((char *, char *, GNode *));
|
||||
static Boolean VarHead __P((char *, Boolean, Buffer));
|
||||
static Boolean VarTail __P((char *, Boolean, Buffer));
|
||||
static Boolean VarSuffix __P((char *, Boolean, Buffer));
|
||||
static Boolean VarRoot __P((char *, Boolean, Buffer));
|
||||
static Boolean VarMatch __P((char *, Boolean, Buffer, char *));
|
||||
static Boolean VarSYSVMatch __P((char *, Boolean, Buffer, VarPattern *));
|
||||
static Boolean VarNoMatch __P((char *, Boolean, Buffer, char *));
|
||||
static Boolean VarSubstitute __P((char *, Boolean, Buffer, VarPattern *));
|
||||
static char *VarModify __P((char *, Boolean (*modProc )(), ClientData));
|
||||
static int VarPrintVar __P((Var *));
|
||||
static void VarDelete __P((ClientData));
|
||||
static Boolean VarHead __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarTail __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarSuffix __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarRoot __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarMatch __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarSYSVMatch __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarNoMatch __P((char *, Boolean, Buffer, ClientData));
|
||||
static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData));
|
||||
static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer,
|
||||
ClientData),
|
||||
ClientData));
|
||||
static int VarPrintVar __P((ClientData, ClientData));
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
@ -178,10 +183,10 @@ static int VarPrintVar __P((Var *));
|
||||
*/
|
||||
static int
|
||||
VarCmp (v, name)
|
||||
Var *v; /* VAR structure to compare */
|
||||
char *name; /* name to look for */
|
||||
ClientData v; /* VAR structure to compare */
|
||||
ClientData name; /* name to look for */
|
||||
{
|
||||
return (strcmp (name, v->name));
|
||||
return (strcmp ((char *) name, ((Var *) v)->name));
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -218,7 +223,7 @@ VarFind (name, ctxt, flags)
|
||||
* and substitute the short version in for 'name' if it matches one of
|
||||
* them.
|
||||
*/
|
||||
if (*name == '.' && isupper(name[1]))
|
||||
if (*name == '.' && isupper((unsigned char) name[1]))
|
||||
switch (name[1]) {
|
||||
case 'A':
|
||||
if (!strcmp(name, ".ALLSRC"))
|
||||
@ -336,11 +341,37 @@ VarAdd (name, val, ctxt)
|
||||
v->flags = 0;
|
||||
|
||||
(void) Lst_AtFront (ctxt->context, (ClientData)v);
|
||||
(void) Lst_AtEnd (allVars, (ClientData) v);
|
||||
if (DEBUG(VAR)) {
|
||||
printf("%s:%s = %s\n", ctxt->name, name, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* VarDelete --
|
||||
* Delete a variable and all the space associated with it.
|
||||
*
|
||||
* Results:
|
||||
* None
|
||||
*
|
||||
* Side Effects:
|
||||
* None
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
VarDelete(vp)
|
||||
ClientData vp;
|
||||
{
|
||||
Var *v = (Var *) vp;
|
||||
free(v->name);
|
||||
Buf_Destroy(v->val, TRUE);
|
||||
free((Address) v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-
|
||||
*-----------------------------------------------------------------------
|
||||
* Var_Delete --
|
||||
@ -370,9 +401,9 @@ Var_Delete(name, ctxt)
|
||||
|
||||
v = (Var *)Lst_Datum(ln);
|
||||
Lst_Remove(ctxt->context, ln);
|
||||
Buf_Destroy(v->val, TRUE);
|
||||
free(v->name);
|
||||
free((char *)v);
|
||||
ln = Lst_Member(allVars, v);
|
||||
Lst_Remove(allVars, ln);
|
||||
VarDelete((ClientData) v);
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,15 +561,23 @@ Var_Exists(name, ctxt)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
char *
|
||||
Var_Value (name, ctxt)
|
||||
Var_Value (name, ctxt, frp)
|
||||
char *name; /* name to find */
|
||||
GNode *ctxt; /* context in which to search for it */
|
||||
char **frp;
|
||||
{
|
||||
Var *v;
|
||||
|
||||
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
|
||||
*frp = NULL;
|
||||
if (v != (Var *) NIL) {
|
||||
return ((char *)Buf_GetAll(v->val, (int *)NULL));
|
||||
char *p = ((char *)Buf_GetAll(v->val, (int *)NULL));
|
||||
if (v->flags & VAR_FROM_ENV) {
|
||||
Buf_Destroy(v->val, FALSE);
|
||||
free((Address) v);
|
||||
*frp = p;
|
||||
}
|
||||
return p;
|
||||
} else {
|
||||
return ((char *) NULL);
|
||||
}
|
||||
@ -560,11 +599,12 @@ Var_Value (name, ctxt)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarHead (word, addSpace, buf)
|
||||
VarHead (word, addSpace, buf, dummy)
|
||||
char *word; /* Word to trim */
|
||||
Boolean addSpace; /* True if need to add a space to the buffer
|
||||
* before sticking in the head */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
ClientData dummy;
|
||||
{
|
||||
register char *slash;
|
||||
|
||||
@ -586,8 +626,8 @@ VarHead (word, addSpace, buf)
|
||||
} else {
|
||||
Buf_AddByte(buf, (Byte)'.');
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
return(dummy ? TRUE : TRUE);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -606,11 +646,12 @@ VarHead (word, addSpace, buf)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarTail (word, addSpace, buf)
|
||||
VarTail (word, addSpace, buf, dummy)
|
||||
char *word; /* Word to trim */
|
||||
Boolean addSpace; /* TRUE if need to stick a space in the
|
||||
* buffer before adding the tail */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
ClientData dummy;
|
||||
{
|
||||
register char *slash;
|
||||
|
||||
@ -626,7 +667,7 @@ VarTail (word, addSpace, buf)
|
||||
} else {
|
||||
Buf_AddBytes (buf, strlen(word), (Byte *)word);
|
||||
}
|
||||
return (TRUE);
|
||||
return (dummy ? TRUE : TRUE);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -644,11 +685,12 @@ VarTail (word, addSpace, buf)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarSuffix (word, addSpace, buf)
|
||||
VarSuffix (word, addSpace, buf, dummy)
|
||||
char *word; /* Word to trim */
|
||||
Boolean addSpace; /* TRUE if need to add a space before placing
|
||||
* the suffix in the buffer */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
ClientData dummy;
|
||||
{
|
||||
register char *dot;
|
||||
|
||||
@ -660,10 +702,9 @@ VarSuffix (word, addSpace, buf)
|
||||
*dot++ = '\0';
|
||||
Buf_AddBytes (buf, strlen (dot), (Byte *)dot);
|
||||
dot[-1] = '.';
|
||||
return (TRUE);
|
||||
} else {
|
||||
return (addSpace);
|
||||
addSpace = TRUE;
|
||||
}
|
||||
return (dummy ? addSpace : addSpace);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -682,11 +723,12 @@ VarSuffix (word, addSpace, buf)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarRoot (word, addSpace, buf)
|
||||
VarRoot (word, addSpace, buf, dummy)
|
||||
char *word; /* Word to trim */
|
||||
Boolean addSpace; /* TRUE if need to add a space to the buffer
|
||||
* before placing the root in it */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
ClientData dummy;
|
||||
{
|
||||
register char *dot;
|
||||
|
||||
@ -702,7 +744,7 @@ VarRoot (word, addSpace, buf)
|
||||
} else {
|
||||
Buf_AddBytes (buf, strlen(word), (Byte *)word);
|
||||
}
|
||||
return (TRUE);
|
||||
return (dummy ? TRUE : TRUE);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -727,9 +769,9 @@ VarMatch (word, addSpace, buf, pattern)
|
||||
* buffer before adding the word, if it
|
||||
* matches */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
char *pattern; /* Pattern the word must match */
|
||||
ClientData pattern; /* Pattern the word must match */
|
||||
{
|
||||
if (Str_Match(word, pattern)) {
|
||||
if (Str_Match(word, (char *) pattern)) {
|
||||
if (addSpace) {
|
||||
Buf_AddByte(buf, (Byte)' ');
|
||||
}
|
||||
@ -758,16 +800,17 @@ VarMatch (word, addSpace, buf, pattern)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarSYSVMatch (word, addSpace, buf, pat)
|
||||
VarSYSVMatch (word, addSpace, buf, patp)
|
||||
char *word; /* Word to examine */
|
||||
Boolean addSpace; /* TRUE if need to add a space to the
|
||||
* buffer before adding the word, if it
|
||||
* matches */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
VarPattern *pat; /* Pattern the word must match */
|
||||
ClientData patp; /* Pattern the word must match */
|
||||
{
|
||||
int len;
|
||||
char *ptr;
|
||||
VarPattern *pat = (VarPattern *) patp;
|
||||
|
||||
if (addSpace)
|
||||
Buf_AddByte(buf, (Byte)' ');
|
||||
@ -805,9 +848,9 @@ VarNoMatch (word, addSpace, buf, pattern)
|
||||
* buffer before adding the word, if it
|
||||
* matches */
|
||||
Buffer buf; /* Buffer in which to store it */
|
||||
char *pattern; /* Pattern the word must match */
|
||||
ClientData pattern; /* Pattern the word must match */
|
||||
{
|
||||
if (!Str_Match(word, pattern)) {
|
||||
if (!Str_Match(word, (char *) pattern)) {
|
||||
if (addSpace) {
|
||||
Buf_AddByte(buf, (Byte)' ');
|
||||
}
|
||||
@ -833,15 +876,16 @@ VarNoMatch (word, addSpace, buf, pattern)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
static Boolean
|
||||
VarSubstitute (word, addSpace, buf, pattern)
|
||||
VarSubstitute (word, addSpace, buf, patternp)
|
||||
char *word; /* Word to modify */
|
||||
Boolean addSpace; /* True if space should be added before
|
||||
* other characters */
|
||||
Buffer buf; /* Buffer for result */
|
||||
register VarPattern *pattern; /* Pattern for substitution */
|
||||
ClientData patternp; /* Pattern for substitution */
|
||||
{
|
||||
register int wordLen; /* Length of word */
|
||||
register char *cp; /* General pointer */
|
||||
VarPattern *pattern = (VarPattern *) patternp;
|
||||
|
||||
wordLen = strlen(word);
|
||||
if ((pattern->flags & VAR_NO_SUB) == 0) {
|
||||
@ -1011,7 +1055,8 @@ VarSubstitute (word, addSpace, buf, pattern)
|
||||
static char *
|
||||
VarModify (str, modProc, datum)
|
||||
char *str; /* String whose words should be trimmed */
|
||||
Boolean (*modProc)(); /* Function to use to modify them */
|
||||
/* Function to use to modify them */
|
||||
Boolean (*modProc) __P((char *, Boolean, Buffer, ClientData));
|
||||
ClientData datum; /* Datum to pass it */
|
||||
{
|
||||
Buffer buf; /* Buffer for the new string */
|
||||
@ -1254,7 +1299,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
|
||||
break;
|
||||
}
|
||||
} else if (((tstr-str) > 4) && (str[2] == '.') &&
|
||||
isupper(str[3]) &&
|
||||
isupper((unsigned char) str[3]) &&
|
||||
((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)))
|
||||
{
|
||||
int len;
|
||||
@ -1722,6 +1767,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr)
|
||||
free(str);
|
||||
}
|
||||
*freePtr = FALSE;
|
||||
Buf_Destroy(v->val, TRUE);
|
||||
free((Address)v);
|
||||
if (dynamic) {
|
||||
str = emalloc(*lengthPtr + 1);
|
||||
@ -1961,16 +2007,27 @@ Var_Init ()
|
||||
{
|
||||
VAR_GLOBAL = Targ_NewGN ("Global");
|
||||
VAR_CMD = Targ_NewGN ("Command");
|
||||
allVars = Lst_Init(FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Var_End ()
|
||||
{
|
||||
Lst_Destroy(allVars, VarDelete);
|
||||
}
|
||||
|
||||
|
||||
/****************** PRINT DEBUGGING INFO *****************/
|
||||
static int
|
||||
VarPrintVar (v)
|
||||
Var *v;
|
||||
VarPrintVar (vp, dummy)
|
||||
ClientData vp;
|
||||
ClientData dummy;
|
||||
{
|
||||
Var *v = (Var *) vp;
|
||||
printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL));
|
||||
return (0);
|
||||
return (dummy ? 0 : 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
@ -1983,5 +2040,5 @@ void
|
||||
Var_Dump (ctxt)
|
||||
GNode *ctxt;
|
||||
{
|
||||
Lst_ForEach (ctxt->context, VarPrintVar);
|
||||
Lst_ForEach (ctxt->context, VarPrintVar, (ClientData) 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user