=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/suff.c,v retrieving revision 1.41 retrieving revision 1.42 diff -c -r1.41 -r1.42 *** src/usr.bin/make/suff.c 2001/05/03 13:41:11 1.41 --- src/usr.bin/make/suff.c 2001/05/23 12:34:49 1.42 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: suff.c,v 1.41 2001/05/03 13:41:11 espie Exp $ */ /* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: suff.c,v 1.42 2001/05/23 12:34:49 espie Exp $ */ /* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */ /* *************** *** 66,72 **** * Suff_ClearSuffixes Clear out all the suffixes and defined * transformations. * ! * Suff_IsTransform Return TRUE if the passed string is the lhs * of a transformation rule. * * Suff_AddSuffix Add the passed string as another known suffix. --- 66,72 ---- * Suff_ClearSuffixes Clear out all the suffixes and defined * transformations. * ! * Suff_IsTransform Return true if the passed string is the lhs * of a transformation rule. * * Suff_AddSuffix Add the passed string as another known suffix. *************** *** 91,111 **** * if the target had no implicit sources. */ ! #include ! #include ! #include "make.h" ! #include "ohash.h" ! #include "dir.h" - #ifndef lint - #if 0 - static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; - #else - UNUSED - static char rcsid[] = "$OpenBSD: suff.c,v 1.41 2001/05/03 13:41:11 espie Exp $"; - #endif - #endif /* not lint */ - static LIST sufflist; /* Lst of suffixes */ #ifdef CLEANUP static LIST suffClean; /* Lst of suffixes to be cleaned */ --- 91,113 ---- * if the target had no implicit sources. */ ! #include ! #include ! #include ! #include "config.h" ! #include "defines.h" ! #include "dir.h" ! #include "arch.h" ! #include "suff.h" ! #include "var.h" ! #include "targ.h" ! #include "error.h" ! #include "str.h" ! #include "lst.h" ! #include "memory.h" ! #include "gnode.h" ! #include "make.h" static LIST sufflist; /* Lst of suffixes */ #ifdef CLEANUP static LIST suffClean; /* Lst of suffixes to be cleaned */ *************** *** 174,180 **** static void SuffFree(void *); #endif static void SuffInsert(Lst, Suff *); ! static Boolean SuffParseTransform(const char *, Suff **, Suff **); static void SuffRebuildGraph(void *, void *); static void SuffAddSrc(void *, void *); static int SuffRemoveSrc(Lst); --- 176,182 ---- static void SuffFree(void *); #endif static void SuffInsert(Lst, Suff *); ! static bool SuffParseTransform(const char *, Suff **, Suff **); static void SuffRebuildGraph(void *, void *); static void SuffAddSrc(void *, void *); static int SuffRemoveSrc(Lst); *************** *** 184,190 **** static void SuffExpandChildren(void *, void *); static void SuffExpandVarChildren(LstNode, GNode *, GNode *); static void SuffExpandWildChildren(LstNode, GNode *, GNode *); ! static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *); static void SuffFindDeps(GNode *, Lst); static void SuffFindArchiveDeps(GNode *, Lst); static void SuffFindNormalDeps(GNode *, Lst); --- 186,192 ---- static void SuffExpandChildren(void *, void *); static void SuffExpandVarChildren(LstNode, GNode *, GNode *); static void SuffExpandWildChildren(LstNode, GNode *, GNode *); ! static bool SuffApplyTransform(GNode *, GNode *, Suff *, Suff *); static void SuffFindDeps(GNode *, Lst); static void SuffFindArchiveDeps(GNode *, Lst); static void SuffFindNormalDeps(GNode *, Lst); *************** *** 192,197 **** --- 194,202 ---- static void SuffPrintSuff(void *); static void SuffPrintTrans(void *); + #ifdef DEBUG_SRC + static void PrintAddr(void *); + #endif /*************** Lst Predicates ****************/ /*- *----------------------------------------------------------------------- *************** *** 440,452 **** * Parse a transformation string to find its two component suffixes. * * Results: ! * TRUE if the string is a valid transformation and FALSE otherwise. * * Side Effects: * The passed pointers are overwritten. *----------------------------------------------------------------------- */ ! static Boolean SuffParseTransform(str, srcPtr, targPtr) const char *str; /* String being parsed */ Suff **srcPtr; /* Place to store source of trans. */ --- 445,457 ---- * Parse a transformation string to find its two component suffixes. * * Results: ! * true if the string is a valid transformation and false otherwise. * * Side Effects: * The passed pointers are overwritten. *----------------------------------------------------------------------- */ ! static bool SuffParseTransform(str, srcPtr, targPtr) const char *str; /* String being parsed */ Suff **srcPtr; /* Place to store source of trans. */ *************** *** 491,499 **** */ *srcPtr = single; *targPtr = suffNull; ! return TRUE; } ! return FALSE; } src = (Suff *)Lst_Datum(srcLn); str2 = str + src->nameLen; --- 496,504 ---- */ *srcPtr = single; *targPtr = suffNull; ! return true; } ! return false; } src = (Suff *)Lst_Datum(srcLn); str2 = str + src->nameLen; *************** *** 505,511 **** if (targLn != NULL) { *srcPtr = src; *targPtr = (Suff *)Lst_Datum(targLn); ! return TRUE; } } } --- 510,516 ---- if (targLn != NULL) { *srcPtr = src; *targPtr = (Suff *)Lst_Datum(targLn); ! return true; } } } *************** *** 514,527 **** /*- *----------------------------------------------------------------------- * Suff_IsTransform -- ! * Return TRUE if the given string is a transformation rule * * Results: ! * TRUE if the string is a concatenation of two known suffixes. ! * FALSE otherwise *----------------------------------------------------------------------- */ ! Boolean Suff_IsTransform(str) const char *str; /* string to check */ { --- 519,532 ---- /*- *----------------------------------------------------------------------- * Suff_IsTransform -- ! * Return true if the given string is a transformation rule * * Results: ! * true if the string is a concatenation of two known suffixes. ! * false otherwise *----------------------------------------------------------------------- */ ! bool Suff_IsTransform(str) const char *str; /* string to check */ { *************** *** 559,565 **** * Make a new graph node for the transformation. It will be filled in * by the Parse module. */ ! gn = Targ_NewGN(line, NULL); Lst_AtEnd(&transforms, gn); } else { /* --- 564,570 ---- * Make a new graph node for the transformation. It will be filled in * by the Parse module. */ ! gn = Targ_NewGN(line); Lst_AtEnd(&transforms, gn); } else { /* *************** *** 804,814 **** Dir_Concat(&inLibs, &s->searchPath); } #endif /* LIBRARIES */ ! Dir_Concat(&s->searchPath, &dirSearchPath); ! } else { ! Lst_Destroy(&s->searchPath, Dir_Destroy); ! Lst_Clone(&s->searchPath, &dirSearchPath, Dir_CopyDir); ! } } Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", &inIncludes), VAR_GLOBAL); --- 809,817 ---- Dir_Concat(&inLibs, &s->searchPath); } #endif /* LIBRARIES */ ! Dir_Concat(&s->searchPath, dirSearchPath); ! } else ! Lst_Clone(&s->searchPath, dirSearchPath, Dir_CopyDir); } Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", &inIncludes), VAR_GLOBAL); *************** *** 920,926 **** #endif } s2 = emalloc(sizeof(Src)); ! s2->file = str_concat(targ->pref, s->name, 0); s2->pref = targ->pref; s2->parent = targ; s2->node = NULL; --- 923,929 ---- #endif } s2 = emalloc(sizeof(Src)); ! s2->file = Str_concat(targ->pref, s->name, 0); s2->pref = targ->pref; s2->parent = targ; s2->node = NULL; *************** *** 1008,1014 **** Lst_Remove(l, ln); free(s); t |= 1; ! return TRUE; } #ifdef DEBUG_SRC else { --- 1011,1017 ---- Lst_Remove(l, ln); free(s); t |= 1; ! return true; } #ifdef DEBUG_SRC else { *************** *** 1051,1057 **** * 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, NULL, TARG_NOCREATE) != NULL) { #ifdef DEBUG_SRC printf("remove %x from %x\n", s, srcs); #endif --- 1054,1060 ---- * 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) != NULL) { #ifdef DEBUG_SRC printf("remove %x from %x\n", s, srcs); #endif *************** *** 1181,1187 **** if (DEBUG(SUFF)) printf("Expanding \"%s\"...", cgn->name); ! cp = Var_Subst(cgn->name, &pgn->context, TRUE); if (cp == NULL) { printf("Problem substituting in %s", cgn->name); printf("\n"); --- 1184,1190 ---- if (DEBUG(SUFF)) printf("Expanding \"%s\"...", cgn->name); ! cp = Var_Subst(cgn->name, &pgn->context, true); if (cp == NULL) { printf("Problem substituting in %s", cgn->name); printf("\n"); *************** *** 1213,1219 **** if (isspace(*cp2)) { /* White-space -- terminate element, find the node, * add it, skip any further spaces. */ ! gn = Targ_FindNode(start, cp2, TARG_CREATE); cp2++; Lst_AtEnd(&members, gn); while (isspace(*cp2)) --- 1216,1222 ---- if (isspace(*cp2)) { /* White-space -- terminate element, find the node, * add it, skip any further spaces. */ ! gn = Targ_FindNodei(start, cp2, TARG_CREATE); cp2++; Lst_AtEnd(&members, gn); while (isspace(*cp2)) *************** *** 1232,1238 **** if (cp2 != start) { /* Stuff left over -- add it to the list too. */ ! gn = Targ_FindNode(start, cp2, TARG_CREATE); Lst_AtEnd(&members, gn); } } --- 1235,1241 ---- if (cp2 != start) { /* Stuff left over -- add it to the list too. */ ! gn = Targ_FindNodei(start, cp2, TARG_CREATE); Lst_AtEnd(&members, gn); } } *************** *** 1285,1291 **** path = &s->searchPath; } else /* Use default search path. */ ! path = &dirSearchPath; /* Expand the word along the chosen path. */ Lst_Init(&exp); --- 1288,1294 ---- path = &s->searchPath; } else /* Use default search path. */ ! path = dirSearchPath; /* Expand the word along the chosen path. */ Lst_Init(&exp); *************** *** 1296,1302 **** GNode *gn; /* New source 8) */ if (DEBUG(SUFF)) printf("%s...", cp); ! gn = Targ_FindNode(cp, NULL, TARG_CREATE); /* If gn isn't already a child of the parent, make it so and * up the parent's count of unmade children. */ --- 1299,1305 ---- GNode *gn; /* New source 8) */ if (DEBUG(SUFF)) printf("%s...", cp); ! gn = Targ_FindNode(cp, TARG_CREATE); /* If gn isn't already a child of the parent, make it so and * up the parent's count of unmade children. */ *************** *** 1361,1367 **** * and suffixes. * * Results: ! * TRUE if successful, FALSE if not. * * Side Effects: * The source and target are linked and the commands from the --- 1364,1370 ---- * and suffixes. * * Results: ! * true if successful, false if not. * * Side Effects: * The source and target are linked and the commands from the *************** *** 1371,1377 **** * the transformation rule. *----------------------------------------------------------------------- */ ! static Boolean SuffApplyTransform(tGn, sGn, t, s) GNode *tGn; /* Target node */ GNode *sGn; /* Source node */ --- 1374,1380 ---- * the transformation rule. *----------------------------------------------------------------------- */ ! static bool SuffApplyTransform(tGn, sGn, t, s) GNode *tGn; /* Target node */ GNode *sGn; /* Source node */ *************** *** 1383,1389 **** char *tname; /* Name of transformation rule */ GNode *gn; /* Node for same */ ! if (Lst_AddNew(&tGn->children, sGn) == SUCCESS) { /* Not already linked, so form the proper links between the * target and source. */ Lst_AtEnd(&sGn->parents, tGn); --- 1386,1392 ---- char *tname; /* Name of transformation rule */ GNode *gn; /* Node for same */ ! if (Lst_AddNew(&tGn->children, sGn)) { /* Not already linked, so form the proper links between the * target and source. */ Lst_AtEnd(&sGn->parents, tGn); *************** *** 1398,1404 **** for (ln=Lst_First(&sGn->cohorts); ln != NULL; ln=Lst_Adv(ln)) { gn = (GNode *)Lst_Datum(ln); ! if (Lst_AddNew(&tGn->children, gn) == SUCCESS) { /* Not already linked, so form the proper links between the * target and source. */ Lst_AtEnd(&gn->parents, tGn); --- 1401,1407 ---- for (ln=Lst_First(&sGn->cohorts); ln != NULL; ln=Lst_Adv(ln)) { gn = (GNode *)Lst_Datum(ln); ! if (Lst_AddNew(&tGn->children, gn)) { /* Not already linked, so form the proper links between the * target and source. */ Lst_AtEnd(&gn->parents, tGn); *************** *** 1407,1413 **** } } /* Locate the transformation rule itself. */ ! tname = str_concat(s->name, t->name, 0); ln = Lst_FindConst(&transforms, SuffGNHasNameP, tname); free(tname); --- 1410,1416 ---- } } /* Locate the transformation rule itself. */ ! tname = Str_concat(s->name, t->name, 0); ln = Lst_FindConst(&transforms, SuffGNHasNameP, tname); free(tname); *************** *** 1415,1423 **** /* * Not really such a transformation rule (can happen when we're * called to link an OP_MEMBER and OP_ARCHV node), so return ! * FALSE. */ ! return FALSE; gn = (GNode *)Lst_Datum(ln); --- 1418,1426 ---- /* * Not really such a transformation rule (can happen when we're * called to link an OP_MEMBER and OP_ARCHV node), so return ! * false. */ ! return false; gn = (GNode *)Lst_Datum(ln); *************** *** 1440,1446 **** * the .IMPSRC variable can be set correctly for the parent. */ Lst_AtEnd(&sGn->iParents, tGn); ! return TRUE; } --- 1443,1449 ---- * the .IMPSRC variable can be set correctly for the parent. */ Lst_AtEnd(&sGn->iParents, tGn); ! return true; } *************** *** 1481,1491 **** * to locate its suffix. This allows us to figure out the suffix to * use for the archive without having to do a quadratic search over the * suffix list, backtracking for each one... */ ! mem = Targ_FindNode(name, eoname, TARG_CREATE); SuffFindDeps(mem, slst); /* Create the link between the two nodes right off. */ ! if (Lst_AddNew(&gn->children, mem) == SUCCESS) { Lst_AtEnd(&mem->parents, gn); gn->unmade++; } --- 1484,1494 ---- * to locate its suffix. This allows us to figure out the suffix to * use for the archive without having to do a quadratic search over the * suffix list, backtracking for each one... */ ! mem = Targ_FindNodei(name, eoname, TARG_CREATE); SuffFindDeps(mem, slst); /* Create the link between the two nodes right off. */ ! if (Lst_AddNew(&gn->children, mem)) { Lst_AtEnd(&mem->parents, gn); gn->unmade++; } *************** *** 1708,1714 **** (Lst_IsEmpty(&gn->children) && Lst_IsEmpty(&gn->commands))) { gn->path = Dir_FindFile(gn->name, ! (targ == NULL ? &dirSearchPath : &targ->suff->searchPath)); if (gn->path != NULL) { char *ptr; --- 1711,1717 ---- (Lst_IsEmpty(&gn->children) && Lst_IsEmpty(&gn->commands))) { gn->path = Dir_FindFile(gn->name, ! (targ == NULL ? dirSearchPath : &targ->suff->searchPath)); if (gn->path != NULL) { char *ptr; *************** *** 1795,1801 **** * transformation rule. Also, the unmade field of gn is incremented. * Etc. */ if (bottom->node == NULL) { ! bottom->node = Targ_FindNode(bottom->file, NULL, TARG_CREATE); } for (src = bottom; src->parent != NULL; src = src->parent) { --- 1798,1804 ---- * transformation rule. Also, the unmade field of gn is incremented. * Etc. */ if (bottom->node == NULL) { ! bottom->node = Targ_FindNode(bottom->file, TARG_CREATE); } for (src = bottom; src->parent != NULL; src = src->parent) { *************** *** 1804,1810 **** src->node->suffix = src->suff; if (targ->node == NULL) { ! targ->node = Targ_FindNode(targ->file, NULL, TARG_CREATE); } SuffApplyTransform(targ->node, src->node, --- 1807,1813 ---- src->node->suffix = src->suff; if (targ->node == NULL) { ! targ->node = Targ_FindNode(targ->file, TARG_CREATE); } SuffApplyTransform(targ->node, src->node, *************** *** 1998,2004 **** suffNull->name = estrdup(""); suffNull->nameLen = 0; Lst_Init(&suffNull->searchPath); ! Dir_Concat(&suffNull->searchPath, &dirSearchPath); Lst_Init(&suffNull->children); Lst_Init(&suffNull->parents); Lst_Init(&suffNull->ref); --- 2001,2007 ---- suffNull->name = estrdup(""); suffNull->nameLen = 0; Lst_Init(&suffNull->searchPath); ! Dir_Concat(&suffNull->searchPath, dirSearchPath); Lst_Init(&suffNull->children); Lst_Init(&suffNull->parents); Lst_Init(&suffNull->ref); *************** *** 2018,2035 **** *---------------------------------------------------------------------- */ void Suff_End() { - #ifdef CLEANUP Lst_Destroy(&sufflist, SuffFree); Lst_Destroy(&suffClean, SuffFree); if (suffNull) SuffFree(suffNull); Lst_Destroy(&srclist, NOFREE); Lst_Destroy(&transforms, NOFREE); - #endif } /********************* DEBUGGING FUNCTIONS **********************/ --- 2021,2038 ---- *---------------------------------------------------------------------- */ + #ifdef CLEANUP void Suff_End() { Lst_Destroy(&sufflist, SuffFree); Lst_Destroy(&suffClean, SuffFree); if (suffNull) SuffFree(suffNull); Lst_Destroy(&srclist, NOFREE); Lst_Destroy(&transforms, NOFREE); } + #endif /********************* DEBUGGING FUNCTIONS **********************/ *************** *** 2104,2106 **** --- 2107,2118 ---- printf("#*** Transformations:\n"); Lst_Every(&transforms, SuffPrintTrans); } + + #ifdef DEBUG_SRC + static void + PrintAddr(a) + void *a; + { + printf("%lx ", (unsigned long)a); + } + #endif