[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.52

1.41      espie       1: /*     $OpenPackages$ */
1.52    ! espie       2: /*     $OpenBSD: suff.c,v 1.51 2004/04/07 13:11:36 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:
                    603:        (void)SuffParseTransform(gn->name, &s, &t);
                    604:
                    605:        if (DEBUG(SUFF)) {
1.8       millert   606:            printf("deleting transformation from `%s' to `%s'\n",
1.1       deraadt   607:                    s->name, t->name);
                    608:        }
                    609:
                    610:        /*
1.41      espie     611:         * Remove the source from the target's children list.
1.1       deraadt   612:         *
                    613:         * We'll be called twice when the next target is seen, but .c and .o
                    614:         * are only linked once...
                    615:         */
1.41      espie     616:        SuffUnRef(&t->children, s);
1.1       deraadt   617:
                    618:        /*
                    619:         * Remove the target from the source's parents list
                    620:         */
1.41      espie     621:        if (s != NULL)
                    622:            SuffUnRef(&s->parents, t);
1.1       deraadt   623:     } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
                    624:        printf("transformation %s complete\n", gn->name);
                    625:     }
                    626: }
                    627:
                    628: /*-
                    629:  *-----------------------------------------------------------------------
                    630:  * SuffRebuildGraph --
                    631:  *     Called from Suff_AddSuffix via Lst_ForEach to search through the
                    632:  *     list of existing transformation rules and rebuild the transformation
                    633:  *     graph when it has been destroyed by Suff_ClearSuffixes. If the
                    634:  *     given rule is a transformation involving this suffix and another,
                    635:  *     existing suffix, the proper relationship is established between
                    636:  *     the two.
                    637:  *
                    638:  * Side Effects:
                    639:  *     The appropriate links will be made between this suffix and
                    640:  *     others if transformation rules exist for it.
                    641:  *-----------------------------------------------------------------------
                    642:  */
1.27      espie     643: static void
1.51      espie     644: SuffRebuildGraph(
                    645:     void       *transformp,    /* Transformation to test */
                    646:     void       *sp)            /* Suffix to rebuild */
1.1       deraadt   647: {
1.41      espie     648:     GNode      *transform = (GNode *)transformp;
                    649:     Suff       *s = (Suff *)sp;
                    650:     char       *cp;
1.1       deraadt   651:     LstNode    ln;
1.41      espie     652:     Suff       *s2;
1.1       deraadt   653:
1.41      espie     654:     /* First see if it is a transformation from this suffix.  */
1.1       deraadt   655:     cp = SuffStrIsPrefix(s->name, transform->name);
1.27      espie     656:     if (cp != NULL) {
1.52    ! espie     657:        ln = suff_find_by_name(cp);
1.18      espie     658:        if (ln != NULL) {
1.41      espie     659:            /* Found target. Link in and return, since it can't be anything
                    660:             * else.  */
1.1       deraadt   661:            s2 = (Suff *)Lst_Datum(ln);
1.29      espie     662:            SuffInsert(&s2->children, s);
                    663:            SuffInsert(&s->parents, s2);
1.27      espie     664:            return;
1.1       deraadt   665:        }
                    666:     }
                    667:
1.41      espie     668:     /* Not from, maybe to?  */
1.1       deraadt   669:     cp = SuffSuffIsSuffix(s, transform->name + strlen(transform->name));
1.27      espie     670:     if (cp != NULL) {
1.41      espie     671:        /* Null-terminate the source suffix in order to find it.  */
                    672:        *cp = '\0';
1.52    ! espie     673:        ln = suff_find_by_name(transform->name);
1.41      espie     674:        /* Replace the start of the target suffix.  */
                    675:        *cp = s->name[0];
1.18      espie     676:        if (ln != NULL) {
1.41      espie     677:            /* Found it -- establish the proper relationship.  */
1.1       deraadt   678:            s2 = (Suff *)Lst_Datum(ln);
1.29      espie     679:            SuffInsert(&s->children, s2);
                    680:            SuffInsert(&s2->parents, s);
1.1       deraadt   681:        }
                    682:     }
                    683: }
                    684:
                    685: /*-
                    686:  *-----------------------------------------------------------------------
                    687:  * Suff_AddSuffix --
                    688:  *     Add the suffix in string to the end of the list of known suffixes.
                    689:  *     Should we restructure the suffix graph? Make doesn't...
                    690:  *
                    691:  * Side Effects:
                    692:  *     A GNode is created for the suffix and a Suff structure is created and
                    693:  *     added to the suffixes list unless the suffix was already known.
                    694:  *-----------------------------------------------------------------------
                    695:  */
                    696: void
1.52    ! espie     697: Suff_AddSuffix(const char *str)
1.1       deraadt   698: {
1.41      espie     699:     Suff         *s;       /* new suffix descriptor */
                    700:     LstNode      ln;
1.1       deraadt   701:
1.52    ! espie     702:     ln = suff_find_by_name(str);
1.18      espie     703:     if (ln == NULL) {
1.41      espie     704:        s = emalloc(sizeof(Suff));
1.1       deraadt   705:
1.41      espie     706:        s->name =       estrdup(str);
                    707:        s->nameLen =    strlen(s->name);
1.30      espie     708:        Lst_Init(&s->searchPath);
1.29      espie     709:        Lst_Init(&s->children);
                    710:        Lst_Init(&s->parents);
                    711:        Lst_Init(&s->ref);
1.41      espie     712:        s->sNum =       sNum++;
                    713:        s->flags =      0;
1.1       deraadt   714:
1.30      espie     715:        Lst_AtEnd(&sufflist, s);
1.1       deraadt   716:        /*
                    717:         * Look for any existing transformations from or to this suffix.
                    718:         * XXX: Only do this after a Suff_ClearSuffixes?
                    719:         */
1.29      espie     720:        Lst_ForEach(&transforms, SuffRebuildGraph, s);
1.5       millert   721:     }
1.1       deraadt   722: }
                    723:
                    724: /*-
                    725:  *-----------------------------------------------------------------------
                    726:  * Suff_GetPath --
                    727:  *     Return the search path for the given suffix, if it's defined.
                    728:  *
                    729:  * Results:
1.18      espie     730:  *     The searchPath for the desired suffix or NULL if the suffix isn't
1.1       deraadt   731:  *     defined.
                    732:  *-----------------------------------------------------------------------
                    733:  */
                    734: Lst
1.52    ! espie     735: Suff_GetPath(const char *sname)
1.1       deraadt   736: {
1.41      espie     737:     LstNode      ln;
                    738:     Suff         *s;
1.1       deraadt   739:
1.52    ! espie     740:     ln = suff_find_by_name(sname);
1.41      espie     741:     if (ln == NULL) {
1.30      espie     742:        return NULL;
1.41      espie     743:     } else {
1.30      espie     744:        s = (Suff *)Lst_Datum(ln);
                    745:        return &s->searchPath;
1.1       deraadt   746:     }
                    747: }
                    748:
                    749: /*-
                    750:  *-----------------------------------------------------------------------
                    751:  * Suff_DoPaths --
                    752:  *     Extend the search paths for all suffixes to include the default
                    753:  *     search path.
                    754:  *
                    755:  * Side Effects:
                    756:  *     The searchPath field of all the suffixes is extended by the
                    757:  *     directories in dirSearchPath. If paths were specified for the
                    758:  *     ".h" suffix, the directories are stuffed into a global variable
                    759:  *     called ".INCLUDES" with each directory preceeded by a -I. The same
                    760:  *     is done for the ".a" suffix, except the variable is called
                    761:  *     ".LIBS" and the flag is -L.
                    762:  *-----------------------------------------------------------------------
                    763:  */
                    764: void
1.51      espie     765: Suff_DoPaths(void)
1.1       deraadt   766: {
1.41      espie     767:     Suff               *s;
                    768:     LstNode            ln;
1.1       deraadt   769:     char               *ptr;
1.41      espie     770:     LIST               inIncludes; /* Cumulative .INCLUDES path */
                    771:     LIST               inLibs;     /* Cumulative .LIBS path */
1.1       deraadt   772:
1.29      espie     773:     Lst_Init(&inIncludes);
                    774:     Lst_Init(&inLibs);
1.1       deraadt   775:
1.41      espie     776:     for (ln = Lst_First(&sufflist); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie     777:        s = (Suff *)Lst_Datum(ln);
1.30      espie     778:        if (!Lst_IsEmpty(&s->searchPath)) {
1.1       deraadt   779: #ifdef INCLUDES
                    780:            if (s->flags & SUFF_INCLUDE) {
1.30      espie     781:                Dir_Concat(&inIncludes, &s->searchPath);
1.1       deraadt   782:            }
                    783: #endif /* INCLUDES */
                    784: #ifdef LIBRARIES
                    785:            if (s->flags & SUFF_LIBRARY) {
1.30      espie     786:                Dir_Concat(&inLibs, &s->searchPath);
1.1       deraadt   787:            }
                    788: #endif /* LIBRARIES */
1.42      espie     789:            Dir_Concat(&s->searchPath, dirSearchPath);
                    790:        } else
                    791:            Lst_Clone(&s->searchPath, dirSearchPath, Dir_CopyDir);
1.1       deraadt   792:     }
                    793:
1.29      espie     794:     Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", &inIncludes), VAR_GLOBAL);
1.1       deraadt   795:     free(ptr);
1.29      espie     796:     Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", &inLibs), VAR_GLOBAL);
1.1       deraadt   797:     free(ptr);
                    798:
1.29      espie     799:     Lst_Destroy(&inIncludes, Dir_Destroy);
                    800:     Lst_Destroy(&inLibs, Dir_Destroy);
1.1       deraadt   801: }
                    802:
                    803: /*-
                    804:  *-----------------------------------------------------------------------
                    805:  * Suff_AddInclude --
                    806:  *     Add the given suffix as a type of file which gets included.
                    807:  *     Called from the parse module when a .INCLUDES line is parsed.
                    808:  *     The suffix must have already been defined.
                    809:  *
                    810:  * Side Effects:
                    811:  *     The SUFF_INCLUDE bit is set in the suffix's flags field
                    812:  *-----------------------------------------------------------------------
                    813:  */
                    814: void
