[BACK]Return to suff.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/suff.c, Revision 1.53

1.41      espie       1: /*     $OpenPackages$ */
1.53    ! robert      2: /*     $OpenBSD: suff.c,v 1.52 2004/05/05 09:10:47 espie Exp $ */
1.5       millert     3: /*     $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $       */
1.1       deraadt     4:
                      5: /*
1.5       millert     6:  * Copyright (c) 1988, 1989, 1990, 1993
                      7:  *     The Regents of the University of California.  All rights reserved.
1.1       deraadt     8:  * Copyright (c) 1989 by Berkeley Softworks
                      9:  * All rights reserved.
                     10:  *
                     11:  * This code is derived from software contributed to Berkeley by
                     12:  * Adam de Boor.
                     13:  *
                     14:  * Redistribution and use in source and binary forms, with or without
                     15:  * modification, are permitted provided that the following conditions
                     16:  * are met:
                     17:  * 1. Redistributions of source code must retain the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer.
                     19:  * 2. Redistributions in binary form must reproduce the above copyright
                     20:  *    notice, this list of conditions and the following disclaimer in the
                     21:  *    documentation and/or other materials provided with the distribution.
1.50      millert    22:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  */
                     38:
                     39: /*-
                     40:  * suff.c --
                     41:  *     Functions to maintain suffix lists and find implicit dependents
                     42:  *     using suffix transformation rules
                     43:  *
                     44:  * Interface:
1.41      espie      45:  *     Suff_Init               Initialize all things to do with suffixes.
1.1       deraadt    46:  *
1.41      espie      47:  *     Suff_End                Cleanup the module
1.1       deraadt    48:  *
1.41      espie      49:  *     Suff_DoPaths            This function is used to make life easier
                     50:  *                             when searching for a file according to its
                     51:  *                             suffix. It takes the global search path,
                     52:  *                             as defined using the .PATH: target, and appends
                     53:  *                             its directories to the path of each of the
                     54:  *                             defined suffixes, as specified using
                     55:  *                             .PATH<suffix>: targets. In addition, all
                     56:  *                             directories given for suffixes labeled as
                     57:  *                             include files or libraries, using the .INCLUDES
                     58:  *                             or .LIBS targets, are played with using
                     59:  *                             Dir_MakeFlags to create the .INCLUDES and
                     60:  *                             .LIBS global variables.
1.1       deraadt    61:  *
1.41      espie      62:  *     Suff_ClearSuffixes      Clear out all the suffixes and defined
                     63:  *                             transformations.
1.1       deraadt    64:  *
1.42      espie      65:  *     Suff_IsTransform        Return true if the passed string is the lhs
1.41      espie      66:  *                             of a transformation rule.
1.1       deraadt    67:  *
1.41      espie      68:  *     Suff_AddSuffix          Add the passed string as another known suffix.
1.1       deraadt    69:  *
1.41      espie      70:  *     Suff_GetPath            Return the search path for the given suffix.
1.1       deraadt    71:  *
1.41      espie      72:  *     Suff_AddInclude         Mark the given suffix as denoting an include
                     73:  *                             file.
1.1       deraadt    74:  *
1.41      espie      75:  *     Suff_AddLib             Mark the given suffix as denoting a library.
1.1       deraadt    76:  *
1.41      espie      77:  *     Suff_AddTransform       Add another transformation to the suffix
                     78:  *                             graph. Returns  GNode suitable for framing, I
                     79:  *                             mean, tacking commands, attributes, etc. on.
1.1       deraadt    80:  *
1.41      espie      81:  *     Suff_SetNull            Define the suffix to consider the suffix of
                     82:  *                             any file that doesn't have a known one.
1.1       deraadt    83:  *
1.41      espie      84:  *     Suff_FindDeps           Find implicit sources for and the location of
                     85:  *                             a target based on its suffix. Returns the
                     86:  *                             bottom-most node added to the graph or NULL
                     87:  *                             if the target had no implicit sources.
1.1       deraadt    88:  */
                     89:
1.42      espie      90: #include <ctype.h>
                     91: #include <stdio.h>
1.43      espie      92: #include <stdlib.h>
1.42      espie      93: #include <string.h>
                     94: #include "config.h"
                     95: #include "defines.h"
                     96: #include "dir.h"
                     97: #include "arch.h"
                     98: #include "suff.h"
                     99: #include "var.h"
                    100: #include "targ.h"
                    101: #include "error.h"
                    102: #include "str.h"
                    103: #include "lst.h"
                    104: #include "memory.h"
                    105: #include "gnode.h"
                    106: #include "make.h"
1.52      espie     107: #include "stats.h"
1.36      espie     108:
1.41      espie     109: static LIST     sufflist;      /* Lst of suffixes */
1.14      espie     110: #ifdef CLEANUP
1.29      espie     111: static LIST     suffClean;     /* Lst of suffixes to be cleaned */
1.14      espie     112: #endif
1.29      espie     113: static LIST     srclist;       /* Lst of sources */
1.41      espie     114: static LIST     transforms;    /* Lst of transformation rules */
1.1       deraadt   115:
1.41      espie     116: static int       sNum = 0;     /* Counter for assigning suffix numbers */
1.1       deraadt   117:
                    118: /*
                    119:  * Structure describing an individual suffix.
                    120:  */
1.40      espie     121: typedef struct Suff_ {
1.41      espie     122:     char        *name;         /* The suffix itself */
                    123:     int         nameLen;       /* Length of the suffix */
                    124:     short       flags;         /* Type of suffix */
1.1       deraadt   125: #define SUFF_INCLUDE     0x01      /* One which is #include'd */
                    126: #define SUFF_LIBRARY     0x02      /* One which contains a library */
1.41      espie     127: #define SUFF_NULL        0x04      /* The empty suffix */
                    128:     LIST        searchPath;    /* The path along which files of this suffix
1.1       deraadt   129:                                 * may be found */
1.41      espie     130:     int         sNum;          /* The suffix number */
                    131:     LIST        parents;       /* Suffixes we have a transformation to */
                    132:     LIST        children;      /* Suffixes we have a transformation from */
1.29      espie     133:     LIST        ref;           /* List of lists this suffix is referenced */
1.1       deraadt   134: } Suff;
                    135:
                    136: /*
                    137:  * Structure used in the search for implied sources.
                    138:  */
1.40      espie     139: typedef struct Src_ {
1.41      espie     140:     char           *file;      /* The file to look for */
                    141:     char           *pref;      /* Prefix from which file was formed */
                    142:     Suff           *suff;      /* The suffix on the file */
1.40      espie     143:     struct Src_     *parent;   /* The Src for which this is a source */
1.41      espie     144:     GNode          *node;      /* The node describing the file */
                    145:     int            children;   /* Count of existing children (so we don't free
1.1       deraadt   146:                                 * this thing too early or never nuke it) */
                    147: #ifdef DEBUG_SRC
1.41      espie     148:     LIST           cp;         /* Debug; children list */
1.1       deraadt   149: #endif
                    150: } Src;
                    151:
                    152: /*
                    153:  * A structure for passing more than one argument to the Lst-library-invoked
                    154:  * function...
                    155:  */
                    156: typedef struct {
1.41      espie     157:     Lst           l;
                    158:     Src           *s;
1.1       deraadt   159: } LstSrc;
                    160:
1.41      espie     161: static Suff        *suffNull;  /* The NULL suffix for this run */
                    162: static Suff        *emptySuff; /* The empty suffix required for POSIX
1.1       deraadt   163:                                 * single-suffix transformation rules */
                    164:
                    165:
1.41      espie     166: static char *SuffStrIsPrefix(const char *, const char *);
                    167: static char *SuffSuffIsSuffix(Suff *, const char *);
                    168: static int SuffSuffIsSuffixP(void *, const void *);
                    169: static int SuffSuffIsPrefix(void *, const void *);
1.52      espie     170: static int SuffHasNameP(void *, const void *);
                    171: static int GNodeHasNameP(void *, const void *);
1.41      espie     172: static void SuffUnRef(Lst, Suff *);
                    173: #ifdef CLEANUP
                    174: static void SuffFree(void *);
                    175: #endif
                    176: static void SuffInsert(Lst, Suff *);
1.42      espie     177: static bool SuffParseTransform(const char *, Suff **, Suff **);
1.41      espie     178: static void SuffRebuildGraph(void *, void *);
                    179: static void SuffAddSrc(void *, void *);
                    180: static int SuffRemoveSrc(Lst);
                    181: static void SuffAddLevel(Lst, Src *);
                    182: static Src *SuffFindThem(Lst, Lst);
                    183: static Src *SuffFindCmds(Src *, Lst);
                    184: static void SuffExpandChildren(void *, void *);
                    185: static void SuffExpandVarChildren(LstNode, GNode *, GNode *);
                    186: static void SuffExpandWildChildren(LstNode, GNode *, GNode *);
1.42      espie     187: static bool SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
1.41      espie     188: static void SuffFindDeps(GNode *, Lst);
                    189: static void SuffFindArchiveDeps(GNode *, Lst);
                    190: static void SuffFindNormalDeps(GNode *, Lst);
                    191: static void SuffPrintName(void *);
                    192: static void SuffPrintSuff(void *);
                    193: static void SuffPrintTrans(void *);
1.1       deraadt   194:
1.52      espie     195: static LstNode suff_find_by_name(const char *);
                    196: static LstNode transform_find_by_name(const char *);
                    197:
1.42      espie     198: #ifdef DEBUG_SRC
                    199: static void PrintAddr(void *);
                    200: #endif
1.1       deraadt   201:        /*************** Lst Predicates ****************/
                    202: /*-
                    203:  *-----------------------------------------------------------------------
                    204:  * SuffStrIsPrefix  --
1.51      espie     205:  *     See if prefix is a prefix of str.
1.1       deraadt   206:  *
                    207:  * Results:
                    208:  *     NULL if it ain't, pointer to character in str after prefix if so
                    209:  *-----------------------------------------------------------------------
                    210:  */
                    211: static char    *
1.51      espie     212: SuffStrIsPrefix(const char *prefix, const char *str)
1.1       deraadt   213: {
1.51      espie     214:     while (*str && *prefix == *str) {
                    215:        prefix++;
1.1       deraadt   216:        str++;
                    217:     }
                    218:
1.51      espie     219:     return *prefix ? NULL : (char *)str;
1.1       deraadt   220: }
                    221:
                    222: /*-
                    223:  *-----------------------------------------------------------------------
                    224:  * SuffSuffIsSuffix  --
1.41      espie     225:  *     See if suff is a suffix of str. str should point to the end of the
                    226:  *     string to check.
1.1       deraadt   227:  *
                    228:  * Results:
1.41      espie     229:  *     NULL if it ain't, pointer to first character of suffix in str if
1.1       deraadt   230:  *     it is.
                    231:  *-----------------------------------------------------------------------
                    232:  */
                    233: static char *
1.51      espie     234: SuffSuffIsSuffix(Suff *s, const char *str)
1.1       deraadt   235: {
1.41      espie     236:     const char    *p1;         /* Pointer into suffix name */
                    237:     const char    *p2;         /* Pointer into string being examined */
1.1       deraadt   238:
                    239:     p1 = s->name + s->nameLen;
                    240:     p2 = str;
                    241:
1.41      espie     242:     while (p1 != s->name) {
1.1       deraadt   243:        p1--;
                    244:        p2--;
1.41      espie     245:        if (*p1 != *p2)
                    246:                return NULL;
1.1       deraadt   247:     }
                    248:
1.41      espie     249:     return (char *)p2;
1.1       deraadt   250: }
                    251:
                    252: /*-
                    253:  *-----------------------------------------------------------------------
                    254:  * SuffSuffIsSuffixP --
                    255:  *     Predicate form of SuffSuffIsSuffix. Passed as the callback function
                    256:  *     to Lst_Find.
                    257:  *
                    258:  * Results:
                    259:  *     0 if the suffix is the one desired, non-zero if not.
                    260:  *-----------------------------------------------------------------------
                    261:  */
                    262: static int
1.51      espie     263: SuffSuffIsSuffixP(void *s, const void *str)
1.1       deraadt   264: {
1.41      espie     265:     return !SuffSuffIsSuffix((Suff *)s, (const char *)str);
1.1       deraadt   266: }
                    267:
                    268: static int
