386BSD 0.1 development
[unix-history] / usr / src / usr.bin / make / arch.c
index 64483a8..ad5a603 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[] = "@(#)arch.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)arch.c     5.7 (Berkeley) 12/28/90";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -70,12 +86,13 @@ static char sccsid[] = "@(#)arch.c  5.3 (Berkeley) %G%";
  *     Arch_Init               Initialize this module.
  */
 
  *     Arch_Init               Initialize this module.
  */
 
-#include    <stdio.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
 #include    <sys/time.h>
 #include    <ctype.h>
 #include    <ar.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
 #include    <sys/time.h>
 #include    <ctype.h>
 #include    <ar.h>
+#include <ranlib.h>
+#include    <stdio.h>
 #include    "make.h"
 #include    "hash.h"
 
 #include    "make.h"
 #include    "hash.h"
 
@@ -237,7 +254,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
             * variables and multi-word variable values.... The results
             * are just placed at the end of the nodeLst we're returning.
             */
             * variables and multi-word variable values.... The results
             * are just placed at the end of the nodeLst we're returning.
             */
-           buf=sacrifice=(char *)malloc(strlen(memName)+strlen(libName)+3);
+           buf = sacrifice = emalloc(strlen(memName)+strlen(libName)+3);
 
            sprintf(buf, "%s(%s)", libName, memName);
 
 
            sprintf(buf, "%s(%s)", libName, memName);
 
@@ -426,7 +443,7 @@ ArchStatMember (archive, member, hash)
     if (ln != NILLNODE) {
        ar = (Arch *) Lst_Datum (ln);
 
     if (ln != NILLNODE) {
        ar = (Arch *) Lst_Datum (ln);
 
-       he = Hash_FindEntry (&ar->members, (Address) member);
+       he = Hash_FindEntry (&ar->members, member);
 
        if (he != (Hash_Entry *) NULL) {
            return ((struct ar_hdr *) Hash_GetValue (he));
 
        if (he != (Hash_Entry *) NULL) {
            return ((struct ar_hdr *) Hash_GetValue (he));
@@ -474,9 +491,9 @@ ArchStatMember (archive, member, hash)
            return ((struct ar_hdr *) NULL);
     }
 
            return ((struct ar_hdr *) NULL);
     }
 
-    ar = (Arch *) malloc (sizeof (Arch));
+    ar = (Arch *)emalloc (sizeof (Arch));
     ar->name = strdup (archive);
     ar->name = strdup (archive);
-    Hash_InitTable (&ar->members, -1, HASH_STRING_KEYS);
+    Hash_InitTable (&ar->members, -1);
     memName[AR_MAX_NAME_LEN] = '\0';
     
     while (fread ((char *)&arh, sizeof (struct ar_hdr), 1, arch) == 1) {
     memName[AR_MAX_NAME_LEN] = '\0';
     
     while (fread ((char *)&arh, sizeof (struct ar_hdr), 1, arch) == 1) {
@@ -498,7 +515,7 @@ ArchStatMember (archive, member, hash)
 
            he = Hash_CreateEntry (&ar->members, strdup (memName),
                                   (Boolean *)NULL);
 
            he = Hash_CreateEntry (&ar->members, strdup (memName),
                                   (Boolean *)NULL);
-           Hash_SetValue (he, (ClientData)malloc (sizeof (struct ar_hdr)));
+           Hash_SetValue (he, (ClientData)emalloc (sizeof (struct ar_hdr)));
            bcopy ((Address)&arh, (Address)Hash_GetValue (he), 
                sizeof (struct ar_hdr));
        }
            bcopy ((Address)&arh, (Address)Hash_GetValue (he), 
                sizeof (struct ar_hdr));
        }
@@ -521,7 +538,7 @@ ArchStatMember (archive, member, hash)
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
-    he = Hash_FindEntry (&ar->members, (Address) member);
+    he = Hash_FindEntry (&ar->members, member);
 
     if (he != (Hash_Entry *) NULL) {
        return ((struct ar_hdr *) Hash_GetValue (he));
 
     if (he != (Hash_Entry *) NULL) {
        return ((struct ar_hdr *) Hash_GetValue (he));
@@ -685,7 +702,7 @@ Arch_Touch (gn)
  *     None.
  *
  * Side Effects:
  *     None.
  *
  * Side Effects:
- *     Both the modification time of the library and of the LIBTOC
+ *     Both the modification time of the library and of the RANLIBMAG
  *     member are set to 'now'.
  *
  *-----------------------------------------------------------------------
  *     member are set to 'now'.
  *
  *-----------------------------------------------------------------------
@@ -698,7 +715,7 @@ Arch_TouchLib (gn)
     struct ar_hdr   arh;       /* Header describing table of contents */
     struct timeval  times[2];  /* Times for utimes() call */
 
     struct ar_hdr   arh;       /* Header describing table of contents */
     struct timeval  times[2];  /* Times for utimes() call */
 
-    arch = ArchFindMember (gn->path, LIBTOC, &arh, "r+");
+    arch = ArchFindMember (gn->path, RANLIBMAG, &arh, "r+");
     sprintf(arh.ar_date, "%-12d", now);
 
     if (arch != (FILE *) NULL) {
     sprintf(arh.ar_date, "%-12d", now);
 
     if (arch != (FILE *) NULL) {
@@ -832,7 +849,7 @@ Arch_FindLib (gn, path)
 {
     char           *libName;   /* file name for archive */
 
 {
     char           *libName;   /* file name for archive */
 
-    libName = (char *)malloc (strlen (gn->name) + 6 - 2);
+    libName = (char *)emalloc (strlen (gn->name) + 6 - 2);
     sprintf(libName, "lib%s.a", &gn->name[2]);
 
     gn->path = Dir_FindFile (libName, path);
     sprintf(libName, "lib%s.a", &gn->name[2]);
 
     gn->path = Dir_FindFile (libName, path);
@@ -866,7 +883,7 @@ Arch_FindLib (gn, path)
  *               make began (i.e. it's been modified in the course
  *               of the make, probably by archiving).
  *         Its modification time doesn't agree with the modification
  *               make began (i.e. it's been modified in the course
  *               of the make, probably by archiving).
  *         Its modification time doesn't agree with the modification
- *               time of its LIBTOC member (i.e. its table of contents
+ *               time of its RANLIBMAG member (i.e. its table of contents
  *               is out-of-date).
  *
  *
  *               is out-of-date).
  *
  *
@@ -892,13 +909,13 @@ Arch_LibOODate (gn)
        struct ar_hdr   *arhPtr;    /* Header for __.SYMDEF */
        int             modTimeTOC; /* The table-of-contents's mod time */
 
        struct ar_hdr   *arhPtr;    /* Header for __.SYMDEF */
        int             modTimeTOC; /* The table-of-contents's mod time */
 
-       arhPtr = ArchStatMember (gn->path, LIBTOC, FALSE);
+       arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
 
        if (arhPtr != (struct ar_hdr *)NULL) {
            (void)sscanf (arhPtr->ar_date, "%12d", &modTimeTOC);
 
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
 
        if (arhPtr != (struct ar_hdr *)NULL) {
            (void)sscanf (arhPtr->ar_date, "%12d", &modTimeTOC);
 
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
-               printf("%s modified %s...", LIBTOC, Targ_FmtTime(modTimeTOC));
+               printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
            }
            oodate = (gn->mtime > modTimeTOC);
        } else {
            }
            oodate = (gn->mtime > modTimeTOC);
        } else {