1.52    ! espie     815: Suff_AddInclude(const char *sname)     /* Name of suffix to mark */
1.1       deraadt   816: {
                    817:     LstNode      ln;
                    818:     Suff         *s;
                    819:
1.52    ! espie     820:     ln = suff_find_by_name(sname);
1.18      espie     821:     if (ln != NULL) {
1.31      espie     822:        s = (Suff *)Lst_Datum(ln);
1.1       deraadt   823:        s->flags |= SUFF_INCLUDE;
                    824:     }
                    825: }
                    826:
                    827: /*-
                    828:  *-----------------------------------------------------------------------
                    829:  * Suff_AddLib --
                    830:  *     Add the given suffix as a type of file which is a library.
                    831:  *     Called from the parse module when parsing a .LIBS line. The
                    832:  *     suffix must have been defined via .SUFFIXES before this is
                    833:  *     called.
                    834:  *
                    835:  * Side Effects:
                    836:  *     The SUFF_LIBRARY bit is set in the suffix's flags field
                    837:  *-----------------------------------------------------------------------
                    838:  */
                    839: void
1.52    ! espie     840: Suff_AddLib(const char *sname) /* Name of suffix to mark */
1.1       deraadt   841: {
                    842:     LstNode      ln;
                    843:     Suff         *s;
                    844:
1.52    ! espie     845:     ln = suff_find_by_name(sname);
1.18      espie     846:     if (ln != NULL) {
1.31      espie     847:        s = (Suff *)Lst_Datum(ln);
1.1       deraadt   848:        s->flags |= SUFF_LIBRARY;
                    849:     }
                    850: }
                    851:
1.41      espie     852:          /********** Implicit Source Search Functions *********/
1.1       deraadt   853:
                    854: /*-
                    855:  *-----------------------------------------------------------------------
                    856:  * SuffAddSrc  --
                    857:  *     Add a suffix as a Src structure to the given list with its parent
                    858:  *     being the given Src structure. If the suffix is the null suffix,
                    859:  *     the prefix is used unaltered as the file name in the Src structure.
                    860:  *
                    861:  * Side Effects:
                    862:  *     A Src structure is created and tacked onto the end of the list
                    863:  *-----------------------------------------------------------------------
                    864:  */
1.27      espie     865: static void
1.51      espie     866: SuffAddSrc(
                    867:     void *sp,      /* suffix for which to create a Src structure */
                    868:     void *lsp)     /* list and parent for the new Src */
1.1       deraadt   869: {
1.27      espie     870:     Suff       *s = (Suff *)sp;
1.41      espie     871:     LstSrc     *ls = (LstSrc *)lsp;
                    872:     Src        *s2;        /* new Src structure */
                    873:     Src        *targ;      /* Target structure */
1.1       deraadt   874:
                    875:     targ = ls->s;
1.5       millert   876:
1.41      espie     877:     if ((s->flags & SUFF_NULL) && *s->name != '\0') {
1.1       deraadt   878:        /*
                    879:         * If the suffix has been marked as the NULL suffix, also create a Src
                    880:         * structure for a file with no suffix attached. Two birds, and all
                    881:         * that...
                    882:         */
1.41      espie     883:        s2 = emalloc(sizeof(Src));
                    884:        s2->file =      estrdup(targ->pref);
                    885:        s2->pref =      targ->pref;
                    886:        s2->parent =    targ;
                    887:        s2->node =      NULL;
                    888:        s2->suff =      s;
1.1       deraadt   889:        s2->children =  0;
                    890:        targ->children += 1;
1.25      espie     891:        Lst_AtEnd(ls->l, s2);
1.1       deraadt   892: #ifdef DEBUG_SRC
1.29      espie     893:        Lst_Init(&s2->cp);
                    894:        Lst_AtEnd(&targ->cp, s2);
1.1       deraadt   895:        printf("1 add %x %x to %x:", targ, s2, ls->l);
1.27      espie     896:        Lst_Every(ls->l, PrintAddr);
1.1       deraadt   897:        printf("\n");
                    898: #endif
                    899:     }
1.41      espie     900:     s2 = emalloc(sizeof(Src));
1.42      espie     901:     s2->file =     Str_concat(targ->pref, s->name, 0);
1.1       deraadt   902:     s2->pref =     targ->pref;
                    903:     s2->parent =    targ;
1.41      espie     904:     s2->node =     NULL;
                    905:     s2->suff =     s;
1.1       deraadt   906:     s2->children =  0;
                    907:     targ->children += 1;
1.25      espie     908:     Lst_AtEnd(ls->l, s2);
1.1       deraadt   909: #ifdef DEBUG_SRC
1.29      espie     910:     Lst_Init(&s2->cp);
                    911:     Lst_AtEnd(&targ->cp, s2);
1.1       deraadt   912:     printf("2 add %x %x to %x:", targ, s2, ls->l);
1.27      espie     913:     Lst_Every(ls->l, PrintAddr);
1.1       deraadt   914:     printf("\n");
                    915: #endif
1.41      espie     916:
1.1       deraadt   917: }
                    918:
                    919: /*-
                    920:  *-----------------------------------------------------------------------
                    921:  * SuffAddLevel  --
                    922:  *     Add all the children of targ as Src structures to the given list
                    923:  *
                    924:  * Side Effects:
1.41      espie     925:  *     Lots of structures are created and added to the list
1.1       deraadt   926:  *-----------------------------------------------------------------------
                    927:  */
                    928: static void
1.51      espie     929: SuffAddLevel(
                    930:     Lst           l,           /* list to which to add the new level */
                    931:     Src           *targ)       /* Src structure to use as the parent */
1.1       deraadt   932: {
1.41      espie     933:     LstSrc        ls;
1.1       deraadt   934:
                    935:     ls.s = targ;
                    936:     ls.l = l;
                    937:
1.29      espie     938:     Lst_ForEach(&targ->suff->children, SuffAddSrc, &ls);
1.1       deraadt   939: }
                    940:
                    941: /*-
                    942:  *----------------------------------------------------------------------
                    943:  * SuffRemoveSrc --
                    944:  *     Free all src structures in list that don't have a reference count
                    945:  *
                    946:  * Results:
1.41      espie     947:  *     Ture if an src was removed
1.1       deraadt   948:  *
                    949:  * Side Effects:
                    950:  *     The memory is free'd.
                    951:  *----------------------------------------------------------------------
                    952:  */
                    953: static int
1.51      espie     954: SuffRemoveSrc(Lst l)
1.1       deraadt   955: {
                    956:     LstNode ln;
                    957:     Src *s;
                    958:     int t = 0;
                    959:
                    960: #ifdef DEBUG_SRC
1.41      espie     961:     printf("cleaning %lx: ", (unsigned long)l);
1.27      espie     962:     Lst_Every(l, PrintAddr);
1.1       deraadt   963:     printf("\n");
                    964: #endif
                    965:
                    966:
1.41      espie     967:     for (ln = Lst_First(l); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie     968:        s = (Src *)Lst_Datum(ln);
1.1       deraadt   969:        if (s->children == 0) {
1.28      espie     970:            free(s->file);
1.1       deraadt   971:            if (!s->parent)
1.28      espie     972:                free(s->pref);
1.1       deraadt   973:            else {
                    974: #ifdef DEBUG_SRC
1.41      espie     975:                LstNode ln2 = Lst_Member(&s->parent->cp, s);
                    976:                if (ln2 != NULL)
                    977:                    Lst_Remove(&s->parent->cp, ln2);
1.1       deraadt   978: #endif
                    979:                --s->parent->children;
                    980:            }
                    981: #ifdef DEBUG_SRC
                    982:            printf("free: [l=%x] p=%x %d\n", l, s, s->children);
1.29      espie     983:            Lst_Destroy(&s->cp, NOFREE);
1.1       deraadt   984: #endif
                    985:            Lst_Remove(l, ln);
1.28      espie     986:            free(s);
1.1       deraadt   987:            t |= 1;
1.42      espie     988:            return true;
1.1       deraadt   989:        }
                    990: #ifdef DEBUG_SRC
                    991:        else {
                    992:            printf("keep: [l=%x] p=%x %d: ", l, s, s->children);
1.29      espie     993:            Lst_Every(&s->cp, PrintAddr);
1.1       deraadt   994:            printf("\n");
                    995:        }
                    996: #endif
                    997:     }
                    998:
                    999:     return t;
                   1000: }
                   1001:
                   1002: /*-
                   1003:  *-----------------------------------------------------------------------
                   1004:  * SuffFindThem --
                   1005:  *     Find the first existing file/target in the list srcs
                   1006:  *
                   1007:  * Results:
                   1008:  *     The lowest structure in the chain of transformations
                   1009:  *-----------------------------------------------------------------------
                   1010:  */
                   1011: static Src *
1.51      espie    1012: SuffFindThem(
                   1013:     Lst           srcs,        /* list of Src structures to search through */
                   1014:     Lst           slst)
1.1       deraadt  1015: {
1.41      espie    1016:     Src           *s;          /* current Src */
                   1017:     Src           *rs;         /* returned Src */
1.1       deraadt  1018:     char          *ptr;
                   1019:
1.41      espie    1020:     rs = NULL;
1.1       deraadt  1021:
1.19      espie    1022:     while ((s = (Src *)Lst_DeQueue(srcs)) != NULL) {
1.1       deraadt  1023:        if (DEBUG(SUFF)) {
1.41      espie    1024:            printf("\ttrying %s...", s->file);
1.1       deraadt  1025:        }
                   1026:
                   1027:        /*
                   1028:         * A file is considered to exist if either a node exists in the
                   1029:         * graph for it or the file actually exists.
                   1030:         */
1.42      espie    1031:        if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) {
1.1       deraadt  1032: #ifdef DEBUG_SRC
                   1033:            printf("remove %x from %x\n", s, srcs);
                   1034: #endif
                   1035:            rs = s;
                   1036:            break;
                   1037:        }
                   1038:
1.30      espie    1039:        if ((ptr = Dir_FindFile(s->file, &s->suff->searchPath)) != NULL) {
1.1       deraadt  1040:            rs = s;
                   1041: #ifdef DEBUG_SRC
                   1042:            printf("remove %x from %x\n", s, srcs);
                   1043: #endif
                   1044:            free(ptr);
                   1045:            break;
                   1046:        }
                   1047:
                   1048:        if (DEBUG(SUFF)) {
1.41      espie    1049:            printf("not there\n");
1.1       deraadt  1050:        }
                   1051:
1.41      espie    1052:        SuffAddLevel(srcs, s);
1.25      espie    1053:        Lst_AtEnd(slst, s);
1.1       deraadt  1054:     }
                   1055:
                   1056:     if (DEBUG(SUFF) && rs) {
1.41      espie    1057:        printf("got it\n");
1.1       deraadt  1058:     }
1.41      espie    1059:     return rs;
1.1       deraadt  1060: }
                   1061:
                   1062: /*-
                   1063:  *-----------------------------------------------------------------------
                   1064:  * SuffFindCmds --
                   1065:  *     See if any of the children of the target in the Src structure is
                   1066:  *     one from which the target can be transformed. If there is one,
                   1067:  *     a Src structure is put together for it and returned.
                   1068:  *
                   1069:  * Results:
1.18      espie    1070:  *     The Src structure of the "winning" child, or NULL if no such beast.
1.1       deraadt  1071:  *
                   1072:  * Side Effects:
                   1073:  *     A Src structure may be allocated.
                   1074:  *-----------------------------------------------------------------------
                   1075:  */
                   1076: static Src *
1.51      espie    1077: SuffFindCmds(
                   1078:     Src        *targ,  /* Src structure to play with */
                   1079:     Lst        slst)
1.41      espie    1080: {
                   1081:     LstNode            ln;     /* General-purpose list node */
                   1082:     GNode              *t,     /* Target GNode */
                   1083:                        *s;     /* Source GNode */
                   1084:     int                prefLen;/* The length of the defined prefix */
                   1085:     Suff               *suff;  /* Suffix on matching beastie */
                   1086:     Src                *ret;   /* Return value */
                   1087:     const char         *cp;
1.1       deraadt  1088:
                   1089:     t = targ->node;
1.41      espie    1090:     prefLen = strlen(targ->pref);
1.1       deraadt  1091:
1.41      espie    1092:     for (ln = Lst_First(&t->children); ln != NULL; ln = Lst_Adv(ln)) {
1.31      espie    1093:        s = (GNode *)Lst_Datum(ln);
1.1       deraadt  1094:
1.41      espie    1095:        cp = strrchr(s->name, '/');
                   1096:        if (cp == NULL) {
1.1       deraadt  1097:            cp = s->name;
                   1098:        } else {
                   1099:            cp++;
                   1100:        }
1.41      espie    1101:        if (strncmp(cp, targ->pref, prefLen) == 0) {
                   1102:            /* The node matches the prefix ok, see if it has a known
                   1103:             * suffix.  */
                   1104:            LstNode ln2;
1.52    ! espie    1105:            ln2 = suff_find_by_name(&cp[prefLen]);
1.41      espie    1106:            if (ln2 != NULL) {
1.1       deraadt  1107:                /*
                   1108:                 * It even has a known suffix, see if there's a transformation
                   1109:                 * defined between the node's suffix and the target's suffix.
                   1110:                 *
                   1111:                 * XXX: Handle multi-stage transformations here, too.
                   1112:                 */
1.41      espie    1113:                suff = (Suff *)Lst_Datum(ln2);
1.1       deraadt  1114:
1.41      espie    1115:                if (Lst_Member(&suff->parents, targ->suff) != NULL) {
1.1       deraadt  1116:                    /*
                   1117:                     * Hot Damn! Create a new Src structure to describe
                   1118:                     * this transformation (making sure to duplicate the
                   1119:                     * source node's name so Suff_FindDeps can free it
                   1120:                     * again (ick)), and return the new structure.
                   1121:                     */
1.41      espie    1122:                    ret = emalloc(sizeof(Src));
1.4       briggs   1123:                    ret->file = estrdup(s->name);
1.1       deraadt  1124:                    ret->pref = targ->pref;
                   1125:                    ret->suff = suff;
                   1126:                    ret->parent = targ;
                   1127:                    ret->node = s;
                   1128:                    ret->children = 0;
                   1129:                    targ->children += 1;
                   1130: #ifdef DEBUG_SRC
1.29      espie    1131:                    Lst_Init(&ret->cp);
1.1       deraadt  1132:                    printf("3 add %x %x\n", targ, ret);
1.29      espie    1133:                    Lst_AtEnd(&targ->cp, ret);
1.1       deraadt  1134: #endif
1.25      espie    1135:                    Lst_AtEnd(slst, ret);
1.1       deraadt  1136:                    if (DEBUG(SUFF)) {
                   1137:                        printf ("\tusing existing source %s\n", s->name);
                   1138:                    }
1.41      espie    1139:                    return ret;
1.1       deraadt  1140:                }
                   1141:            }
                   1142:        }
                   1143:     }
1.41      espie    1144:     return NULL;
                   1145: }
                   1146:
                   1147: static void