1.52      espie     269: SuffHasNameP(void *s, const void *sname)
1.1       deraadt   270: {
1.41      espie     271:     return strcmp((const char *)sname, ((Suff *)s)->name);
1.1       deraadt   272: }
                    273:
1.52      espie     274: static LstNode
                    275: suff_find_by_name(const char *name)
                    276: {
                    277: #ifdef STATS_SUFF
                    278:     STAT_SUFF_LOOKUP_NAME++;
                    279: #endif
                    280:     return Lst_FindConst(&sufflist, SuffHasNameP, name);
                    281: }
                    282:
                    283: static int
                    284: GNodeHasNameP(void *gn, const void *name)
                    285: {
                    286:     return strcmp((const char *)name, ((GNode *)gn)->name);
                    287: }
                    288:
                    289: static LstNode
                    290: transform_find_by_name(const char *name)
                    291: {
                    292: #ifdef STATS_SUFF
                    293:     STAT_TRANSFORM_LOOKUP_NAME++;
                    294: #endif
                    295:     return Lst_FindConst(&transforms, GNodeHasNameP, name);
                    296: }
1.1       deraadt   297: /*-
                    298:  *-----------------------------------------------------------------------
                    299:  * SuffSuffIsPrefix  --
                    300:  *     See if the suffix described by s is a prefix of the string. Care
                    301:  *     must be taken when using this to search for transformations and
                    302:  *     what-not, since there could well be two suffixes, one of which
                    303:  *     is a prefix of the other...
                    304:  *
                    305:  * Results:
                    306:  *     0 if s is a prefix of str. non-zero otherwise
                    307:  *-----------------------------------------------------------------------
                    308:  */
                    309: static int
1.51      espie     310: SuffSuffIsPrefix(void *s, const void *str)
1.1       deraadt   311: {
1.41      espie     312:     return SuffStrIsPrefix(((Suff *)s)->name, (const char *)str) == NULL ? 1 : 0;
1.1       deraadt   313: }
                    314:
1.41      espie     315:            /*********** Maintenance Functions ************/
1.1       deraadt   316:
                    317: static void
1.51      espie     318: SuffUnRef(Lst l, Suff *sp)
1.1       deraadt   319: {
1.41      espie     320:     LstNode ln = Lst_Member(l, sp);
1.24      espie     321:     if (ln != NULL)
1.1       deraadt   322:        Lst_Remove(l, ln);
                    323: }
                    324:
1.41      espie     325: #ifdef CLEANUP
1.1       deraadt   326: /*-
                    327:  *-----------------------------------------------------------------------
1.41      espie     328:  * SuffFree  --
                    329:  *     Free up all memory associated with the given suffix structure.
                    330:  *
                    331:  * Side Effects:
                    332:  *     the suffix entry is detroyed
1.1       deraadt   333:  *-----------------------------------------------------------------------
                    334:  */
1.24      espie     335: static void
1.51      espie     336: SuffFree(void *sp)
1.1       deraadt   337: {
1.41      espie     338:     Suff       *s = (Suff *)sp;
                    339:
                    340:     if (s == suffNull)
                    341:        suffNull = NULL;
                    342:
                    343:     if (s == emptySuff)
                    344:        emptySuff = NULL;
                    345:
                    346:     Lst_Destroy(&s->ref, NOFREE);
                    347:     Lst_Destroy(&s->children, NOFREE);
                    348:     Lst_Destroy(&s->parents, NOFREE);
                    349:     Lst_Destroy(&s->searchPath, Dir_Destroy);
                    350:
                    351:     free(s->name);
                    352:     free(s);
1.1       deraadt   353: }
1.41      espie     354: #endif
                    355:
                    356:
1.1       deraadt   357: /*-
                    358:  *-----------------------------------------------------------------------
                    359:  * SuffInsert  --
                    360:  *     Insert the suffix into the list keeping the list ordered by suffix
                    361:  *     numbers.
                    362:  *
                    363:  * Side Effects:
                    364:  *     The reference count of the suffix is incremented
                    365:  *-----------------------------------------------------------------------
                    366:  */
                    367: static void
1.51      espie     368: SuffInsert(Lst l, Suff *s)
1.1       deraadt   369: {
1.41      espie     370:     LstNode      ln;           /* current element in l we're examining */
                    371:     Suff         *s2 = NULL;   /* the suffix descriptor in this element */
1.1       deraadt   372:
1.41      espie     373:     for (ln = Lst_First(l); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie     374:        s2 = (Suff *)Lst_Datum(ln);
1.41      espie     375:        if (s2->sNum >= s->sNum)
1.1       deraadt   376:            break;
                    377:     }
                    378:
                    379:     if (DEBUG(SUFF)) {
                    380:        printf("inserting %s(%d)...", s->name, s->sNum);
                    381:     }
1.18      espie     382:     if (ln == NULL) {
1.1       deraadt   383:        if (DEBUG(SUFF)) {
                    384:            printf("at end of list\n");
                    385:        }
1.25      espie     386:        Lst_AtEnd(l, s);
1.29      espie     387:        Lst_AtEnd(&s->ref, l);
1.1       deraadt   388:     } else if (s2->sNum != s->sNum) {
                    389:        if (DEBUG(SUFF)) {
                    390:            printf("before %s(%d)\n", s2->name, s2->sNum);
                    391:        }
1.25      espie     392:        Lst_Insert(l, ln, s);
1.29      espie     393:        Lst_AtEnd(&s->ref, l);
1.1       deraadt   394:     } else if (DEBUG(SUFF)) {
                    395:        printf("already there\n");
                    396:     }
                    397: }
                    398:
                    399: /*-
                    400:  *-----------------------------------------------------------------------
                    401:  * Suff_ClearSuffixes --
                    402:  *     This is gross. Nuke the list of suffixes but keep all transformation
                    403:  *     rules around. The transformation graph is destroyed in this process,
                    404:  *     but we leave the list of rules so when a new graph is formed the rules
                    405:  *     will remain.
                    406:  *     This function is called from the parse module when a
                    407:  *     .SUFFIXES:\n line is encountered.
                    408:  *
                    409:  * Side Effects:
                    410:  *     the sufflist and its graph nodes are destroyed
                    411:  *-----------------------------------------------------------------------
                    412:  */
                    413: void
1.51      espie     414: Suff_ClearSuffixes(void)
1.1       deraadt   415: {
1.14      espie     416: #ifdef CLEANUP
1.30      espie     417:     Lst_ConcatDestroy(&suffClean, &sufflist);
1.14      espie     418: #endif
1.30      espie     419:     Lst_Init(&sufflist);
1.1       deraadt   420:     sNum = 0;
                    421:     suffNull = emptySuff;
                    422: }
                    423:
                    424: /*-
                    425:  *-----------------------------------------------------------------------
                    426:  * SuffParseTransform --
                    427:  *     Parse a transformation string to find its two component suffixes.
                    428:  *
                    429:  * Results:
1.42      espie     430:  *     true if the string is a valid transformation and false otherwise.
1.1       deraadt   431:  *
                    432:  * Side Effects:
                    433:  *     The passed pointers are overwritten.
                    434:  *-----------------------------------------------------------------------
                    435:  */
1.42      espie     436: static bool
1.51      espie     437: SuffParseTransform(
                    438:     const char         *str,           /* String being parsed */
                    439:     Suff               **srcPtr,       /* Place to store source of trans. */
                    440:     Suff               **targPtr)      /* Place to store target of trans. */
1.41      espie     441: {
                    442:     LstNode            srcLn;      /* element in suffix list of trans source*/
                    443:     Suff               *src;       /* Source of transformation */
                    444:     LstNode            targLn;     /* element in suffix list of trans target*/
                    445:     const char         *str2;      /* Extra pointer (maybe target suffix) */
                    446:     LstNode            singleLn;   /* element in suffix list of any suffix
1.1       deraadt   447:                                     * that exactly matches str */
1.41      espie     448:     Suff               *single = NULL;/* Source of possible transformation to
1.1       deraadt   449:                                     * null suffix */
                    450:
1.18      espie     451:     srcLn = NULL;
                    452:     singleLn = NULL;
1.5       millert   453:
1.1       deraadt   454:     /*
                    455:      * Loop looking first for a suffix that matches the start of the
                    456:      * string and then for one that exactly matches the rest of it. If
                    457:      * we can find two that meet these criteria, we've successfully
                    458:      * parsed the string.
                    459:      */
                    460:     for (;;) {
1.41      espie     461:        if (srcLn == NULL)
                    462:            srcLn = Lst_FindConst(&sufflist, SuffSuffIsPrefix, str);
                    463:        else
                    464:            srcLn = Lst_FindFromConst(Lst_Succ(srcLn), SuffSuffIsPrefix, str);
1.18      espie     465:        if (srcLn == NULL) {
1.1       deraadt   466:            /*
                    467:             * Ran out of source suffixes -- no such rule
                    468:             */
1.18      espie     469:            if (singleLn != NULL) {
1.1       deraadt   470:                /*
                    471:                 * Not so fast Mr. Smith! There was a suffix that encompassed
                    472:                 * the entire string, so we assume it was a transformation
                    473:                 * to the null suffix (thank you POSIX). We still prefer to
                    474:                 * find a double rule over a singleton, hence we leave this
                    475:                 * check until the end.
                    476:                 *
                    477:                 * XXX: Use emptySuff over suffNull?
                    478:                 */
                    479:                *srcPtr = single;
                    480:                *targPtr = suffNull;
1.42      espie     481:                return true;
1.1       deraadt   482:            }
1.42      espie     483:            return false;
1.1       deraadt   484:        }
1.31      espie     485:        src = (Suff *)Lst_Datum(srcLn);
1.1       deraadt   486:        str2 = str + src->nameLen;
                    487:        if (*str2 == '\0') {
                    488:            single = src;
                    489:            singleLn = srcLn;
                    490:        } else {
1.52      espie     491:            targLn = suff_find_by_name(str2);
1.18      espie     492:            if (targLn != NULL) {
1.1       deraadt   493:                *srcPtr = src;
                    494:                *targPtr = (Suff *)Lst_Datum(targLn);
1.42      espie     495:                return true;
1.1       deraadt   496:            }
                    497:        }
                    498:     }
                    499: }
                    500:
                    501: /*-
                    502:  *-----------------------------------------------------------------------
                    503:  * Suff_IsTransform  --
1.42      espie     504:  *     Return true if the given string is a transformation rule
1.1       deraadt   505:  *
                    506:  * Results:
1.42      espie     507:  *     true if the string is a concatenation of two known suffixes.
                    508:  *     false otherwise
1.1       deraadt   509:  *-----------------------------------------------------------------------
                    510:  */
1.42      espie     511: bool
1.51      espie     512: Suff_IsTransform(const char *str)
1.1       deraadt   513: {
1.41      espie     514:     Suff         *src, *targ;
1.1       deraadt   515:
1.41      espie     516:     return SuffParseTransform(str, &src, &targ);
1.1       deraadt   517: }
                    518:
                    519: /*-
                    520:  *-----------------------------------------------------------------------
                    521:  * Suff_AddTransform --
                    522:  *     Add the transformation rule described by the line to the
                    523:  *     list of rules and place the transformation itself in the graph
                    524:  *
                    525:  * Results:
                    526:  *     The node created for the transformation in the transforms list
                    527:  *
                    528:  * Side Effects:
                    529:  *     The node is placed on the end of the transforms Lst and links are
                    530:  *     made between the two suffixes mentioned in the target name
                    531:  *-----------------------------------------------------------------------
                    532:  */
                    533: GNode *
1.51      espie     534: Suff_AddTransform(const char *line)
1.1       deraadt   535: {
1.41      espie     536:     GNode        *gn;          /* GNode of transformation rule */
                    537:     Suff         *s,           /* source suffix */
                    538:                  *t;           /* target suffix */
                    539:     LstNode      ln;           /* Node for existing transformation */
1.1       deraadt   540:
1.52      espie     541:     ln = transform_find_by_name(line);
1.18      espie     542:     if (ln == NULL) {
1.1       deraadt   543:        /*
                    544:         * Make a new graph node for the transformation. It will be filled in
1.5       millert   545:         * by the Parse module.
1.1       deraadt   546:         */
1.42      espie     547:        gn = Targ_NewGN(line);
1.29      espie     548:        Lst_AtEnd(&transforms, gn);
1.1       deraadt   549:     } else {
                    550:        /*
                    551:         * New specification for transformation rule. Just nuke the old list
                    552:         * of commands so they can be filled in again... We don't actually
                    553:         * free the commands themselves, because a given command can be
                    554:         * attached to several different transformations.
                    555:         */
1.31      espie     556:        gn = (GNode *)Lst_Datum(ln);
1.29      espie     557:        Lst_Destroy(&gn->commands, NOFREE);
1.41      espie     558:        Lst_Init(&gn->commands);
1.29      espie     559:        Lst_Destroy(&gn->children, NOFREE);
                    560:        Lst_Init(&gn->children);
1.1       deraadt   561:     }
                    562:
                    563:     gn->type = OP_TRANSFORM;
                    564:
                    565:     (void)SuffParseTransform(line, &s, &t);
                    566:
                    567:     /*
1.5       millert   568:      * link the two together in the proper relationship and order
1.1       deraadt   569:      */
                    570:     if (DEBUG(SUFF)) {
                    571:        printf("defining transformation from `%s' to `%s'\n",
                    572:                s->name, t->name);
                    573:     }
1.29      espie     574:     SuffInsert(&t->children, s);
                    575:     SuffInsert(&s->parents, t);
1.1       deraadt   576:
1.41      espie     577:     return gn;
1.1       deraadt   578: }
                    579:
                    580: /*-
                    581:  *-----------------------------------------------------------------------
                    582:  * Suff_EndTransform --
                    583:  *     Handle the finish of a transformation definition, removing the
                    584:  *     transformation from the graph if it has neither commands nor
                    585:  *     sources. This is a callback procedure for the Parse module via
                    586:  *     Lst_ForEach
                    587:  *
                    588:  * Side Effects:
                    589:  *     If the node has no commands or children, the children and parents
                    590:  *     lists of the affected suffices are altered.
                    591:  *-----------------------------------------------------------------------
                    592:  */
1.27      espie     593: void
1.51      espie     594: Suff_EndTransform(void *gnp)
1.1       deraadt   595: {
1.27      espie     596:     GNode *gn = (GNode *)gnp;
1.5       millert   597:
1.29      espie     598:     if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(&gn->commands) &&
                    599:        Lst_IsEmpty(&gn->children))
1.1       deraadt   600:     {
                    601:        Suff    *s, *t;
                    602:
1.53    ! robert    603:        if (!SuffParseTransform(gn->name, &s, &t))
        !           604:            return;
1.1       deraadt   605:
                    606:        if (DEBUG(SUFF)) {
1.8       millert   607:            printf("deleting transformation from `%s' to `%s'\n",
1.1       deraadt   608:                    s->name, t->name);
                    609:        }
                    610:
                    611:        /*
1.41      espie     612:         * Remove the source from the target's children list.
1.1       deraadt   613:         *
                    614:         * We'll be called twice when the next target is seen, but .c and .o
                    615:         * are only linked once...
                    616:         */
1.41      espie     617:        SuffUnRef(&t->children, s);
1.1       deraadt   618:
                    619:        /*
                    620:         * Remove the target from the source's parents list
                    621:         */
1.41      espie     622:        if (s != NULL)
                    623:            SuffUnRef(&s->parents, t);
1.1       deraadt   624:     } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
                    625:        printf("transformation %s complete\n", gn->name);
                    626:     }
                    627: }
                    628:
                    629: /*-
                    630:  *-----------------------------------------------------------------------
                    631:  * SuffRebuildGraph --
                    632:  *     Called from Suff_AddSuffix via Lst_ForEach to search through the
                    633:  *     list of existing transformation rules and rebuild the transformation
                    634:  *     graph when it has been destroyed by Suff_ClearSuffixes. If the
                    635:  *     given rule is a transformation involving this suffix and another,
                    636:  *     existing suffix, the proper relationship is established between
                    637:  *     the two.
                    638:  *
                    639:  * Side Effects:
                    640:  *     The appropriate links will be made between this suffix and
                    641:  *     others if transformation rules exist for it.
                    642:  *-----------------------------------------------------------------------
                    643:  */
1.27      espie     644: static void
1.51      espie     645: SuffRebuildGraph(
                    646:     void       *transformp,    /* Transformation to test */
                    647:     void       *sp)            /* Suffix to rebuild */
1.1       deraadt   648: {
1.41      espie     649:     GNode      *transform = (GNode *)transformp;
                    650:     Suff       *s = (Suff *)sp;
                    651:     char       *cp;
1.1       deraadt   652:     LstNode    ln;
1.41      espie     653:     Suff       *s2;
1.1       deraadt   654:
1.41      espie     655:     /* First see if it is a transformation from this suffix.  */
1.1       deraadt   656:     cp = SuffStrIsPrefix(s->name, transform->name);
1.27      espie     657:     if (cp != NULL) {
1.52      espie     658:        ln = suff_find_by_name(cp);
1.18      espie     659:        if (ln != NULL) {
1.41      espie     660:            /* Found target. Link in and return, since it can't be anything
                    661:             * else.  */
1.1       deraadt   662:            s2 = (Suff *)Lst_Datum(ln);
1.29      espie     663:            SuffInsert(&s2->children, s);
                    664:            SuffInsert(&s->parents, s2);
1.27      espie     665:            return;
1.1       deraadt   666:        }
                    667:     }
                    668:
1.41      espie     669:     /* Not from, maybe to?  */
1.1       deraadt   670:     cp = SuffSuffIsSuffix(s, transform->name + strlen(transform->name));
1.27      espie     671:     if (cp != NULL) {
1.41      espie     672:        /* Null-terminate the source suffix in order to find it.  */
                    673:        *cp = '\0';
1.52      espie     674:        ln = suff_find_by_name(transform->name);
1.41      espie     675:        /* Replace the start of the target suffix.  */
                    676:        *cp = s->name[0];
1.18      espie     677:        if (ln != NULL) {
1.41      espie     678:            /* Found it -- establish the proper relationship.  */
1.1       deraadt   679:            s2 = (Suff *)Lst_Datum(ln);
1.29      espie     680:            SuffInsert(&s->children, s2);
                    681:            SuffInsert(&s2->parents, s);
1.1       deraadt   682:        }
                    683:     }
                    684: }
                    685:
                    686: /*-
                    687:  *-----------------------------------------------------------------------
                    688:  * Suff_AddSuffix --
                    689:  *     Add the suffix in string to the end of the list of known suffixes.
                    690:  *     Should we restructure the suffix graph? Make doesn't...
                    691:  *
                    692:  * Side Effects:
                    693:  *     A GNode is created for the suffix and a Suff structure is created and
                    694:  *     added to the suffixes list unless the suffix was already known.
                    695:  *-----------------------------------------------------------------------
                    696:  */
                    697: void
1.52      espie     698: Suff_AddSuffix(const char *str)
1.1       deraadt   699: {
1.41      espie     700:     Suff         *s;       /* new suffix descriptor */
                    701:     LstNode      ln;
1.1       deraadt   702:
1.52      espie     703:     ln = suff_find_by_name(str);
1.18      espie     704:     if (ln == NULL) {
1.41      espie     705:        s = emalloc(sizeof(Suff));
1.1       deraadt   706:
1.41      espie     707:        s->name =       estrdup(str);
                    708:        s->nameLen =    strlen(s->name);
1.30      espie     709:        Lst_Init(&s->searchPath);
1.29      espie     710:        Lst_Init(&s->children);
                    711:        Lst_Init(&s->parents);
                    712:        Lst_Init(&s->ref);
1.41      espie     713:        s->sNum =       sNum++;
                    714:        s->flags =      0;
1.1       deraadt   715:
1.30      espie     716:        Lst_AtEnd(&sufflist, s);
1.1       deraadt   717:        /*
                    718:         * Look for any existing transformations from or to this suffix.
                    719:         * XXX: Only do this after a Suff_ClearSuffixes?
                    720:         */
1.29      espie     721:        Lst_ForEach(&transforms, SuffRebuildGraph, s);
1.5       millert   722:     }
1.1       deraadt   723: }
                    724:
                    725: /*-
                    726:  *-----------------------------------------------------------------------
                    727:  * Suff_GetPath --
                    728:  *     Return the search path for the given suffix, if it's defined.
                    729:  *
                    730:  * Results:
1.18      espie     731:  *     The searchPath for the desired suffix or NULL if the suffix isn't
1.1       deraadt   732:  *     defined.
                    733:  *-----------------------------------------------------------------------
                    734:  */
                    735: Lst
1.52      espie     736: Suff_GetPath(const char *sname)
1.1       deraadt   737: {
1.41      espie     738:     LstNode      ln;
                    739:     Suff         *s;
1.1       deraadt   740:
1.52      espie     741:     ln = suff_find_by_name(sname);
1.41      espie     742:     if (ln == NULL) {
1.30      espie     743:        return NULL;
1.41      espie     744:     } else {
1.30      espie     745:        s = (Suff *)Lst_Datum(ln);
                    746:        return &s->searchPath;
1.1       deraadt   747:     }
                    748: }
                    749:
                    750: /*-
                    751:  *-----------------------------------------------------------------------
                    752:  * Suff_DoPaths --
                    753:  *     Extend the search paths for all suffixes to include the default
                    754:  *     search path.
                    755:  *
                    756:  * Side Effects:
                    757:  *     The searchPath field of all the suffixes is extended by the
                    758:  *     directories in dirSearchPath. If paths were specified for the
                    759:  *     ".h" suffix, the directories are stuffed into a global variable
                    760:  *     called ".INCLUDES" with each directory preceeded by a -I. The same
                    761:  *     is done for the ".a" suffix, except the variable is called
                    762:  *     ".LIBS" and the flag is -L.
                    763:  *-----------------------------------------------------------------------
                    764:  */
                    765: void
1.51      espie     766: Suff_DoPaths(void)
1.1       deraadt   767: {
1.41      espie     768:     Suff               *s;
                    769:     LstNode            ln;
1.1       deraadt   770:     char               *ptr;
1.41      espie     771:     LIST               inIncludes; /* Cumulative .INCLUDES path */
                    772:     LIST               inLibs;     /* Cumulative .LIBS path */
1.1       deraadt   773:
1.29      espie     774:     Lst_Init(&inIncludes);
                    775:     Lst_Init(&inLibs);
1.1       deraadt   776:
1.41      espie     777:     for (ln = Lst_First(&sufflist); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie     778:        s = (Suff *)Lst_Datum(ln);
1.30      espie     779:        if (!Lst_IsEmpty(&s->searchPath)) {
1.1       deraadt   780: #ifdef INCLUDES
                    781:            if (s->flags & SUFF_INCLUDE) {
1.30      espie     782:                Dir_Concat(&inIncludes, &s->searchPath);
1.1       deraadt   783:            }
                    784: #endif /* INCLUDES */
                    785: #ifdef LIBRARIES
                    786:            if (s->flags & SUFF_LIBRARY) {
1.30      espie     787:                Dir_Concat(&inLibs, &s->searchPath);
1.1       deraadt   788:            }
                    789: #endif /* LIBRARIES */
1.42      espie     790:            Dir_Concat(&s->searchPath, dirSearchPath);
                    791:        } else
                    792:            Lst_Clone(&s->searchPath, dirSearchPath, Dir_CopyDir);
1.1       deraadt   793:     }
                    794:
1.29      espie     795:     Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", &inIncludes), VAR_GLOBAL);
1.1       deraadt   796:     free(ptr);
1.29      espie     797:     Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", &inLibs), VAR_GLOBAL);
1.1       deraadt   798:     free(ptr);
                    799:
1.29      espie     800:     Lst_Destroy(&inIncludes, Dir_Destroy);
                    801:     Lst_Destroy(&inLibs, Dir_Destroy);
1.1       deraadt   802: }
                    803:
                    804: /*-
                    805:  *-----------------------------------------------------------------------
                    806:  * Suff_AddInclude --
                    807:  *     Add the given suffix as a type of file which gets included.
                    808:  *     Called from the parse module when a .INCLUDES line is parsed.
                    809:  *     The suffix must have already been defined.
                    810:  *
                    811:  * Side Effects:
                    812:  *     The SUFF_INCLUDE bit is set in the suffix's flags field
                    813:  *-----------------------------------------------------------------------
                    814:  */
                    815: void
