386BSD 0.1 development
[unix-history] / usr / src / usr.bin / make / arch.c
index 8ca6183..ad5a603 100644 (file)
@@ -1,19 +1,49 @@
+/*
+ * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
+ * Copyright (c) 1988, 1989 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, 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
+static char sccsid[] = "@(#)arch.c     5.7 (Berkeley) 12/28/90";
+#endif /* not lint */
+
 /*-
  * arch.c --
  *     Functions to manipulate libraries, archives and their members.
  *
 /*-
  * arch.c --
  *     Functions to manipulate libraries, archives and their members.
  *
- * Copyright (c) 1988, 1989 by the Regents of the University of California
- * Copyright (c) 1988, 1989 by Adam de Boor
- * Copyright (c) 1989 by Berkeley Softworks
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any non-commercial purpose
- * and without fee is hereby granted, provided that the above copyright
- * notice appears in all copies.  The University of California,
- * Berkeley Softworks and Adam de Boor make no representations about
- * the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
  *     Once again, cacheing/hashing comes into play in the manipulation
  * of archives. The first time an archive is referenced, all of its members'
  * headers are read and hashed and the archive closed again. All hashed
  *     Once again, cacheing/hashing comes into play in the manipulation
  * of archives. The first time an archive is referenced, all of its members'
  * headers are read and hashed and the archive closed again. All hashed
  *
  *     Arch_Init               Initialize this module.
  */
  *
  *     Arch_Init               Initialize this module.
  */
-#ifndef lint
-static char *rcsid = "$Id: arch.c,v 1.20 89/11/14 13:43:37 adam Exp $ SPRITE (Berkeley)";
-#endif lint
 
 
-#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"
 
@@ -77,7 +105,7 @@ typedef struct Arch {
 } Arch;
 
 static FILE *ArchFindMember();
 } Arch;
 
 static FILE *ArchFindMember();
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
@@ -226,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);
 
@@ -326,7 +354,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
     *linePtr = cp;
     return (SUCCESS);
 }
     *linePtr = cp;
     return (SUCCESS);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
@@ -348,7 +376,7 @@ ArchFindArchive (ar, archName)
 {
     return (strcmp (archName, ar->name));
 }
 {
     return (strcmp (archName, ar->name));
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
@@ -415,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));
@@ -463,9 +491,9 @@ ArchStatMember (archive, member, hash)
            return ((struct ar_hdr *) NULL);
     }
 
            return ((struct ar_hdr *) NULL);
     }
 
-    ar = (Arch *) malloc (sizeof (Arch));
-    ar->name = Str_New (archive);
-    Hash_InitTable (&ar->members, -1, HASH_STRING_KEYS);
+    ar = (Arch *)emalloc (sizeof (Arch));
+    ar->name = strdup (archive);
+    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) {
@@ -485,9 +513,9 @@ ArchStatMember (archive, member, hash)
            }
            cp[1] = '\0';
 
            }
            cp[1] = '\0';
 
-           he = Hash_CreateEntry (&ar->members, Str_New (memName),
+           he = Hash_CreateEntry (&ar->members, strdup (memName),
                                   (Boolean *)NULL);
                                   (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));
        }
@@ -510,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));
@@ -518,7 +546,7 @@ ArchStatMember (archive, member, hash)
        return ((struct ar_hdr *) NULL);
     }
 }
        return ((struct ar_hdr *) NULL);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
@@ -630,7 +658,7 @@ ArchFindMember (archive, member, arhPtr, mode)
     fclose (arch);
     return ((FILE *) NULL);
 }
     fclose (arch);
     return ((FILE *) NULL);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
@@ -663,7 +691,7 @@ Arch_Touch (gn)
        fclose (arch);
     }
 }
        fclose (arch);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
@@ -674,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'.
  *
  *-----------------------------------------------------------------------
@@ -687,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) {
@@ -699,7 +727,7 @@ Arch_TouchLib (gn)
        utimes(gn->path, times);
     }
 }
        utimes(gn->path, times);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
@@ -733,7 +761,7 @@ Arch_MTime (gn)
     gn->mtime = modTime;
     return (modTime);
 }
     gn->mtime = modTime;
     return (modTime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
@@ -793,7 +821,7 @@ Arch_MemMTime (gn)
 
     return (gn->mtime);
 }
 
     return (gn->mtime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
@@ -821,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);
@@ -834,7 +862,7 @@ Arch_FindLib (gn, path)
     Var_Set (TARGET, gn->path == (char *) NULL ? gn->name : gn->path, gn);
 #endif LIBRARIES
 }
     Var_Set (TARGET, gn->path == (char *) NULL ? gn->name : gn->path, gn);
 #endif LIBRARIES
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_LibOODate --
 /*-
  *-----------------------------------------------------------------------
  * Arch_LibOODate --
@@ -855,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).
  *
  *
@@ -881,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 {
@@ -902,7 +930,7 @@ Arch_LibOODate (gn)
     }
     return (oodate);
 }
     }
     return (oodate);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --