BSD 4_4 release
[unix-history] / usr / src / usr.bin / make / suff.c
index 1824d65..fab2895 100644 (file)
@@ -1,29 +1,43 @@
 /*
 /*
- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
- * Copyright (c) 1988, 1989 by Adam de Boor
+ * Copyright (c) 1988, 1989, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)suff.c     5.6 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)suff.c     8.1 (Berkeley) 6/6/93";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -77,6 +91,8 @@ static char sccsid[] = "@(#)suff.c    5.6 (Berkeley) 6/1/90";
 
 #include         <stdio.h>
 #include         "make.h"
 
 #include         <stdio.h>
 #include         "make.h"
+#include         "hash.h"
+#include         "dir.h"
 #include         "bit.h"
 
 static Lst       sufflist;     /* Lst of suffixes */
 #include         "bit.h"
 
 static Lst       sufflist;     /* Lst of suffixes */
@@ -114,10 +130,43 @@ typedef struct _Src {
                                 * this thing too early or never nuke it) */
 } Src;
 
                                 * this thing too early or never nuke it) */
 } Src;
 
+/*
+ * A structure for passing more than one argument to the Lst-library-invoked
+ * function...
+ */
+typedef struct {
+    Lst            l;
+    Src            *s;
+} LstSrc;
+
 static Suff        *suffNull;  /* The NULL suffix for this run */
 static Suff        *emptySuff; /* The empty suffix required for POSIX
                                 * single-suffix transformation rules */
 
 static Suff        *suffNull;  /* The NULL suffix for this run */
 static Suff        *emptySuff; /* The empty suffix required for POSIX
                                 * single-suffix transformation rules */
 
+
+static char *SuffStrIsPrefix __P((char *, char *));
+static char *SuffSuffIsSuffix __P((Suff *, char *));
+static int SuffSuffIsSuffixP __P((Suff *, char *));
+static int SuffSuffHasNameP __P((Suff *, char *));
+static int SuffSuffIsPrefix __P((Suff *, char *));
+static int SuffGNHasNameP __P((GNode *, char *));
+static void SuffFree __P((Suff *));
+static void SuffInsert __P((Lst, Suff *));
+static Boolean SuffParseTransform __P((char *, Suff **, Suff **));
+static int SuffRebuildGraph __P((GNode *, Suff *));
+static int SuffAddSrc __P((Suff *, LstSrc *));
+static void SuffAddLevel __P((Lst, Src *));
+static void SuffFreeSrc __P((Src *));
+static Src *SuffFindThem __P((Lst));
+static Src *SuffFindCmds __P((Src *));
+static int SuffExpandChildren __P((GNode *, GNode *));
+static Boolean SuffApplyTransform __P((GNode *, GNode *, Suff *, Suff *));
+static void SuffFindArchiveDeps __P((GNode *));
+static void SuffFindNormalDeps __P((GNode *));
+static int SuffPrintName __P((Suff *));
+static int SuffPrintSuff __P((Suff *));
+static int SuffPrintTrans __P((GNode *));
+
        /*************** Lst Predicates ****************/
 /*-
  *-----------------------------------------------------------------------
        /*************** Lst Predicates ****************/
 /*-
  *-----------------------------------------------------------------------
@@ -191,6 +240,7 @@ SuffSuffIsSuffix (s, str)
  *
  *-----------------------------------------------------------------------
  */
  *
  *-----------------------------------------------------------------------
  */
+static int
 SuffSuffIsSuffixP(s, str)
     Suff       *s;
     char       *str;
 SuffSuffIsSuffixP(s, str)
     Suff       *s;
     char       *str;