1.52      espie     816: Suff_AddInclude(const char *sname)     /* Name of suffix to mark */
1.1       deraadt   817: {
                    818:     LstNode      ln;
                    819:     Suff         *s;
                    820:
1.52      espie     821:     ln = suff_find_by_name(sname);
1.18      espie     822:     if (ln != NULL) {
1.31      espie     823:        s = (Suff *)Lst_Datum(ln);
1.1       deraadt   824:        s->flags |= SUFF_INCLUDE;
                    825:     }
                    826: }
                    827:
                    828: /*-
                    829:  *-----------------------------------------------------------------------
                    830:  * Suff_AddLib --
                    831:  *     Add the given suffix as a type of file which is a library.
                    832:  *     Called from the parse module when parsing a .LIBS line. The
                    833:  *     suffix must have been defined via .SUFFIXES before this is
                    834:  *     called.
                    835:  *
                    836:  * Side Effects:
                    837:  *     The SUFF_LIBRARY bit is set in the suffix's flags field
                    838:  *-----------------------------------------------------------------------
                    839:  */
                    840: void
1.52      espie     841: Suff_AddLib(const char *sname) /* Name of suffix to mark */
1.1       deraadt   842: {
                    843:     LstNode      ln;
                    844:     Suff         *s;
                    845:
1.52      espie     846:     ln = suff_find_by_name(sname);
1.18      espie     847:     if (ln != NULL) {
1.31      espie     848:        s = (Suff *)Lst_Datum(ln);
1.1       deraadt   849:        s->flags |= SUFF_LIBRARY;
                    850:     }
                    851: }
                    852:
1.41      espie     853:          /********** Implicit Source Search Functions *********/
1.1       deraadt   854:
                    855: /*-
                    856:  *-----------------------------------------------------------------------
                    857:  * SuffAddSrc  --
                    858:  *     Add a suffix as a Src structure to the given list with its parent
                    859:  *     being the given Src structure. If the suffix is the null suffix,
                    860:  *     the prefix is used unaltered as the file name in the Src structure.
                    861:  *
                    862:  * Side Effects:
                    863:  *     A Src structure is created and tacked onto the end of the list
                    864:  *-----------------------------------------------------------------------
                    865:  */
1.27      espie     866: static void
1.51      espie     867: SuffAddSrc(
                    868:     void *sp,      /* suffix for which to create a Src structure */
                    869:     void *lsp)     /* list and parent for the new Src */
1.1       deraadt   870: {
1.27      espie     871:     Suff       *s = (Suff *)sp;
1.41      espie     872:     LstSrc     *ls = (LstSrc *)lsp;
                    873:     Src        *s2;        /* new Src structure */
                    874:     Src        *targ;      /* Target structure */
1.1       deraadt   875:
                    876:     targ = ls->s;
1.5       millert   877:
1.41      espie     878:     if ((s->flags & SUFF_NULL) && *s->name != '\0') {
1.1       deraadt   879:        /*
                    880:         * If the suffix has been marked as the NULL suffix, also create a Src
                    881:         * structure for a file with no suffix attached. Two birds, and all
                    882:         * that...
                    883:         */
1.41      espie     884:        s2 = emalloc(sizeof(Src));
                    885:        s2->file =      estrdup(targ->pref);
                    886:        s2->pref =      targ->pref;
                    887:        s2->parent =    targ;
                    888:        s2->node =      NULL;
                    889:        s2->suff =      s;
1.1       deraadt   890:        s2->children =  0;
                    891:        targ->children += 1;
1.25      espie     892:        Lst_AtEnd(ls->l, s2);
1.1       deraadt   893: #ifdef DEBUG_SRC
1.29      espie     894:        Lst_Init(&s2->cp);
                    895:        Lst_AtEnd(&targ->cp, s2);
1.1       deraadt   896:        printf("1 add %x %x to %x:", targ, s2, ls->l);
1.27      espie     897:        Lst_Every(ls->l, PrintAddr);
1.1       deraadt   898:        printf("\n");
                    899: #endif
                    900:     }
1.41      espie     901:     s2 = emalloc(sizeof(Src));
1.42      espie     902:     s2->file =     Str_concat(targ->pref, s->name, 0);
1.1       deraadt   903:     s2->pref =     targ->pref;
                    904:     s2->parent =    targ;
1.41      espie     905:     s2->node =     NULL;
                    906:     s2->suff =     s;
1.1       deraadt   907:     s2->children =  0;
                    908:     targ->children += 1;
1.25      espie     909:     Lst_AtEnd(ls->l, s2);
1.1       deraadt   910: #ifdef DEBUG_SRC
1.29      espie     911:     Lst_Init(&s2->cp);
                    912:     Lst_AtEnd(&targ->cp, s2);
1.1       deraadt   913:     printf("2 add %x %x to %x:", targ, s2, ls->l);
1.27      espie     914:     Lst_Every(ls->l, PrintAddr);
1.1       deraadt   915:     printf("\n");
                    916: #endif
1.41      espie     917:
1.1       deraadt   918: }
                    919:
                    920: /*-
                    921:  *-----------------------------------------------------------------------
                    922:  * SuffAddLevel  --
                    923:  *     Add all the children of targ as Src structures to the given list
                    924:  *
                    925:  * Side Effects:
1.41      espie     926:  *     Lots of structures are created and added to the list
1.1       deraadt   927:  *-----------------------------------------------------------------------
                    928:  */
                    929: static void
1.51      espie     930: SuffAddLevel(
                    931:     Lst           l,           /* list to which to add the new level */
                    932:     Src           *targ)       /* Src structure to use as the parent */
1.1       deraadt   933: {
1.41      espie     934:     LstSrc        ls;
1.1       deraadt   935:
                    936:     ls.s = targ;
                    937:     ls.l = l;
                    938:
1.29      espie     939:     Lst_ForEach(&targ->suff->children, SuffAddSrc, &ls);
1.1       deraadt   940: }
                    941:
                    942: /*-
                    943:  *----------------------------------------------------------------------
                    944:  * SuffRemoveSrc --
                    945:  *     Free all src structures in list that don't have a reference count
                    946:  *
                    947:  * Results:
1.41      espie     948:  *     Ture if an src was removed
1.1       deraadt   949:  *
                    950:  * Side Effects:
                    951:  *     The memory is free'd.
                    952:  *----------------------------------------------------------------------
                    953:  */
                    954: static int
1.51      espie     955: SuffRemoveSrc(Lst l)
1.1       deraadt   956: {
                    957:     LstNode ln;
                    958:     Src *s;
                    959:     int t = 0;
                    960:
                    961: #ifdef DEBUG_SRC
1.41      espie     962:     printf("cleaning %lx: ", (unsigned long)l);
1.27      espie     963:     Lst_Every(l, PrintAddr);
1.1       deraadt   964:     printf("\n");
                    965: #endif
                    966:
                    967:
1.41      espie     968:     for (ln = Lst_First(l); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie     969:        s = (Src *)Lst_Datum(ln);
1.1       deraadt   970:        if (s->children == 0) {
1.28      espie     971:            free(s->file);
1.1       deraadt   972:            if (!s->parent)
1.28      espie     973:                free(s->pref);
1.1       deraadt   974:            else {
                    975: #ifdef DEBUG_SRC
1.41      espie     976:                LstNode ln2 = Lst_Member(&s->parent->cp, s);
                    977:                if (ln2 != NULL)
                    978:                    Lst_Remove(&s->parent->cp, ln2);
1.1       deraadt   979: #endif
                    980:                --s->parent->children;
                    981:            }
                    982: #ifdef DEBUG_SRC
                    983:            printf("free: [l=%x] p=%x %d\n", l, s, s->children);
1.29      espie     984:            Lst_Destroy(&s->cp, NOFREE);
1.1       deraadt   985: #endif
                    986:            Lst_Remove(l, ln);
1.28      espie     987:            free(s);
1.1       deraadt   988:            t |= 1;
1.42      espie     989:            return true;
1.1       deraadt   990:        }
                    991: #ifdef DEBUG_SRC
                    992:        else {
                    993:            printf("keep: [l=%x] p=%x %d: ", l, s, s->children);
1.29      espie     994:            Lst_Every(&s->cp, PrintAddr);
1.1       deraadt   995:            printf("\n");
                    996:        }
                    997: #endif
                    998:     }
                    999:
                   1000:     return t;
                   1001: }
                   1002:
                   1003: /*-
                   1004:  *-----------------------------------------------------------------------
                   1005:  * SuffFindThem --
                   1006:  *     Find the first existing file/target in the list srcs
                   1007:  *
                   1008:  * Results:
                   1009:  *     The lowest structure in the chain of transformations
                   1010:  *-----------------------------------------------------------------------
                   1011:  */
                   1012: static Src *
1.51      espie    1013: SuffFindThem(
                   1014:     Lst           srcs,        /* list of Src structures to search through */
                   1015:     Lst           slst)
1.1       deraadt  1016: {
1.41      espie    1017:     Src           *s;          /* current Src */
                   1018:     Src           *rs;         /* returned Src */
1.1       deraadt  1019:     char          *ptr;
                   1020:
1.41      espie    1021:     rs = NULL;
1.1       deraadt  1022:
1.19      espie    1023:     while ((s = (Src *)Lst_DeQueue(srcs)) != NULL) {
1.1       deraadt  1024:        if (DEBUG(SUFF)) {
1.41      espie    1025:            printf("\ttrying %s...", s->file);
1.1       deraadt  1026:        }
                   1027:
                   1028:        /*
                   1029:         * A file is considered to exist if either a node exists in the
                   1030:         * graph for it or the file actually exists.
                   1031:         */
1.42      espie    1032:        if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) {
1.1       deraadt  1033: #ifdef DEBUG_SRC
                   1034:            printf("remove %x from %x\n", s, srcs);
                   1035: #endif
                   1036:            rs = s;
                   1037:            break;
                   1038:        }
                   1039:
1.30      espie    1040:        if ((ptr = Dir_FindFile(s->file, &s->suff->searchPath)) != NULL) {
1.1       deraadt  1041:            rs = s;
                   1042: #ifdef DEBUG_SRC
                   1043:            printf("remove %x from %x\n", s, srcs);
                   1044: #endif
                   1045:            free(ptr);
                   1046:            break;
                   1047:        }
                   1048:
                   1049:        if (DEBUG(SUFF)) {
1.41      espie    1050:            printf("not there\n");
1.1       deraadt  1051:        }
                   1052:
1.41      espie    1053:        SuffAddLevel(srcs, s);
1.25      espie    1054:        Lst_AtEnd(slst, s);
1.1       deraadt  1055:     }
                   1056:
                   1057:     if (DEBUG(SUFF) && rs) {
1.41      espie    1058:        printf("got it\n");
1.1       deraadt  1059:     }
1.41      espie    1060:     return rs;
1.1       deraadt  1061: }
                   1062:
                   1063: /*-
                   1064:  *-----------------------------------------------------------------------
                   1065:  * SuffFindCmds --
                   1066:  *     See if any of the children of the target in the Src structure is
                   1067:  *     one from which the target can be transformed. If there is one,
                   1068:  *     a Src structure is put together for it and returned.
                   1069:  *
                   1070:  * Results:
1.18      espie    1071:  *     The Src structure of the "winning" child, or NULL if no such beast.
1.1       deraadt  1072:  *
                   1073:  * Side Effects:
                   1074:  *     A Src structure may be allocated.
                   1075:  *-----------------------------------------------------------------------
                   1076:  */
                   1077: static Src *
1.51      espie    1078: SuffFindCmds(
                   1079:     Src        *targ,  /* Src structure to play with */
                   1080:     Lst        slst)