1.51      espie    1148: SuffExpandVarChildren(LstNode after, GNode *cgn, GNode *pgn)
1.41      espie    1149: {
                   1150:     GNode      *gn;            /* New source 8) */
                   1151:     char       *cp;            /* Expanded value */
                   1152:     LIST       members;
                   1153:
                   1154:
                   1155:     if (DEBUG(SUFF))
                   1156:        printf("Expanding \"%s\"...", cgn->name);
                   1157:
1.42      espie    1158:     cp = Var_Subst(cgn->name, &pgn->context, true);
1.41      espie    1159:     if (cp == NULL) {
                   1160:        printf("Problem substituting in %s", cgn->name);
                   1161:        printf("\n");
                   1162:        return;
                   1163:     }
                   1164:
                   1165:     Lst_Init(&members);
                   1166:
                   1167:     if (cgn->type & OP_ARCHV) {
                   1168:        /*
                   1169:         * Node was an archive(member) target, so we want to call
                   1170:         * on the Arch module to find the nodes for us, expanding
                   1171:         * variables in the parent's context.
                   1172:         */
                   1173:        char    *sacrifice = cp;
                   1174:
                   1175:        (void)Arch_ParseArchive(&sacrifice, &members, &pgn->context);
                   1176:     } else {
                   1177:        /* Break the result into a vector of strings whose nodes
                   1178:         * we can find, then add those nodes to the members list.
                   1179:         * Unfortunately, we can't use brk_string because it
                   1180:         * doesn't understand about variable specifications with
                   1181:         * spaces in them...  */
                   1182:        char        *start, *cp2;
                   1183:
                   1184:        for (start = cp; *start == ' ' || *start == '\t'; start++)
                   1185:            continue;
                   1186:        for (cp2 = start; *cp2 != '\0';) {
                   1187:            if (isspace(*cp2)) {
                   1188:                /* White-space -- terminate element, find the node,
                   1189:                 * add it, skip any further spaces.  */
1.42      espie    1190:                gn = Targ_FindNodei(start, cp2, TARG_CREATE);
1.41      espie    1191:                cp2++;
                   1192:                Lst_AtEnd(&members, gn);
                   1193:                while (isspace(*cp2))
                   1194:                    cp2++;
                   1195:                /* Adjust cp2 for increment at start of loop, but
                   1196:                 * set start to first non-space.  */
                   1197:                start = cp2;
                   1198:            } else if (*cp2 == '$')
                   1199:                /* Start of a variable spec -- contact variable module
                   1200:                 * to find the end so we can skip over it.  */
                   1201:                cp2 += Var_ParseSkip(cp2, &pgn->context, NULL);
                   1202:            else if (*cp2 == '\\' && cp2[1] != '\0')
                   1203:                /* Escaped something -- skip over it.  */
                   1204:                cp2+=2;
1.49      espie    1205:            else
                   1206:                cp2++;
1.41      espie    1207:        }
                   1208:
                   1209:        if (cp2 != start) {
                   1210:            /* Stuff left over -- add it to the list too.  */
1.42      espie    1211:            gn = Targ_FindNodei(start, cp2, TARG_CREATE);
1.41      espie    1212:            Lst_AtEnd(&members, gn);
                   1213:        }
                   1214:     }
                   1215:     /* Add all elements of the members list to the parent node.  */
                   1216:     while ((gn = (GNode *)Lst_DeQueue(&members)) != NULL) {
                   1217:        if (DEBUG(SUFF))
                   1218:            printf("%s...", gn->name);
                   1219:        if (Lst_Member(&pgn->children, gn) == NULL) {
                   1220:            Lst_Append(&pgn->children, after, gn);
                   1221:            after = Lst_Adv(after);
                   1222:            Lst_AtEnd(&gn->parents, pgn);
                   1223:            pgn->unmade++;
                   1224:        }
                   1225:     }
                   1226:     /* Free the result.  */
                   1227:     free(cp);
                   1228:     if (DEBUG(SUFF))
                   1229:        printf("\n");
                   1230: }
                   1231:
                   1232: static void
1.51      espie    1233: SuffExpandWildChildren(LstNode after, GNode *cgn, GNode *pgn)
1.41      espie    1234: {
                   1235:     LstNode    ln;             /* List element for old source */
                   1236:     char       *cp;            /* Expanded value */
                   1237:
                   1238:     LIST       exp;        /* List of expansions */
                   1239:     Lst        path;       /* Search path along which to expand */
                   1240:
                   1241:     if (DEBUG(SUFF))
                   1242:        printf("Wildcard expanding \"%s\"...", cgn->name);
                   1243:
                   1244:     /* Find a path along which to expand the word.
                   1245:      *
                   1246:      * If the word has a known suffix, use that path.
                   1247:      * If it has no known suffix and we're allowed to use the null
                   1248:      *  suffix, use its path.
                   1249:      * Else use the default system search path.  */
                   1250:     cp = cgn->name + strlen(cgn->name);
                   1251:     ln = Lst_FindConst(&sufflist, SuffSuffIsSuffixP, cp);
                   1252:
                   1253:     if (ln != NULL) {
                   1254:        Suff    *s = (Suff *)Lst_Datum(ln);
                   1255:
                   1256:        if (DEBUG(SUFF))
                   1257:            printf("suffix is \"%s\"...", s->name);
                   1258:        path = &s->searchPath;
                   1259:     } else
                   1260:        /* Use default search path.  */
1.42      espie    1261:        path = dirSearchPath;
1.41      espie    1262:
                   1263:     /* Expand the word along the chosen path. */
                   1264:     Lst_Init(&exp);
                   1265:     Dir_Expand(cgn->name, path, &exp);
                   1266:
                   1267:     /* Fetch next expansion off the list and find its GNode.  */
                   1268:     while ((cp = (char *)Lst_DeQueue(&exp)) != NULL) {
                   1269:        GNode           *gn;            /* New source 8) */
                   1270:        if (DEBUG(SUFF))
                   1271:            printf("%s...", cp);
1.42      espie    1272:        gn = Targ_FindNode(cp, TARG_CREATE);
1.41      espie    1273:
                   1274:        /* If gn isn't already a child of the parent, make it so and
                   1275:         * up the parent's count of unmade children.  */
                   1276:        if (Lst_Member(&pgn->children, gn) == NULL) {
                   1277:            Lst_Append(&pgn->children, after, gn);
                   1278:            after = Lst_Adv(after);
                   1279:            Lst_AtEnd(&gn->parents, pgn);
                   1280:            pgn->unmade++;
                   1281:        }
                   1282:     }
                   1283:
                   1284:     if (DEBUG(SUFF))
                   1285:        printf("\n");
1.1       deraadt  1286: }
                   1287:
                   1288: /*-
                   1289:  *-----------------------------------------------------------------------
                   1290:  * SuffExpandChildren --
                   1291:  *     Expand the names of any children of a given node that contain
                   1292:  *     variable invocations or file wildcards into actual targets.
                   1293:  *
                   1294:  * Side Effects:
                   1295:  *     The expanded node is removed from the parent's list of children,
                   1296:  *     and the parent's unmade counter is decremented, but other nodes
1.41      espie    1297:  *     may be added.
1.1       deraadt  1298:  *-----------------------------------------------------------------------
                   1299:  */
1.27      espie    1300: static void
1.51      espie    1301: SuffExpandChildren(
                   1302:     void       *cgnp,          /* Child to examine */
                   1303:     void       *pgnp)          /* Parent node being processed */
1.1       deraadt  1304: {
1.41      espie    1305:     GNode      *cgn = (GNode *)cgnp;
                   1306:     GNode      *pgn = (GNode *)pgnp;
                   1307:     LstNode    ln;
                   1308:     /* New nodes effectively take the place of the child, so we place them
                   1309:      * after the child.  */
                   1310:     ln = Lst_Member(&pgn->children, cgn);
1.1       deraadt  1311:
1.41      espie    1312:     /* First do variable expansion -- this takes precedence over
1.1       deraadt  1313:      * wildcard expansion. If the result contains wildcards, they'll be gotten
                   1314:      * to later since the resulting words are tacked on to the end of
1.41      espie    1315:      * the children list.  */
                   1316:     if (strchr(cgn->name, '$') != NULL)
                   1317:        SuffExpandVarChildren(ln, cgn, pgn);
                   1318:     else if (Dir_HasWildcards(cgn->name))
                   1319:        SuffExpandWildChildren(ln, cgn, pgn);
                   1320:     else
                   1321:        /* Third case: nothing to expand.  */
                   1322:        return;
1.1       deraadt  1323:
1.41      espie    1324:     /* Since the source was expanded, remove it from the list of children to
                   1325:      * keep it from being processed.  */
                   1326:     pgn->unmade--;
                   1327:     Lst_Remove(&pgn->children, ln);
1.1       deraadt  1328: }
                   1329:
                   1330: /*-
                   1331:  *-----------------------------------------------------------------------
                   1332:  * SuffApplyTransform --
                   1333:  *     Apply a transformation rule, given the source and target nodes
                   1334:  *     and suffixes.
                   1335:  *
                   1336:  * Results:
1.42      espie    1337:  *     true if successful, false if not.
1.1       deraadt  1338:  *
                   1339:  * Side Effects:
                   1340:  *     The source and target are linked and the commands from the
                   1341:  *     transformation are added to the target node's commands list.
                   1342:  *     All attributes but OP_DEPMASK and OP_TRANSFORM are applied
                   1343:  *     to the target. The target also inherits all the sources for
                   1344:  *     the transformation rule.
                   1345:  *-----------------------------------------------------------------------
                   1346:  */
1.42      espie    1347: static bool
1.51      espie    1348: SuffApplyTransform(
                   1349:     GNode      *tGn,   /* Target node */
                   1350:     GNode      *sGn,   /* Source node */
                   1351:     Suff       *t,     /* Target suffix */
                   1352:     Suff       *s)     /* Source suffix */