@@ -305,7 +355,7 @@ SuffInsert (l, s)
     Suff          *s;          /* the suffix to insert */
 {
     LstNode      ln;           /* current element in l we're examining */
     Suff          *s;          /* the suffix to insert */
 {
     LstNode      ln;           /* current element in l we're examining */
-    Suff          *s2;         /* the suffix descriptor in this element */
+    Suff          *s2 = NULL;  /* the suffix descriptor in this element */
 
     if (Lst_Open (l) == FAILURE) {
        return;
 
     if (Lst_Open (l) == FAILURE) {
        return;
@@ -388,7 +438,7 @@ SuffParseTransform(str, srcPtr, targPtr)
     register char      *str2;      /* Extra pointer (maybe target suffix) */
     LstNode            singleLn;   /* element in suffix list of any suffix
                                     * that exactly matches str */
     register char      *str2;      /* Extra pointer (maybe target suffix) */
     LstNode            singleLn;   /* element in suffix list of any suffix
                                     * that exactly matches str */
-    Suff               *single;    /* Source of possible transformation to
+    Suff               *single = NULL;/* Source of possible transformation to
                                     * null suffix */
 
     srcLn = NILLNODE;
                                     * null suffix */
 
     srcLn = NILLNODE;
@@ -400,7 +450,7 @@ SuffParseTransform(str, srcPtr, targPtr)
      * we can find two that meet these criteria, we've successfully
      * parsed the string.
      */
      * we can find two that meet these criteria, we've successfully
      * parsed the string.
      */
-    while (1) {
+    for (;;) {
        if (srcLn == NILLNODE) {
            srcLn = Lst_Find(sufflist, (ClientData)str, SuffSuffIsPrefix);
        } else {
        if (srcLn == NILLNODE) {
            srcLn = Lst_Find(sufflist, (ClientData)str, SuffSuffIsPrefix);
        } else {
@@ -854,14 +904,6 @@ Suff_AddLib (sname)
 }
 
          /********** Implicit Source Search Functions *********/
 }
 
          /********** Implicit Source Search Functions *********/
-/*
- * A structure for passing more than one argument to the Lst-library-invoked
- * function...
- */
-typedef struct {
-    Lst            l;
-    Src            *s;
-} LstSrc;
 
 /*-
  *-----------------------------------------------------------------------
 
 /*-
  *-----------------------------------------------------------------------
@@ -1053,7 +1095,7 @@ SuffFindCmds (targ)
     while ((ln = Lst_Next (t->children)) != NILLNODE) {
        s = (GNode *)Lst_Datum (ln);
 
     while ((ln = Lst_Next (t->children)) != NILLNODE) {
        s = (GNode *)Lst_Datum (ln);
 
-       cp = rindex (s->name, '/');
+       cp = strrchr (s->name, '/');
        if (cp == (char *)NULL) {
            cp = s->name;
        } else {
        if (cp == (char *)NULL) {
            cp = s->name;
        } else {
@@ -1142,11 +1184,11 @@ SuffExpandChildren(cgn, pgn)
      * to later since the resulting words are tacked on to the end of
      * the children list.
      */
      * to later since the resulting words are tacked on to the end of
      * the children list.
      */
-    if (index(cgn->name, '$') != (char *)NULL) {
+    if (strchr(cgn->name, '$') != (char *)NULL) {
        if (DEBUG(SUFF)) {
            printf("Expanding \"%s\"...", cgn->name);
        }
        if (DEBUG(SUFF)) {
            printf("Expanding \"%s\"...", cgn->name);
        }
-       cp = Var_Subst(cgn->name, pgn, TRUE);
+       cp = Var_Subst(NULL, cgn->name, pgn, TRUE);
 
        if (cp != (char *)NULL) {
            Lst     members = Lst_Init(FALSE);
 
        if (cp != (char *)NULL) {
            Lst     members = Lst_Init(FALSE);
@@ -1171,9 +1213,8 @@ SuffExpandChildren(cgn, pgn)
                char        *start;
                char        *initcp = cp;   /* For freeing... */
 
                char        *start;
                char        *initcp = cp;   /* For freeing... */
 
-               for (start = cp; *start == ' ' || *start == '\t'; start++) {
-                   ;
-               }
+               for (start = cp; *start == ' ' || *start == '\t'; start++) 
+                   continue;
                for (cp = start; *cp != '\0'; cp++) {
                    if (*cp == ' ' || *cp == '\t') {
                        /*
                for (cp = start; *cp != '\0'; cp++) {
                    if (*cp == ' ' || *cp == '\t') {
                        /*
@@ -1480,7 +1521,6 @@ SuffFindArchiveDeps(gn)
     };
     char       *vals[sizeof(copy)/sizeof(copy[0])];
     int                i;          /* Index into copy and vals */
     };
     char       *vals[sizeof(copy)/sizeof(copy[0])];
     int                i;          /* Index into copy and vals */
-    char       *cp;        /* Suffix for member */
     Suff       *ms;        /* Suffix descriptor for member */
     char       *name;      /* Start of member's name */
     
     Suff       *ms;        /* Suffix descriptor for member */
     char       *name;      /* Start of member's name */
     
@@ -1488,8 +1528,8 @@ SuffFindArchiveDeps(gn)
      * The node is an archive(member) pair. so we must find a
      * suffix for both of them.
      */
      * The node is an archive(member) pair. so we must find a
      * suffix for both of them.
      */
-    eoarch = index (gn->name, '(');
-    eoname = index (eoarch, ')');
+    eoarch = strchr (gn->name, '(');
+    eoname = strchr (eoarch, ')');
 
     *eoname = '\0';      /* Nuke parentheses during suffix search */
     *eoarch = '\0';      /* So a suffix can be found */
 
     *eoname = '\0';      /* Nuke parentheses during suffix search */
     *eoarch = '\0';      /* So a suffix can be found */
@@ -1609,7 +1649,6 @@ SuffFindNormalDeps(gn)
 {
     char       *eoname;    /* End of name */
     char       *sopref;    /* Start of prefix */
 {
     char       *eoname;    /* End of name */
     char       *sopref;    /* Start of prefix */
-    Suff       *s;         /* Current suffix */
     LstNode    ln;         /* Next suffix node to check */
     Lst                srcs;       /* List of sources at which to look */
     Lst                targs;      /* List of targets to which things can be
     LstNode    ln;         /* Next suffix node to check */
     Lst                srcs;       /* List of sources at which to look */
     Lst                targs;      /* List of targets to which things can be
@@ -1675,7 +1714,7 @@ SuffFindNormalDeps(gn)
             */
            prefLen = (eoname - targ->suff->nameLen) - sopref;
            targ->pref = emalloc(prefLen + 1);
             */
            prefLen = (eoname - targ->suff->nameLen) - sopref;
            targ->pref = emalloc(prefLen + 1);
-           bcopy(sopref, targ->pref, prefLen);
+           memcpy(targ->pref, sopref, prefLen);
            targ->pref[prefLen] = '\0';
 
            /*
            targ->pref[prefLen] = '\0';
 
            /*
@@ -1735,9 +1774,8 @@ SuffFindNormalDeps(gn)
         * Work up the transformation path to find the suffix of the
         * target to which the transformation was made.
         */
         * Work up the transformation path to find the suffix of the
         * target to which the transformation was made.
         */
-       for (targ = bottom; targ->parent != NULL; targ = targ->parent) {
-           ;
-       }
+       for (targ = bottom; targ->parent != NULL; targ = targ->parent)
+           continue;
     }
 
     /*
     }
 
     /*
@@ -2104,19 +2142,19 @@ SuffPrintSuff (s)
                    printf ("LIBRARY");
                    break;
            }
                    printf ("LIBRARY");
                    break;
            }
-           putc(flags ? '|' : ')', stdout);
+           fputc(flags ? '|' : ')', stdout);
        }
     }
        }
     }
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     printf ("#\tTo: ");
     Lst_ForEach (s->parents, SuffPrintName, (ClientData)0);
     printf ("#\tTo: ");
     Lst_ForEach (s->parents, SuffPrintName, (ClientData)0);
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     printf ("#\tFrom: ");
     Lst_ForEach (s->children, SuffPrintName, (ClientData)0);
     printf ("#\tFrom: ");
     Lst_ForEach (s->children, SuffPrintName, (ClientData)0);
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     printf ("#\tSearch Path: ");
     Dir_PrintPath (s->searchPath);
     printf ("#\tSearch Path: ");
     Dir_PrintPath (s->searchPath);
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     return (0);
 }
 
     return (0);
 }
 
@@ -2128,12 +2166,13 @@ SuffPrintTrans (t)
 
     printf ("%-16s: ", t->name);
     Targ_PrintType (t->type);
 
     printf ("%-16s: ", t->name);
     Targ_PrintType (t->type);
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     Lst_ForEach (t->commands, Targ_PrintCmd, (ClientData)0);
     Lst_ForEach (t->commands, Targ_PrintCmd, (ClientData)0);
-    putc ('\n', stdout);
+    fputc ('\n', stdout);
     return(0);
 }
 
     return(0);
 }
 
+void
 Suff_PrintAll()
 {
     printf ("#*** Suffixes:\n");
 Suff_PrintAll()
 {
     printf ("#*** Suffixes:\n");
@@ -2142,4 +2181,3 @@ Suff_PrintAll()
     printf ("#*** Transformations:\n");
     Lst_ForEach (transforms, SuffPrintTrans, (ClientData)0);
 }
     printf ("#*** Transformations:\n");
     Lst_ForEach (transforms, SuffPrintTrans, (ClientData)0);
 }
-