1.41      espie    1081: {
                   1082:     LstNode            ln;     /* General-purpose list node */
                   1083:     GNode              *t,     /* Target GNode */
                   1084:                        *s;     /* Source GNode */
                   1085:     int                prefLen;/* The length of the defined prefix */
                   1086:     Suff               *suff;  /* Suffix on matching beastie */
                   1087:     Src                *ret;   /* Return value */
                   1088:     const char         *cp;
1.1       deraadt  1089:
                   1090:     t = targ->node;
1.41      espie    1091:     prefLen = strlen(targ->pref);
1.1       deraadt  1092:
1.41      espie    1093:     for (ln = Lst_First(&t->children); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie    1094:        s = (GNode *)Lst_Datum(ln);
1.1       deraadt  1095:
1.41      espie    1096:        cp = strrchr(s->name, '/');
                   1097:        if (cp == NULL) {
1.1       deraadt  1098:            cp = s->name;
                   1099:        } else {
                   1100:            cp++;
                   1101:        }
1.41      espie    1102:        if (strncmp(cp, targ->pref, prefLen) == 0) {
                   1103:            /* The node matches the prefix ok, see if it has a known
                   1104:             * suffix.  */
                   1105:            LstNode ln2;
1.52      espie    1106:            ln2 = suff_find_by_name(&cp[prefLen]);
1.41      espie    1107:            if (ln2 != NULL) {
1.1       deraadt  1108:                /*
                   1109:                 * It even has a known suffix, see if there's a transformation
                   1110:                 * defined between the node's suffix and the target's suffix.
                   1111:                 *
                   1112:                 * XXX: Handle multi-stage transformations here, too.
                   1113:                 */
1.41      espie    1114:                suff = (Suff *)Lst_Datum(ln2);
1.1       deraadt  1115:
1.41      espie    1116:                if (Lst_Member(&suff->parents, targ->suff) != NULL) {
1.1       deraadt  1117:                    /*
                   1118:                     * Hot Damn! Create a new Src structure to describe
                   1119:                     * this transformation (making sure to duplicate the
                   1120:                     * source node's name so Suff_FindDeps can free it
                   1121:                     * again (ick)), and return the new structure.
                   1122:                     */
1.41      espie    1123:                    ret = emalloc(sizeof(Src));
1.4       briggs   1124:                    ret->file = estrdup(s->name);
1.1       deraadt  1125:                    ret->pref = targ->pref;
                   1126:                    ret->suff = suff;
                   1127:                    ret->parent = targ;
                   1128:                    ret->node = s;
                   1129:                    ret->children = 0;
                   1130:                    targ->children += 1;
                   1131: #ifdef DEBUG_SRC
1.29      espie    1132:                    Lst_Init(&ret->cp);
1.1       deraadt  1133:                    printf("3 add %x %x\n", targ, ret);
1.29      espie    1134:                    Lst_AtEnd(&targ->cp, ret);
1.1       deraadt  1135: #endif
1.25      espie    1136:                    Lst_AtEnd(slst, ret);
1.1       deraadt  1137:                    if (DEBUG(SUFF)) {
                   1138:                        printf ("\tusing existing source %s\n", s->name);
                   1139:                    }
1.41      espie    1140:                    return ret;
1.1       deraadt  1141:                }
                   1142:            }
                   1143:        }
                   1144:     }
1.41      espie    1145:     return NULL;
                   1146: }
                   1147:
                   1148: static void
1.51      espie    1149: SuffExpandVarChildren(LstNode after, GNode *cgn, GNode *pgn)
1.41      espie    1150: {
                   1151:     GNode      *gn;            /* New source 8) */
                   1152:     char       *cp;            /* Expanded value */
                   1153:     LIST       members;
                   1154:
                   1155:
                   1156:     if (DEBUG(SUFF))
                   1157:        printf("Expanding \"%s\"...", cgn->name);
                   1158:
1.42      espie    1159:     cp = Var_Subst(cgn->name, &pgn->context, true);
1.41      espie    1160:     if (cp == NULL) {
                   1161:        printf("Problem substituting in %s", cgn->name);
                   1162:        printf("\n");
                   1163:        return;
                   1164:     }
                   1165:
                   1166:     Lst_Init(&members);
                   1167:
                   1168:     if (cgn->type & OP_ARCHV) {
                   1169:        /*
                   1170:         * Node was an archive(member) target, so we want to call
                   1171:         * on the Arch module to find the nodes for us, expanding
                   1172:         * variables in the parent's context.
                   1173:         */
                   1174:        char    *sacrifice = cp;
                   1175:
                   1176:        (void)Arch_ParseArchive(&sacrifice, &members, &pgn->context);
                   1177:     } else {
                   1178:        /* Break the result into a vector of strings whose nodes
                   1179:         * we can find, then add those nodes to the members list.
                   1180:         * Unfortunately, we can't use brk_string because it
                   1181:         * doesn't understand about variable specifications with
                   1182:         * spaces in them...  */
                   1183:        char        *start, *cp2;
                   1184:
                   1185:        for (start = cp; *start == ' ' || *start == '\t'; start++)
                   1186:            continue;
                   1187:        for (cp2 = start; *cp2 != '\0';) {
                   1188:            if (isspace(*cp2)) {
                   1189:                /* White-space -- terminate element, find the node,
                   1190:                 * add it, skip any further spaces.  */
1.42      espie    1191:                gn = Targ_FindNodei(start, cp2, TARG_CREATE);
1.41      espie    1192:                cp2++;
                   1193:                Lst_AtEnd(&members, gn);
                   1194:                while (isspace(*cp2))
                   1195:                    cp2++;
                   1196:                /* Adjust cp2 for increment at start of loop, but
                   1197:                 * set start to first non-space.  */
                   1198:                start = cp2;
                   1199:            } else if (*cp2 == '$')
                   1200:                /* Start of a variable spec -- contact variable module
                   1201:                 * to find the end so we can skip over it.  */
                   1202:                cp2 += Var_ParseSkip(cp2, &pgn->context, NULL);
                   1203:            else if (*cp2 == '\\' && cp2[1] != '\0')
                   1204:                /* Escaped something -- skip over it.  */
                   1205:                cp2+=2;
1.49      espie    1206:            else
                   1207:                cp2++;
1.41      espie    1208:        }
                   1209:
                   1210:        if (cp2 != start) {
                   1211:            /* Stuff left over -- add it to the list too.  */
1.42      espie    1212:            gn = Targ_FindNodei(start, cp2, TARG_CREATE);
1.41      espie    1213:            Lst_AtEnd(&members, gn);
                   1214:        }
                   1215:     }
                   1216:     /* Add all elements of the members list to the parent node.  */
                   1217:     while ((gn = (GNode *)Lst_DeQueue(&members)) != NULL) {
                   1218:        if (DEBUG(SUFF))
                   1219:            printf("%s...", gn->name);
                   1220:        if (Lst_Member(&pgn->children, gn) == NULL) {
                   1221:            Lst_Append(&pgn->children, after, gn);
                   1222:            after = Lst_Adv(after);
                   1223:            Lst_AtEnd(&gn->parents, pgn);
                   1224:            pgn->unmade++;
                   1225:        }
                   1226:     }
                   1227:     /* Free the result.  */
                   1228:     free(cp);
                   1229:     if (DEBUG(SUFF))
                   1230:        printf("\n");
                   1231: }
                   1232:
                   1233: static void
1.51      espie    1234: SuffExpandWildChildren(LstNode after, GNode *cgn, GNode *pgn)
1.41      espie    1235: {
                   1236:     LstNode    ln;             /* List element for old source */
                   1237:     char       *cp;            /* Expanded value */
                   1238:
                   1239:     LIST       exp;        /* List of expansions */
                   1240:     Lst        path;       /* Search path along which to expand */
                   1241:
                   1242:     if (DEBUG(SUFF))
                   1243:        printf("Wildcard expanding \"%s\"...", cgn->name);
                   1244:
                   1245:     /* Find a path along which to expand the word.
                   1246:      *
                   1247:      * If the word has a known suffix, use that path.
                   1248:      * If it has no known suffix and we're allowed to use the null
                   1249:      *  suffix, use its path.
                   1250:      * Else use the default system search path.  */
                   1251:     cp = cgn->name + strlen(cgn->name);
                   1252:     ln = Lst_FindConst(&sufflist, SuffSuffIsSuffixP, cp);
                   1253:
                   1254:     if (ln != NULL) {
                   1255:        Suff    *s = (Suff *)Lst_Datum(ln);
                   1256:
                   1257:        if (DEBUG(SUFF))
                   1258:            printf("suffix is \"%s\"...", s->name);
                   1259:        path = &s->searchPath;
                   1260:     } else
                   1261:        /* Use default search path.  */
1.42      espie    1262:        path = dirSearchPath;
1.41      espie    1263:
                   1264:     /* Expand the word along the chosen path. */
                   1265:     Lst_Init(&exp);
                   1266:     Dir_Expand(cgn->name, path, &exp);
                   1267:
                   1268:     /* Fetch next expansion off the list and find its GNode.  */
                   1269:     while ((cp = (char *)Lst_DeQueue(&exp)) != NULL) {
                   1270:        GNode           *gn;            /* New source 8) */
                   1271:        if (DEBUG(SUFF))
                   1272:            printf("%s...", cp);
1.42      espie    1273:        gn = Targ_FindNode(cp, TARG_CREATE);
1.41      espie    1274:
                   1275:        /* If gn isn't already a child of the parent, make it so and
                   1276:         * up the parent's count of unmade children.  */
                   1277:        if (Lst_Member(&pgn->children, gn) == NULL) {
                   1278:            Lst_Append(&pgn->children, after, gn);
                   1279:            after = Lst_Adv(after);
                   1280:            Lst_AtEnd(&gn->parents, pgn);
                   1281:            pgn->unmade++;
                   1282:        }
                   1283:     }
                   1284:
                   1285:     if (DEBUG(SUFF))
                   1286:        printf("\n");
1.1       deraadt  1287: }
                   1288:
                   1289: /*-
                   1290:  *-----------------------------------------------------------------------
                   1291:  * SuffExpandChildren --
                   1292:  *     Expand the names of any children of a given node that contain
                   1293:  *     variable invocations or file wildcards into actual targets.
                   1294:  *
                   1295:  * Side Effects:
                   1296:  *     The expanded node is removed from the parent's list of children,
                   1297:  *     and the parent's unmade counter is decremented, but other nodes
1.41      espie    1298:  *     may be added.
1.1       deraadt  1299:  *-----------------------------------------------------------------------
                   1300:  */
1.27      espie    1301: static void
1.51      espie    1302: SuffExpandChildren(
                   1303:     void       *cgnp,          /* Child to examine */
                   1304:     void       *pgnp)          /* Parent node being processed */
1.1       deraadt  1305: {
1.41      espie    1306:     GNode      *cgn = (GNode *)cgnp;
                   1307:     GNode      *pgn = (GNode *)pgnp;
                   1308:     LstNode    ln;
                   1309:     /* New nodes effectively take the place of the child, so we place them
                   1310:      * after the child.  */
                   1311:     ln = Lst_Member(&pgn->children, cgn);
1.1       deraadt  1312:
1.41      espie    1313:     /* First do variable expansion -- this takes precedence over
1.1       deraadt  1314:      * wildcard expansion. If the result contains wildcards, they'll be gotten
                   1315:      * to later since the resulting words are tacked on to the end of
1.41      espie    1316:      * the children list.  */
                   1317:     if (strchr(cgn->name, '$') != NULL)
                   1318:        SuffExpandVarChildren(ln, cgn, pgn);
                   1319:     else if (Dir_HasWildcards(cgn->name))
                   1320:        SuffExpandWildChildren(ln, cgn, pgn);
                   1321:     else
                   1322:        /* Third case: nothing to expand.  */
                   1323:        return;
1.1       deraadt  1324:
1.41      espie    1325:     /* Since the source was expanded, remove it from the list of children to
                   1326:      * keep it from being processed.  */
                   1327:     pgn->unmade--;
                   1328:     Lst_Remove(&pgn->children, ln);
1.1       deraadt  1329: }
                   1330:
                   1331: /*-
                   1332:  *-----------------------------------------------------------------------
                   1333:  * SuffApplyTransform --
                   1334:  *     Apply a transformation rule, given the source and target nodes
                   1335:  *     and suffixes.
                   1336:  *
                   1337:  * Results:
1.42      espie    1338:  *     true if successful, false if not.
1.1       deraadt  1339:  *
                   1340:  * Side Effects:
                   1341:  *     The source and target are linked and the commands from the
                   1342:  *     transformation are added to the target node's commands list.
                   1343:  *     All attributes but OP_DEPMASK and OP_TRANSFORM are applied
                   1344:  *     to the target. The target also inherits all the sources for
                   1345:  *     the transformation rule.
                   1346:  *-----------------------------------------------------------------------
                   1347:  */
1.42      espie    1348: static bool
1.51      espie    1349: SuffApplyTransform(
                   1350:     GNode      *tGn,   /* Target node */
                   1351:     GNode      *sGn,   /* Source node */
                   1352:     Suff       *t,     /* Target suffix */
                   1353:     Suff       *s)     /* Source suffix */
