Home | History | Annotate | Line # | Download | only in make
suff.c revision 1.42
      1 /*	$NetBSD: suff.c,v 1.42 2003/08/07 11:14:57 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1989, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Adam de Boor.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * Copyright (c) 1989 by Berkeley Softworks
     37  * All rights reserved.
     38  *
     39  * This code is derived from software contributed to Berkeley by
     40  * Adam de Boor.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  * 3. All advertising materials mentioning features or use of this software
     51  *    must display the following acknowledgement:
     52  *	This product includes software developed by the University of
     53  *	California, Berkeley and its contributors.
     54  * 4. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  */
     70 
     71 #ifdef MAKE_BOOTSTRAP
     72 static char rcsid[] = "$NetBSD: suff.c,v 1.42 2003/08/07 11:14:57 agc Exp $";
     73 #else
     74 #include <sys/cdefs.h>
     75 #ifndef lint
     76 #if 0
     77 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
     78 #else
     79 __RCSID("$NetBSD: suff.c,v 1.42 2003/08/07 11:14:57 agc Exp $");
     80 #endif
     81 #endif /* not lint */
     82 #endif
     83 
     84 /*-
     85  * suff.c --
     86  *	Functions to maintain suffix lists and find implicit dependents
     87  *	using suffix transformation rules
     88  *
     89  * Interface:
     90  *	Suff_Init 	    	Initialize all things to do with suffixes.
     91  *
     92  *	Suff_End 	    	Cleanup the module
     93  *
     94  *	Suff_DoPaths	    	This function is used to make life easier
     95  *	    	  	    	when searching for a file according to its
     96  *	    	  	    	suffix. It takes the global search path,
     97  *	    	  	    	as defined using the .PATH: target, and appends
     98  *	    	  	    	its directories to the path of each of the
     99  *	    	  	    	defined suffixes, as specified using
    100  *	    	  	    	.PATH<suffix>: targets. In addition, all
    101  *	    	  	    	directories given for suffixes labeled as
    102  *	    	  	    	include files or libraries, using the .INCLUDES
    103  *	    	  	    	or .LIBS targets, are played with using
    104  *	    	  	    	Dir_MakeFlags to create the .INCLUDES and
    105  *	    	  	    	.LIBS global variables.
    106  *
    107  *	Suff_ClearSuffixes  	Clear out all the suffixes and defined
    108  *	    	  	    	transformations.
    109  *
    110  *	Suff_IsTransform    	Return TRUE if the passed string is the lhs
    111  *	    	  	    	of a transformation rule.
    112  *
    113  *	Suff_AddSuffix	    	Add the passed string as another known suffix.
    114  *
    115  *	Suff_GetPath	    	Return the search path for the given suffix.
    116  *
    117  *	Suff_AddInclude	    	Mark the given suffix as denoting an include
    118  *	    	  	    	file.
    119  *
    120  *	Suff_AddLib	    	Mark the given suffix as denoting a library.
    121  *
    122  *	Suff_AddTransform   	Add another transformation to the suffix
    123  *	    	  	    	graph. Returns  GNode suitable for framing, I
    124  *	    	  	    	mean, tacking commands, attributes, etc. on.
    125  *
    126  *	Suff_SetNull	    	Define the suffix to consider the suffix of
    127  *	    	  	    	any file that doesn't have a known one.
    128  *
    129  *	Suff_FindDeps	    	Find implicit sources for and the location of
    130  *	    	  	    	a target based on its suffix. Returns the
    131  *	    	  	    	bottom-most node added to the graph or NILGNODE
    132  *	    	  	    	if the target had no implicit sources.
    133  */
    134 
    135 #include    	  <stdio.h>
    136 #include	  "make.h"
    137 #include	  "hash.h"
    138 #include	  "dir.h"
    139 
    140 static Lst       sufflist;	/* Lst of suffixes */
    141 #ifdef CLEANUP
    142 static Lst	 suffClean;	/* Lst of suffixes to be cleaned */
    143 #endif
    144 static Lst	 srclist;	/* Lst of sources */
    145 static Lst       transforms;	/* Lst of transformation rules */
    146 
    147 static int        sNum = 0;	/* Counter for assigning suffix numbers */
    148 
    149 /*
    150  * Structure describing an individual suffix.
    151  */
    152 typedef struct _Suff {
    153     char         *name;	    	/* The suffix itself */
    154     int		 nameLen;	/* Length of the suffix */
    155     short	 flags;      	/* Type of suffix */
    156 #define SUFF_INCLUDE	  0x01	    /* One which is #include'd */
    157 #define SUFF_LIBRARY	  0x02	    /* One which contains a library */
    158 #define SUFF_NULL 	  0x04	    /* The empty suffix */
    159     Lst    	 searchPath;	/* The path along which files of this suffix
    160 				 * may be found */
    161     int          sNum;	      	/* The suffix number */
    162     int		 refCount;	/* Reference count of list membership */
    163     Lst          parents;	/* Suffixes we have a transformation to */
    164     Lst          children;	/* Suffixes we have a transformation from */
    165     Lst		 ref;		/* List of lists this suffix is referenced */
    166 } Suff;
    167 
    168 /*
    169  * for SuffSuffIsSuffix
    170  */
    171 typedef struct {
    172     char	*ename;		/* The end of the name */
    173     int		 len;		/* Length of the name */
    174 } SuffixCmpData;
    175 
    176 /*
    177  * Structure used in the search for implied sources.
    178  */
    179 typedef struct _Src {
    180     char            *file;	/* The file to look for */
    181     char    	    *pref;  	/* Prefix from which file was formed */
    182     Suff            *suff;	/* The suffix on the file */
    183     struct _Src     *parent;	/* The Src for which this is a source */
    184     GNode           *node;	/* The node describing the file */
    185     int	    	    children;	/* Count of existing children (so we don't free
    186 				 * this thing too early or never nuke it) */
    187 #ifdef DEBUG_SRC
    188     Lst		    cp;		/* Debug; children list */
    189 #endif
    190 } Src;
    191 
    192 /*
    193  * A structure for passing more than one argument to the Lst-library-invoked
    194  * function...
    195  */
    196 typedef struct {
    197     Lst            l;
    198     Src            *s;
    199 } LstSrc;
    200 
    201 typedef struct {
    202     GNode	  **gn;
    203     Suff	   *s;
    204     Boolean	    r;
    205 } GNodeSuff;
    206 
    207 static Suff 	    *suffNull;	/* The NULL suffix for this run */
    208 static Suff 	    *emptySuff;	/* The empty suffix required for POSIX
    209 				 * single-suffix transformation rules */
    210 
    211 
    212 static char *SuffStrIsPrefix(char *, char *);
    213 static char *SuffSuffIsSuffix(Suff *, SuffixCmpData *);
    214 static int SuffSuffIsSuffixP(ClientData, ClientData);
    215 static int SuffSuffHasNameP(ClientData, ClientData);
    216 static int SuffSuffIsPrefix(ClientData, ClientData);
    217 static int SuffGNHasNameP(ClientData, ClientData);
    218 static void SuffUnRef(ClientData, ClientData);
    219 static void SuffFree(ClientData);
    220 static void SuffInsert(Lst, Suff *);
    221 static void SuffRemove(Lst, Suff *);
    222 static Boolean SuffParseTransform(char *, Suff **, Suff **);
    223 static int SuffRebuildGraph(ClientData, ClientData);
    224 static int SuffScanTargets(ClientData, ClientData);
    225 static int SuffAddSrc(ClientData, ClientData);
    226 static int SuffRemoveSrc(Lst);
    227 static void SuffAddLevel(Lst, Src *);
    228 static Src *SuffFindThem(Lst, Lst);
    229 static Src *SuffFindCmds(Src *, Lst);
    230 static int SuffExpandChildren(LstNode, GNode *);
    231 static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
    232 static void SuffFindDeps(GNode *, Lst);
    233 static void SuffFindArchiveDeps(GNode *, Lst);
    234 static void SuffFindNormalDeps(GNode *, Lst);
    235 static int SuffPrintName(ClientData, ClientData);
    236 static int SuffPrintSuff(ClientData, ClientData);
    237 static int SuffPrintTrans(ClientData, ClientData);
    238 
    239 	/*************** Lst Predicates ****************/
    240 /*-
    241  *-----------------------------------------------------------------------
    242  * SuffStrIsPrefix  --
    243  *	See if pref is a prefix of str.
    244  *
    245  * Input:
    246  *	pref		possible prefix
    247  *	str		string to check
    248  *
    249  * Results:
    250  *	NULL if it ain't, pointer to character in str after prefix if so
    251  *
    252  * Side Effects:
    253  *	None
    254  *-----------------------------------------------------------------------
    255  */
    256 static char    *
    257 SuffStrIsPrefix(char *pref, char *str)
    258 {
    259     while (*str && *pref == *str) {
    260 	pref++;
    261 	str++;
    262     }
    263 
    264     return (*pref ? NULL : str);
    265 }
    266 
    267 /*-
    268  *-----------------------------------------------------------------------
    269  * SuffSuffIsSuffix  --
    270  *	See if suff is a suffix of str. sd->ename should point to THE END
    271  *	of the string to check. (THE END == the null byte)
    272  *
    273  * Input:
    274  *	s		possible suffix
    275  *	sd		string to examine
    276  *
    277  * Results:
    278  *	NULL if it ain't, pointer to character in str before suffix if
    279  *	it is.
    280  *
    281  * Side Effects:
    282  *	None
    283  *-----------------------------------------------------------------------
    284  */
    285 static char *
    286 SuffSuffIsSuffix(Suff *s, SuffixCmpData *sd)
    287 {
    288     char  *p1;	    	/* Pointer into suffix name */
    289     char  *p2;	    	/* Pointer into string being examined */
    290 
    291     if (sd->len < s->nameLen)
    292 	return NULL;		/* this string is shorter than the suffix */
    293 
    294     p1 = s->name + s->nameLen;
    295     p2 = sd->ename;
    296 
    297     while (p1 >= s->name && *p1 == *p2) {
    298 	p1--;
    299 	p2--;
    300     }
    301 
    302     return (p1 == s->name - 1 ? p2 : NULL);
    303 }
    304 
    305 /*-
    306  *-----------------------------------------------------------------------
    307  * SuffSuffIsSuffixP --
    308  *	Predicate form of SuffSuffIsSuffix. Passed as the callback function
    309  *	to Lst_Find.
    310  *
    311  * Results:
    312  *	0 if the suffix is the one desired, non-zero if not.
    313  *
    314  * Side Effects:
    315  *	None.
    316  *
    317  *-----------------------------------------------------------------------
    318  */
    319 static int
    320 SuffSuffIsSuffixP(ClientData s, ClientData sd)
    321 {
    322     return(!SuffSuffIsSuffix((Suff *) s, (SuffixCmpData *) sd));
    323 }
    324 
    325 /*-
    326  *-----------------------------------------------------------------------
    327  * SuffSuffHasNameP --
    328  *	Callback procedure for finding a suffix based on its name. Used by
    329  *	Suff_GetPath.
    330  *
    331  * Input:
    332  *	s		Suffix to check
    333  *	sd		Desired name
    334  *
    335  * Results:
    336  *	0 if the suffix is of the given name. non-zero otherwise.
    337  *
    338  * Side Effects:
    339  *	None
    340  *-----------------------------------------------------------------------
    341  */
    342 static int
    343 SuffSuffHasNameP(ClientData s, ClientData sname)
    344 {
    345     return (strcmp ((char *) sname, ((Suff *) s)->name));
    346 }
    347 
    348 /*-
    349  *-----------------------------------------------------------------------
    350  * SuffSuffIsPrefix  --
    351  *	See if the suffix described by s is a prefix of the string. Care
    352  *	must be taken when using this to search for transformations and
    353  *	what-not, since there could well be two suffixes, one of which
    354  *	is a prefix of the other...
    355  *
    356  * Input:
    357  *	s		suffix to compare
    358  *	str		string to examine
    359  *
    360  * Results:
    361  *	0 if s is a prefix of str. non-zero otherwise
    362  *
    363  * Side Effects:
    364  *	None
    365  *-----------------------------------------------------------------------
    366  */
    367 static int
    368 SuffSuffIsPrefix(ClientData s, ClientData str)
    369 {
    370     return (SuffStrIsPrefix (((Suff *) s)->name, (char *) str) == NULL ? 1 : 0);
    371 }
    372 
    373 /*-
    374  *-----------------------------------------------------------------------
    375  * SuffGNHasNameP  --
    376  *	See if the graph node has the desired name
    377  *
    378  * Input:
    379  *	gn		current node we're looking at
    380  *	name		name we're looking for
    381  *
    382  * Results:
    383  *	0 if it does. non-zero if it doesn't
    384  *
    385  * Side Effects:
    386  *	None
    387  *-----------------------------------------------------------------------
    388  */
    389 static int
    390 SuffGNHasNameP(ClientData gn, ClientData name)
    391 {
    392     return (strcmp ((char *) name, ((GNode *) gn)->name));
    393 }
    394 
    395  	    /*********** Maintenance Functions ************/
    396 
    397 static void
    398 SuffUnRef(ClientData lp, ClientData sp)
    399 {
    400     Lst l = (Lst) lp;
    401 
    402     LstNode ln = Lst_Member(l, sp);
    403     if (ln != NILLNODE) {
    404 	Lst_Remove(l, ln);
    405 	((Suff *) sp)->refCount--;
    406     }
    407 }
    408 
    409 /*-
    410  *-----------------------------------------------------------------------
    411  * SuffFree  --
    412  *	Free up all memory associated with the given suffix structure.
    413  *
    414  * Results:
    415  *	none
    416  *
    417  * Side Effects:
    418  *	the suffix entry is detroyed
    419  *-----------------------------------------------------------------------
    420  */
    421 static void
    422 SuffFree(ClientData sp)
    423 {
    424     Suff           *s = (Suff *) sp;
    425 
    426     if (s == suffNull)
    427 	suffNull = NULL;
    428 
    429     if (s == emptySuff)
    430 	emptySuff = NULL;
    431 
    432 #ifdef notdef
    433     /* We don't delete suffixes in order, so we cannot use this */
    434     if (s->refCount)
    435 	Punt("Internal error deleting suffix `%s' with refcount = %d", s->name,
    436 	    s->refCount);
    437 #endif
    438 
    439     Lst_Destroy (s->ref, NOFREE);
    440     Lst_Destroy (s->children, NOFREE);
    441     Lst_Destroy (s->parents, NOFREE);
    442     Lst_Destroy (s->searchPath, Dir_Destroy);
    443 
    444     free ((Address)s->name);
    445     free ((Address)s);
    446 }
    447 
    448 /*-
    449  *-----------------------------------------------------------------------
    450  * SuffRemove  --
    451  *	Remove the suffix into the list
    452  *
    453  * Results:
    454  *	None
    455  *
    456  * Side Effects:
    457  *	The reference count for the suffix is decremented and the
    458  *	suffix is possibly freed
    459  *-----------------------------------------------------------------------
    460  */
    461 static void
    462 SuffRemove(Lst l, Suff *s)
    463 {
    464     SuffUnRef((ClientData) l, (ClientData) s);
    465     if (s->refCount == 0) {
    466 	SuffUnRef ((ClientData) sufflist, (ClientData) s);
    467 	SuffFree((ClientData) s);
    468     }
    469 }
    470 
    471 /*-
    473  *-----------------------------------------------------------------------
    474  * SuffInsert  --
    475  *	Insert the suffix into the list keeping the list ordered by suffix
    476  *	numbers.
    477  *
    478  * Input:
    479  *	l		the list where in s should be inserted
    480  *	s		the suffix to insert
    481  *
    482  * Results:
    483  *	None
    484  *
    485  * Side Effects:
    486  *	The reference count of the suffix is incremented
    487  *-----------------------------------------------------------------------
    488  */
    489 static void
    490 SuffInsert(Lst l, Suff *s)
    491 {
    492     LstNode 	  ln;		/* current element in l we're examining */
    493     Suff          *s2 = NULL;	/* the suffix descriptor in this element */
    494 
    495     if (Lst_Open (l) == FAILURE) {
    496 	return;
    497     }
    498     while ((ln = Lst_Next (l)) != NILLNODE) {
    499 	s2 = (Suff *) Lst_Datum (ln);
    500 	if (s2->sNum >= s->sNum) {
    501 	    break;
    502 	}
    503     }
    504 
    505     Lst_Close (l);
    506     if (DEBUG(SUFF)) {
    507 	printf("inserting %s(%d)...", s->name, s->sNum);
    508     }
    509     if (ln == NILLNODE) {
    510 	if (DEBUG(SUFF)) {
    511 	    printf("at end of list\n");
    512 	}
    513 	(void)Lst_AtEnd (l, (ClientData)s);
    514 	s->refCount++;
    515 	(void)Lst_AtEnd(s->ref, (ClientData) l);
    516     } else if (s2->sNum != s->sNum) {
    517 	if (DEBUG(SUFF)) {
    518 	    printf("before %s(%d)\n", s2->name, s2->sNum);
    519 	}
    520 	(void)Lst_Insert (l, ln, (ClientData)s);
    521 	s->refCount++;
    522 	(void)Lst_AtEnd(s->ref, (ClientData) l);
    523     } else if (DEBUG(SUFF)) {
    524 	printf("already there\n");
    525     }
    526 }
    527 
    528 /*-
    529  *-----------------------------------------------------------------------
    530  * Suff_ClearSuffixes --
    531  *	This is gross. Nuke the list of suffixes but keep all transformation
    532  *	rules around. The transformation graph is destroyed in this process,
    533  *	but we leave the list of rules so when a new graph is formed the rules
    534  *	will remain.
    535  *	This function is called from the parse module when a
    536  *	.SUFFIXES:\n line is encountered.
    537  *
    538  * Results:
    539  *	none
    540  *
    541  * Side Effects:
    542  *	the sufflist and its graph nodes are destroyed
    543  *-----------------------------------------------------------------------
    544  */
    545 void
    546 Suff_ClearSuffixes(void)
    547 {
    548 #ifdef CLEANUP
    549     Lst_Concat (suffClean, sufflist, LST_CONCLINK);
    550 #endif
    551     sufflist = Lst_Init(FALSE);
    552     sNum = 0;
    553     suffNull = emptySuff;
    554 }
    555 
    556 /*-
    557  *-----------------------------------------------------------------------
    558  * SuffParseTransform --
    559  *	Parse a transformation string to find its two component suffixes.
    560  *
    561  * Input:
    562  *	str		String being parsed
    563  *	srcPtr		Place to store source of trans.
    564  *	targPtr		Place to store target of trans.
    565  *
    566  * Results:
    567  *	TRUE if the string is a valid transformation and FALSE otherwise.
    568  *
    569  * Side Effects:
    570  *	The passed pointers are overwritten.
    571  *
    572  *-----------------------------------------------------------------------
    573  */
    574 static Boolean
    575 SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
    576 {
    577     LstNode		srcLn;	    /* element in suffix list of trans source*/
    578     Suff		*src;	    /* Source of transformation */
    579     LstNode		targLn;	    /* element in suffix list of trans target*/
    580     char		*str2;	    /* Extra pointer (maybe target suffix) */
    581     LstNode 	    	singleLn;   /* element in suffix list of any suffix
    582 				     * that exactly matches str */
    583     Suff    	    	*single = NULL;/* Source of possible transformation to
    584 				     * null suffix */
    585 
    586     srcLn = NILLNODE;
    587     singleLn = NILLNODE;
    588 
    589     /*
    590      * Loop looking first for a suffix that matches the start of the
    591      * string and then for one that exactly matches the rest of it. If
    592      * we can find two that meet these criteria, we've successfully
    593      * parsed the string.
    594      */
    595     for (;;) {
    596 	if (srcLn == NILLNODE) {
    597 	    srcLn = Lst_Find(sufflist, (ClientData)str, SuffSuffIsPrefix);
    598 	} else {
    599 	    srcLn = Lst_FindFrom (sufflist, Lst_Succ(srcLn), (ClientData)str,
    600 				  SuffSuffIsPrefix);
    601 	}
    602 	if (srcLn == NILLNODE) {
    603 	    /*
    604 	     * Ran out of source suffixes -- no such rule
    605 	     */
    606 	    if (singleLn != NILLNODE) {
    607 		/*
    608 		 * Not so fast Mr. Smith! There was a suffix that encompassed
    609 		 * the entire string, so we assume it was a transformation
    610 		 * to the null suffix (thank you POSIX). We still prefer to
    611 		 * find a double rule over a singleton, hence we leave this
    612 		 * check until the end.
    613 		 *
    614 		 * XXX: Use emptySuff over suffNull?
    615 		 */
    616 		*srcPtr = single;
    617 		*targPtr = suffNull;
    618 		return(TRUE);
    619 	    }
    620 	    return (FALSE);
    621 	}
    622 	src = (Suff *) Lst_Datum (srcLn);
    623 	str2 = str + src->nameLen;
    624 	if (*str2 == '\0') {
    625 	    single = src;
    626 	    singleLn = srcLn;
    627 	} else {
    628 	    targLn = Lst_Find(sufflist, (ClientData)str2, SuffSuffHasNameP);
    629 	    if (targLn != NILLNODE) {
    630 		*srcPtr = src;
    631 		*targPtr = (Suff *)Lst_Datum(targLn);
    632 		return (TRUE);
    633 	    }
    634 	}
    635     }
    636 }
    637 
    638 /*-
    639  *-----------------------------------------------------------------------
    640  * Suff_IsTransform  --
    641  *	Return TRUE if the given string is a transformation rule
    642  *
    643  *
    644  * Input:
    645  *	str		string to check
    646  *
    647  * Results:
    648  *	TRUE if the string is a concatenation of two known suffixes.
    649  *	FALSE otherwise
    650  *
    651  * Side Effects:
    652  *	None
    653  *-----------------------------------------------------------------------
    654  */
    655 Boolean
    656 Suff_IsTransform(char *str)
    657 {
    658     Suff    	  *src, *targ;
    659 
    660     return (SuffParseTransform(str, &src, &targ));
    661 }
    662 
    663 /*-
    664  *-----------------------------------------------------------------------
    665  * Suff_AddTransform --
    666  *	Add the transformation rule described by the line to the
    667  *	list of rules and place the transformation itself in the graph
    668  *
    669  * Input:
    670  *	line		name of transformation to add
    671  *
    672  * Results:
    673  *	The node created for the transformation in the transforms list
    674  *
    675  * Side Effects:
    676  *	The node is placed on the end of the transforms Lst and links are
    677  *	made between the two suffixes mentioned in the target name
    678  *-----------------------------------------------------------------------
    679  */
    680 GNode *
    681 Suff_AddTransform(char *line)
    682 {
    683     GNode         *gn;		/* GNode of transformation rule */
    684     Suff          *s,		/* source suffix */
    685                   *t;		/* target suffix */
    686     LstNode 	  ln;	    	/* Node for existing transformation */
    687 
    688     ln = Lst_Find (transforms, (ClientData)line, SuffGNHasNameP);
    689     if (ln == NILLNODE) {
    690 	/*
    691 	 * Make a new graph node for the transformation. It will be filled in
    692 	 * by the Parse module.
    693 	 */
    694 	gn = Targ_NewGN (line);
    695 	(void)Lst_AtEnd (transforms, (ClientData)gn);
    696     } else {
    697 	/*
    698 	 * New specification for transformation rule. Just nuke the old list
    699 	 * of commands so they can be filled in again... We don't actually
    700 	 * free the commands themselves, because a given command can be
    701 	 * attached to several different transformations.
    702 	 */
    703 	gn = (GNode *) Lst_Datum (ln);
    704 	Lst_Destroy (gn->commands, NOFREE);
    705 	Lst_Destroy (gn->children, NOFREE);
    706 	gn->commands = Lst_Init (FALSE);
    707 	gn->children = Lst_Init (FALSE);
    708     }
    709 
    710     gn->type = OP_TRANSFORM;
    711 
    712     (void)SuffParseTransform(line, &s, &t);
    713 
    714     /*
    715      * link the two together in the proper relationship and order
    716      */
    717     if (DEBUG(SUFF)) {
    718 	printf("defining transformation from `%s' to `%s'\n",
    719 		s->name, t->name);
    720     }
    721     SuffInsert (t->children, s);
    722     SuffInsert (s->parents, t);
    723 
    724     return (gn);
    725 }
    726 
    727 /*-
    728  *-----------------------------------------------------------------------
    729  * Suff_EndTransform --
    730  *	Handle the finish of a transformation definition, removing the
    731  *	transformation from the graph if it has neither commands nor
    732  *	sources. This is a callback procedure for the Parse module via
    733  *	Lst_ForEach
    734  *
    735  * Input:
    736  *	gnp		Node for transformation
    737  *	dummy		Node for transformation
    738  *
    739  * Results:
    740  *	=== 0
    741  *
    742  * Side Effects:
    743  *	If the node has no commands or children, the children and parents
    744  *	lists of the affected suffices are altered.
    745  *
    746  *-----------------------------------------------------------------------
    747  */
    748 int
    749 Suff_EndTransform(ClientData gnp, ClientData dummy)
    750 {
    751     GNode *gn = (GNode *) gnp;
    752 
    753     if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
    754 	gn = (GNode *) Lst_Datum (Lst_Last (gn->cohorts));
    755     if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) &&
    756 	Lst_IsEmpty(gn->children))
    757     {
    758 	Suff	*s, *t;
    759 
    760 	/*
    761 	 * SuffParseTransform() may fail for special rules which are not
    762 	 * actual transformation rules. (e.g. .DEFAULT)
    763 	 */
    764 	if (SuffParseTransform(gn->name, &s, &t)) {
    765 	    Lst	 p;
    766 
    767 	    if (DEBUG(SUFF)) {
    768 		printf("deleting transformation from `%s' to `%s'\n",
    769 		s->name, t->name);
    770 	    }
    771 
    772 	    /*
    773 	     * Store s->parents because s could be deleted in SuffRemove
    774 	     */
    775 	    p = s->parents;
    776 
    777 	    /*
    778 	     * Remove the source from the target's children list. We check for a
    779 	     * nil return to handle a beanhead saying something like
    780 	     *  .c.o .c.o:
    781 	     *
    782 	     * We'll be called twice when the next target is seen, but .c and .o
    783 	     * are only linked once...
    784 	     */
    785 	    SuffRemove(t->children, s);
    786 
    787 	    /*
    788 	     * Remove the target from the source's parents list
    789 	     */
    790 	    SuffRemove(p, t);
    791 	}
    792     } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
    793 	printf("transformation %s complete\n", gn->name);
    794     }
    795 
    796     return(dummy ? 0 : 0);
    797 }
    798 
    799 /*-
    800  *-----------------------------------------------------------------------
    801  * SuffRebuildGraph --
    802  *	Called from Suff_AddSuffix via Lst_ForEach to search through the
    803  *	list of existing transformation rules and rebuild the transformation
    804  *	graph when it has been destroyed by Suff_ClearSuffixes. If the
    805  *	given rule is a transformation involving this suffix and another,
    806  *	existing suffix, the proper relationship is established between
    807  *	the two.
    808  *
    809  * Input:
    810  *	transformp	Transformation to test
    811  *	sp		Suffix to rebuild
    812  *
    813  * Results:
    814  *	Always 0.
    815  *
    816  * Side Effects:
    817  *	The appropriate links will be made between this suffix and
    818  *	others if transformation rules exist for it.
    819  *
    820  *-----------------------------------------------------------------------
    821  */
    822 static int
    823 SuffRebuildGraph(ClientData transformp, ClientData sp)
    824 {
    825     GNode   	*transform = (GNode *) transformp;
    826     Suff    	*s = (Suff *) sp;
    827     char 	*cp;
    828     LstNode	ln;
    829     Suff  	*s2;
    830     SuffixCmpData sd;
    831 
    832     /*
    833      * First see if it is a transformation from this suffix.
    834      */
    835     cp = SuffStrIsPrefix(s->name, transform->name);
    836     if (cp != (char *)NULL) {
    837 	ln = Lst_Find(sufflist, (ClientData)cp, SuffSuffHasNameP);
    838 	if (ln != NILLNODE) {
    839 	    /*
    840 	     * Found target. Link in and return, since it can't be anything
    841 	     * else.
    842 	     */
    843 	    s2 = (Suff *)Lst_Datum(ln);
    844 	    SuffInsert(s2->children, s);
    845 	    SuffInsert(s->parents, s2);
    846 	    return(0);
    847 	}
    848     }
    849 
    850     /*
    851      * Not from, maybe to?
    852      */
    853     sd.len = strlen(transform->name);
    854     sd.ename = transform->name + sd.len;
    855     cp = SuffSuffIsSuffix(s, &sd);
    856     if (cp != (char *)NULL) {
    857 	/*
    858 	 * Null-terminate the source suffix in order to find it.
    859 	 */
    860 	cp[1] = '\0';
    861 	ln = Lst_Find(sufflist, (ClientData)transform->name, SuffSuffHasNameP);
    862 	/*
    863 	 * Replace the start of the target suffix
    864 	 */
    865 	cp[1] = s->name[0];
    866 	if (ln != NILLNODE) {
    867 	    /*
    868 	     * Found it -- establish the proper relationship
    869 	     */
    870 	    s2 = (Suff *)Lst_Datum(ln);
    871 	    SuffInsert(s->children, s2);
    872 	    SuffInsert(s2->parents, s);
    873 	}
    874     }
    875     return(0);
    876 }
    877 
    878 /*-
    879  *-----------------------------------------------------------------------
    880  * SuffScanTargets --
    881  *	Called from Suff_AddSuffix via Lst_ForEach to search through the
    882  *	list of existing targets and find if any of the existing targets
    883  *	can be turned into a transformation rule.
    884  *
    885  * Results:
    886  *	1 if a new main target has been selected, 0 otherwise.
    887  *
    888  * Side Effects:
    889  *	If such a target is found and the target is the current main
    890  *	target, the main target is set to NULL and the next target
    891  *	examined (if that exists) becomes the main target.
    892  *
    893  *-----------------------------------------------------------------------
    894  */
    895 static int
    896 SuffScanTargets(ClientData targetp, ClientData gsp)
    897 {
    898     GNode   	*target = (GNode *) targetp;
    899     GNodeSuff	*gs = (GNodeSuff *) gsp;
    900     Suff	*s, *t;
    901     char 	*ptr;
    902 
    903     if (*gs->gn == NILGNODE && gs->r && (target->type & OP_NOTARGET) == 0) {
    904 	*gs->gn = target;
    905 	Targ_SetMain(target);
    906 	return 1;
    907     }
    908 
    909     if (target->type == OP_TRANSFORM)
    910 	return 0;
    911 
    912     if ((ptr = strstr(target->name, gs->s->name)) == NULL ||
    913 	ptr == target->name)
    914 	return 0;
    915 
    916     if (SuffParseTransform(target->name, &s, &t)) {
    917 	if (*gs->gn == target) {
    918 	    gs->r = TRUE;
    919 	    *gs->gn = NILGNODE;
    920 	    Targ_SetMain(NILGNODE);
    921 	}
    922 	Lst_Destroy (target->children, NOFREE);
    923 	target->children = Lst_Init (FALSE);
    924 	target->type = OP_TRANSFORM;
    925 	/*
    926 	 * link the two together in the proper relationship and order
    927 	 */
    928 	if (DEBUG(SUFF)) {
    929 	    printf("defining transformation from `%s' to `%s'\n",
    930 		s->name, t->name);
    931 	}
    932 	SuffInsert (t->children, s);
    933 	SuffInsert (s->parents, t);
    934     }
    935     return 0;
    936 }
    937 
    938 /*-
    939  *-----------------------------------------------------------------------
    940  * Suff_AddSuffix --
    941  *	Add the suffix in string to the end of the list of known suffixes.
    942  *	Should we restructure the suffix graph? Make doesn't...
    943  *
    944  * Input:
    945  *	str		the name of the suffix to add
    946  *
    947  * Results:
    948  *	None
    949  *
    950  * Side Effects:
    951  *	A GNode is created for the suffix and a Suff structure is created and
    952  *	added to the suffixes list unless the suffix was already known.
    953  *	The mainNode passed can be modified if a target mutated into a
    954  *	transform and that target happened to be the main target.
    955  *-----------------------------------------------------------------------
    956  */
    957 void
    958 Suff_AddSuffix(char *str, GNode **gn)
    959 {
    960     Suff          *s;	    /* new suffix descriptor */
    961     LstNode 	  ln;
    962     GNodeSuff	  gs;
    963 
    964     ln = Lst_Find (sufflist, (ClientData)str, SuffSuffHasNameP);
    965     if (ln == NILLNODE) {
    966 	s = (Suff *) emalloc (sizeof (Suff));
    967 
    968 	s->name =   	estrdup (str);
    969 	s->nameLen = 	strlen (s->name);
    970 	s->searchPath = Lst_Init (FALSE);
    971 	s->children = 	Lst_Init (FALSE);
    972 	s->parents = 	Lst_Init (FALSE);
    973 	s->ref = 	Lst_Init (FALSE);
    974 	s->sNum =   	sNum++;
    975 	s->flags =  	0;
    976 	s->refCount =	1;
    977 
    978 	(void)Lst_AtEnd (sufflist, (ClientData)s);
    979 	/*
    980 	 * We also look at our existing targets list to see if adding
    981 	 * this suffix will make one of our current targets mutate into
    982 	 * a suffix rule. This is ugly, but other makes treat all targets
    983 	 * that start with a . as suffix rules.
    984 	 */
    985 	gs.gn = gn;
    986 	gs.s  = s;
    987 	gs.r  = FALSE;
    988 	Lst_ForEach (Targ_List(), SuffScanTargets, (ClientData) &gs);
    989 	/*
    990 	 * Look for any existing transformations from or to this suffix.
    991 	 * XXX: Only do this after a Suff_ClearSuffixes?
    992 	 */
    993 	Lst_ForEach (transforms, SuffRebuildGraph, (ClientData) s);
    994     }
    995 }
    996 
    997 /*-
    998  *-----------------------------------------------------------------------
    999  * Suff_GetPath --
   1000  *	Return the search path for the given suffix, if it's defined.
   1001  *
   1002  * Results:
   1003  *	The searchPath for the desired suffix or NILLST if the suffix isn't
   1004  *	defined.
   1005  *
   1006  * Side Effects:
   1007  *	None
   1008  *-----------------------------------------------------------------------
   1009  */
   1010 Lst
   1011 Suff_GetPath(char *sname)
   1012 {
   1013     LstNode   	  ln;
   1014     Suff    	  *s;
   1015 
   1016     ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
   1017     if (ln == NILLNODE) {
   1018 	return (NILLST);
   1019     } else {
   1020 	s = (Suff *) Lst_Datum (ln);
   1021 	return (s->searchPath);
   1022     }
   1023 }
   1024 
   1025 /*-
   1026  *-----------------------------------------------------------------------
   1027  * Suff_DoPaths --
   1028  *	Extend the search paths for all suffixes to include the default
   1029  *	search path.
   1030  *
   1031  * Results:
   1032  *	None.
   1033  *
   1034  * Side Effects:
   1035  *	The searchPath field of all the suffixes is extended by the
   1036  *	directories in dirSearchPath. If paths were specified for the
   1037  *	".h" suffix, the directories are stuffed into a global variable
   1038  *	called ".INCLUDES" with each directory preceded by a -I. The same
   1039  *	is done for the ".a" suffix, except the variable is called
   1040  *	".LIBS" and the flag is -L.
   1041  *-----------------------------------------------------------------------
   1042  */
   1043 void
   1044 Suff_DoPaths(void)
   1045 {
   1046     Suff	   	*s;
   1047     LstNode  		ln;
   1048     char		*ptr;
   1049     Lst	    	    	inIncludes; /* Cumulative .INCLUDES path */
   1050     Lst	    	    	inLibs;	    /* Cumulative .LIBS path */
   1051 
   1052     if (Lst_Open (sufflist) == FAILURE) {
   1053 	return;
   1054     }
   1055 
   1056     inIncludes = Lst_Init(FALSE);
   1057     inLibs = Lst_Init(FALSE);
   1058 
   1059     while ((ln = Lst_Next (sufflist)) != NILLNODE) {
   1060 	s = (Suff *) Lst_Datum (ln);
   1061 	if (!Lst_IsEmpty (s->searchPath)) {
   1062 #ifdef INCLUDES
   1063 	    if (s->flags & SUFF_INCLUDE) {
   1064 		Dir_Concat(inIncludes, s->searchPath);
   1065 	    }
   1066 #endif /* INCLUDES */
   1067 #ifdef LIBRARIES
   1068 	    if (s->flags & SUFF_LIBRARY) {
   1069 		Dir_Concat(inLibs, s->searchPath);
   1070 	    }
   1071 #endif /* LIBRARIES */
   1072 	    Dir_Concat(s->searchPath, dirSearchPath);
   1073 	} else {
   1074 	    Lst_Destroy (s->searchPath, Dir_Destroy);
   1075 	    s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir);
   1076 	}
   1077     }
   1078 
   1079     Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL, 0);
   1080     free(ptr);
   1081     Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL, 0);
   1082     free(ptr);
   1083 
   1084     Lst_Destroy(inIncludes, Dir_Destroy);
   1085     Lst_Destroy(inLibs, Dir_Destroy);
   1086 
   1087     Lst_Close (sufflist);
   1088 }
   1089 
   1090 /*-
   1091  *-----------------------------------------------------------------------
   1092  * Suff_AddInclude --
   1093  *	Add the given suffix as a type of file which gets included.
   1094  *	Called from the parse module when a .INCLUDES line is parsed.
   1095  *	The suffix must have already been defined.
   1096  *
   1097  * Input:
   1098  *	sname		Name of the suffix to mark
   1099  *
   1100  * Results:
   1101  *	None.
   1102  *
   1103  * Side Effects:
   1104  *	The SUFF_INCLUDE bit is set in the suffix's flags field
   1105  *
   1106  *-----------------------------------------------------------------------
   1107  */
   1108 void
   1109 Suff_AddInclude(char *sname)
   1110 {
   1111     LstNode	  ln;
   1112     Suff	  *s;
   1113 
   1114     ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
   1115     if (ln != NILLNODE) {
   1116 	s = (Suff *) Lst_Datum (ln);
   1117 	s->flags |= SUFF_INCLUDE;
   1118     }
   1119 }
   1120 
   1121 /*-
   1122  *-----------------------------------------------------------------------
   1123  * Suff_AddLib --
   1124  *	Add the given suffix as a type of file which is a library.
   1125  *	Called from the parse module when parsing a .LIBS line. The
   1126  *	suffix must have been defined via .SUFFIXES before this is
   1127  *	called.
   1128  *
   1129  * Input:
   1130  *	sname		Name of the suffix to mark
   1131  *
   1132  * Results:
   1133  *	None.
   1134  *
   1135  * Side Effects:
   1136  *	The SUFF_LIBRARY bit is set in the suffix's flags field
   1137  *
   1138  *-----------------------------------------------------------------------
   1139  */
   1140 void
   1141 Suff_AddLib(char *sname)
   1142 {
   1143     LstNode	  ln;
   1144     Suff	  *s;
   1145 
   1146     ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
   1147     if (ln != NILLNODE) {
   1148 	s = (Suff *) Lst_Datum (ln);
   1149 	s->flags |= SUFF_LIBRARY;
   1150     }
   1151 }
   1152 
   1153  	  /********** Implicit Source Search Functions *********/
   1154 
   1155 /*-
   1156  *-----------------------------------------------------------------------
   1157  * SuffAddSrc  --
   1158  *	Add a suffix as a Src structure to the given list with its parent
   1159  *	being the given Src structure. If the suffix is the null suffix,
   1160  *	the prefix is used unaltered as the file name in the Src structure.
   1161  *
   1162  * Input:
   1163  *	sp		suffix for which to create a Src structure
   1164  *	lsp		list and parent for the new Src
   1165  *
   1166  * Results:
   1167  *	always returns 0
   1168  *
   1169  * Side Effects:
   1170  *	A Src structure is created and tacked onto the end of the list
   1171  *-----------------------------------------------------------------------
   1172  */
   1173 static int
   1174 SuffAddSrc(ClientData sp, ClientData lsp)
   1175 {
   1176     Suff	*s = (Suff *) sp;
   1177     LstSrc      *ls = (LstSrc *) lsp;
   1178     Src         *s2;	    /* new Src structure */
   1179     Src    	*targ; 	    /* Target structure */
   1180 
   1181     targ = ls->s;
   1182 
   1183     if ((s->flags & SUFF_NULL) && (*s->name != '\0')) {
   1184 	/*
   1185 	 * If the suffix has been marked as the NULL suffix, also create a Src
   1186 	 * structure for a file with no suffix attached. Two birds, and all
   1187 	 * that...
   1188 	 */
   1189 	s2 = (Src *) emalloc (sizeof (Src));
   1190 	s2->file =  	estrdup(targ->pref);
   1191 	s2->pref =  	targ->pref;
   1192 	s2->parent = 	targ;
   1193 	s2->node =  	NILGNODE;
   1194 	s2->suff =  	s;
   1195 	s->refCount++;
   1196 	s2->children =	0;
   1197 	targ->children += 1;
   1198 	(void)Lst_AtEnd (ls->l, (ClientData)s2);
   1199 #ifdef DEBUG_SRC
   1200 	s2->cp = Lst_Init(FALSE);
   1201 	Lst_AtEnd(targ->cp, (ClientData) s2);
   1202 	printf("1 add %x %x to %x:", targ, s2, ls->l);
   1203 	Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
   1204 	printf("\n");
   1205 #endif
   1206     }
   1207     s2 = (Src *) emalloc (sizeof (Src));
   1208     s2->file = 	    str_concat (targ->pref, s->name, 0);
   1209     s2->pref =	    targ->pref;
   1210     s2->parent =    targ;
   1211     s2->node = 	    NILGNODE;
   1212     s2->suff = 	    s;
   1213     s->refCount++;
   1214     s2->children =  0;
   1215     targ->children += 1;
   1216     (void)Lst_AtEnd (ls->l, (ClientData)s2);
   1217 #ifdef DEBUG_SRC
   1218     s2->cp = Lst_Init(FALSE);
   1219     Lst_AtEnd(targ->cp, (ClientData) s2);
   1220     printf("2 add %x %x to %x:", targ, s2, ls->l);
   1221     Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
   1222     printf("\n");
   1223 #endif
   1224 
   1225     return(0);
   1226 }
   1227 
   1228 /*-
   1229  *-----------------------------------------------------------------------
   1230  * SuffAddLevel  --
   1231  *	Add all the children of targ as Src structures to the given list
   1232  *
   1233  * Input:
   1234  *	l		list to which to add the new level
   1235  *	targ		Src structure to use as the parent
   1236  *
   1237  * Results:
   1238  *	None
   1239  *
   1240  * Side Effects:
   1241  * 	Lots of structures are created and added to the list
   1242  *-----------------------------------------------------------------------
   1243  */
   1244 static void
   1245 SuffAddLevel(Lst l, Src *targ)
   1246 {
   1247     LstSrc         ls;
   1248 
   1249     ls.s = targ;
   1250     ls.l = l;
   1251 
   1252     Lst_ForEach (targ->suff->children, SuffAddSrc, (ClientData)&ls);
   1253 }
   1254 
   1255 /*-
   1256  *----------------------------------------------------------------------
   1257  * SuffRemoveSrc --
   1258  *	Free all src structures in list that don't have a reference count
   1259  *
   1260  * Results:
   1261  *	Ture if an src was removed
   1262  *
   1263  * Side Effects:
   1264  *	The memory is free'd.
   1265  *----------------------------------------------------------------------
   1266  */
   1267 static int
   1268 SuffRemoveSrc(Lst l)
   1269 {
   1270     LstNode ln;
   1271     Src *s;
   1272     int t = 0;
   1273 
   1274     if (Lst_Open (l) == FAILURE) {
   1275 	return 0;
   1276     }
   1277 #ifdef DEBUG_SRC
   1278     printf("cleaning %lx: ", (unsigned long) l);
   1279     Lst_ForEach(l, PrintAddr, (ClientData) 0);
   1280     printf("\n");
   1281 #endif
   1282 
   1283 
   1284     while ((ln = Lst_Next (l)) != NILLNODE) {
   1285 	s = (Src *) Lst_Datum (ln);
   1286 	if (s->children == 0) {
   1287 	    free ((Address)s->file);
   1288 	    if (!s->parent)
   1289 		free((Address)s->pref);
   1290 	    else {
   1291 #ifdef DEBUG_SRC
   1292 		LstNode ln = Lst_Member(s->parent->cp, (ClientData)s);
   1293 		if (ln != NILLNODE)
   1294 		    Lst_Remove(s->parent->cp, ln);
   1295 #endif
   1296 		--s->parent->children;
   1297 	    }
   1298 #ifdef DEBUG_SRC
   1299 	    printf("free: [l=%x] p=%x %d\n", l, s, s->children);
   1300 	    Lst_Destroy(s->cp, NOFREE);
   1301 #endif
   1302 	    Lst_Remove(l, ln);
   1303 	    free ((Address)s);
   1304 	    t |= 1;
   1305 	    Lst_Close(l);
   1306 	    return TRUE;
   1307 	}
   1308 #ifdef DEBUG_SRC
   1309 	else {
   1310 	    printf("keep: [l=%x] p=%x %d: ", l, s, s->children);
   1311 	    Lst_ForEach(s->cp, PrintAddr, (ClientData) 0);
   1312 	    printf("\n");
   1313 	}
   1314 #endif
   1315     }
   1316 
   1317     Lst_Close(l);
   1318 
   1319     return t;
   1320 }
   1321 
   1322 /*-
   1323  *-----------------------------------------------------------------------
   1324  * SuffFindThem --
   1325  *	Find the first existing file/target in the list srcs
   1326  *
   1327  * Input:
   1328  *	srcs		list of Src structures to search through
   1329  *
   1330  * Results:
   1331  *	The lowest structure in the chain of transformations
   1332  *
   1333  * Side Effects:
   1334  *	None
   1335  *-----------------------------------------------------------------------
   1336  */
   1337 static Src *
   1338 SuffFindThem(Lst srcs, Lst slst)
   1339 {
   1340     Src            *s;		/* current Src */
   1341     Src		   *rs;		/* returned Src */
   1342     char	   *ptr;
   1343 
   1344     rs = (Src *) NULL;
   1345 
   1346     while (!Lst_IsEmpty (srcs)) {
   1347 	s = (Src *) Lst_DeQueue (srcs);
   1348 
   1349 	if (DEBUG(SUFF)) {
   1350 	    printf ("\ttrying %s...", s->file);
   1351 	}
   1352 
   1353 	/*
   1354 	 * A file is considered to exist if either a node exists in the
   1355 	 * graph for it or the file actually exists.
   1356 	 */
   1357 	if (Targ_FindNode(s->file, TARG_NOCREATE) != NILGNODE) {
   1358 #ifdef DEBUG_SRC
   1359 	    printf("remove %x from %x\n", s, srcs);
   1360 #endif
   1361 	    rs = s;
   1362 	    break;
   1363 	}
   1364 
   1365 	if ((ptr = Dir_FindFile (s->file, s->suff->searchPath)) != NULL) {
   1366 	    rs = s;
   1367 #ifdef DEBUG_SRC
   1368 	    printf("remove %x from %x\n", s, srcs);
   1369 #endif
   1370 	    free(ptr);
   1371 	    break;
   1372 	}
   1373 
   1374 	if (DEBUG(SUFF)) {
   1375 	    printf ("not there\n");
   1376 	}
   1377 
   1378 	SuffAddLevel (srcs, s);
   1379 	Lst_AtEnd(slst, (ClientData) s);
   1380     }
   1381 
   1382     if (DEBUG(SUFF) && rs) {
   1383 	printf ("got it\n");
   1384     }
   1385     return (rs);
   1386 }
   1387 
   1388 /*-
   1389  *-----------------------------------------------------------------------
   1390  * SuffFindCmds --
   1391  *	See if any of the children of the target in the Src structure is
   1392  *	one from which the target can be transformed. If there is one,
   1393  *	a Src structure is put together for it and returned.
   1394  *
   1395  * Input:
   1396  *	targ		Src structure to play with
   1397  *
   1398  * Results:
   1399  *	The Src structure of the "winning" child, or NIL if no such beast.
   1400  *
   1401  * Side Effects:
   1402  *	A Src structure may be allocated.
   1403  *
   1404  *-----------------------------------------------------------------------
   1405  */
   1406 static Src *
   1407 SuffFindCmds(Src *targ, Lst slst)
   1408 {
   1409     LstNode 	  	ln; 	/* General-purpose list node */
   1410     GNode		*t, 	/* Target GNode */
   1411 	    	  	*s; 	/* Source GNode */
   1412     int	    	  	prefLen;/* The length of the defined prefix */
   1413     Suff    	  	*suff;	/* Suffix on matching beastie */
   1414     Src	    	  	*ret;	/* Return value */
   1415     char    	  	*cp;
   1416 
   1417     t = targ->node;
   1418     (void) Lst_Open (t->children);
   1419     prefLen = strlen (targ->pref);
   1420 
   1421     while ((ln = Lst_Next (t->children)) != NILLNODE) {
   1422 	s = (GNode *)Lst_Datum (ln);
   1423 
   1424 	cp = strrchr (s->name, '/');
   1425 	if (cp == (char *)NULL) {
   1426 	    cp = s->name;
   1427 	} else {
   1428 	    cp++;
   1429 	}
   1430 	if (strncmp (cp, targ->pref, prefLen) == 0) {
   1431 	    /*
   1432 	     * The node matches the prefix ok, see if it has a known
   1433 	     * suffix.
   1434 	     */
   1435 	    ln = Lst_Find (sufflist, (ClientData)&cp[prefLen],
   1436 			   SuffSuffHasNameP);
   1437 	    if (ln != NILLNODE) {
   1438 		/*
   1439 		 * It even has a known suffix, see if there's a transformation
   1440 		 * defined between the node's suffix and the target's suffix.
   1441 		 *
   1442 		 * XXX: Handle multi-stage transformations here, too.
   1443 		 */
   1444 		suff = (Suff *)Lst_Datum (ln);
   1445 
   1446 		if (Lst_Member (suff->parents,
   1447 				(ClientData)targ->suff) != NILLNODE)
   1448 		{
   1449 		    /*
   1450 		     * Hot Damn! Create a new Src structure to describe
   1451 		     * this transformation (making sure to duplicate the
   1452 		     * source node's name so Suff_FindDeps can free it
   1453 		     * again (ick)), and return the new structure.
   1454 		     */
   1455 		    ret = (Src *)emalloc (sizeof (Src));
   1456 		    ret->file = estrdup(s->name);
   1457 		    ret->pref = targ->pref;
   1458 		    ret->suff = suff;
   1459 		    suff->refCount++;
   1460 		    ret->parent = targ;
   1461 		    ret->node = s;
   1462 		    ret->children = 0;
   1463 		    targ->children += 1;
   1464 #ifdef DEBUG_SRC
   1465 		    ret->cp = Lst_Init(FALSE);
   1466 		    printf("3 add %x %x\n", targ, ret);
   1467 		    Lst_AtEnd(targ->cp, (ClientData) ret);
   1468 #endif
   1469 		    Lst_AtEnd(slst, (ClientData) ret);
   1470 		    if (DEBUG(SUFF)) {
   1471 			printf ("\tusing existing source %s\n", s->name);
   1472 		    }
   1473 		    return (ret);
   1474 		}
   1475 	    }
   1476 	}
   1477     }
   1478     Lst_Close (t->children);
   1479     return ((Src *)NULL);
   1480 }
   1481 
   1482 /*-
   1483  *-----------------------------------------------------------------------
   1484  * SuffExpandChildren --
   1485  *	Expand the names of any children of a given node that contain
   1486  *	variable invocations or file wildcards into actual targets.
   1487  *
   1488  * Input:
   1489  *	prevLN		Child to examine
   1490  *	pgn		Parent node being processed
   1491  *
   1492  * Results:
   1493  *	=== 0 (continue)
   1494  *
   1495  * Side Effects:
   1496  *	The expanded node is removed from the parent's list of children,
   1497  *	and the parent's unmade counter is decremented, but other nodes
   1498  * 	may be added.
   1499  *
   1500  *-----------------------------------------------------------------------
   1501  */
   1502 static int
   1503 SuffExpandChildren(LstNode prevLN, GNode *pgn)
   1504 {
   1505     GNode   	*cgn = (GNode *) Lst_Datum(prevLN);
   1506     GNode	*gn;	    /* New source 8) */
   1507     LstNode	ln;	    /* List element for old source */
   1508     char	*cp;	    /* Expanded value */
   1509 
   1510     /*
   1511      * First do variable expansion -- this takes precedence over
   1512      * wildcard expansion. If the result contains wildcards, they'll be gotten
   1513      * to later since the resulting words are tacked on to the end of
   1514      * the children list.
   1515      */
   1516     if (strchr(cgn->name, '$') != (char *)NULL) {
   1517 	if (DEBUG(SUFF)) {
   1518 	    printf("Expanding \"%s\"...", cgn->name);
   1519 	}
   1520 	cp = Var_Subst(NULL, cgn->name, pgn, TRUE);
   1521 
   1522 	if (cp != (char *)NULL) {
   1523 	    Lst	    members = Lst_Init(FALSE);
   1524 
   1525 	    if (cgn->type & OP_ARCHV) {
   1526 		/*
   1527 		 * Node was an archive(member) target, so we want to call
   1528 		 * on the Arch module to find the nodes for us, expanding
   1529 		 * variables in the parent's context.
   1530 		 */
   1531 		char	*sacrifice = cp;
   1532 
   1533 		(void)Arch_ParseArchive(&sacrifice, members, pgn);
   1534 	    } else {
   1535 		/*
   1536 		 * Break the result into a vector of strings whose nodes
   1537 		 * we can find, then add those nodes to the members list.
   1538 		 * Unfortunately, we can't use brk_string b/c it
   1539 		 * doesn't understand about variable specifications with
   1540 		 * spaces in them...
   1541 		 */
   1542 		char	    *start;
   1543 		char	    *initcp = cp;   /* For freeing... */
   1544 
   1545 		for (start = cp; *start == ' ' || *start == '\t'; start++)
   1546 		    continue;
   1547 		for (cp = start; *cp != '\0'; cp++) {
   1548 		    if (*cp == ' ' || *cp == '\t') {
   1549 			/*
   1550 			 * White-space -- terminate element, find the node,
   1551 			 * add it, skip any further spaces.
   1552 			 */
   1553 			*cp++ = '\0';
   1554 			gn = Targ_FindNode(start, TARG_CREATE);
   1555 			(void)Lst_AtEnd(members, (ClientData)gn);
   1556 			while (*cp == ' ' || *cp == '\t') {
   1557 			    cp++;
   1558 			}
   1559 			/*
   1560 			 * Adjust cp for increment at start of loop, but
   1561 			 * set start to first non-space.
   1562 			 */
   1563 			start = cp--;
   1564 		    } else if (*cp == '$') {
   1565 			/*
   1566 			 * Start of a variable spec -- contact variable module
   1567 			 * to find the end so we can skip over it.
   1568 			 */
   1569 			char	*junk;
   1570 			int 	len;
   1571 			Boolean	doFree;
   1572 
   1573 			junk = Var_Parse(cp, pgn, TRUE, &len, &doFree);
   1574 			if (junk != var_Error) {
   1575 			    cp += len - 1;
   1576 			}
   1577 
   1578 			if (doFree) {
   1579 			    free(junk);
   1580 			}
   1581 		    } else if (*cp == '\\' && *cp != '\0') {
   1582 			/*
   1583 			 * Escaped something -- skip over it
   1584 			 */
   1585 			cp++;
   1586 		    }
   1587 		}
   1588 
   1589 		if (cp != start) {
   1590 		    /*
   1591 		     * Stuff left over -- add it to the list too
   1592 		     */
   1593 		    gn = Targ_FindNode(start, TARG_CREATE);
   1594 		    (void)Lst_AtEnd(members, (ClientData)gn);
   1595 		}
   1596 		/*
   1597 		 * Point cp back at the beginning again so the variable value
   1598 		 * can be freed.
   1599 		 */
   1600 		cp = initcp;
   1601 	    }
   1602 	    /*
   1603 	     * Add all elements of the members list to the parent node.
   1604 	     */
   1605 	    while(!Lst_IsEmpty(members)) {
   1606 		gn = (GNode *)Lst_DeQueue(members);
   1607 
   1608 		if (DEBUG(SUFF)) {
   1609 		    printf("%s...", gn->name);
   1610 		}
   1611 		if (Lst_Member(pgn->children, (ClientData)gn) == NILLNODE) {
   1612 		    (void)Lst_Append(pgn->children, prevLN, (ClientData)gn);
   1613 		    prevLN = Lst_Succ(prevLN);
   1614 		    (void)Lst_AtEnd(gn->parents, (ClientData)pgn);
   1615 		    pgn->unmade++;
   1616 		}
   1617 	    }
   1618 	    Lst_Destroy(members, NOFREE);
   1619 	    /*
   1620 	     * Free the result
   1621 	     */
   1622 	    free((char *)cp);
   1623 	}
   1624 	/*
   1625 	 * Now the source is expanded, remove it from the list of children to
   1626 	 * keep it from being processed.
   1627 	 */
   1628 	if (DEBUG(SUFF)) {
   1629 	    printf("\n");
   1630 	}
   1631 	return(1);
   1632     } else if (Dir_HasWildcards(cgn->name)) {
   1633 	Lst 	explist;    /* List of expansions */
   1634 	Lst 	path;	    /* Search path along which to expand */
   1635 	SuffixCmpData sd;   /* Search string data */
   1636 
   1637 	/*
   1638 	 * Find a path along which to expand the word.
   1639 	 *
   1640 	 * If the word has a known suffix, use that path.
   1641 	 * If it has no known suffix and we're allowed to use the null
   1642 	 *   suffix, use its path.
   1643 	 * Else use the default system search path.
   1644 	 */
   1645 	sd.len = strlen(cgn->name);
   1646 	sd.ename = cgn->name + sd.len;
   1647 	ln = Lst_Find(sufflist, (ClientData)&sd, SuffSuffIsSuffixP);
   1648 
   1649 	if (DEBUG(SUFF)) {
   1650 	    printf("Wildcard expanding \"%s\"...", cgn->name);
   1651 	}
   1652 
   1653 	if (ln != NILLNODE) {
   1654 	    Suff    *s = (Suff *)Lst_Datum(ln);
   1655 
   1656 	    if (DEBUG(SUFF)) {
   1657 		printf("suffix is \"%s\"...", s->name);
   1658 	    }
   1659 	    path = s->searchPath;
   1660 	} else {
   1661 	    /*
   1662 	     * Use default search path
   1663 	     */
   1664 	    path = dirSearchPath;
   1665 	}
   1666 
   1667 	/*
   1668 	 * Expand the word along the chosen path
   1669 	 */
   1670 	explist = Lst_Init(FALSE);
   1671 	Dir_Expand(cgn->name, path, explist);
   1672 
   1673 	while (!Lst_IsEmpty(explist)) {
   1674 	    /*
   1675 	     * Fetch next expansion off the list and find its GNode
   1676 	     */
   1677 	    cp = (char *)Lst_DeQueue(explist);
   1678 
   1679 	    if (DEBUG(SUFF)) {
   1680 		printf("%s...", cp);
   1681 	    }
   1682 	    gn = Targ_FindNode(cp, TARG_CREATE);
   1683 
   1684 	    /*
   1685 	     * If gn isn't already a child of the parent, make it so and
   1686 	     * up the parent's count of unmade children.
   1687 	     */
   1688 	    if (Lst_Member(pgn->children, (ClientData)gn) == NILLNODE) {
   1689 		(void)Lst_Append(pgn->children, prevLN, (ClientData)gn);
   1690 		prevLN = Lst_Succ(prevLN);
   1691 		(void)Lst_AtEnd(gn->parents, (ClientData)pgn);
   1692 		pgn->unmade++;
   1693 	    }
   1694 	}
   1695 
   1696 	/*
   1697 	 * Nuke what's left of the list
   1698 	 */
   1699 	Lst_Destroy(explist, NOFREE);
   1700 
   1701 	/*
   1702 	 * Now the source is expanded, remove it from the list of children to
   1703 	 * keep it from being processed.
   1704 	 */
   1705 	if (DEBUG(SUFF)) {
   1706 	    printf("\n");
   1707 	}
   1708 	return(1);
   1709     }
   1710 
   1711     return(0);
   1712 }
   1713 
   1714 /*-
   1715  *-----------------------------------------------------------------------
   1716  * SuffApplyTransform --
   1717  *	Apply a transformation rule, given the source and target nodes
   1718  *	and suffixes.
   1719  *
   1720  * Input:
   1721  *	tGn		Target node
   1722  *	sGn		Source node
   1723  *	t		Target suffix
   1724  *	s		Source suffix
   1725  *
   1726  * Results:
   1727  *	TRUE if successful, FALSE if not.
   1728  *
   1729  * Side Effects:
   1730  *	The source and target are linked and the commands from the
   1731  *	transformation are added to the target node's commands list.
   1732  *	All attributes but OP_DEPMASK and OP_TRANSFORM are applied
   1733  *	to the target. The target also inherits all the sources for
   1734  *	the transformation rule.
   1735  *
   1736  *-----------------------------------------------------------------------
   1737  */
   1738 static Boolean
   1739 SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
   1740 {
   1741     LstNode 	ln, nln;    /* General node */
   1742     char    	*tname;	    /* Name of transformation rule */
   1743     GNode   	*gn;	    /* Node for same */
   1744 
   1745     /*
   1746      * Form the proper links between the target and source.
   1747      */
   1748     (void)Lst_AtEnd(tGn->children, (ClientData)sGn);
   1749     (void)Lst_AtEnd(sGn->parents, (ClientData)tGn);
   1750     tGn->unmade += 1;
   1751 
   1752     /*
   1753      * Locate the transformation rule itself
   1754      */
   1755     tname = str_concat(s->name, t->name, 0);
   1756     ln = Lst_Find(transforms, (ClientData)tname, SuffGNHasNameP);
   1757     free(tname);
   1758 
   1759     if (ln == NILLNODE) {
   1760 	/*
   1761 	 * Not really such a transformation rule (can happen when we're
   1762 	 * called to link an OP_MEMBER and OP_ARCHV node), so return
   1763 	 * FALSE.
   1764 	 */
   1765 	return(FALSE);
   1766     }
   1767 
   1768     gn = (GNode *)Lst_Datum(ln);
   1769 
   1770     if (DEBUG(SUFF)) {
   1771 	printf("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
   1772     }
   1773 
   1774     /*
   1775      * Record last child for expansion purposes
   1776      */
   1777     ln = Lst_Last(tGn->children);
   1778 
   1779     /*
   1780      * Pass the buck to Make_HandleUse to apply the rule
   1781      */
   1782     (void)Make_HandleUse(gn, tGn);
   1783 
   1784     /*
   1785      * Deal with wildcards and variables in any acquired sources
   1786      */
   1787     ln = Lst_Succ(ln);
   1788     while (ln != NILLNODE) {
   1789 	if (SuffExpandChildren(ln, tGn)) {
   1790 	    nln = Lst_Succ(ln);
   1791 	    tGn->unmade--;
   1792 	    Lst_Remove(tGn->children, ln);
   1793 	    ln = nln;
   1794 	} else
   1795 	    ln = Lst_Succ(ln);
   1796     }
   1797 
   1798     /*
   1799      * Keep track of another parent to which this beast is transformed so
   1800      * the .IMPSRC variable can be set correctly for the parent.
   1801      */
   1802     (void)Lst_AtEnd(sGn->iParents, (ClientData)tGn);
   1803 
   1804     return(TRUE);
   1805 }
   1806 
   1807 
   1808 /*-
   1809  *-----------------------------------------------------------------------
   1810  * SuffFindArchiveDeps --
   1811  *	Locate dependencies for an OP_ARCHV node.
   1812  *
   1813  * Input:
   1814  *	gn		Node for which to locate dependencies
   1815  *
   1816  * Results:
   1817  *	None
   1818  *
   1819  * Side Effects:
   1820  *	Same as Suff_FindDeps
   1821  *
   1822  *-----------------------------------------------------------------------
   1823  */
   1824 static void
   1825 SuffFindArchiveDeps(GNode *gn, Lst slst)
   1826 {
   1827     char    	*eoarch;    /* End of archive portion */
   1828     char    	*eoname;    /* End of member portion */
   1829     GNode   	*mem;	    /* Node for member */
   1830     static const char	*copy[] = {
   1831 	/* Variables to be copied from the member node */
   1832 	TARGET,	    	    /* Must be first */
   1833 	PREFIX,	    	    /* Must be second */
   1834     };
   1835     int	    	i;  	    /* Index into copy and vals */
   1836     Suff    	*ms;	    /* Suffix descriptor for member */
   1837     char    	*name;	    /* Start of member's name */
   1838 
   1839     /*
   1840      * The node is an archive(member) pair. so we must find a
   1841      * suffix for both of them.
   1842      */
   1843     eoarch = strchr (gn->name, '(');
   1844     eoname = strchr (eoarch, ')');
   1845 
   1846     *eoname = '\0';	  /* Nuke parentheses during suffix search */
   1847     *eoarch = '\0';	  /* So a suffix can be found */
   1848 
   1849     name = eoarch + 1;
   1850 
   1851     /*
   1852      * To simplify things, call Suff_FindDeps recursively on the member now,
   1853      * so we can simply compare the member's .PREFIX and .TARGET variables
   1854      * to locate its suffix. This allows us to figure out the suffix to
   1855      * use for the archive without having to do a quadratic search over the
   1856      * suffix list, backtracking for each one...
   1857      */
   1858     mem = Targ_FindNode(name, TARG_CREATE);
   1859     SuffFindDeps(mem, slst);
   1860 
   1861     /*
   1862      * Create the link between the two nodes right off
   1863      */
   1864     (void)Lst_AtEnd(gn->children, (ClientData)mem);
   1865     (void)Lst_AtEnd(mem->parents, (ClientData)gn);
   1866     gn->unmade += 1;
   1867 
   1868     /*
   1869      * Copy in the variables from the member node to this one.
   1870      */
   1871     for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
   1872 	char *p1;
   1873 	Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn, 0);
   1874 	if (p1)
   1875 	    free(p1);
   1876 
   1877     }
   1878 
   1879     ms = mem->suffix;
   1880     if (ms == NULL) {
   1881 	/*
   1882 	 * Didn't know what it was -- use .NULL suffix if not in make mode
   1883 	 */
   1884 	if (DEBUG(SUFF)) {
   1885 	    printf("using null suffix\n");
   1886 	}
   1887 	ms = suffNull;
   1888     }
   1889 
   1890 
   1891     /*
   1892      * Set the other two local variables required for this target.
   1893      */
   1894     Var_Set (MEMBER, name, gn, 0);
   1895     Var_Set (ARCHIVE, gn->name, gn, 0);
   1896 
   1897     if (ms != NULL) {
   1898 	/*
   1899 	 * Member has a known suffix, so look for a transformation rule from
   1900 	 * it to a possible suffix of the archive. Rather than searching
   1901 	 * through the entire list, we just look at suffixes to which the
   1902 	 * member's suffix may be transformed...
   1903 	 */
   1904 	LstNode		ln;
   1905 	SuffixCmpData	sd;		/* Search string data */
   1906 
   1907 	/*
   1908 	 * Use first matching suffix...
   1909 	 */
   1910 	sd.len = eoarch - gn->name;
   1911 	sd.ename = eoarch;
   1912 	ln = Lst_Find(ms->parents, &sd, SuffSuffIsSuffixP);
   1913 
   1914 	if (ln != NILLNODE) {
   1915 	    /*
   1916 	     * Got one -- apply it
   1917 	     */
   1918 	    if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
   1919 		DEBUG(SUFF))
   1920 	    {
   1921 		printf("\tNo transformation from %s -> %s\n",
   1922 		       ms->name, ((Suff *)Lst_Datum(ln))->name);
   1923 	    }
   1924 	}
   1925     }
   1926 
   1927     /*
   1928      * Replace the opening and closing parens now we've no need of the separate
   1929      * pieces.
   1930      */
   1931     *eoarch = '('; *eoname = ')';
   1932 
   1933     /*
   1934      * Pretend gn appeared to the left of a dependency operator so
   1935      * the user needn't provide a transformation from the member to the
   1936      * archive.
   1937      */
   1938     if (OP_NOP(gn->type)) {
   1939 	gn->type |= OP_DEPENDS;
   1940     }
   1941 
   1942     /*
   1943      * Flag the member as such so we remember to look in the archive for
   1944      * its modification time.
   1945      */
   1946     mem->type |= OP_MEMBER;
   1947 }
   1948 
   1949 /*-
   1950  *-----------------------------------------------------------------------
   1951  * SuffFindNormalDeps --
   1952  *	Locate implicit dependencies for regular targets.
   1953  *
   1954  * Input:
   1955  *	gn		Node for which to find sources
   1956  *
   1957  * Results:
   1958  *	None.
   1959  *
   1960  * Side Effects:
   1961  *	Same as Suff_FindDeps...
   1962  *
   1963  *-----------------------------------------------------------------------
   1964  */
   1965 static void
   1966 SuffFindNormalDeps(GNode *gn, Lst slst)
   1967 {
   1968     char    	*eoname;    /* End of name */
   1969     char    	*sopref;    /* Start of prefix */
   1970     LstNode 	ln, nln;    /* Next suffix node to check */
   1971     Lst	    	srcs;	    /* List of sources at which to look */
   1972     Lst	    	targs;	    /* List of targets to which things can be
   1973 			     * transformed. They all have the same file,
   1974 			     * but different suff and pref fields */
   1975     Src	    	*bottom;    /* Start of found transformation path */
   1976     Src 	*src;	    /* General Src pointer */
   1977     char    	*pref;	    /* Prefix to use */
   1978     Src	    	*targ;	    /* General Src target pointer */
   1979     SuffixCmpData sd;	    /* Search string data */
   1980 
   1981 
   1982     sd.len = strlen(gn->name);
   1983     sd.ename = eoname = gn->name + sd.len;
   1984 
   1985     sopref = gn->name;
   1986 
   1987     /*
   1988      * Begin at the beginning...
   1989      */
   1990     ln = Lst_First(sufflist);
   1991     srcs = Lst_Init(FALSE);
   1992     targs = Lst_Init(FALSE);
   1993 
   1994     /*
   1995      * We're caught in a catch-22 here. On the one hand, we want to use any
   1996      * transformation implied by the target's sources, but we can't examine
   1997      * the sources until we've expanded any variables/wildcards they may hold,
   1998      * and we can't do that until we've set up the target's local variables
   1999      * and we can't do that until we know what the proper suffix for the
   2000      * target is (in case there are two suffixes one of which is a suffix of
   2001      * the other) and we can't know that until we've found its implied
   2002      * source, which we may not want to use if there's an existing source
   2003      * that implies a different transformation.
   2004      *
   2005      * In an attempt to get around this, which may not work all the time,
   2006      * but should work most of the time, we look for implied sources first,
   2007      * checking transformations to all possible suffixes of the target,
   2008      * use what we find to set the target's local variables, expand the
   2009      * children, then look for any overriding transformations they imply.
   2010      * Should we find one, we discard the one we found before.
   2011      */
   2012 
   2013     while (ln != NILLNODE) {
   2014 	/*
   2015 	 * Look for next possible suffix...
   2016 	 */
   2017 	ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP);
   2018 
   2019 	if (ln != NILLNODE) {
   2020 	    int	    prefLen;	    /* Length of the prefix */
   2021 
   2022 	    /*
   2023 	     * Allocate a Src structure to which things can be transformed
   2024 	     */
   2025 	    targ = (Src *)emalloc(sizeof (Src));
   2026 	    targ->file = estrdup(gn->name);
   2027 	    targ->suff = (Suff *)Lst_Datum(ln);
   2028 	    targ->suff->refCount++;
   2029 	    targ->node = gn;
   2030 	    targ->parent = (Src *)NULL;
   2031 	    targ->children = 0;
   2032 #ifdef DEBUG_SRC
   2033 	    targ->cp = Lst_Init(FALSE);
   2034 #endif
   2035 
   2036 	    /*
   2037 	     * Allocate room for the prefix, whose end is found by subtracting
   2038 	     * the length of the suffix from the end of the name.
   2039 	     */
   2040 	    prefLen = (eoname - targ->suff->nameLen) - sopref;
   2041 	    targ->pref = emalloc(prefLen + 1);
   2042 	    memcpy(targ->pref, sopref, prefLen);
   2043 	    targ->pref[prefLen] = '\0';
   2044 
   2045 	    /*
   2046 	     * Add nodes from which the target can be made
   2047 	     */
   2048 	    SuffAddLevel(srcs, targ);
   2049 
   2050 	    /*
   2051 	     * Record the target so we can nuke it
   2052 	     */
   2053 	    (void)Lst_AtEnd(targs, (ClientData)targ);
   2054 
   2055 	    /*
   2056 	     * Search from this suffix's successor...
   2057 	     */
   2058 	    ln = Lst_Succ(ln);
   2059 	}
   2060     }
   2061 
   2062     /*
   2063      * Handle target of unknown suffix...
   2064      */
   2065     if (Lst_IsEmpty(targs) && suffNull != NULL) {
   2066 	if (DEBUG(SUFF)) {
   2067 	    printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
   2068 	}
   2069 
   2070 	targ = (Src *)emalloc(sizeof (Src));
   2071 	targ->file = estrdup(gn->name);
   2072 	targ->suff = suffNull;
   2073 	targ->suff->refCount++;
   2074 	targ->node = gn;
   2075 	targ->parent = (Src *)NULL;
   2076 	targ->children = 0;
   2077 	targ->pref = estrdup(sopref);
   2078 #ifdef DEBUG_SRC
   2079 	targ->cp = Lst_Init(FALSE);
   2080 #endif
   2081 
   2082 	/*
   2083 	 * Only use the default suffix rules if we don't have commands
   2084 	 * defined for this gnode; traditional make programs used to
   2085 	 * not define suffix rules if the gnode had children but we
   2086 	 * don't do this anymore.
   2087 	 */
   2088 	if (Lst_IsEmpty(gn->commands))
   2089 	    SuffAddLevel(srcs, targ);
   2090 	else {
   2091 	    if (DEBUG(SUFF))
   2092 		printf("not ");
   2093 	}
   2094 
   2095 	if (DEBUG(SUFF))
   2096 	    printf("adding suffix rules\n");
   2097 
   2098 	(void)Lst_AtEnd(targs, (ClientData)targ);
   2099     }
   2100 
   2101     /*
   2102      * Using the list of possible sources built up from the target suffix(es),
   2103      * try and find an existing file/target that matches.
   2104      */
   2105     bottom = SuffFindThem(srcs, slst);
   2106 
   2107     if (bottom == (Src *)NULL) {
   2108 	/*
   2109 	 * No known transformations -- use the first suffix found for setting
   2110 	 * the local variables.
   2111 	 */
   2112 	if (!Lst_IsEmpty(targs)) {
   2113 	    targ = (Src *)Lst_Datum(Lst_First(targs));
   2114 	} else {
   2115 	    targ = (Src *)NULL;
   2116 	}
   2117     } else {
   2118 	/*
   2119 	 * Work up the transformation path to find the suffix of the
   2120 	 * target to which the transformation was made.
   2121 	 */
   2122 	for (targ = bottom; targ->parent != NULL; targ = targ->parent)
   2123 	    continue;
   2124     }
   2125 
   2126     Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0);
   2127 
   2128     pref = (targ != NULL) ? targ->pref : gn->name;
   2129     Var_Set(PREFIX, pref, gn, 0);
   2130 
   2131     /*
   2132      * Now we've got the important local variables set, expand any sources
   2133      * that still contain variables or wildcards in their names.
   2134      */
   2135     ln = Lst_First(gn->children);
   2136     while (ln != NILLNODE) {
   2137 	if (SuffExpandChildren(ln, gn)) {
   2138 	    nln = Lst_Succ(ln);
   2139 	    gn->unmade--;
   2140 	    Lst_Remove(gn->children, ln);
   2141 	    ln = nln;
   2142 	} else
   2143 	    ln = Lst_Succ(ln);
   2144     }
   2145 
   2146     if (targ == NULL) {
   2147 	if (DEBUG(SUFF)) {
   2148 	    printf("\tNo valid suffix on %s\n", gn->name);
   2149 	}
   2150 
   2151 sfnd_abort:
   2152 	/*
   2153 	 * Deal with finding the thing on the default search path. We
   2154 	 * always do that, not only if the node is only a source (not
   2155 	 * on the lhs of a dependency operator or [XXX] it has neither
   2156 	 * children or commands) as the old pmake did.
   2157 	 */
   2158 	if ((gn->type & (OP_PHONY|OP_NOPATH)) == 0) {
   2159 	    free(gn->path);
   2160 	    gn->path = Dir_FindFile(gn->name,
   2161 				    (targ == NULL ? dirSearchPath :
   2162 				     targ->suff->searchPath));
   2163 	    if (gn->path != NULL) {
   2164 		char *ptr;
   2165 		Var_Set(TARGET, gn->path, gn, 0);
   2166 
   2167 		if (targ != NULL) {
   2168 		    /*
   2169 		     * Suffix known for the thing -- trim the suffix off
   2170 		     * the path to form the proper .PREFIX variable.
   2171 		     */
   2172 		    int     savep = strlen(gn->path) - targ->suff->nameLen;
   2173 		    char    savec;
   2174 
   2175 		    if (gn->suffix)
   2176 			gn->suffix->refCount--;
   2177 		    gn->suffix = targ->suff;
   2178 		    gn->suffix->refCount++;
   2179 
   2180 		    savec = gn->path[savep];
   2181 		    gn->path[savep] = '\0';
   2182 
   2183 		    if ((ptr = strrchr(gn->path, '/')) != NULL)
   2184 			ptr++;
   2185 		    else
   2186 			ptr = gn->path;
   2187 
   2188 		    Var_Set(PREFIX, ptr, gn, 0);
   2189 
   2190 		    gn->path[savep] = savec;
   2191 		} else {
   2192 		    /*
   2193 		     * The .PREFIX gets the full path if the target has
   2194 		     * no known suffix.
   2195 		     */
   2196 		    if (gn->suffix)
   2197 			gn->suffix->refCount--;
   2198 		    gn->suffix = NULL;
   2199 
   2200 		    if ((ptr = strrchr(gn->path, '/')) != NULL)
   2201 			ptr++;
   2202 		    else
   2203 			ptr = gn->path;
   2204 
   2205 		    Var_Set(PREFIX, ptr, gn, 0);
   2206 		}
   2207 	    }
   2208 	}
   2209 
   2210 	goto sfnd_return;
   2211     }
   2212 
   2213     /*
   2214      * If the suffix indicates that the target is a library, mark that in
   2215      * the node's type field.
   2216      */
   2217     if (targ->suff->flags & SUFF_LIBRARY) {
   2218 	gn->type |= OP_LIB;
   2219     }
   2220 
   2221     /*
   2222      * Check for overriding transformation rule implied by sources
   2223      */
   2224     if (!Lst_IsEmpty(gn->children)) {
   2225 	src = SuffFindCmds(targ, slst);
   2226 
   2227 	if (src != (Src *)NULL) {
   2228 	    /*
   2229 	     * Free up all the Src structures in the transformation path
   2230 	     * up to, but not including, the parent node.
   2231 	     */
   2232 	    while (bottom && bottom->parent != NULL) {
   2233 		if (Lst_Member(slst, (ClientData) bottom) == NILLNODE) {
   2234 		    Lst_AtEnd(slst, (ClientData) bottom);
   2235 		}
   2236 		bottom = bottom->parent;
   2237 	    }
   2238 	    bottom = src;
   2239 	}
   2240     }
   2241 
   2242     if (bottom == NULL) {
   2243 	/*
   2244 	 * No idea from where it can come -- return now.
   2245 	 */
   2246 	goto sfnd_abort;
   2247     }
   2248 
   2249     /*
   2250      * We now have a list of Src structures headed by 'bottom' and linked via
   2251      * their 'parent' pointers. What we do next is create links between
   2252      * source and target nodes (which may or may not have been created)
   2253      * and set the necessary local variables in each target. The
   2254      * commands for each target are set from the commands of the
   2255      * transformation rule used to get from the src suffix to the targ
   2256      * suffix. Note that this causes the commands list of the original
   2257      * node, gn, to be replaced by the commands of the final
   2258      * transformation rule. Also, the unmade field of gn is incremented.
   2259      * Etc.
   2260      */
   2261     if (bottom->node == NILGNODE) {
   2262 	bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);
   2263     }
   2264 
   2265     for (src = bottom; src->parent != (Src *)NULL; src = src->parent) {
   2266 	targ = src->parent;
   2267 
   2268 	if (src->node->suffix)
   2269 	    src->node->suffix->refCount--;
   2270 	src->node->suffix = src->suff;
   2271 	src->node->suffix->refCount++;
   2272 
   2273 	if (targ->node == NILGNODE) {
   2274 	    targ->node = Targ_FindNode(targ->file, TARG_CREATE);
   2275 	}
   2276 
   2277 	SuffApplyTransform(targ->node, src->node,
   2278 			   targ->suff, src->suff);
   2279 
   2280 	if (targ->node != gn) {
   2281 	    /*
   2282 	     * Finish off the dependency-search process for any nodes
   2283 	     * between bottom and gn (no point in questing around the
   2284 	     * filesystem for their implicit source when it's already
   2285 	     * known). Note that the node can't have any sources that
   2286 	     * need expanding, since SuffFindThem will stop on an existing
   2287 	     * node, so all we need to do is set the standard and System V
   2288 	     * variables.
   2289 	     */
   2290 	    targ->node->type |= OP_DEPS_FOUND;
   2291 
   2292 	    Var_Set(PREFIX, targ->pref, targ->node, 0);
   2293 
   2294 	    Var_Set(TARGET, targ->node->name, targ->node, 0);
   2295 	}
   2296     }
   2297 
   2298     if (gn->suffix)
   2299 	gn->suffix->refCount--;
   2300     gn->suffix = src->suff;
   2301     gn->suffix->refCount++;
   2302 
   2303     /*
   2304      * Nuke the transformation path and the Src structures left over in the
   2305      * two lists.
   2306      */
   2307 sfnd_return:
   2308     if (bottom)
   2309 	if (Lst_Member(slst, (ClientData) bottom) == NILLNODE)
   2310 	    Lst_AtEnd(slst, (ClientData) bottom);
   2311 
   2312     while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
   2313 	continue;
   2314 
   2315     Lst_Concat(slst, srcs, LST_CONCLINK);
   2316     Lst_Concat(slst, targs, LST_CONCLINK);
   2317 }
   2318 
   2319 
   2320 /*-
   2321  *-----------------------------------------------------------------------
   2322  * Suff_FindDeps  --
   2323  *	Find implicit sources for the target described by the graph node
   2324  *	gn
   2325  *
   2326  * Results:
   2327  *	Nothing.
   2328  *
   2329  * Side Effects:
   2330  *	Nodes are added to the graph below the passed-in node. The nodes
   2331  *	are marked to have their IMPSRC variable filled in. The
   2332  *	PREFIX variable is set for the given node and all its
   2333  *	implied children.
   2334  *
   2335  * Notes:
   2336  *	The path found by this target is the shortest path in the
   2337  *	transformation graph, which may pass through non-existent targets,
   2338  *	to an existing target. The search continues on all paths from the
   2339  *	root suffix until a file is found. I.e. if there's a path
   2340  *	.o -> .c -> .l -> .l,v from the root and the .l,v file exists but
   2341  *	the .c and .l files don't, the search will branch out in
   2342  *	all directions from .o and again from all the nodes on the
   2343  *	next level until the .l,v node is encountered.
   2344  *
   2345  *-----------------------------------------------------------------------
   2346  */
   2347 
   2348 void
   2349 Suff_FindDeps(GNode *gn)
   2350 {
   2351 
   2352     SuffFindDeps(gn, srclist);
   2353     while (SuffRemoveSrc(srclist))
   2354 	continue;
   2355 }
   2356 
   2357 
   2358 /*
   2359  * Input:
   2360  *	gn		node we're dealing with
   2361  *
   2362  */
   2363 static void
   2364 SuffFindDeps(GNode *gn, Lst slst)
   2365 {
   2366     if (gn->type & (OP_DEPS_FOUND|OP_PHONY)) {
   2367 	/*
   2368 	 * If dependencies already found, no need to do it again...
   2369 	 * If this is a .PHONY target, we do not apply suffix rules.
   2370 	 */
   2371 	return;
   2372     } else {
   2373 	gn->type |= OP_DEPS_FOUND;
   2374     }
   2375 
   2376     if (DEBUG(SUFF)) {
   2377 	printf ("SuffFindDeps (%s)\n", gn->name);
   2378     }
   2379 
   2380     if (gn->type & OP_ARCHV) {
   2381 	SuffFindArchiveDeps(gn, slst);
   2382     } else if (gn->type & OP_LIB) {
   2383 	/*
   2384 	 * If the node is a library, it is the arch module's job to find it
   2385 	 * and set the TARGET variable accordingly. We merely provide the
   2386 	 * search path, assuming all libraries end in ".a" (if the suffix
   2387 	 * hasn't been defined, there's nothing we can do for it, so we just
   2388 	 * set the TARGET variable to the node's name in order to give it a
   2389 	 * value).
   2390 	 */
   2391 	LstNode	ln;
   2392 	Suff	*s;
   2393 
   2394 	ln = Lst_Find (sufflist, (ClientData)UNCONST(LIBSUFF),
   2395 	    SuffSuffHasNameP);
   2396 	if (gn->suffix)
   2397 	    gn->suffix->refCount--;
   2398 	if (ln != NILLNODE) {
   2399 	    gn->suffix = s = (Suff *) Lst_Datum (ln);
   2400 	    gn->suffix->refCount++;
   2401 	    Arch_FindLib (gn, s->searchPath);
   2402 	} else {
   2403 	    gn->suffix = NULL;
   2404 	    Var_Set (TARGET, gn->name, gn, 0);
   2405 	}
   2406 	/*
   2407 	 * Because a library (-lfoo) target doesn't follow the standard
   2408 	 * filesystem conventions, we don't set the regular variables for
   2409 	 * the thing. .PREFIX is simply made empty...
   2410 	 */
   2411 	Var_Set(PREFIX, "", gn, 0);
   2412     } else {
   2413 	SuffFindNormalDeps(gn, slst);
   2414     }
   2415 }
   2416 
   2417 /*-
   2418  *-----------------------------------------------------------------------
   2419  * Suff_SetNull --
   2420  *	Define which suffix is the null suffix.
   2421  *
   2422  * Input:
   2423  *	name		Name of null suffix
   2424  *
   2425  * Results:
   2426  *	None.
   2427  *
   2428  * Side Effects:
   2429  *	'suffNull' is altered.
   2430  *
   2431  * Notes:
   2432  *	Need to handle the changing of the null suffix gracefully so the
   2433  *	old transformation rules don't just go away.
   2434  *
   2435  *-----------------------------------------------------------------------
   2436  */
   2437 void
   2438 Suff_SetNull(char *name)
   2439 {
   2440     Suff    *s;
   2441     LstNode ln;
   2442 
   2443     ln = Lst_Find(sufflist, (ClientData)name, SuffSuffHasNameP);
   2444     if (ln != NILLNODE) {
   2445 	s = (Suff *)Lst_Datum(ln);
   2446 	if (suffNull != (Suff *)NULL) {
   2447 	    suffNull->flags &= ~SUFF_NULL;
   2448 	}
   2449 	s->flags |= SUFF_NULL;
   2450 	/*
   2451 	 * XXX: Here's where the transformation mangling would take place
   2452 	 */
   2453 	suffNull = s;
   2454     } else {
   2455 	Parse_Error (PARSE_WARNING, "Desired null suffix %s not defined.",
   2456 		     name);
   2457     }
   2458 }
   2459 
   2460 /*-
   2461  *-----------------------------------------------------------------------
   2462  * Suff_Init --
   2463  *	Initialize suffixes module
   2464  *
   2465  * Results:
   2466  *	None
   2467  *
   2468  * Side Effects:
   2469  *	Many
   2470  *-----------------------------------------------------------------------
   2471  */
   2472 void
   2473 Suff_Init(void)
   2474 {
   2475     sufflist = Lst_Init (FALSE);
   2476 #ifdef CLEANUP
   2477     suffClean = Lst_Init(FALSE);
   2478 #endif
   2479     srclist = Lst_Init (FALSE);
   2480     transforms = Lst_Init (FALSE);
   2481 
   2482     sNum = 0;
   2483     /*
   2484      * Create null suffix for single-suffix rules (POSIX). The thing doesn't
   2485      * actually go on the suffix list or everyone will think that's its
   2486      * suffix.
   2487      */
   2488     emptySuff = suffNull = (Suff *) emalloc (sizeof (Suff));
   2489 
   2490     suffNull->name =   	    estrdup ("");
   2491     suffNull->nameLen =     0;
   2492     suffNull->searchPath =  Lst_Init (FALSE);
   2493     Dir_Concat(suffNull->searchPath, dirSearchPath);
   2494     suffNull->children =    Lst_Init (FALSE);
   2495     suffNull->parents =	    Lst_Init (FALSE);
   2496     suffNull->ref =	    Lst_Init (FALSE);
   2497     suffNull->sNum =   	    sNum++;
   2498     suffNull->flags =  	    SUFF_NULL;
   2499     suffNull->refCount =    1;
   2500 
   2501 }
   2502 
   2503 
   2504 /*-
   2505  *----------------------------------------------------------------------
   2506  * Suff_End --
   2507  *	Cleanup the this module
   2508  *
   2509  * Results:
   2510  *	None
   2511  *
   2512  * Side Effects:
   2513  *	The memory is free'd.
   2514  *----------------------------------------------------------------------
   2515  */
   2516 
   2517 void
   2518 Suff_End(void)
   2519 {
   2520 #ifdef CLEANUP
   2521     Lst_Destroy(sufflist, SuffFree);
   2522     Lst_Destroy(suffClean, SuffFree);
   2523     if (suffNull)
   2524 	SuffFree(suffNull);
   2525     Lst_Destroy(srclist, NOFREE);
   2526     Lst_Destroy(transforms, NOFREE);
   2527 #endif
   2528 }
   2529 
   2530 
   2531 /********************* DEBUGGING FUNCTIONS **********************/
   2532 
   2533 static int SuffPrintName(ClientData s, ClientData dummy)
   2534 {
   2535     printf ("%s ", ((Suff *) s)->name);
   2536     return (dummy ? 0 : 0);
   2537 }
   2538 
   2539 static int
   2540 SuffPrintSuff(ClientData sp, ClientData dummy)
   2541 {
   2542     Suff    *s = (Suff *) sp;
   2543     int	    flags;
   2544     int	    flag;
   2545 
   2546     printf ("# `%s' [%d] ", s->name, s->refCount);
   2547 
   2548     flags = s->flags;
   2549     if (flags) {
   2550 	fputs (" (", stdout);
   2551 	while (flags) {
   2552 	    flag = 1 << (ffs(flags) - 1);
   2553 	    flags &= ~flag;
   2554 	    switch (flag) {
   2555 		case SUFF_NULL:
   2556 		    printf ("NULL");
   2557 		    break;
   2558 		case SUFF_INCLUDE:
   2559 		    printf ("INCLUDE");
   2560 		    break;
   2561 		case SUFF_LIBRARY:
   2562 		    printf ("LIBRARY");
   2563 		    break;
   2564 	    }
   2565 	    fputc(flags ? '|' : ')', stdout);
   2566 	}
   2567     }
   2568     fputc ('\n', stdout);
   2569     printf ("#\tTo: ");
   2570     Lst_ForEach (s->parents, SuffPrintName, (ClientData)0);
   2571     fputc ('\n', stdout);
   2572     printf ("#\tFrom: ");
   2573     Lst_ForEach (s->children, SuffPrintName, (ClientData)0);
   2574     fputc ('\n', stdout);
   2575     printf ("#\tSearch Path: ");
   2576     Dir_PrintPath (s->searchPath);
   2577     fputc ('\n', stdout);
   2578     return (dummy ? 0 : 0);
   2579 }
   2580 
   2581 static int
   2582 SuffPrintTrans(ClientData tp, ClientData dummy)
   2583 {
   2584     GNode   *t = (GNode *) tp;
   2585 
   2586     printf ("%-16s: ", t->name);
   2587     Targ_PrintType (t->type);
   2588     fputc ('\n', stdout);
   2589     Lst_ForEach (t->commands, Targ_PrintCmd, (ClientData)0);
   2590     fputc ('\n', stdout);
   2591     return(dummy ? 0 : 0);
   2592 }
   2593 
   2594 void
   2595 Suff_PrintAll(void)
   2596 {
   2597     printf ("#*** Suffixes:\n");
   2598     Lst_ForEach (sufflist, SuffPrintSuff, (ClientData)0);
   2599 
   2600     printf ("#*** Transformations:\n");
   2601     Lst_ForEach (transforms, SuffPrintTrans, (ClientData)0);
   2602 }
   2603