1.1       deraadt  1353: {
1.41      espie    1354:     LstNode    ln;     /* General node */
1.39      espie    1355:     LstNode    np;         /* Next node for loop */
1.41      espie    1356:     char       *tname; /* Name of transformation rule */
                   1357:     GNode      *gn;    /* Node for same */
1.1       deraadt  1358:
1.42      espie    1359:     if (Lst_AddNew(&tGn->children, sGn)) {
1.41      espie    1360:        /* Not already linked, so form the proper links between the
                   1361:         * target and source.  */
1.29      espie    1362:        Lst_AtEnd(&sGn->parents, tGn);
1.41      espie    1363:        tGn->unmade++;
1.1       deraadt  1364:     }
                   1365:
                   1366:     if ((sGn->type & OP_OPMASK) == OP_DOUBLEDEP) {
1.41      espie    1367:        /* When a :: node is used as the implied source of a node, we have
1.1       deraadt  1368:         * to link all its cohorts in as sources as well. Only the initial
                   1369:         * sGn gets the target in its iParents list, however, as that
1.41      espie    1370:         * will be sufficient to get the .IMPSRC variable set for tGn.  */
1.31      espie    1371:        for (ln=Lst_First(&sGn->cohorts); ln != NULL; ln=Lst_Adv(ln)) {
1.1       deraadt  1372:            gn = (GNode *)Lst_Datum(ln);
                   1373:
1.42      espie    1374:            if (Lst_AddNew(&tGn->children, gn)) {
1.41      espie    1375:                /* Not already linked, so form the proper links between the
                   1376:                 * target and source.  */
1.29      espie    1377:                Lst_AtEnd(&gn->parents, tGn);
1.41      espie    1378:                tGn->unmade++;
1.1       deraadt  1379:            }
                   1380:        }
                   1381:     }
1.41      espie    1382:     /* Locate the transformation rule itself.  */
1.42      espie    1383:     tname = Str_concat(s->name, t->name, 0);
1.52    ! espie    1384:     ln = transform_find_by_name(tname);
1.1       deraadt  1385:     free(tname);
                   1386:
1.41      espie    1387:     if (ln == NULL)
1.1       deraadt  1388:        /*
                   1389:         * Not really such a transformation rule (can happen when we're
                   1390:         * called to link an OP_MEMBER and OP_ARCHV node), so return
1.42      espie    1391:         * false.
1.1       deraadt  1392:         */
1.42      espie    1393:        return false;
1.1       deraadt  1394:
                   1395:     gn = (GNode *)Lst_Datum(ln);
1.5       millert  1396:
1.41      espie    1397:     if (DEBUG(SUFF))
1.1       deraadt  1398:        printf("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
                   1399:
1.41      espie    1400:     /* Record last child for expansion purposes.  */
1.29      espie    1401:     ln = Lst_Last(&tGn->children);
1.5       millert  1402:
1.41      espie    1403:     /* Pass the buck to Make_HandleUse to apply the rule.  */
                   1404:     Make_HandleUse(gn, tGn);
1.1       deraadt  1405:
1.41      espie    1406:     /* Deal with wildcards and variables in any acquired sources.  */
1.39      espie    1407:     for (ln = Lst_Succ(ln); ln != NULL; ln = np) {
                   1408:        np = Lst_Adv(ln);
                   1409:        SuffExpandChildren(Lst_Datum(ln), tGn);
                   1410:     }
1.1       deraadt  1411:
1.41      espie    1412:     /* Keep track of another parent to which this beast is transformed so
                   1413:      * the .IMPSRC variable can be set correctly for the parent.  */
1.29      espie    1414:     Lst_AtEnd(&sGn->iParents, tGn);
1.1       deraadt  1415:
1.42      espie    1416:     return true;
1.1       deraadt  1417: }
                   1418:
                   1419:
                   1420: /*-
                   1421:  *-----------------------------------------------------------------------
                   1422:  * SuffFindArchiveDeps --
                   1423:  *     Locate dependencies for an OP_ARCHV node.
                   1424:  *
                   1425:  * Side Effects:
                   1426:  *     Same as Suff_FindDeps
                   1427:  *-----------------------------------------------------------------------
                   1428:  */
                   1429: static void
1.51      espie    1430: SuffFindArchiveDeps(
                   1431:     GNode      *gn,        /* Node for which to locate dependencies */
                   1432:     Lst        slst)
1.1       deraadt  1433: {
1.41      espie    1434:     char       *eoarch;    /* End of archive portion */
                   1435:     char       *eoname;    /* End of member portion */
                   1436:     GNode      *mem;       /* Node for member */
                   1437:     Suff       *ms;        /* Suffix descriptor for member */
                   1438:     char       *name;      /* Start of member's name */
                   1439:
                   1440:     /* The node is an archive(member) pair. so we must find a suffix
                   1441:      * for both of them.  */
                   1442:     eoarch = strchr(gn->name, '(');
                   1443:     if (eoarch == NULL)
1.6       millert  1444:        return;
1.1       deraadt  1445:
1.41      espie    1446:     name = eoarch + 1;
1.1       deraadt  1447:
1.41      espie    1448:     eoname = strchr(name, ')');
                   1449:     if (eoname == NULL)
                   1450:        return;
1.5       millert  1451:
1.41      espie    1452:     /* To simplify things, call Suff_FindDeps recursively on the member now,
1.1       deraadt  1453:      * so we can simply compare the member's .PREFIX and .TARGET variables
                   1454:      * to locate its suffix. This allows us to figure out the suffix to
                   1455:      * use for the archive without having to do a quadratic search over the
1.41      espie    1456:      * suffix list, backtracking for each one...  */
1.42      espie    1457:     mem = Targ_FindNodei(name, eoname, TARG_CREATE);
1.1       deraadt  1458:     SuffFindDeps(mem, slst);
                   1459:
1.41      espie    1460:     /* Create the link between the two nodes right off. */
1.42      espie    1461:     if (Lst_AddNew(&gn->children, mem)) {
1.29      espie    1462:        Lst_AtEnd(&mem->parents, gn);
1.41      espie    1463:        gn->unmade++;
1.1       deraadt  1464:     }
1.5       millert  1465:
1.34      espie    1466:     /* Copy variables from member node to this one.  */
                   1467:     Varq_Set(TARGET_INDEX, Varq_Value(TARGET_INDEX, mem), gn);
                   1468:     Varq_Set(PREFIX_INDEX, Varq_Value(PREFIX_INDEX, mem), gn);
1.1       deraadt  1469:
                   1470:     ms = mem->suffix;
                   1471:     if (ms == NULL) {
1.41      espie    1472:        /* Didn't know what it was -- use .NULL suffix if not in make mode.  */
                   1473:        if (DEBUG(SUFF))
1.1       deraadt  1474:            printf("using null suffix\n");
                   1475:        ms = suffNull;
                   1476:     }
                   1477:
                   1478:
1.41      espie    1479:     /* Set the other two local variables required for this target.  */
                   1480:     Varq_Set(MEMBER_INDEX, mem->name, gn);
1.32      espie    1481:     Varq_Set(ARCHIVE_INDEX, gn->name, gn);
1.1       deraadt  1482:
                   1483:     if (ms != NULL) {
                   1484:        /*
                   1485:         * Member has a known suffix, so look for a transformation rule from
                   1486:         * it to a possible suffix of the archive. Rather than searching
                   1487:         * through the entire list, we just look at suffixes to which the
                   1488:         * member's suffix may be transformed...
                   1489:         */
1.41      espie    1490:        LstNode     ln;
1.1       deraadt  1491:
1.41      espie    1492:        /* Use first matching suffix...  */
                   1493:        ln = Lst_FindConst(&ms->parents, SuffSuffIsSuffixP, eoarch);
1.1       deraadt  1494:
1.18      espie    1495:        if (ln != NULL) {
1.41      espie    1496:            /* Got one -- apply it.  */
1.1       deraadt  1497:            if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
                   1498:                DEBUG(SUFF))
                   1499:                printf("\tNo transformation from %s -> %s\n",
                   1500:                       ms->name, ((Suff *)Lst_Datum(ln))->name);
                   1501:        }
                   1502:     }
                   1503:
1.41      espie    1504:     /* Pretend gn appeared to the left of a dependency operator so
1.1       deraadt  1505:      * the user needn't provide a transformation from the member to the
1.41      espie    1506:      * archive.  */
                   1507:     if (OP_NOP(gn->type))
1.1       deraadt  1508:        gn->type |= OP_DEPENDS;
                   1509:
1.41      espie    1510:     /* Flag the member as such so we remember to look in the archive for
                   1511:      * its modification time.  */
1.1       deraadt  1512:     mem->type |= OP_MEMBER;
                   1513: }
                   1514:
                   1515: /*-
                   1516:  *-----------------------------------------------------------------------
                   1517:  * SuffFindNormalDeps --
                   1518:  *     Locate implicit dependencies for regular targets.
                   1519:  *
                   1520:  * Side Effects:
                   1521:  *     Same as Suff_FindDeps...
                   1522:  *-----------------------------------------------------------------------
                   1523:  */
                   1524: static void
1.51      espie    1525: SuffFindNormalDeps(
                   1526:     GNode      *gn,        /* Node for which to find sources */
                   1527:     Lst        slst)
1.1       deraadt  1528: {
1.41      espie    1529:     char       *eoname;    /* End of name */
                   1530:     char       *sopref;    /* Start of prefix */
                   1531:     LstNode    ln;         /* Next suffix node to check */
1.39      espie    1532:     LstNode    np;
1.41      espie    1533:     LIST       srcs;       /* List of sources at which to look */
                   1534:     LIST       targs;      /* List of targets to which things can be
1.1       deraadt  1535:                             * transformed. They all have the same file,
                   1536:                             * but different suff and pref fields */
1.41      espie    1537:     Src        *bottom;    /* Start of found transformation path */
1.1       deraadt  1538:     Src        *src;       /* General Src pointer */
1.41      espie    1539:     char       *pref;      /* Prefix to use */
                   1540:     Src        *targ;      /* General Src target pointer */
1.1       deraadt  1541:
                   1542:
                   1543:     eoname = gn->name + strlen(gn->name);
                   1544:
                   1545:     sopref = gn->name;
1.5       millert  1546:
1.41      espie    1547:     /* Begin at the beginning...  */
1.30      espie    1548:     ln = Lst_First(&sufflist);
                   1549:     Lst_Init(&srcs);
                   1550:     Lst_Init(&targs);
1.1       deraadt  1551:
1.41      espie    1552:     /* We're caught in a catch-22 here. On the one hand, we want to use any
1.1       deraadt  1553:      * transformation implied by the target's sources, but we can't examine
                   1554:      * the sources until we've expanded any variables/wildcards they may hold,
                   1555:      * and we can't do that until we've set up the target's local variables
                   1556:      * and we can't do that until we know what the proper suffix for the
                   1557:      * target is (in case there are two suffixes one of which is a suffix of
                   1558:      * the other) and we can't know that until we've found its implied
                   1559:      * source, which we may not want to use if there's an existing source
                   1560:      * that implies a different transformation.
                   1561:      *
                   1562:      * In an attempt to get around this, which may not work all the time,
                   1563:      * but should work most of the time, we look for implied sources first,
                   1564:      * checking transformations to all possible suffixes of the target,
                   1565:      * use what we find to set the target's local variables, expand the
                   1566:      * children, then look for any overriding transformations they imply.
1.41      espie    1567:      * Should we find one, we discard the one we found before. */
1.1       deraadt  1568:
1.18      espie    1569:     while (ln != NULL) {
1.41      espie    1570:        /* Look for next possible suffix...  */
                   1571:        ln = Lst_FindFromConst(ln, SuffSuffIsSuffixP, eoname);
1.1       deraadt  1572:
1.18      espie    1573:        if (ln != NULL) {
1.41      espie    1574:            int     prefLen;        /* Length of the prefix */
                   1575:            Src     *targ;
1.5       millert  1576:
1.41      espie    1577:            /* Allocate a Src structure to which things can be transformed.  */
                   1578:            targ = emalloc(sizeof(Src));
1.4       briggs   1579:            targ->file = estrdup(gn->name);
1.1       deraadt  1580:            targ->suff = (Suff *)Lst_Datum(ln);
                   1581:            targ->node = gn;
1.41      espie    1582:            targ->parent = NULL;
1.1       deraadt  1583:            targ->children = 0;
                   1584: #ifdef DEBUG_SRC
1.29      espie    1585:            Lst_Init(&targ->cp);
1.1       deraadt  1586: #endif
1.5       millert  1587:
1.41      espie    1588:            /* Allocate room for the prefix, whose end is found by subtracting
                   1589:             * the length of the suffix from the end of the name.  */
1.1       deraadt  1590:            prefLen = (eoname - targ->suff->nameLen) - sopref;
                   1591:            targ->pref = emalloc(prefLen + 1);
                   1592:            memcpy(targ->pref, sopref, prefLen);
                   1593:            targ->pref[prefLen] = '\0';
                   1594:
1.30      espie    1595:            /* Add nodes from which the target can be made.  */
                   1596:            SuffAddLevel(&srcs, targ);
1.1       deraadt  1597:
1.30      espie    1598:            /* Record the target so we can nuke it.  */
                   1599:            Lst_AtEnd(&targs, targ);
1.1       deraadt  1600:
1.30      espie    1601:            /* Search from this suffix's successor...  */
1.1       deraadt  1602:            ln = Lst_Succ(ln);
                   1603:        }
                   1604:     }
                   1605:
1.41      espie    1606:     /* Handle target of unknown suffix...  */
1.30      espie    1607:     if (Lst_IsEmpty(&targs) && suffNull != NULL) {
1.1       deraadt  1608:        if (DEBUG(SUFF)) {
1.5       millert  1609:            printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
1.1       deraadt  1610:        }
1.5       millert  1611:
1.41      espie    1612:        targ = emalloc(sizeof(Src));
1.4       briggs   1613:        targ->file = estrdup(gn->name);
1.1       deraadt  1614:        targ->suff = suffNull;
                   1615:        targ->node = gn;
1.41      espie    1616:        targ->parent = NULL;
1.1       deraadt  1617:        targ->children = 0;
1.4       briggs   1618:        targ->pref = estrdup(sopref);
1.1       deraadt  1619: #ifdef DEBUG_SRC
1.29      espie    1620:        Lst_Init(&targ->cp);
1.1       deraadt  1621: #endif
                   1622:
1.41      espie    1623:        /* Only use the default suffix rules if we don't have commands
                   1624:         * or dependencies defined for this gnode.  */
1.29      espie    1625:        if (Lst_IsEmpty(&gn->commands) && Lst_IsEmpty(&gn->children))
1.30      espie    1626:            SuffAddLevel(&srcs, targ);
1.1       deraadt  1627:        else {
1.5       millert  1628:            if (DEBUG(SUFF))
1.1       deraadt  1629:                printf("not ");
                   1630:        }
                   1631:
1.5       millert  1632:        if (DEBUG(SUFF))
1.1       deraadt  1633:            printf("adding suffix rules\n");
                   1634:
1.30      espie    1635:        Lst_AtEnd(&targs, targ);
1.1       deraadt  1636:     }
1.5       millert  1637:
1.41      espie    1638:     /* Using the list of possible sources built up from the target suffix(es),
                   1639:      * try and find an existing file/target that matches.  */
1.30      espie    1640:     bottom = SuffFindThem(&srcs, slst);
1.1       deraadt  1641:
1.30      espie    1642:     if (bottom == NULL) {
1.41      espie    1643:        /* No known transformations -- use the first suffix found for setting
                   1644:         * the local variables.  */
1.30      espie    1645:        if (!Lst_IsEmpty(&targs))
                   1646:            targ = (Src *)Lst_Datum(Lst_First(&targs));
                   1647:        else
                   1648:            targ = NULL;
1.1       deraadt  1649:     } else {
1.41      espie    1650:        /* Work up the transformation path to find the suffix of the
                   1651:         * target to which the transformation was made.  */
1.1       deraadt  1652:        for (targ = bottom; targ->parent != NULL; targ = targ->parent)
                   1653:            continue;
                   1654:     }
                   1655:
1.41      espie    1656:     /* The .TARGET variable we always set to be the name at this point,
1.1       deraadt  1657:      * since it's only set to the path if the thing is only a source and
                   1658:      * if it's only a source, it doesn't matter what we put here as far
1.41      espie    1659:      * as expanding sources is concerned, since it has none... */
1.32      espie    1660:     Varq_Set(TARGET_INDEX, gn->name, gn);
1.1       deraadt  1661:
1.41      espie    1662:     pref = targ != NULL ? targ->pref : gn->name;
1.32      espie    1663:     Varq_Set(PREFIX_INDEX, pref, gn);
1.1       deraadt  1664:
1.41      espie    1665:     /* Now we've got the important local variables set, expand any sources
                   1666:      * that still contain variables or wildcards in their names.  */
1.39      espie    1667:     for (ln = Lst_First(&gn->children); ln != NULL; ln = np) {
                   1668:        np = Lst_Adv(ln);
                   1669:        SuffExpandChildren(Lst_Datum(ln), gn);
                   1670:     }
1.5       millert  1671:
1.1       deraadt  1672:     if (targ == NULL) {
1.41      espie    1673:        if (DEBUG(SUFF))
1.1       deraadt  1674:            printf("\tNo valid suffix on %s\n", gn->name);
                   1675:
                   1676: sfnd_abort:
1.41      espie    1677:        /* Deal with finding the thing on the default search path if the
1.1       deraadt  1678:         * node is only a source (not on the lhs of a dependency operator
1.41      espie    1679:         * or [XXX] it has neither children or commands).  */
1.1       deraadt  1680:        if (OP_NOP(gn->type) ||
1.29      espie    1681:            (Lst_IsEmpty(&gn->children) && Lst_IsEmpty(&gn->commands)))
1.1       deraadt  1682:        {
                   1683:            gn->path = Dir_FindFile(gn->name,
1.42      espie    1684:                                    (targ == NULL ? dirSearchPath :
1.30      espie    1685:                                     &targ->suff->searchPath));
1.1       deraadt  1686:            if (gn->path != NULL) {
1.2       deraadt  1687:                char *ptr;
1.32      espie    1688:                Varq_Set(TARGET_INDEX, gn->path, gn);
1.1       deraadt  1689:
                   1690:                if (targ != NULL) {
1.41      espie    1691:                    /* Suffix known for the thing -- trim the suffix off
                   1692:                     * the path to form the proper .PREFIX variable.  */
                   1693:                    int         savep = strlen(gn->path) - targ->suff->nameLen;
1.1       deraadt  1694:                    char        savec;
                   1695:
                   1696:                    gn->suffix = targ->suff;
                   1697:
1.2       deraadt  1698:                    savec = gn->path[savep];
                   1699:                    gn->path[savep] = '\0';
1.1       deraadt  1700:
1.2       deraadt  1701:                    if ((ptr = strrchr(gn->path, '/')) != NULL)
                   1702:                        ptr++;
                   1703:                    else
                   1704:                        ptr = gn->path;
1.1       deraadt  1705:
1.32      espie    1706:                    Varq_Set(PREFIX_INDEX, ptr, gn);
1.2       deraadt  1707:
                   1708:                    gn->path[savep] = savec;
1.1       deraadt  1709:                } else {
1.41      espie    1710:                    /* The .PREFIX gets the full path if the target has
                   1711:                     * no known suffix.  */
1.1       deraadt  1712:                    gn->suffix = NULL;
                   1713:
1.2       deraadt  1714:                    if ((ptr = strrchr(gn->path, '/')) != NULL)
                   1715:                        ptr++;
                   1716:                    else
                   1717:                        ptr = gn->path;
                   1718:
1.32      espie    1719:                    Varq_Set(PREFIX_INDEX, ptr, gn);
1.1       deraadt  1720:                }
                   1721:            }
                   1722:        } else {
1.41      espie    1723:            /* Not appropriate to search for the thing -- set the
1.1       deraadt  1724:             * path to be the name so Dir_MTime won't go grovelling for
1.41      espie    1725:             * it.  */
                   1726:            gn->suffix = targ == NULL ? NULL : targ->suff;
1.11      espie    1727:            efree(gn->path);
1.4       briggs   1728:            gn->path = estrdup(gn->name);
1.1       deraadt  1729:        }
1.5       millert  1730:
1.1       deraadt  1731:        goto sfnd_return;
                   1732:     }
                   1733:
1.41      espie    1734:     /* If the suffix indicates that the target is a library, mark that in
                   1735:      * the node's type field.  */
1.1       deraadt  1736:     if (targ->suff->flags & SUFF_LIBRARY) {
                   1737:        gn->type |= OP_LIB;
                   1738:     }
                   1739:
1.41      espie    1740:     /* Check for overriding transformation rule implied by sources.  */
1.29      espie    1741:     if (!Lst_IsEmpty(&gn->children)) {
1.1       deraadt  1742:        src = SuffFindCmds(targ, slst);
                   1743:
1.41      espie    1744:        if (src != NULL) {
                   1745:            /* Free up all the Src structures in the transformation path
                   1746:             * up to, but not including, the parent node.  */
1.1       deraadt  1747:            while (bottom && bottom->parent != NULL) {
1.41      espie    1748:                (void)Lst_AddNew(slst, bottom);
1.1       deraadt  1749:                bottom = bottom->parent;
                   1750:            }
                   1751:            bottom = src;
                   1752:        }
                   1753:     }
                   1754:
                   1755:     if (bottom == NULL) {
1.41      espie    1756:        /* No idea from where it can come -- return now.  */
1.1       deraadt  1757:        goto sfnd_abort;
                   1758:     }
                   1759:
1.41      espie    1760:     /* We now have a list of Src structures headed by 'bottom' and linked via
1.1       deraadt  1761:      * their 'parent' pointers. What we do next is create links between
                   1762:      * source and target nodes (which may or may not have been created)
                   1763:      * and set the necessary local variables in each target. The
                   1764:      * commands for each target are set from the commands of the
                   1765:      * transformation rule used to get from the src suffix to the targ
                   1766:      * suffix. Note that this causes the commands list of the original
                   1767:      * node, gn, to be replaced by the commands of the final
                   1768:      * transformation rule. Also, the unmade field of gn is incremented.
1.41      espie    1769:      * Etc.  */
1.18      espie    1770:     if (bottom->node == NULL) {
1.42      espie    1771:        bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);
1.1       deraadt  1772:     }
1.5       millert  1773:
1.41      espie    1774:     for (src = bottom; src->parent != NULL; src = src->parent) {
1.1       deraadt  1775:        targ = src->parent;
                   1776:
                   1777:        src->node->suffix = src->suff;
                   1778:
1.18      espie    1779:        if (targ->node == NULL) {
1.42      espie    1780:            targ->node = Targ_FindNode(targ->file, TARG_CREATE);
1.1       deraadt  1781:        }
                   1782:
                   1783:        SuffApplyTransform(targ->node, src->node,
                   1784:                           targ->suff, src->suff);
                   1785:
                   1786:        if (targ->node != gn) {
1.41      espie    1787:            /* Finish off the dependency-search process for any nodes
1.1       deraadt  1788:             * between bottom and gn (no point in questing around the
                   1789:             * filesystem for their implicit source when it's already
                   1790:             * known). Note that the node can't have any sources that
                   1791:             * need expanding, since SuffFindThem will stop on an existing
                   1792:             * node, so all we need to do is set the standard and System V
1.41      espie    1793:             * variables.  */
1.1       deraadt  1794:            targ->node->type |= OP_DEPS_FOUND;
                   1795:
1.32      espie    1796:            Varq_Set(PREFIX_INDEX, targ->pref, targ->node);
1.5       millert  1797:
1.32      espie    1798:            Varq_Set(TARGET_INDEX, targ->node->name, targ->node);
1.1       deraadt  1799:        }
                   1800:     }
                   1801:
                   1802:     gn->suffix = src->suff;
                   1803:
1.41      espie    1804:     /* So Dir_MTime doesn't go questing for it...  */
1.11      espie    1805:     efree(gn->path);
1.4       briggs   1806:     gn->path = estrdup(gn->name);
1.1       deraadt  1807:
1.41      espie    1808:     /* Nuke the transformation path and the Src structures left over in the
                   1809:      * two lists.  */
1.1       deraadt  1810: sfnd_return:
                   1811:     if (bottom)
1.41      espie    1812:        (void)Lst_AddNew(slst, bottom);
1.1       deraadt  1813:
1.30      espie    1814:     while (SuffRemoveSrc(&srcs) || SuffRemoveSrc(&targs))
1.1       deraadt  1815:        continue;
                   1816:
1.30      espie    1817:     Lst_ConcatDestroy(slst, &srcs);
                   1818:     Lst_ConcatDestroy(slst, &targs);
1.1       deraadt  1819: }
1.5       millert  1820:
                   1821:
1.1       deraadt  1822: /*-
                   1823:  *-----------------------------------------------------------------------
                   1824:  * Suff_FindDeps  --
                   1825:  *     Find implicit sources for the target described by the graph node
                   1826:  *     gn
                   1827:  *
                   1828:  * Side Effects:
                   1829:  *     Nodes are added to the graph below the passed-in node. The nodes
                   1830:  *     are marked to have their IMPSRC variable filled in. The
                   1831:  *     PREFIX variable is set for the given node and all its
                   1832:  *     implied children.
                   1833:  *
                   1834:  * Notes:
                   1835:  *     The path found by this target is the shortest path in the
                   1836:  *     transformation graph, which may pass through non-existent targets,
                   1837:  *     to an existing target. The search continues on all paths from the
                   1838:  *     root suffix until a file is found. I.e. if there's a path
                   1839:  *     .o -> .c -> .l -> .l,v from the root and the .l,v file exists but
                   1840:  *     the .c and .l files don't, the search will branch out in
                   1841:  *     all directions from .o and again from all the nodes on the
                   1842:  *     next level until the .l,v node is encountered.
                   1843:  *-----------------------------------------------------------------------
                   1844:  */
                   1845:
                   1846: void
1.51      espie    1847: Suff_FindDeps(GNode *gn)
1.1       deraadt  1848: {
1.5       millert  1849:
1.29      espie    1850:     SuffFindDeps(gn, &srclist);
                   1851:     while (SuffRemoveSrc(&srclist))
1.1       deraadt  1852:        continue;
                   1853: }
                   1854:
                   1855:
                   1856: static void