1.1       deraadt  1354: {
1.41      espie    1355:     LstNode    ln;     /* General node */
1.39      espie    1356:     LstNode    np;         /* Next node for loop */
1.41      espie    1357:     char       *tname; /* Name of transformation rule */
                   1358:     GNode      *gn;    /* Node for same */
1.1       deraadt  1359:
1.42      espie    1360:     if (Lst_AddNew(&tGn->children, sGn)) {
1.41      espie    1361:        /* Not already linked, so form the proper links between the
                   1362:         * target and source.  */
1.29      espie    1363:        Lst_AtEnd(&sGn->parents, tGn);
1.41      espie    1364:        tGn->unmade++;
1.1       deraadt  1365:     }
                   1366:
                   1367:     if ((sGn->type & OP_OPMASK) == OP_DOUBLEDEP) {
1.41      espie    1368:        /* When a :: node is used as the implied source of a node, we have
1.1       deraadt  1369:         * to link all its cohorts in as sources as well. Only the initial
                   1370:         * sGn gets the target in its iParents list, however, as that
1.41      espie    1371:         * will be sufficient to get the .IMPSRC variable set for tGn.  */
1.31      espie    1372:        for (ln=Lst_First(&sGn->cohorts); ln != NULL; ln=Lst_Adv(ln)) {
1.1       deraadt  1373:            gn = (GNode *)Lst_Datum(ln);
                   1374:
1.42      espie    1375:            if (Lst_AddNew(&tGn->children, gn)) {
1.41      espie    1376:                /* Not already linked, so form the proper links between the
                   1377:                 * target and source.  */
1.29      espie    1378:                Lst_AtEnd(&gn->parents, tGn);
1.41      espie    1379:                tGn->unmade++;
1.1       deraadt  1380:            }
                   1381:        }
                   1382:     }
1.41      espie    1383:     /* Locate the transformation rule itself.  */
1.42      espie    1384:     tname = Str_concat(s->name, t->name, 0);
1.52      espie    1385:     ln = transform_find_by_name(tname);
1.1       deraadt  1386:     free(tname);
                   1387:
1.41      espie    1388:     if (ln == NULL)
1.1       deraadt  1389:        /*
                   1390:         * Not really such a transformation rule (can happen when we're
                   1391:         * called to link an OP_MEMBER and OP_ARCHV node), so return
1.42      espie    1392:         * false.
1.1       deraadt  1393:         */
1.42      espie    1394:        return false;
1.1       deraadt  1395:
                   1396:     gn = (GNode *)Lst_Datum(ln);
1.5       millert  1397:
1.41      espie    1398:     if (DEBUG(SUFF))
1.1       deraadt  1399:        printf("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
                   1400:
1.41      espie    1401:     /* Record last child for expansion purposes.  */
1.29      espie    1402:     ln = Lst_Last(&tGn->children);
1.5       millert  1403:
1.41      espie    1404:     /* Pass the buck to Make_HandleUse to apply the rule.  */
                   1405:     Make_HandleUse(gn, tGn);
1.1       deraadt  1406:
1.41      espie    1407:     /* Deal with wildcards and variables in any acquired sources.  */
1.39      espie    1408:     for (ln = Lst_Succ(ln); ln != NULL; ln = np) {
                   1409:        np = Lst_Adv(ln);
                   1410:        SuffExpandChildren(Lst_Datum(ln), tGn);
                   1411:     }
1.1       deraadt  1412:
1.41      espie    1413:     /* Keep track of another parent to which this beast is transformed so
                   1414:      * the .IMPSRC variable can be set correctly for the parent.  */
1.29      espie    1415:     Lst_AtEnd(&sGn->iParents, tGn);
1.1       deraadt  1416:
1.42      espie    1417:     return true;
1.1       deraadt  1418: }
                   1419:
                   1420:
                   1421: /*-
                   1422:  *-----------------------------------------------------------------------
                   1423:  * SuffFindArchiveDeps --
                   1424:  *     Locate dependencies for an OP_ARCHV node.
                   1425:  *
                   1426:  * Side Effects:
                   1427:  *     Same as Suff_FindDeps
                   1428:  *-----------------------------------------------------------------------
                   1429:  */
                   1430: static void
1.51      espie    1431: SuffFindArchiveDeps(
                   1432:     GNode      *gn,        /* Node for which to locate dependencies */
                   1433:     Lst        slst)
1.1       deraadt  1434: {
1.41      espie    1435:     char       *eoarch;    /* End of archive portion */
                   1436:     char       *eoname;    /* End of member portion */
                   1437:     GNode      *mem;       /* Node for member */
                   1438:     Suff       *ms;        /* Suffix descriptor for member */
                   1439:     char       *name;      /* Start of member's name */
                   1440:
                   1441:     /* The node is an archive(member) pair. so we must find a suffix
                   1442:      * for both of them.  */
                   1443:     eoarch = strchr(gn->name, '(');
                   1444:     if (eoarch == NULL)
1.6       millert  1445:        return;
1.1       deraadt  1446:
1.41      espie    1447:     name = eoarch + 1;
1.1       deraadt  1448:
1.41      espie    1449:     eoname = strchr(name, ')');
                   1450:     if (eoname == NULL)
                   1451:        return;
1.5       millert  1452:
1.41      espie    1453:     /* To simplify things, call Suff_FindDeps recursively on the member now,
1.1       deraadt  1454:      * so we can simply compare the member's .PREFIX and .TARGET variables
                   1455:      * to locate its suffix. This allows us to figure out the suffix to
                   1456:      * use for the archive without having to do a quadratic search over the
1.41      espie    1457:      * suffix list, backtracking for each one...  */
1.42      espie    1458:     mem = Targ_FindNodei(name, eoname, TARG_CREATE);
1.1       deraadt  1459:     SuffFindDeps(mem, slst);
                   1460:
1.41      espie    1461:     /* Create the link between the two nodes right off. */
1.42      espie    1462:     if (Lst_AddNew(&gn->children, mem)) {
1.29      espie    1463:        Lst_AtEnd(&mem->parents, gn);
1.41      espie    1464:        gn->unmade++;
1.1       deraadt  1465:     }
1.5       millert  1466:
1.34      espie    1467:     /* Copy variables from member node to this one.  */
                   1468:     Varq_Set(TARGET_INDEX, Varq_Value(TARGET_INDEX, mem), gn);
                   1469:     Varq_Set(PREFIX_INDEX, Varq_Value(PREFIX_INDEX, mem), gn);
1.1       deraadt  1470:
                   1471:     ms = mem->suffix;
                   1472:     if (ms == NULL) {
1.41      espie    1473:        /* Didn't know what it was -- use .NULL suffix if not in make mode.  */
                   1474:        if (DEBUG(SUFF))
1.1       deraadt  1475:            printf("using null suffix\n");
                   1476:        ms = suffNull;
                   1477:     }
                   1478:
                   1479:
1.41      espie    1480:     /* Set the other two local variables required for this target.  */
                   1481:     Varq_Set(MEMBER_INDEX, mem->name, gn);
1.32      espie    1482:     Varq_Set(ARCHIVE_INDEX, gn->name, gn);
1.1       deraadt  1483:
                   1484:     if (ms != NULL) {
                   1485:        /*
                   1486:         * Member has a known suffix, so look for a transformation rule from
                   1487:         * it to a possible suffix of the archive. Rather than searching
                   1488:         * through the entire list, we just look at suffixes to which the
                   1489:         * member's suffix may be transformed...
                   1490:         */
1.41      espie    1491:        LstNode     ln;
1.1       deraadt  1492:
1.41      espie    1493:        /* Use first matching suffix...  */
                   1494:        ln = Lst_FindConst(&ms->parents, SuffSuffIsSuffixP, eoarch);
1.1       deraadt  1495:
1.18      espie    1496:        if (ln != NULL) {
1.41      espie    1497:            /* Got one -- apply it.  */
1.1       deraadt  1498:            if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
                   1499:                DEBUG(SUFF))
                   1500:                printf("\tNo transformation from %s -> %s\n",
                   1501:                       ms->name, ((Suff *)Lst_Datum(ln))->name);
                   1502:        }
                   1503:     }
                   1504:
1.41      espie    1505:     /* Pretend gn appeared to the left of a dependency operator so
1.1       deraadt  1506:      * the user needn't provide a transformation from the member to the
1.41      espie    1507:      * archive.  */
                   1508:     if (OP_NOP(gn->type))
1.1       deraadt  1509:        gn->type |= OP_DEPENDS;
                   1510:
1.41      espie    1511:     /* Flag the member as such so we remember to look in the archive for
                   1512:      * its modification time.  */
1.1       deraadt  1513:     mem->type |= OP_MEMBER;
                   1514: }
                   1515:
                   1516: /*-
                   1517:  *-----------------------------------------------------------------------
                   1518:  * SuffFindNormalDeps --
                   1519:  *     Locate implicit dependencies for regular targets.
                   1520:  *
                   1521:  * Side Effects:
                   1522:  *     Same as Suff_FindDeps...
                   1523:  *-----------------------------------------------------------------------
                   1524:  */
                   1525: static void
1.51      espie    1526: SuffFindNormalDeps(
                   1527:     GNode      *gn,        /* Node for which to find sources */
                   1528:     Lst        slst)
