Ignore:
Timestamp:
Nov 26, 2002, 10:24:54 PM (23 years ago)
Author:
bird
Message:

Import of RELENG_4_7_0_RELEASE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/kmk/arch.c

    r8 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)arch.c   8.2 (Berkeley) 1/2/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/arch.c,v 1.32 2002/10/09 03:42:09 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)arch.c      8.2 (Berkeley) 1/2/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/arch.c,v 1.15.2.1 2001/02/13 03:13:57 will Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    114118} Arch;
    115119
    116 static int ArchFindArchive(void *, void *);
    117 static void ArchFree(void *);
    118 static struct ar_hdr *ArchStatMember(char *, char *, Boolean);
    119 static FILE *ArchFindMember(char *, char *, struct ar_hdr *, char *);
     120static int ArchFindArchive __P((ClientData, ClientData));
     121static void ArchFree __P((ClientData));
     122static struct ar_hdr *ArchStatMember __P((char *, char *, Boolean));
     123static FILE *ArchFindMember __P((char *, char *, struct ar_hdr *, char *));
    120124#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
    121 #define SVR4ARCHIVES
    122 static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
     125#define SVR4ARCHIVES
     126static int ArchSVR4Entry __P((Arch *, char *, size_t, FILE *));
    123127#endif
    124128
     
    137141 */
    138142static void
    139 ArchFree(void *ap)
     143ArchFree(ap)
     144    ClientData ap;
    140145{
    141146    Arch *a = (Arch *) ap;
     
    147152         entry != NULL;
    148153         entry = Hash_EnumNext(&search))
    149         free(Hash_GetValue(entry));
     154        free((Address) Hash_GetValue (entry));
    150155
    151156    free(a->name);
    152157    efree(a->fnametab);
    153158    Hash_DeleteTable(&a->members);
    154     free(a);
     159    free((Address) a);
    155160}
    156161
     
    162167 *      Parse the archive specification in the given line and find/create
    163168 *      the nodes for the specified archive members, placing their nodes
    164  *      on the given list, given the pointer to the start of the
    165  *      specification, a Lst on which to place the nodes, and a context
    166  *      in which to expand variables.
     169 *      on the given list.
    167170 *
    168171 * Results:
     
    177180 */
    178181ReturnStatus
    179 Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt)
    180 {
    181     char            *cp;            /* Pointer into line */
     182Arch_ParseArchive (linePtr, nodeLst, ctxt)
     183    char            **linePtr;      /* Pointer to start of specification */
     184    Lst             nodeLst;        /* Lst on which to place the nodes */
     185    GNode           *ctxt;          /* Context in which to expand variables */
     186{
     187    register char   *cp;            /* Pointer into line */
    182188    GNode           *gn;            /* New node */
    183189    char            *libName;       /* Library-part of specification */
     
    230236        Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */
    231237
    232         while (*cp != '\0' && *cp != ')' && isspace ((unsigned char) *cp)) {
     238        while (*cp != '\0' && *cp != ')' && isspace (*cp)) {
    233239            cp++;
    234240        }
    235241        memName = cp;
    236         while (*cp != '\0' && *cp != ')' && !isspace ((unsigned char) *cp)) {
     242        while (*cp != '\0' && *cp != ')' && !isspace (*cp)) {
    237243            if (*cp == '$') {
    238244                /*
     
    305311             * are just placed at the end of the nodeLst we're returning.
    306312             */
    307 
    308313            sz = strlen(memName) + strlen(libName) + 3;
    309314            buf = sacrifice = emalloc(sz);
    310 
    311315            snprintf(buf, sz, "%s(%s)", libName, memName);
    312316
     
    319323                gn = Targ_FindNode(buf, TARG_CREATE);
    320324
    321                 if (gn == NULL) {
     325                if (gn == NILGNODE) {
    322326                    free(buf);
    323327                    return(FAILURE);
    324328                } else {
    325329                    gn->type |= OP_ARCHV;
    326                     (void)Lst_AtEnd(nodeLst, (void *)gn);
     330                    (void)Lst_AtEnd(nodeLst, (ClientData)gn);
    327331                }
    328332            } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) {
     
    355359                free(member);
    356360                gn = Targ_FindNode (nameBuf, TARG_CREATE);
    357                 if (gn == NULL) {
     361                if (gn == NILGNODE) {
    358362                    free(nameBuf);
    359363                    return (FAILURE);
     
    367371                     */
    368372                    gn->type |= OP_ARCHV;
    369                     (void) Lst_AtEnd (nodeLst, (void *)gn);
     373                    (void) Lst_AtEnd (nodeLst, (ClientData)gn);
    370374                }
    371375            }
     
    378382            gn = Targ_FindNode (nameBuf, TARG_CREATE);
    379383            free(nameBuf);
    380             if (gn == NULL) {
     384            if (gn == NILGNODE) {
    381385                return (FAILURE);
    382386            } else {
     
    389393                 */
    390394                gn->type |= OP_ARCHV;
    391                 (void) Lst_AtEnd (nodeLst, (void *)gn);
     395                (void) Lst_AtEnd (nodeLst, (ClientData)gn);
    392396            }
    393397        }
     
    413417    do {
    414418        cp++;
    415     } while (*cp != '\0' && isspace ((unsigned char) *cp));
     419    } while (*cp != '\0' && isspace (*cp));
    416420
    417421    *linePtr = cp;
     
    423427 * ArchFindArchive --
    424428 *      See if the given archive is the one we are looking for. Called
    425  *      From ArchStatMember and ArchFindMember via Lst_Find with the
    426  *      current list element and the name we want.
     429 *      From ArchStatMember and ArchFindMember via Lst_Find.
    427430 *
    428431 * Results:
     
    435438 */
    436439static int
    437 ArchFindArchive (void *ar, void *archName)
     440ArchFindArchive (ar, archName)
     441    ClientData    ar;             /* Current list element */
     442    ClientData    archName;       /* Name we want */
    438443{
    439444    return (strcmp ((char *) archName, ((Arch *) ar)->name));
     
    444449 * ArchStatMember --
    445450 *      Locate a member of an archive, given the path of the archive and
    446  *      the path of the desired member, and a boolean representing whether
    447  *      or not the archive should be hashed (if not already hashed).
     451 *      the path of the desired member.
    448452 *
    449453 * Results:
     
    459463 */
    460464static struct ar_hdr *
    461 ArchStatMember (char *archive, char *member, Boolean hash)
    462 {
    463 #define AR_MAX_NAME_LEN     (sizeof(arh.ar_name)-1)
     465ArchStatMember (archive, member, hash)
     466    char          *archive;   /* Path to the archive */
     467    char          *member;    /* Name of member. If it is a path, only the
     468                               * last component is used. */
     469    Boolean       hash;       /* TRUE if archive should be hashed if not
     470                               * already so. */
     471{
     472#define AR_MAX_NAME_LEN     (sizeof(arh.ar_name)-1)
    464473    FILE *        arch;       /* Stream to archive */
    465474    int           size;       /* Size of archive member */
     
    483492        member = cp + 1;
    484493
    485     ln = Lst_Find (archives, (void *) archive, ArchFindArchive);
    486     if (ln != NULL) {
     494    ln = Lst_Find (archives, (ClientData) archive, ArchFindArchive);
     495    if (ln != NILLNODE) {
    487496        ar = (Arch *) Lst_Datum (ln);
    488497
     
    494503            /* Try truncated name */
    495504            char copy[AR_MAX_NAME_LEN+1];
    496             size_t len = strlen (member);
     505            int len = strlen (member);
    497506
    498507            if (len > AR_MAX_NAME_LEN) {
     
    615624                memName[elen] = '\0';
    616625                fseek (arch, -elen, SEEK_CUR);
    617                 /* XXX Multiple levels may be asked for, make this conditional
    618                  * on one, and use DEBUGF.
    619                  */
    620626                if (DEBUG(ARCH) || DEBUG(MAKE)) {
    621                     fprintf(stderr, "ArchStat: Extended format entry for %s\n", memName);
     627                    printf("ArchStat: Extended format entry for %s\n", memName);
    622628                }
    623629            }
     
    625631
    626632            he = Hash_CreateEntry (&ar->members, memName, NULL);
    627             Hash_SetValue (he, (void *)emalloc (sizeof (struct ar_hdr)));
    628             memcpy (Hash_GetValue (he), &arh,
     633            Hash_SetValue (he, (ClientData)emalloc (sizeof (struct ar_hdr)));
     634            memcpy ((Address)Hash_GetValue (he), (Address)&arh,
    629635                sizeof (struct ar_hdr));
    630636        }
     
    634640    fclose (arch);
    635641
    636     (void) Lst_AtEnd (archives, (void *) ar);
     642    (void) Lst_AtEnd (archives, (ClientData) ar);
    637643
    638644    /*
     
    652658    Hash_DeleteTable (&ar->members);
    653659    efree(ar->fnametab);
    654     free (ar);
     660    free ((Address)ar);
    655661    return (NULL);
    656662}
     
    678684 */
    679685static int
    680 ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch)
    681 {
    682 #define ARLONGNAMES1 "//"
    683 #define ARLONGNAMES2 "/ARFILENAMES"
     686ArchSVR4Entry(ar, name, size, arch)
     687        Arch *ar;
     688        char *name;
     689        size_t size;
     690        FILE *arch;
     691{
     692#define ARLONGNAMES1 "//"
     693#define ARLONGNAMES2 "/ARFILENAMES"
    684694    size_t entry;
    685695    char *ptr, *eptr;
     
    689699
    690700        if (ar->fnametab != NULL) {
    691             DEBUGF(ARCH, ("Attempted to redefine an SVR4 name table\n"));
     701            if (DEBUG(ARCH)) {
     702                printf("Attempted to redefine an SVR4 name table\n");
     703            }
    692704            return -1;
    693705        }
     
    701713
    702714        if (fread(ar->fnametab, size, 1, arch) != 1) {
    703             DEBUGF(ARCH, ("Reading an SVR4 name table failed\n"));
     715            if (DEBUG(ARCH)) {
     716                printf("Reading an SVR4 name table failed\n");
     717            }
    704718            return -1;
    705719        }
     
    718732                break;
    719733            }
    720         DEBUGF(ARCH, ("Found svr4 archive name table with %zu entries\n", entry));
     734        if (DEBUG(ARCH)) {
     735            printf("Found svr4 archive name table with %d entries\n", entry);
     736        }
    721737        return 0;
    722738    }
     
    727743    entry = (size_t) strtol(&name[1], &eptr, 0);
    728744    if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
    729         DEBUGF(ARCH, ("Could not parse SVR4 name %s\n", name));
     745        if (DEBUG(ARCH)) {
     746            printf("Could not parse SVR4 name %s\n", name);
     747        }
    730748        return 2;
    731749    }
    732750    if (entry >= ar->fnamesize) {
    733         DEBUGF(ARCH, ("SVR4 entry offset %s is greater than %zu\n",
    734                name, ar->fnamesize));
     751        if (DEBUG(ARCH)) {
     752            printf("SVR4 entry offset %s is greater than %d\n",
     753                   name, ar->fnamesize);
     754        }
    735755        return 2;
    736756    }
    737757
    738     DEBUGF(ARCH, ("Replaced %s with %s\n", name, &ar->fnametab[entry]));
     758    if (DEBUG(ARCH)) {
     759        printf("Replaced %s with %s\n", name, &ar->fnametab[entry]);
     760    }
    739761
    740762    (void) strncpy(name, &ar->fnametab[entry], MAXPATHLEN);
     
    750772 *      Locate a member of an archive, given the path of the archive and
    751773 *      the path of the desired member. If the archive is to be modified,
    752  *      the mode should be "r+", if not, it should be "r".  arhPtr is a
    753  *      poitner to the header structure to fill in.
     774 *      the mode should be "r+", if not, it should be "r".
    754775 *
    755776 * Results:
     
    764785 */
    765786static FILE *
    766 ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode)
     787ArchFindMember (archive, member, arhPtr, mode)
     788    char          *archive;   /* Path to the archive */
     789    char          *member;    /* Name of member. If it is a path, only the
     790                               * last component is used. */
     791    struct ar_hdr *arhPtr;    /* Pointer to header structure to be filled in */
     792    char          *mode;      /* The mode for opening the stream */
    767793{
    768794    FILE *        arch;       /* Stream to archive */
     
    770796    char          *cp;        /* Useful character pointer */
    771797    char          magic[SARMAG];
    772     size_t        len, tlen;
     798    int           len, tlen;
    773799
    774800    arch = fopen (archive, mode);
     
    853879                }
    854880                ename[elen] = '\0';
    855                 /*
    856                  * XXX choose one.
    857                  */
    858881                if (DEBUG(ARCH) || DEBUG(MAKE)) {
    859882                    printf("ArchFind: Extended format entry for %s\n", ename);
     
    907930 */
    908931void
    909 Arch_Touch (GNode *gn)
     932Arch_Touch (gn)
     933    GNode         *gn;    /* Node of member to touch */
    910934{
    911935    FILE *        arch;   /* Stream open to archive, positioned properly */
     
    942966 */
    943967void
    944 Arch_TouchLib (GNode *gn)
     968Arch_TouchLib (gn)
     969    GNode           *gn;        /* The node of the library to touch */
    945970{
    946971#ifdef RANLIBMAG
     
    965990 *-----------------------------------------------------------------------
    966991 * Arch_MTime --
    967  *      Return the modification time of a member of an archive, given its
    968  *      name.
     992 *      Return the modification time of a member of an archive.
    969993 *
    970994 * Results:
     
    9781002 */
    9791003int
    980 Arch_MTime(GNode *gn)
     1004Arch_MTime (gn)
     1005    GNode         *gn;        /* Node describing archive member */
    9811006{
    9821007    struct ar_hdr *arhPtr;    /* Header of desired member */
     
    10151040 */
    10161041int
    1017 Arch_MemMTime (GNode *gn)
     1042Arch_MemMTime (gn)
     1043    GNode         *gn;
    10181044{
    10191045    LstNode       ln;
     
    10261052        return (0);
    10271053    }
    1028     while ((ln = Lst_Next (gn->parents)) != NULL) {
     1054    while ((ln = Lst_Next (gn->parents)) != NILLNODE) {
    10291055        pgn = (GNode *) Lst_Datum (ln);
    10301056
     
    10621088 *-----------------------------------------------------------------------
    10631089 * Arch_FindLib --
    1064  *      Search for a named library along the given search path.
     1090 *      Search for a library along the given search path.
    10651091 *
    10661092 * Results:
     
    10801106 */
    10811107void
    1082 Arch_FindLib (GNode *gn, Lst path)
     1108Arch_FindLib (gn, path)
     1109    GNode           *gn;              /* Node of library to find */
     1110    Lst             path;             /* Search path */
    10831111{
    10841112    char            *libName;   /* file name for archive */
     
    11041132 * Arch_LibOODate --
    11051133 *      Decide if a node with the OP_LIB attribute is out-of-date. Called
    1106  *      from Make_OODate to make its life easier, with the library's
    1107  *      graph node.
     1134 *      from Make_OODate to make its life easier.
    11081135 *
    11091136 *      There are several ways for a library to be out-of-date that are
     
    11381165 */
    11391166Boolean
    1140 Arch_LibOODate (GNode *gn)
     1167Arch_LibOODate (gn)
     1168    GNode         *gn;          /* The library's graph node */
    11411169{
    11421170    Boolean       oodate;
     
    11561184            modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10);
    11571185
    1158             /* XXX choose one. */
    11591186            if (DEBUG(ARCH) || DEBUG(MAKE)) {
    11601187                printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
     
    11911218 */
    11921219void
    1193 Arch_Init (void)
     1220Arch_Init ()
    11941221{
    11951222    archives = Lst_Init (FALSE);
     
    12121239 */
    12131240void
    1214 Arch_End (void)
     1241Arch_End ()
    12151242{
    12161243    Lst_Destroy(archives, ArchFree);
Note: See TracChangeset for help on using the changeset viewer.