1.51      espie    1857: SuffFindDeps(GNode *gn, Lst slst)
1.1       deraadt  1858: {
                   1859:     if (gn->type & OP_DEPS_FOUND) {
                   1860:        /*
                   1861:         * If dependencies already found, no need to do it again...
                   1862:         */
                   1863:        return;
                   1864:     } else {
                   1865:        gn->type |= OP_DEPS_FOUND;
                   1866:     }
1.5       millert  1867:
1.1       deraadt  1868:     if (DEBUG(SUFF)) {
1.41      espie    1869:        printf("SuffFindDeps (%s)\n", gn->name);
1.1       deraadt  1870:     }
1.5       millert  1871:
1.1       deraadt  1872:     if (gn->type & OP_ARCHV) {
                   1873:        SuffFindArchiveDeps(gn, slst);
                   1874:     } else if (gn->type & OP_LIB) {
                   1875:        /*
                   1876:         * If the node is a library, it is the arch module's job to find it
                   1877:         * and set the TARGET variable accordingly. We merely provide the
                   1878:         * search path, assuming all libraries end in ".a" (if the suffix
                   1879:         * hasn't been defined, there's nothing we can do for it, so we just
                   1880:         * set the TARGET variable to the node's name in order to give it a
                   1881:         * value).
                   1882:         */
1.41      espie    1883:        LstNode ln;
1.1       deraadt  1884:        Suff    *s;
1.5       millert  1885:
1.52    ! espie    1886:        ln = suff_find_by_name(LIBSUFF);
1.18      espie    1887:        if (ln != NULL) {
1.31      espie    1888:            gn->suffix = s = (Suff *)Lst_Datum(ln);
1.30      espie    1889:            Arch_FindLib(gn, &s->searchPath);
1.1       deraadt  1890:        } else {
                   1891:            gn->suffix = NULL;
1.32      espie    1892:            Varq_Set(TARGET_INDEX, gn->name, gn);
1.1       deraadt  1893:        }
                   1894:        /*
                   1895:         * Because a library (-lfoo) target doesn't follow the standard
                   1896:         * filesystem conventions, we don't set the regular variables for
                   1897:         * the thing. .PREFIX is simply made empty...
                   1898:         */
1.32      espie    1899:        Varq_Set(PREFIX_INDEX, "", gn);
1.41      espie    1900:     } else
1.1       deraadt  1901:        SuffFindNormalDeps(gn, slst);
                   1902: }
                   1903:
                   1904: /*-
                   1905:  *-----------------------------------------------------------------------
                   1906:  * Suff_SetNull --
                   1907:  *     Define which suffix is the null suffix.
                   1908:  *
                   1909:  * Side Effects:
                   1910:  *     'suffNull' is altered.
                   1911:  *
                   1912:  * Notes:
                   1913:  *     Need to handle the changing of the null suffix gracefully so the
                   1914:  *     old transformation rules don't just go away.
                   1915:  *-----------------------------------------------------------------------
                   1916:  */
                   1917: void
1.52    ! espie    1918: Suff_SetNull(const char *name)
1.1       deraadt  1919: {
                   1920:     Suff    *s;
                   1921:     LstNode ln;
                   1922:
1.52    ! espie    1923:     ln = suff_find_by_name(name);
1.18      espie    1924:     if (ln != NULL) {
1.1       deraadt  1925:        s = (Suff *)Lst_Datum(ln);
1.41      espie    1926:        if (suffNull != NULL) {
1.1       deraadt  1927:            suffNull->flags &= ~SUFF_NULL;
                   1928:        }
                   1929:        s->flags |= SUFF_NULL;
                   1930:        /*
                   1931:         * XXX: Here's where the transformation mangling would take place
                   1932:         */
                   1933:        suffNull = s;
                   1934:     } else {
1.41      espie    1935:        Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
1.1       deraadt  1936:                     name);
                   1937:     }
                   1938: }
                   1939:
                   1940: /*-
                   1941:  *-----------------------------------------------------------------------
                   1942:  * Suff_Init --
                   1943:  *     Initialize suffixes module
                   1944:  *
                   1945:  * Side Effects:
                   1946:  *     Many
                   1947:  *-----------------------------------------------------------------------
                   1948:  */
                   1949: void
1.51      espie    1950: Suff_Init(void)
1.1       deraadt  1951: {
1.46      espie    1952:     Static_Lst_Init(&sufflist);
1.14      espie    1953: #ifdef CLEANUP
1.46      espie    1954:     Static_Lst_Init(&suffClean);
1.14      espie    1955: #endif
1.46      espie    1956:     Static_Lst_Init(&srclist);
                   1957:     Static_Lst_Init(&transforms);
1.1       deraadt  1958:
                   1959:     sNum = 0;
                   1960:     /*
                   1961:      * Create null suffix for single-suffix rules (POSIX). The thing doesn't
                   1962:      * actually go on the suffix list or everyone will think that's its
                   1963:      * suffix.
                   1964:      */
1.41      espie    1965:     emptySuff = suffNull = emalloc(sizeof(Suff));
1.1       deraadt  1966:
1.41      espie    1967:     suffNull->name =       estrdup("");
1.1       deraadt  1968:     suffNull->nameLen =     0;
1.30      espie    1969:     Lst_Init(&suffNull->searchPath);
1.42      espie    1970:     Dir_Concat(&suffNull->searchPath, dirSearchPath);
1.29      espie    1971:     Lst_Init(&suffNull->children);
                   1972:     Lst_Init(&suffNull->parents);
                   1973:     Lst_Init(&suffNull->ref);
1.41      espie    1974:     suffNull->sNum =       sNum++;
                   1975:     suffNull->flags =      SUFF_NULL;
1.1       deraadt  1976:
                   1977: }
                   1978:
                   1979:
                   1980: /*-
                   1981:  *----------------------------------------------------------------------
                   1982:  * Suff_End --
                   1983:  *     Cleanup the this module
                   1984:  *
                   1985:  * Side Effects:
                   1986:  *     The memory is free'd.
                   1987:  *----------------------------------------------------------------------
                   1988:  */
                   1989:
1.42      espie    1990: #ifdef CLEANUP
1.1       deraadt  1991: void
1.51      espie    1992: Suff_End(void)
1.1       deraadt  1993: {
1.30      espie    1994:     Lst_Destroy(&sufflist, SuffFree);
1.29      espie    1995:     Lst_Destroy(&suffClean, SuffFree);
1.1       deraadt  1996:     if (suffNull)
                   1997:        SuffFree(suffNull);
1.29      espie    1998:     Lst_Destroy(&srclist, NOFREE);
                   1999:     Lst_Destroy(&transforms, NOFREE);
1.42      espie    2000: }
1.14      espie    2001: #endif
1.1       deraadt  2002:
                   2003:
                   2004: /********************* DEBUGGING FUNCTIONS **********************/
                   2005:
1.51      espie    2006: static void SuffPrintName(void *s)
1.1       deraadt  2007: {
1.27      espie    2008:     printf("%s ", ((Suff *)s)->name);
1.1       deraadt  2009: }
                   2010:
1.27      espie    2011: static void
1.51      espie    2012: SuffPrintSuff(void *sp)
1.1       deraadt  2013: {
1.27      espie    2014:     Suff    *s = (Suff *)sp;
1.41      espie    2015:     int     flags;
                   2016:     int     flag;
1.1       deraadt  2017:
1.27      espie    2018:     printf("# `%s' ", s->name);
1.5       millert  2019:
1.1       deraadt  2020:     flags = s->flags;
                   2021:     if (flags) {
1.27      espie    2022:        fputs(" (", stdout);
1.1       deraadt  2023:        while (flags) {
                   2024:            flag = 1 << (ffs(flags) - 1);
                   2025:            flags &= ~flag;
                   2026:            switch (flag) {
                   2027:                case SUFF_NULL:
1.27      espie    2028:                    printf("NULL");
1.1       deraadt  2029:                    break;
                   2030:                case SUFF_INCLUDE:
1.27      espie    2031:                    printf("INCLUDE");
1.1       deraadt  2032:                    break;
                   2033:                case SUFF_LIBRARY:
1.27      espie    2034:                    printf("LIBRARY");
1.1       deraadt  2035:                    break;
                   2036:            }
                   2037:            fputc(flags ? '|' : ')', stdout);
                   2038:        }
                   2039:     }
1.41      espie    2040:     fputc('\n', stdout);
                   2041:     printf("#\tTo: ");
1.29      espie    2042:     Lst_Every(&s->parents, SuffPrintName);
1.41      espie    2043:     fputc('\n', stdout);
                   2044:     printf("#\tFrom: ");
1.29      espie    2045:     Lst_Every(&s->children, SuffPrintName);
1.41      espie    2046:     fputc('\n', stdout);
                   2047:     printf("#\tSearch Path: ");
1.30      espie    2048:     Dir_PrintPath(&s->searchPath);
1.27      espie    2049:     fputc('\n', stdout);
1.1       deraadt  2050: }
                   2051:
1.27      espie    2052: static void
1.51      espie    2053: SuffPrintTrans(void *tp)
1.1       deraadt  2054: {
1.27      espie    2055:     GNode   *t = (GNode *)tp;
1.1       deraadt  2056:
1.27      espie    2057:     printf("%-16s: ", t->name);
                   2058:     Targ_PrintType(t->type);
                   2059:     fputc('\n', stdout);
1.29      espie    2060:     Lst_Every(&t->commands, Targ_PrintCmd);
1.27      espie    2061:     fputc('\n', stdout);
1.1       deraadt  2062: }
                   2063:
                   2064: void
1.51      espie    2065: Suff_PrintAll(void)
1.1       deraadt  2066: {
1.27      espie    2067:     printf("#*** Suffixes:\n");
1.30      espie    2068:     Lst_Every(&sufflist, SuffPrintSuff);
1.1       deraadt  2069:
1.27      espie    2070:     printf("#*** Transformations:\n");
1.29      espie    2071:     Lst_Every(&transforms, SuffPrintTrans);
1.1       deraadt  2072: }
1.42      espie    2073:
                   2074: #ifdef DEBUG_SRC
                   2075: static void
1.51      espie    2076: PrintAddr(void *a)
1.42      espie    2077: {
                   2078:     printf("%lx ", (unsigned long)a);
                   2079: }
                   2080: #endif