1.1       deraadt  1529: {
1.41      espie    1530:     char       *eoname;    /* End of name */
                   1531:     char       *sopref;    /* Start of prefix */
                   1532:     LstNode    ln;         /* Next suffix node to check */
1.39      espie    1533:     LstNode    np;
1.41      espie    1534:     LIST       srcs;       /* List of sources at which to look */
                   1535:     LIST       targs;      /* List of targets to which things can be
1.1       deraadt  1536:                             * transformed. They all have the same file,
                   1537:                             * but different suff and pref fields */
1.41      espie    1538:     Src        *bottom;    /* Start of found transformation path */
1.1       deraadt  1539:     Src        *src;       /* General Src pointer */
1.41      espie    1540:     char       *pref;      /* Prefix to use */
                   1541:     Src        *targ;      /* General Src target pointer */
1.1       deraadt  1542:
                   1543:
                   1544:     eoname = gn->name + strlen(gn->name);
                   1545:
                   1546:     sopref = gn->name;
1.5       millert  1547:
1.41      espie    1548:     /* Begin at the beginning...  */
1.30      espie    1549:     ln = Lst_First(&sufflist);
                   1550:     Lst_Init(&srcs);
                   1551:     Lst_Init(&targs);
1.1       deraadt  1552:
1.41      espie    1553:     /* We're caught in a catch-22 here. On the one hand, we want to use any
1.1       deraadt  1554:      * transformation implied by the target's sources, but we can't examine
                   1555:      * the sources until we've expanded any variables/wildcards they may hold,
                   1556:      * and we can't do that until we've set up the target's local variables
                   1557:      * and we can't do that until we know what the proper suffix for the
                   1558:      * target is (in case there are two suffixes one of which is a suffix of
                   1559:      * the other) and we can't know that until we've found its implied
                   1560:      * source, which we may not want to use if there's an existing source
                   1561:      * that implies a different transformation.
                   1562:      *
                   1563:      * In an attempt to get around this, which may not work all the time,
                   1564:      * but should work most of the time, we look for implied sources first,
                   1565:      * checking transformations to all possible suffixes of the target,
                   1566:      * use what we find to set the target's local variables, expand the
                   1567:      * children, then look for any overriding transformations they imply.
1.41      espie    1568:      * Should we find one, we discard the one we found before. */
1.1       deraadt  1569:
1.18      espie    1570:     while (ln != NULL) {
1.41      espie    1571:        /* Look for next possible suffix...  */
                   1572:        ln = Lst_FindFromConst(ln, SuffSuffIsSuffixP, eoname);
1.1       deraadt  1573:
1.18      espie    1574:        if (ln != NULL) {
1.41      espie    1575:            int     prefLen;        /* Length of the prefix */
                   1576:            Src     *targ;
1.5       millert  1577:
1.41      espie    1578:            /* Allocate a Src structure to which things can be transformed.  */
                   1579:            targ = emalloc(sizeof(Src));
1.4       briggs   1580:            targ->file = estrdup(gn->name);
1.1       deraadt  1581:            targ->suff = (Suff *)Lst_Datum(ln);
                   1582:            targ->node = gn;
1.41      espie    1583:            targ->parent = NULL;
1.1       deraadt  1584:            targ->children = 0;
                   1585: #ifdef DEBUG_SRC
1.29      espie    1586:            Lst_Init(&targ->cp);
1.1       deraadt  1587: #endif
1.5       millert  1588:
1.41      espie    1589:            /* Allocate room for the prefix, whose end is found by subtracting
                   1590:             * the length of the suffix from the end of the name.  */
1.1       deraadt  1591:            prefLen = (eoname - targ->suff->nameLen) - sopref;
                   1592:            targ->pref = emalloc(prefLen + 1);
                   1593:            memcpy(targ->pref, sopref, prefLen);
                   1594:            targ->pref[prefLen] = '\0';
                   1595:
1.30      espie    1596:            /* Add nodes from which the target can be made.  */
                   1597:            SuffAddLevel(&srcs, targ);
1.1       deraadt  1598:
1.30      espie    1599:            /* Record the target so we can nuke it.  */
                   1600:            Lst_AtEnd(&targs, targ);
1.1       deraadt  1601:
1.30      espie    1602:            /* Search from this suffix's successor...  */
1.1       deraadt  1603:            ln = Lst_Succ(ln);
                   1604:        }
                   1605:     }
                   1606:
1.41      espie    1607:     /* Handle target of unknown suffix...  */
1.30      espie    1608:     if (Lst_IsEmpty(&targs) && suffNull != NULL) {
1.1       deraadt  1609:        if (DEBUG(SUFF)) {
1.5       millert  1610:            printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
1.1       deraadt  1611:        }
1.5       millert  1612:
1.41      espie    1613:        targ = emalloc(sizeof(Src));
1.4       briggs   1614:        targ->file = estrdup(gn->name);
1.1       deraadt  1615:        targ->suff = suffNull;
                   1616:        targ->node = gn;
1.41      espie    1617:        targ->parent = NULL;
1.1       deraadt  1618:        targ->children = 0;
1.4       briggs   1619:        targ->pref = estrdup(sopref);
1.1       deraadt  1620: #ifdef DEBUG_SRC
1.29      espie    1621:        Lst_Init(&targ->cp);
1.1       deraadt  1622: #endif
                   1623:
1.41      espie    1624:        /* Only use the default suffix rules if we don't have commands
                   1625:         * or dependencies defined for this gnode.  */
1.29      espie    1626:        if (Lst_IsEmpty(&gn->commands) && Lst_IsEmpty(&gn->children))
1.30      espie    1627:            SuffAddLevel(&srcs, targ);
1.1       deraadt  1628:        else {
1.5       millert  1629:            if (DEBUG(SUFF))
1.1       deraadt  1630:                printf("not ");
                   1631:        }
                   1632:
1.5       millert  1633:        if (DEBUG(SUFF))
1.1       deraadt  1634:            printf("adding suffix rules\n");
                   1635:
1.30      espie    1636:        Lst_AtEnd(&targs, targ);
1.1       deraadt  1637:     }
1.5       millert  1638:
1.41      espie    1639:     /* Using the list of possible sources built up from the target suffix(es),
                   1640:      * try and find an existing file/target that matches.  */
1.30      espie    1641:     bottom = SuffFindThem(&srcs, slst);
1.1       deraadt  1642:
1.30      espie    1643:     if (bottom == NULL) {
1.41      espie    1644:        /* No known transformations -- use the first suffix found for setting
                   1645:         * the local variables.  */
1.30      espie    1646:        if (!Lst_IsEmpty(&targs))
                   1647:            targ = (Src *)Lst_Datum(Lst_First(&targs));
                   1648:        else
                   1649:            targ = NULL;
1.1       deraadt  1650:     } else {
1.41      espie    1651:        /* Work up the transformation path to find the suffix of the
                   1652:         * target to which the transformation was made.  */
1.1       deraadt  1653:        for (targ = bottom; targ->parent != NULL; targ = targ->parent)
                   1654:            continue;
                   1655:     }
                   1656:
1.41      espie    1657:     /* The .TARGET variable we always set to be the name at this point,
1.1       deraadt  1658:      * since it's only set to the path if the thing is only a source and
                   1659:      * if it's only a source, it doesn't matter what we put here as far
1.41      espie    1660:      * as expanding sources is concerned, since it has none... */
1.32      espie    1661:     Varq_Set(TARGET_INDEX, gn->name, gn);
1.1       deraadt  1662:
1.41      espie    1663:     pref = targ != NULL ? targ->pref : gn->name;
1.32      espie    1664:     Varq_Set(PREFIX_INDEX, pref, gn);
1.1       deraadt  1665:
1.41      espie    1666:     /* Now we've got the important local variables set, expand any sources
                   1667:      * that still contain variables or wildcards in their names.  */
1.39      espie    1668:     for (ln = Lst_First(&gn->children); ln != NULL; ln = np) {
                   1669:        np = Lst_Adv(ln);
                   1670:        SuffExpandChildren(Lst_Datum(ln), gn);
                   1671:     }
1.5       millert  1672:
1.1       deraadt  1673:     if (targ == NULL) {
1.41      espie    1674:        if (DEBUG(SUFF))
1.1       deraadt  1675:            printf("\tNo valid suffix on %s\n", gn->name);
                   1676:
                   1677: sfnd_abort:
1.41      espie    1678:        /* Deal with finding the thing on the default search path if the
1.1       deraadt  1679:         * node is only a source (not on the lhs of a dependency operator
1.41      espie    1680:         * or [XXX] it has neither children or commands).  */
1.1       deraadt  1681:        if (OP_NOP(gn->type) ||
1.29      espie    1682:            (Lst_IsEmpty(&gn->children) && Lst_IsEmpty(&gn->commands)))
1.1       deraadt  1683:        {
                   1684:            gn->path = Dir_FindFile(gn->name,
1.42      espie    1685:                                    (targ == NULL ? dirSearchPath :
1.30      espie    1686:                                     &targ->suff->searchPath));
1.1       deraadt  1687:            if (gn->path != NULL) {
1.2       deraadt  1688:                char *ptr;
1.32      espie    1689:                Varq_Set(TARGET_INDEX, gn->path, gn);
1.1       deraadt  1690:
                   1691:                if (targ != NULL) {
1.41      espie    1692:                    /* Suffix known for the thing -- trim the suffix off
                   1693:                     * the path to form the proper .PREFIX variable.  */
                   1694:                    int         savep = strlen(gn->path) - targ->suff->nameLen;
1.1       deraadt  1695:                    char        savec;
                   1696:
                   1697:                    gn->suffix = targ->suff;
                   1698:
1.2       deraadt  1699:                    savec = gn->path[savep];
                   1700:                    gn->path[savep] = '\0';
1.1       deraadt  1701:
1.2       deraadt  1702:                    if ((ptr = strrchr(gn->path, '/')) != NULL)
                   1703:                        ptr++;
                   1704:                    else
                   1705:                        ptr = gn->path;
1.1       deraadt  1706:
1.32      espie    1707:                    Varq_Set(PREFIX_INDEX, ptr, gn);
1.2       deraadt  1708:
                   1709:                    gn->path[savep] = savec;
1.1       deraadt  1710:                } else {
1.41      espie    1711:                    /* The .PREFIX gets the full path if the target has
                   1712:                     * no known suffix.  */
1.1       deraadt  1713:                    gn->suffix = NULL;
                   1714:
1.2       deraadt  1715:                    if ((ptr = strrchr(gn->path, '/')) != NULL)
                   1716:                        ptr++;
                   1717:                    else
                   1718:                        ptr = gn->path;
                   1719:
1.32      espie    1720:                    Varq_Set(PREFIX_INDEX, ptr, gn);
1.1       deraadt  1721:                }
                   1722:            }
                   1723:        } else {
1.41      espie    1724:            /* Not appropriate to search for the thing -- set the
1.1       deraadt  1725:             * path to be the name so Dir_MTime won't go grovelling for
1.41      espie    1726:             * it.  */
                   1727:            gn->suffix = targ == NULL ? NULL : targ->suff;
1.11      espie    1728:            efree(gn->path);
1.4       briggs   1729:            gn->path = estrdup(gn->name);
1.1       deraadt  1730:        }
1.5       millert  1731:
1.1       deraadt  1732:        goto sfnd_return;
                   1733:     }
                   1734:
1.41      espie    1735:     /* If the suffix indicates that the target is a library, mark that in
                   1736:      * the node's type field.  */
1.1       deraadt  1737:     if (targ->suff->flags & SUFF_LIBRARY) {
                   1738:        gn->type |= OP_LIB;
                   1739:     }
                   1740:
1.41      espie    1741:     /* Check for overriding transformation rule implied by sources.  */
1.29      espie    1742:     if (!Lst_IsEmpty(&gn->children)) {
1.1       deraadt  1743:        src = SuffFindCmds(targ, slst);
                   1744:
1.41      espie    1745:        if (src != NULL) {
                   1746:            /* Free up all the Src structures in the transformation path
                   1747:             * up to, but not including, the parent node.  */
1.1       deraadt  1748:            while (bottom && bottom->parent != NULL) {
1.41      espie    1749:                (void)Lst_AddNew(slst, bottom);
1.1       deraadt  1750:                bottom = bottom->parent;
                   1751:            }
                   1752:            bottom = src;
                   1753:        }
                   1754:     }
                   1755:
                   1756:     if (bottom == NULL) {
1.41      espie    1757:        /* No idea from where it can come -- return now.  */
1.1       deraadt  1758:        goto sfnd_abort;
                   1759:     }
                   1760:
1.41      espie    1761:     /* We now have a list of Src structures headed by 'bottom' and linked via
1.1       deraadt  1762:      * their 'parent' pointers. What we do next is create links between
                   1763:      * source and target nodes (which may or may not have been created)
                   1764:      * and set the necessary local variables in each target. The
                   1765:      * commands for each target are set from the commands of the
                   1766:      * transformation rule used to get from the src suffix to the targ
                   1767:      * suffix. Note that this causes the commands list of the original
                   1768:      * node, gn, to be replaced by the commands of the final
                   1769:      * transformation rule. Also, the unmade field of gn is incremented.
1.41      espie    1770:      * Etc.  */
1.18      espie    1771:     if (bottom->node == NULL) {
1.42      espie    1772:        bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);
1.1       deraadt  1773:     }
1.5       millert  1774:
1.41      espie    1775:     for (src = bottom; src->parent != NULL; src = src->parent) {
1.1       deraadt  1776:        targ = src->parent;
                   1777:
                   1778:        src->node->suffix = src->suff;
                   1779:
1.18      espie    1780:        if (targ->node == NULL) {
1.42      espie    1781:            targ->node = Targ_FindNode(targ->file, TARG_CREATE);
1.1       deraadt  1782:        }
                   1783:
                   1784:        SuffApplyTransform(targ->node, src->node,
                   1785:                           targ->suff, src->suff);
                   1786:
                   1787:        if (targ->node != gn) {
1.41      espie    1788:            /* Finish off the dependency-search process for any nodes
1.1       deraadt  1789:             * between bottom and gn (no point in questing around the
                   1790:             * filesystem for their implicit source when it's already
                   1791:             * known). Note that the node can't have any sources that
                   1792:             * need expanding, since SuffFindThem will stop on an existing
                   1793:             * node, so all we need to do is set the standard and System V
1.41      espie    1794:             * variables.  */
1.1       deraadt  1795:            targ->node->type |= OP_DEPS_FOUND;
                   1796:
1.32      espie    1797:            Varq_Set(PREFIX_INDEX, targ->pref, targ->node);
1.5       millert  1798:
1.32      espie    1799:            Varq_Set(TARGET_INDEX, targ->node->name, targ->node);
1.1       deraadt  1800:        }
                   1801:     }
                   1802:
                   1803:     gn->suffix = src->suff;
                   1804:
1.41      espie    1805:     /* So Dir_MTime doesn't go questing for it...  */
1.11      espie    1806:     efree(gn->path);
1.4       briggs   1807:     gn->path = estrdup(gn->name);
1.1       deraadt  1808:
1.41      espie    1809:     /* Nuke the transformation path and the Src structures left over in the
                   1810:      * two lists.  */
1.1       deraadt  1811: sfnd_return:
                   1812:     if (bottom)
