386BSD 0.1 development
[unix-history] / usr / src / usr.bin / make / suff.c
index a8d8a08..ebb7714 100644 (file)
@@ -7,21 +7,37 @@
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
  * 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 the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)suff.c     5.6 (Berkeley) 6/1/90";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -682,7 +698,7 @@ Suff_AddSuffix (str)
 
     ln = Lst_Find (sufflist, (ClientData)str, SuffSuffHasNameP);
     if (ln == NILLNODE) {
 
     ln = Lst_Find (sufflist, (ClientData)str, SuffSuffHasNameP);
     if (ln == NILLNODE) {
-       s = (Suff *) malloc (sizeof (Suff));
+       s = (Suff *) emalloc (sizeof (Suff));
 
        s->name =       strdup (str);
        s->nameLen =    strlen (s->name);
 
        s->name =       strdup (str);
        s->nameLen =    strlen (s->name);
@@ -891,7 +907,7 @@ SuffAddSrc (s, ls)
         * structure for a file with no suffix attached. Two birds, and all
         * that...
         */
         * structure for a file with no suffix attached. Two birds, and all
         * that...
         */
-       s2 = (Src *) malloc (sizeof (Src));
+       s2 = (Src *) emalloc (sizeof (Src));
        s2->file =      strdup(targ->pref);
        s2->pref =      targ->pref;
        s2->parent =    targ;
        s2->file =      strdup(targ->pref);
        s2->pref =      targ->pref;
        s2->parent =    targ;
@@ -901,8 +917,8 @@ SuffAddSrc (s, ls)
        targ->children += 1;
        (void)Lst_AtEnd (ls->l, (ClientData)s2);
     }
        targ->children += 1;
        (void)Lst_AtEnd (ls->l, (ClientData)s2);
     }
-    s2 = (Src *) malloc (sizeof (Src));
-    s2->file =             Str_Concat (targ->pref, s->name, 0);
+    s2 = (Src *) emalloc (sizeof (Src));
+    s2->file =             str_concat (targ->pref, s->name, 0);
     s2->pref =     targ->pref;
     s2->parent =    targ;
     s2->node =             NILGNODE;
     s2->pref =     targ->pref;
     s2->parent =    targ;
     s2->node =             NILGNODE;
@@ -1082,7 +1098,7 @@ SuffFindCmds (targ)
                     * source node's name so Suff_FindDeps can free it
                     * again (ick)), and return the new structure.
                     */
                     * source node's name so Suff_FindDeps can free it
                     * again (ick)), and return the new structure.
                     */
-                   ret = (Src *)malloc (sizeof(Src));
+                   ret = (Src *)emalloc (sizeof(Src));
                    ret->file = strdup(s->name);
                    ret->pref = targ->pref;
                    ret->suff = suff;
                    ret->file = strdup(s->name);
                    ret->pref = targ->pref;
                    ret->suff = suff;
@@ -1162,7 +1178,7 @@ SuffExpandChildren(cgn, pgn)
                /*
                 * Break the result into a vector of strings whose nodes
                 * we can find, then add those nodes to the members list.
                /*
                 * Break the result into a vector of strings whose nodes
                 * we can find, then add those nodes to the members list.
-                * Unfortunately, we can't use Str_BreakString b/c it
+                * Unfortunately, we can't use brk_string b/c it
                 * doesn't understand about variable specifications with
                 * spaces in them...
                 */
                 * doesn't understand about variable specifications with
                 * spaces in them...
                 */
@@ -1285,11 +1301,6 @@ SuffExpandChildren(cgn, pgn)
                printf("suffix is \"%s\"...", s->name);
            }
            path = s->searchPath;
                printf("suffix is \"%s\"...", s->name);
            }
            path = s->searchPath;
-       } else if ((suffNull != (Suff *)NULL) && !amMake) {
-           if (DEBUG(SUFF)) {
-               printf("using .NULL(%s)...", suffNull->name);
-           }
-           path = suffNull->searchPath;
        } else {
            /*
             * Use default search path
        } else {
            /*
             * Use default search path
@@ -1409,7 +1420,7 @@ SuffApplyTransform(tGn, sGn, t, s)
     /*
      * Locate the transformation rule itself
      */
     /*
      * Locate the transformation rule itself
      */
-    tname = Str_Concat(s->name, t->name, 0);
+    tname = str_concat(s->name, t->name, 0);
     ln = Lst_Find(transforms, (ClientData)tname, SuffGNHasNameP);
     free(tname);
 
     ln = Lst_Find(transforms, (ClientData)tname, SuffGNHasNameP);
     free(tname);
 
@@ -1626,24 +1637,7 @@ SuffFindNormalDeps(gn)
 
     eoname = gn->name + strlen(gn->name);
 
 
     eoname = gn->name + strlen(gn->name);
 
-    /*
-     * Figure the start of the prefix: if not in System V or Make mode,
-     * we remove any leading components from the target's name so we can
-     * better search for the source.
-     *
-     * XXX: Use leading components in search if not found elsewhere?
-     */
-    if (!sysVmake && !amMake) {
-       char    *cp = rindex(gn->name, '/');
-
-       if (cp != NULL) {
-           sopref = cp + 1;
-       } else {
-           sopref = gn->name;
-       }
-    } else {
-       sopref = gn->name;
-    }
+    sopref = gn->name;
     
     /*
      * Begin at the beginning...
     
     /*
      * Begin at the beginning...
@@ -1683,7 +1677,7 @@ SuffFindNormalDeps(gn)
            /*
             * Allocate a Src structure to which things can be transformed
             */
            /*
             * Allocate a Src structure to which things can be transformed
             */
-           targ = (Src *)malloc(sizeof(Src));
+           targ = (Src *)emalloc(sizeof(Src));
            targ->file = strdup(gn->name);
            targ->suff = (Suff *)Lst_Datum(ln);
            targ->node = gn;
            targ->file = strdup(gn->name);
            targ->suff = (Suff *)Lst_Datum(ln);
            targ->node = gn;
@@ -1694,7 +1688,7 @@ SuffFindNormalDeps(gn)
             * the length of the suffix from the end of the name.
             */
            prefLen = (eoname - targ->suff->nameLen) - sopref;
             * the length of the suffix from the end of the name.
             */
            prefLen = (eoname - targ->suff->nameLen) - sopref;
-           targ->pref = malloc(prefLen + 1);
+           targ->pref = emalloc(prefLen + 1);
            bcopy(sopref, targ->pref, prefLen);
            targ->pref[prefLen] = '\0';
 
            bcopy(sopref, targ->pref, prefLen);
            targ->pref[prefLen] = '\0';
 
@@ -1723,7 +1717,7 @@ SuffFindNormalDeps(gn)
            printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
        }
        
            printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
        }
        
-       targ = (Src *)malloc(sizeof(Src));
+       targ = (Src *)emalloc(sizeof(Src));
        targ->file = strdup(gn->name);
        targ->suff = suffNull;
        targ->node = gn;
        targ->file = strdup(gn->name);
        targ->suff = suffNull;
        targ->node = gn;
@@ -2082,7 +2076,7 @@ Suff_Init ()
      * actually go on the suffix list or everyone will think that's its
      * suffix.
      */
      * actually go on the suffix list or everyone will think that's its
      * suffix.
      */
-    emptySuff = suffNull = (Suff *) malloc (sizeof (Suff));
+    emptySuff = suffNull = (Suff *) emalloc (sizeof (Suff));
 
     suffNull->name =               strdup ("");
     suffNull->nameLen =     0;
 
     suffNull->name =               strdup ("");
     suffNull->nameLen =     0;