1.41      espie    1813:        (void)Lst_AddNew(slst, bottom);
1.1       deraadt  1814:
1.30      espie    1815:     while (SuffRemoveSrc(&srcs) || SuffRemoveSrc(&targs))
1.1       deraadt  1816:        continue;
                   1817:
1.30      espie    1818:     Lst_ConcatDestroy(slst, &srcs);
                   1819:     Lst_ConcatDestroy(slst, &targs);
1.1       deraadt  1820: }
1.5       millert  1821:
                   1822:
1.1       deraadt  1823: /*-
                   1824:  *-----------------------------------------------------------------------
                   1825:  * Suff_FindDeps  --
                   1826:  *     Find implicit sources for the target described by the graph node
                   1827:  *     gn
                   1828:  *
                   1829:  * Side Effects:
                   1830:  *     Nodes are added to the graph below the passed-in node. The nodes
                   1831:  *     are marked to have their IMPSRC variable filled in. The
                   1832:  *     PREFIX variable is set for the given node and all its
                   1833:  *     implied children.
                   1834:  *
                   1835:  * Notes:
                   1836:  *     The path found by this target is the shortest path in the
                   1837:  *     transformation graph, which may pass through non-existent targets,
                   1838:  *     to an existing target. The search continues on all paths from the
                   1839:  *     root suffix until a file is found. I.e. if there's a path
                   1840:  *     .o -> .c -> .l -> .l,v from the root and the .l,v file exists but
                   1841:  *     the .c and .l files don't, the search will branch out in
                   1842:  *     all directions from .o and again from all the nodes on the
                   1843:  *     next level until the .l,v node is encountered.
                   1844:  *-----------------------------------------------------------------------
                   1845:  */
                   1846:
                   1847: void
1.51      espie    1848: Suff_FindDeps(GNode *gn)
1.1       deraadt  1849: {
1.5       millert  1850:
1.29      espie    1851:     SuffFindDeps(gn, &srclist);
                   1852:     while (SuffRemoveSrc(&srclist))
1.1       deraadt  1853:        continue;
                   1854: }
                   1855:
                   1856:
                   1857: static void
1.51      espie    1858: SuffFindDeps(GNode *gn, Lst slst)
1.1       deraadt  1859: {
                   1860:     if (gn->type & OP_DEPS_FOUND) {
                   1861:        /*
                   1862:         * If dependencies already found, no need to do it again...
                   1863:         */
                   1864:        return;
                   1865:     } else {
                   1866:        gn->type |= OP_DEPS_FOUND;
                   1867:     }
1.5       millert  1868:
1.1       deraadt  1869:     if (DEBUG(SUFF)) {
1.41      espie    1870:        printf("SuffFindDeps (%s)\n", gn->name);
1.1       deraadt  1871:     }
1.5       millert  1872:
1.1       deraadt  1873:     if (gn->type & OP_ARCHV) {
                   1874:        SuffFindArchiveDeps(gn, slst);
                   1875:     } else if (gn->type & OP_LIB) {
                   1876:        /*
                   1877:         * If the node is a library, it is the arch module's job to find it
                   1878:         * and set the TARGET variable accordingly. We merely provide the
                   1879:         * search path, assuming all libraries end in ".a" (if the suffix
                   1880:         * hasn't been defined, there's nothing we can do for it, so we just
                   1881:         * set the TARGET variable to the node's name in order to give it a
                   1882:         * value).
                   1883:         */
1.41      espie    1884:        LstNode ln;
1.1       deraadt  1885:        Suff    *s;
1.5       millert  1886:
1.52      espie    1887:        ln = suff_find_by_name(LIBSUFF);
1.18      espie    1888:        if (ln != NULL) {
1.31      espie    1889:            gn->suffix = s = (Suff *)Lst_Datum(ln);
1.30      espie    1890:            Arch_FindLib(gn, &s->searchPath);
1.1       deraadt  1891:        } else {
                   1892:            gn->suffix = NULL;
1.32      espie    1893:            Varq_Set(TARGET_INDEX, gn->name, gn);
1.1       deraadt  1894:        }
                   1895:        /*
                   1896:         * Because a library (-lfoo) target doesn't follow the standard
                   1897:         * filesystem conventions, we don't set the regular variables for
                   1898:         * the thing. .PREFIX is simply made empty...
                   1899:         */
1.32      espie    1900:        Varq_Set(PREFIX_INDEX, "", gn);
1.41      espie    1901:     } else
1.1       deraadt  1902:        SuffFindNormalDeps(gn, slst);
                   1903: }
                   1904:
                   1905: /*-
                   1906:  *-----------------------------------------------------------------------
                   1907:  * Suff_SetNull --
                   1908:  *     Define which suffix is the null suffix.
                   1909:  *
                   1910:  * Side Effects:
                   1911:  *     'suffNull' is altered.
                   1912:  *
                   1913:  * Notes:
                   1914:  *     Need to handle the changing of the null suffix gracefully so the
                   1915:  *     old transformation rules don't just go away.
                   1916:  *-----------------------------------------------------------------------
                   1917:  */
                   1918: void
1.52      espie    1919: Suff_SetNull(const char *name)
1.1       deraadt  1920: {
                   1921:     Suff    *s;
                   1922:     LstNode ln;
                   1923:
1.52      espie    1924:     ln = suff_find_by_name(name);
1.18      espie    1925:     if (ln != NULL) {
1.1       deraadt  1926:        s = (Suff *)Lst_Datum(ln);
1.41      espie    1927:        if (suffNull != NULL) {
1.1       deraadt  1928:            suffNull->flags &= ~SUFF_NULL;
                   1929:        }
                   1930:        s->flags |= SUFF_NULL;
                   1931:        /*
                   1932:         * XXX: Here's where the transformation mangling would take place
                   1933:         */
                   1934:        suffNull = s;
                   1935:     } else {
1.41      espie    1936:        Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
1.1       deraadt  1937:                     name);
                   1938:     }
                   1939: }
                   1940:
                   1941: /*-
                   1942:  *-----------------------------------------------------------------------
                   1943:  * Suff_Init --
                   1944:  *     Initialize suffixes module
                   1945:  *
                   1946:  * Side Effects:
                   1947:  *     Many
                   1948:  *-----------------------------------------------------------------------
                   1949:  */
                   1950: void
1.51      espie    1951: Suff_Init(void)
1.1       deraadt  1952: {
1.46      espie    1953:     Static_Lst_Init(&sufflist);
1.14      espie    1954: #ifdef CLEANUP
1.46      espie    1955:     Static_Lst_Init(&suffClean);
1.14      espie    1956: #endif
1.46      espie    1957:     Static_Lst_Init(&srclist);
                   1958:     Static_Lst_Init(&transforms);
1.1       deraadt  1959:
                   1960:     sNum = 0;
                   1961:     /*
                   1962:      * Create null suffix for single-suffix rules (POSIX). The thing doesn't
                   1963:      * actually go on the suffix list or everyone will think that's its
                   1964:      * suffix.
                   1965:      */
1.41      espie    1966:     emptySuff = suffNull = emalloc(sizeof(Suff));
1.1       deraadt  1967:
1.41      espie    1968:     suffNull->name =       estrdup("");
1.1       deraadt  1969:     suffNull->nameLen =     0;
1.30      espie    1970:     Lst_Init(&suffNull->searchPath);
1.42      espie    1971:     Dir_Concat(&suffNull->searchPath, dirSearchPath);
1.29      espie    1972:     Lst_Init(&suffNull->children);
                   1973:     Lst_Init(&suffNull->parents);
                   1974:     Lst_Init(&suffNull->ref);
1.41      espie    1975:     suffNull->sNum =       sNum++;
                   1976:     suffNull->flags =      SUFF_NULL;
1.1       deraadt  1977:
                   1978: }
                   1979:
                   1980:
                   1981: /*-
                   1982:  *----------------------------------------------------------------------
                   1983:  * Suff_End --
                   1984:  *     Cleanup the this module
                   1985:  *
                   1986:  * Side Effects:
                   1987:  *     The memory is free'd.
                   1988:  *----------------------------------------------------------------------
                   1989:  */
                   1990:
1.42      espie    1991: #ifdef CLEANUP
1.1       deraadt  1992: void
1.51      espie    1993: Suff_End(void)
1.1       deraadt  1994: {
1.30      espie    1995:     Lst_Destroy(&sufflist, SuffFree);
1.29      espie    1996:     Lst_Destroy(&suffClean, SuffFree);
1.1       deraadt  1997:     if (suffNull)
                   1998:        SuffFree(suffNull);
1.29      espie    1999:     Lst_Destroy(&srclist, NOFREE);
                   2000:     Lst_Destroy(&transforms, NOFREE);
1.42      espie    2001: }
1.14      espie    2002: #endif
1.1       deraadt  2003:
                   2004:
                   2005: /********************* DEBUGGING FUNCTIONS **********************/
                   2006:
1.51      espie    2007: static void SuffPrintName(void *s)
1.1       deraadt  2008: {
1.27      espie    2009:     printf("%s ", ((Suff *)s)->name);
1.1       deraadt  2010: }
                   2011:
1.27      espie    2012: static void
1.51      espie    2013: SuffPrintSuff(void *sp)
1.1       deraadt  2014: {
1.27      espie    2015:     Suff    *s = (Suff *)sp;
1.41      espie    2016:     int     flags;
                   2017:     int     flag;
1.1       deraadt  2018:
1.27      espie    2019:     printf("# `%s' ", s->name);
1.5       millert  2020:
1.1       deraadt  2021:     flags = s->flags;
                   2022:     if (flags) {
1.27      espie    2023:        fputs(" (", stdout);
1.1       deraadt  2024:        while (flags) {
                   2025:            flag = 1 << (ffs(flags) - 1);
                   2026:            flags &= ~flag;
                   2027:            switch (flag) {
                   2028:                case SUFF_NULL:
1.27      espie    2029:                    printf("NULL");
1.1       deraadt  2030:                    break;
                   2031:                case SUFF_INCLUDE:
1.27      espie    2032:                    printf("INCLUDE");
1.1       deraadt  2033:                    break;
                   2034:                case SUFF_LIBRARY:
1.27      espie    2035:                    printf("LIBRARY");
1.1       deraadt  2036:                    break;
                   2037:            }
                   2038:            fputc(flags ? '|' : ')', stdout);
                   2039:        }
                   2040:     }
1.41      espie    2041:     fputc('\n', stdout);
                   2042:     printf("#\tTo: ");
1.29      espie    2043:     Lst_Every(&s->parents, SuffPrintName);
1.41      espie    2044:     fputc('\n', stdout);
                   2045:     printf("#\tFrom: ");
1.29      espie    2046:     Lst_Every(&s->children, SuffPrintName);
1.41      espie    2047:     fputc('\n', stdout);
                   2048:     printf("#\tSearch Path: ");
1.30      espie    2049:     Dir_PrintPath(&s->searchPath);
1.27      espie    2050:     fputc('\n', stdout);
1.1       deraadt  2051: }
                   2052:
1.27      espie    2053: static void
1.51      espie    2054: SuffPrintTrans(void *tp)
1.1       deraadt  2055: {
1.27      espie    2056:     GNode   *t = (GNode *)tp;
1.1       deraadt  2057:
1.27      espie    2058:     printf("%-16s: ", t->name);
                   2059:     Targ_PrintType(t->type);
                   2060:     fputc('\n', stdout);
1.29      espie    2061:     Lst_Every(&t->commands, Targ_PrintCmd);
1.27      espie    2062:     fputc('\n', stdout);
1.1       deraadt  2063: }
                   2064:
                   2065: void
1.51      espie    2066: Suff_PrintAll(void)
1.1       deraadt  2067: {
1.27      espie    2068:     printf("#*** Suffixes:\n");
1.30      espie    2069:     Lst_Every(&sufflist, SuffPrintSuff);
1.1       deraadt  2070:
1.27      espie    2071:     printf("#*** Transformations:\n");
1.29      espie    2072:     Lst_Every(&transforms, SuffPrintTrans);
1.1       deraadt  2073: }
1.42      espie    2074:
                   2075: #ifdef DEBUG_SRC
                   2076: static void
1.51      espie    2077: PrintAddr(void *a)
1.42      espie    2078: {
                   2079:     printf("%lx ", (unsigned long)a);
                   2080: }
                   2081: #endif