VirtualBox

Changeset 24 in kBuild


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

Import of RELENG_4_7_0_RELEASE

Location:
branches/FREEBSD/src/kmk
Files:
59 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/kmk/Makefile

    r10 r24  
    11#       @(#)Makefile    5.2 (Berkeley) 12/28/90
    2 #       $Id$
    3 # $FreeBSD: src/usr.bin/make/Makefile,v 1.29 2002/10/10 19:27:48 jmallett Exp $
     2# $FreeBSD: src/usr.bin/make/Makefile,v 1.13.2.1 2001/05/25 08:33:40 sobomax Exp $
    43
    54PROG=   make
    6 CFLAGS+=-I${.CURDIR}
     5CFLAGS+= -I${.CURDIR}
    76SRCS=   arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \
    8         make.c parse.c str.c suff.c targ.c util.c var.c
     7        make.c parse.c str.c suff.c targ.c var.c util.c
    98SRCS+=  lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
    109        lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \
     
    1615NOSHARED?=      YES
    1716
    18 CFLAGS+=-DMAKE_VERSION=\"5200209170\"
    19 .if defined(_UPGRADING)
    20 CFLAGS+=-D__FBSDID=__RCSID
    21 .endif
    22 
    23 # XXX: kernel currently broken
    24 # CFLAGS+=-DUSE_KQUEUE
    25 
    26 main.o: ${MAKEFILE}
    27 
    28 # Set the shell which make(1) uses.  Bourne is the default, but a decent
    29 # Korn shell works fine, and much faster.  Using the C shell for this
    30 # will almost certainly break everything, but it's Unix tradition to
    31 # allow you to shoot yourself in the foot if you want to :-)
    32 
    33 MAKE_SHELL?=    sh
    34 .if ${MAKE_SHELL} == "csh"
    35 CFLAGS+=        -DDEFSHELL=0
    36 .elif ${MAKE_SHELL} == "sh"
    37 CFLAGS+=        -DDEFSHELL=1
    38 .elif ${MAKE_SHELL} == "ksh"
    39 CFLAGS+=        -DDEFSHELL=2
    40 .else
    41 .error "MAKE_SHELL must be set to one of \"csh\", \"sh\" or \"ksh\"."
    42 .endif
    43 
    4417.include <bsd.prog.mk>
  • branches/FREEBSD/src/kmk/Makefile.dist

    r10 r24  
    1 # $FreeBSD: src/usr.bin/make/Makefile.dist,v 1.2 2001/03/01 06:26:32 imp Exp $
    21# a very simple makefile...
    32pmake:
    43        @echo 'make started.'
    5         cc -DDEFSHELL=1 -I. -c *.c
     4        cc -I. -c *.c
    65        cd lst.lib; cc -I.. -c *.c
    76        cc *.o lst.lib/*.o -o pmake
  • branches/FREEBSD/src/kmk/PSD.doc/stubs

    r9 r24  
    1 .\" $FreeBSD: src/usr.bin/make/PSD.doc/stubs,v 1.1 2000/11/24 10:05:30 ru Exp $
     1.\" $FreeBSD: src/usr.bin/make/PSD.doc/stubs,v 1.1.2.1 2000/11/24 10:08:45 ru Exp $
    22.\"
    33.de Ix
  • branches/FREEBSD/src/kmk/PSD.doc/tutorial.ms

    r9 r24  
    3636.\"
    3737.\"     @(#)tutorial.ms 8.1 (Berkeley) 8/18/93
    38 .\" $FreeBSD: src/usr.bin/make/PSD.doc/tutorial.ms,v 1.12 2002/05/16 02:19:09 trhodes Exp $
     38.\" $FreeBSD: src/usr.bin/make/PSD.doc/tutorial.ms,v 1.8.2.2 2000/11/24 10:08:45 ru Exp $
    3939.\"
    4040.so stubs
     
    603603.LP
    604604The value of a variable may be retrieved by enclosing the variable
    605 name in parentheses or curly braces and preceding the whole thing
     605name in parentheses or curly braces and preceeding the whole thing
    606606with a dollar sign.
    607607.LP
     
    12441244and various other information on how PMake was configured.
    12451245.Ix 0 ref configuration
    1246 .Ix 0 ref makefilesystem
     1246.Ix 0 ref makefile system
    12471247.IP \fB\-i\fP
    12481248.Ix 0 def flags -i
     
    24012401.CW .h
    24022402suffix is already marked in this way in the system makefile.
    2403 .Ix 0 ref makefilesystem
     2403.Ix 0 ref makefile system
    24042404E.g. if you have
    24052405.DS
     
    26412641You are allowed to use any character except
    26422642colon or exclamation point to separate the two strings. This so-called
    2643 delimiter character may be placed in either string by preceding it
     2643delimiter character may be placed in either string by preceeding it
    26442644with a backslash.
    26452645.IP T
  • 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);
  • branches/FREEBSD/src/kmk/buf.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)buf.c    8.1 (Berkeley) 6/6/93
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/buf.c,v 1.18 2002/10/09 03:42:09 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)buf.c       8.1 (Berkeley) 6/6/93";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/buf.c,v 1.11 1999/09/11 13:08:01 hoek Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/*-
     
    5356
    5457#ifndef max
    55 #define max(a,b)  ((a) > (b) ? (a) : (b))
     58#define max(a,b)  ((a) > (b) ? (a) : (b))
    5659#endif
    5760
     
    6366 *      buffer in case it holds a string.
    6467 */
    65 #define BufExpand(bp,nb) \
     68#define BufExpand(bp,nb) \
    6669        if (bp->left < (nb)+1) {\
    6770            int newSize = (bp)->size + max((nb)+1,BUF_ADD_INC); \
     
    7578        }
    7679
    77 #define BUF_DEF_SIZE    256     /* Default buffer size */
    78 #define BUF_ADD_INC     256     /* Expansion increment when Adding */
    79 #define BUF_UNGET_INC   16      /* Expansion increment when Ungetting */
     80#define BUF_DEF_SIZE    256     /* Default buffer size */
     81#define BUF_ADD_INC     256     /* Expansion increment when Adding */
     82#define BUF_UNGET_INC   16      /* Expansion increment when Ungetting */
    8083
    8184/*-
     
    9396 */
    9497void
    95 Buf_OvAddByte (Buffer bp, int byte)
    96 {
     98Buf_OvAddByte (bp, byte)
     99    register Buffer bp;
     100    int    byte;
     101{
     102    int nbytes = 1;
    97103    bp->left = 0;
    98     BufExpand (bp, 1);
     104    BufExpand (bp, nbytes);
    99105
    100106    *bp->inPtr++ = byte;
     
    122128 */
    123129void
    124 Buf_AddBytes (Buffer bp, int numBytes, const Byte *bytesPtr)
     130Buf_AddBytes (bp, numBytes, bytesPtr)
     131    register Buffer bp;
     132    int     numBytes;
     133    const Byte *bytesPtr;
    125134{
    126135
     
    152161 */
    153162void
    154 Buf_UngetByte (Buffer bp, int byte)
     163Buf_UngetByte (bp, byte)
     164    register Buffer bp;
     165    int    byte;
    155166{
    156167
     
    201212 */
    202213void
    203 Buf_UngetBytes (Buffer bp, int numBytes, Byte *bytesPtr)
     214Buf_UngetBytes (bp, numBytes, bytesPtr)
     215    register Buffer bp;
     216    int     numBytes;
     217    Byte    *bytesPtr;
    204218{
    205219
     
    244258 */
    245259int
    246 Buf_GetByte (Buffer bp)
     260Buf_GetByte (bp)
     261    register Buffer bp;
    247262{
    248263    int     res;
     
    277292 */
    278293int
    279 Buf_GetBytes (Buffer bp, int numBytes, Byte *bytesPtr)
     294Buf_GetBytes (bp, numBytes, bytesPtr)
     295    register Buffer bp;
     296    int     numBytes;
     297    Byte    *bytesPtr;
    280298{
    281299
     
    309327 */
    310328Byte *
    311 Buf_GetAll (Buffer bp, int *numBytesPtr)
     329Buf_GetAll (bp, numBytesPtr)
     330    register Buffer bp;
     331    int     *numBytesPtr;
    312332{
    313333
     
    334354 */
    335355void
    336 Buf_Discard (Buffer bp, int numBytes)
     356Buf_Discard (bp, numBytes)
     357    register Buffer bp;
     358    int     numBytes;
    337359{
    338360
     
    362384 */
    363385int
    364 Buf_Size (Buffer buf)
     386Buf_Size (buf)
     387    Buffer  buf;
    365388{
    366389    return (buf->inPtr - buf->outPtr);
     
    384407 */
    385408Buffer
    386 Buf_Init (int size)
     409Buf_Init (size)
     410    int     size;       /* Initial size for the buffer */
    387411{
    388412    Buffer bp;          /* New Buffer */
     
    405429 *-----------------------------------------------------------------------
    406430 * Buf_Destroy --
    407  *      Destroy a buffer, and optionally free its data, too.
     431 *      Nuke a buffer and all its resources.
    408432 *
    409433 * Results:
     
    416440 */
    417441void
    418 Buf_Destroy (Buffer buf, Boolean freeData)
     442Buf_Destroy (buf, freeData)
     443    Buffer  buf;        /* Buffer to destroy */
     444    Boolean freeData;   /* TRUE if the data should be destroyed as well */
    419445{
    420446
     
    441467 */
    442468void
    443 Buf_ReplaceLastByte (Buffer buf, int byte)
     469Buf_ReplaceLastByte (buf, byte)
     470    Buffer buf; /* buffer to augment */
     471    int byte;   /* byte to be written */
    444472{
    445473    if (buf->inPtr == buf->outPtr)
  • branches/FREEBSD/src/kmk/buf.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)buf.h       8.2 (Berkeley) 4/28/95
    40  * $FreeBSD: src/usr.bin/make/buf.h,v 1.12 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)buf.h 8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/buf.h,v 1.9 1999/08/28 01:03:26 peter Exp $
    4140 */
    4241
     
    4746
    4847#ifndef _BUF_H
    49 #define _BUF_H
     48#define _BUF_H
    5049
    5150#include    "sprite.h"
     
    6665                (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
    6766
    68 #define BUF_ERROR 256
     67#define BUF_ERROR 256
    6968
    70 void Buf_OvAddByte(Buffer, int);
    71 void Buf_AddBytes(Buffer, int, const Byte *);
    72 void Buf_UngetByte(Buffer, int);
    73 void Buf_UngetBytes(Buffer, int, Byte *);
    74 int Buf_GetByte(Buffer);
    75 int Buf_GetBytes(Buffer, int, Byte *);
    76 Byte *Buf_GetAll(Buffer, int *);
    77 void Buf_Discard(Buffer, int);
    78 int Buf_Size(Buffer);
    79 Buffer Buf_Init(int);
    80 void Buf_Destroy(Buffer, Boolean);
    81 void Buf_ReplaceLastByte(Buffer, int);
     69void Buf_OvAddByte __P((Buffer, int));
     70void Buf_AddBytes __P((Buffer, int, const Byte *));
     71void Buf_UngetByte __P((Buffer, int));
     72void Buf_UngetBytes __P((Buffer, int, Byte *));
     73int Buf_GetByte __P((Buffer));
     74int Buf_GetBytes __P((Buffer, int, Byte *));
     75Byte *Buf_GetAll __P((Buffer, int *));
     76void Buf_Discard __P((Buffer, int));
     77int Buf_Size __P((Buffer));
     78Buffer Buf_Init __P((int));
     79void Buf_Destroy __P((Buffer, Boolean));
     80void Buf_ReplaceLastByte __P((Buffer, int));
    8281
    8382#endif /* _BUF_H */
  • branches/FREEBSD/src/kmk/compat.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)compat.c 8.2 (Berkeley) 3/19/94
    4037 */
    4138
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/compat.c,v 1.34 2002/10/09 03:42:09 jmallett Exp $");
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)compat.c    8.2 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/compat.c,v 1.16.2.2 2000/07/01 12:24:21 ps Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/*-
     
    6366#include    <errno.h>
    6467#include    <signal.h>
    65 #include    <unistd.h>
    6668#include    "make.h"
    6769#include    "hash.h"
     
    7880static char         meta[256];
    7981
    80 static GNode        *curTarg = NULL;
     82static GNode        *curTarg = NILGNODE;
    8183static GNode        *ENDNode;
    82 static void CompatInterrupt(int);
    83 static int CompatRunCommand(void *, void *);
    84 static int CompatMake(void *, void *);
    85 static int shellneed(char *);
     84static void CompatInterrupt __P((int));
     85static int CompatRunCommand __P((ClientData, ClientData));
     86static int CompatMake __P((ClientData, ClientData));
    8687
    8788static char *sh_builtin[] = {
     
    105106 */
    106107static void
    107 CompatInterrupt (int signo)
     108CompatInterrupt (signo)
     109    int     signo;
    108110{
    109111    GNode   *gn;
    110112
    111     if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
     113    if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
    112114        char      *p1;
    113115        char      *file = Var_Value (TARGET, curTarg, &p1);
     
    123125        if (signo == SIGINT) {
    124126            gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    125             if (gn != NULL) {
    126                 Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
     127            if (gn != NILGNODE) {
     128                Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    127129            }
    128130        }
     
    150152 */
    151153static int
    152 shellneed (char *cmd)
     154shellneed (cmd)
     155        char *cmd;
    153156{
    154157        char **av, **p;
     
    168171 *      Execute the next command for a target. If the command returns an
    169172 *      error, the node's made field is set to ERROR and creation stops.
    170  *      The node from which the command came is also given.
    171173 *
    172174 * Results:
     
    179181 */
    180182static int
    181 CompatRunCommand (void *cmdp, void *gnp)
     183CompatRunCommand (cmdp, gnp)
     184    ClientData    cmdp;         /* Command to execute */
     185    ClientData    gnp;          /* Node from which the command came */
    182186{
    183187    char          *cmdStart;    /* Start of expanded command */
    184     char          *cp;
     188    register char *cp;
    185189    Boolean       silent,       /* Don't print command */
    186190                  errCheck;     /* Check errors */
     
    188192    int           status;       /* Description of child's death */
    189193    int           cpid;         /* Child actually found */
    190     ReturnStatus  rstat;        /* Status of fork */
     194    ReturnStatus  stat;         /* Status of fork */
    191195    LstNode       cmdNode;      /* Node where current command is located */
    192196    char          **av;         /* Argument vector for thing to exec */
    193197    int           argc;         /* Number of arguments in av or 0 if not
    194198                                 * dynamically allocated */
     199    Boolean       local;        /* TRUE if command should be executed
     200                                 * locally */
    195201    int           internal;     /* Various values.. */
    196202    char          *cmd = (char *) cmdp;
     
    208214    errCheck = !(gn->type & OP_IGNORE);
    209215
    210     cmdNode = Lst_Member (gn->commands, (void *)cmd);
     216    cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
    211217    cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
    212218
     
    225231        cmd = cmdStart;
    226232    }
    227     Lst_Replace (cmdNode, (void *)cmdStart);
     233    Lst_Replace (cmdNode, (ClientData)cmdStart);
    228234
    229235    if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
    230         (void)Lst_AtEnd(ENDNode->commands, (void *)cmdStart);
     236        (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
    231237        return(0);
    232238    } else if (strcmp(cmdStart, "...") == 0) {
     
    315321    }
    316322
     323    local = TRUE;
     324
    317325    /*
    318326     * Fork and execute the single command. If the fork fails, we abort.
     
    323331    }
    324332    if (cpid == 0) {
    325         execvp(av[0], av);
    326         (void) write (STDERR_FILENO, av[0], strlen (av[0]));
    327         (void) write (STDERR_FILENO, ":", 1);
    328         (void) write (STDERR_FILENO, strerror(errno), strlen(strerror(errno)));
    329         (void) write (STDERR_FILENO, "\n", 1);
     333        if (local) {
     334            execvp(av[0], av);
     335            (void) write (2, av[0], strlen (av[0]));
     336            (void) write (2, ":", 1);
     337            (void) write (2, strerror(errno), strlen(strerror(errno)));
     338            (void) write (2, "\n", 1);
     339        } else {
     340            (void)execv(av[0], av);
     341        }
    330342        exit(1);
    331343    }
     
    347359    while (1) {
    348360
    349         while ((rstat = wait(&reason)) != cpid) {
    350             if (rstat == -1 && errno != EINTR) {
     361        while ((stat = wait(&reason)) != cpid) {
     362            if (stat == -1 && errno != EINTR) {
    351363                break;
    352364            }
    353365        }
    354366
    355         if (rstat > -1) {
     367        if (stat > -1) {
    356368            if (WIFSTOPPED(reason)) {
    357369                status = WSTOPSIG(reason);              /* stopped */
     
    388400            break;
    389401        } else {
    390             Fatal ("error in wait: %d", rstat);
     402            Fatal ("error in wait: %d", stat);
    391403            /*NOTREACHED*/
    392404        }
     
    400412 *-----------------------------------------------------------------------
    401413 * CompatMake --
    402  *      Make a target, given the parent, to abort if necessary.
     414 *      Make a target.
    403415 *
    404416 * Results:
     
    411423 */
    412424static int
    413 CompatMake (void *gnp, void *pgnp)
     425CompatMake (gnp, pgnp)
     426    ClientData  gnp;        /* The node to make */
     427    ClientData  pgnp;       /* Parent to abort if necessary */
    414428{
    415429    GNode *gn = (GNode *) gnp;
     
    429443        gn->made = BEINGMADE;
    430444        Suff_FindDeps (gn);
    431         Lst_ForEach (gn->children, CompatMake, (void *)gn);
     445        Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
    432446        if (!gn->make) {
    433447            gn->made = ABORTED;
     
    436450        }
    437451
    438         if (Lst_Member (gn->iParents, pgn) != NULL) {
     452        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    439453            char *p1;
    440454            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
     
    448462         * Make_OODate function.
    449463         */
    450         DEBUGF(MAKE, ("Examining %s...", gn->name));
     464        if (DEBUG(MAKE)) {
     465            printf("Examining %s...", gn->name);
     466        }
    451467        if (! Make_OODate(gn)) {
    452468            gn->made = UPTODATE;
    453             DEBUGF(MAKE, ("up-to-date.\n"));
     469            if (DEBUG(MAKE)) {
     470                printf("up-to-date.\n");
     471            }
    454472            return (0);
    455         } else {
    456             DEBUGF(MAKE, ("out-of-date.\n"));
     473        } else if (DEBUG(MAKE)) {
     474            printf("out-of-date.\n");
    457475        }
    458476
     
    490508            if (!touchFlag) {
    491509                curTarg = gn;
    492                 Lst_ForEach (gn->commands, CompatRunCommand, (void *)gn);
    493                 curTarg = NULL;
     510                Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
     511                curTarg = NILGNODE;
    494512            } else {
    495513                Job_Touch (gn, gn->type & OP_SILENT);
     
    561579            if (gn->cmtime > gn->mtime)
    562580                gn->mtime = gn->cmtime;
    563             DEBUGF(MAKE, ("update time: %s\n", Targ_FmtTime(gn->mtime)));
     581            if (DEBUG(MAKE)) {
     582                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
     583            }
    564584#endif
    565585            if (!(gn->type & OP_EXEC)) {
     
    583603        pgn->make = FALSE;
    584604    } else {
    585         if (Lst_Member (gn->iParents, pgn) != NULL) {
     605        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    586606            char *p1;
    587607            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
     
    617637 *-----------------------------------------------------------------------
    618638 * Compat_Run --
    619  *      Start making again, given a list of target nodes.
     639 *      Initialize this mode and start making.
    620640 *
    621641 * Results:
     
    628648 */
    629649void
    630 Compat_Run(Lst targs)
     650Compat_Run(targs)
     651    Lst           targs;    /* List of target nodes to re-create */
    631652{
    632653    char          *cp;      /* Pointer to string of shell meta-characters */
     
    662683    if (!queryFlag) {
    663684        gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    664         if (gn != NULL) {
    665             Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
     685        if (gn != NILGNODE) {
     686            Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    666687            if (gn->made == ERROR) {
    667688                printf("\n\nStop.\n");
     
    698719     */
    699720    if (errors == 0) {
    700         Lst_ForEach(ENDNode->commands, CompatRunCommand, (void *)gn);
     721        Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
    701722    }
    702723}
  • branches/FREEBSD/src/kmk/cond.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)cond.c   8.2 (Berkeley) 1/2/94
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/cond.c,v 1.24 2002/10/09 03:42:09 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)cond.c      8.2 (Berkeley) 1/2/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/cond.c,v 1.12 1999/09/11 13:08:01 hoek Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/*-
     
    97100 * last two fields are stored in condInvert and condDefProc, respectively.
    98101 */
    99 static void CondPushBack(Token);
    100 static int CondGetArg(char **, char **, char *, Boolean);
    101 static Boolean CondDoDefined(int, char *);
    102 static int CondStrMatch(void *, void *);
    103 static Boolean CondDoMake(int, char *);
    104 static Boolean CondDoExists(int, char *);
    105 static Boolean CondDoTarget(int, char *);
    106 static char * CondCvtArg(char *, double *);
    107 static Token CondToken(Boolean);
    108 static Token CondT(Boolean);
    109 static Token CondF(Boolean);
    110 static Token CondE(Boolean);
     102static void CondPushBack __P((Token));
     103static int CondGetArg __P((char **, char **, char *, Boolean));
     104static Boolean CondDoDefined __P((int, char *));
     105static int CondStrMatch __P((ClientData, ClientData));
     106static Boolean CondDoMake __P((int, char *));
     107static Boolean CondDoExists __P((int, char *));
     108static Boolean CondDoTarget __P((int, char *));
     109static char * CondCvtArg __P((char *, double *));
     110static Token CondToken __P((Boolean));
     111static Token CondT __P((Boolean));
     112static Token CondF __P((Boolean));
     113static Token CondE __P((Boolean));
    111114
    112115static struct If {
     
    114117    int         formlen;      /* Length of form */
    115118    Boolean     doNot;        /* TRUE if default function should be negated */
    116     Boolean     (*defProc)(int, char *); /* Default function to apply */
     119    Boolean     (*defProc) __P((int, char *)); /* Default function to apply */
    117120} ifs[] = {
    118121    { "ifdef",    5,      FALSE,  CondDoDefined },
     
    126129static Boolean    condInvert;           /* Invert the default function */
    127130static Boolean    (*condDefProc)        /* Default function to apply */
    128 (int, char *);
     131                    __P((int, char *));
    129132static char       *condExpr;            /* The expression to parse */
    130133static Token      condPushBack=None;    /* Single push-back token used in
     
    154157 */
    155158static void
    156 CondPushBack (Token t)
     159CondPushBack (t)
     160    Token         t;    /* Token to push back into the "stream" */
    157161{
    158162    condPushBack = t;
     
    163167 *-----------------------------------------------------------------------
    164168 * CondGetArg --
    165  *      Find the argument of a built-in function.  parens is set to TRUE
    166  *      if the arguments are bounded by parens.
     169 *      Find the argument of a built-in function.
    167170 *
    168171 * Results:
     
    176179 */
    177180static int
    178 CondGetArg (char **linePtr, char **argPtr, char *func, Boolean parens)
    179 {
    180     char          *cp;
     181CondGetArg (linePtr, argPtr, func, parens)
     182    char          **linePtr;
     183    char          **argPtr;
     184    char          *func;
     185    Boolean       parens;       /* TRUE if arg should be bounded by parens */
     186{
     187    register char *cp;
    181188    int           argLen;
    182     Buffer        buf;
     189    register Buffer buf;
    183190
    184191    cp = *linePtr;
     
    275282 */
    276283static Boolean
    277 CondDoDefined (int argLen, char *arg)
     284CondDoDefined (argLen, arg)
     285    int     argLen;
     286    char    *arg;
    278287{
    279288    char    savec = arg[argLen];
     
    308317 */
    309318static int
    310 CondStrMatch(void *string, void *pattern)
     319CondStrMatch(string, pattern)
     320    ClientData    string;
     321    ClientData    pattern;
    311322{
    312323    return(!Str_Match((char *) string,(char *) pattern));
     
    328339 */
    329340static Boolean
    330 CondDoMake (int argLen, char *arg)
     341CondDoMake (argLen, arg)
     342    int     argLen;
     343    char    *arg;
    331344{
    332345    char    savec = arg[argLen];
     
    334347
    335348    arg[argLen] = '\0';
    336     if (Lst_Find (create, (void *)arg, CondStrMatch) == NULL) {
     349    if (Lst_Find (create, (ClientData)arg, CondStrMatch) == NILLNODE) {
    337350        result = FALSE;
    338351    } else {
     
    358371 */
    359372static Boolean
    360 CondDoExists (int argLen, char *arg)
     373CondDoExists (argLen, arg)
     374    int     argLen;
     375    char    *arg;
    361376{
    362377    char    savec = arg[argLen];
     
    391406 */
    392407static Boolean
    393 CondDoTarget (int argLen, char *arg)
     408CondDoTarget (argLen, arg)
     409    int     argLen;
     410    char    *arg;
    394411{
    395412    char    savec = arg[argLen];
     
    399416    arg[argLen] = '\0';
    400417    gn = Targ_FindNode(arg, TARG_NOCREATE);
    401     if ((gn != NULL) && !OP_NOP(gn->type)) {
     418    if ((gn != NILGNODE) && !OP_NOP(gn->type)) {
    402419        result = TRUE;
    403420    } else {
     
    430447 */
    431448static char *
    432 CondCvtArg(char *str, double *value)
     449CondCvtArg(str, value)
     450    register char       *str;
     451    double              *value;
    433452{
    434453    if ((*str == '0') && (str[1] == 'x')) {
    435         long i;
     454        register long i;
    436455
    437456        for (str += 2, i = 0; ; str++) {
     
    470489 */
    471490static Token
    472 CondToken(Boolean doEval)
     491CondToken(doEval)
     492    Boolean doEval;
    473493{
    474494    Token         t;
     
    649669                    Buf_Destroy(buf, FALSE);
    650670
    651                     DEBUGF(COND, ("lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
    652                            lhs, string, op));
     671                    if (DEBUG(COND)) {
     672                        printf("lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
     673                               lhs, string, op);
     674                    }
    653675                    /*
    654676                     * Null-terminate rhs and perform the comparison.
     
    697719                    } else {
    698720                        char *c = CondCvtArg(rhs, &right);
    699                         if (*c != '\0' && !isspace((unsigned char) *c))
     721                        if (*c != '\0' && !isspace(*c))
    700722                            goto do_string_compare;
    701723                        if (rhs == condExpr) {
     
    710732                    }
    711733
    712                     DEBUGF(COND, ("left = %f, right = %f, op = %.2s\n", left,
    713                            right, op));
     734                    if (DEBUG(COND)) {
     735                        printf("left = %f, right = %f, op = %.2s\n", left,
     736                               right, op);
     737                    }
    714738                    switch(op[0]) {
    715739                    case '!':
     
    743767                        }
    744768                        break;
    745                     default:
    746                         break;
    747769                    }
    748770                }
     
    753775            }
    754776            default: {
    755                 Boolean (*evalProc)(int, char *);
     777                Boolean (*evalProc) __P((int, char *));
    756778                Boolean invert = FALSE;
    757779                char    *arg;
     
    906928 */
    907929static Token
    908 CondT(Boolean doEval)
     930CondT(doEval)
     931    Boolean doEval;
    909932{
    910933    Token   t;
     
    955978 */
    956979static Token
    957 CondF(Boolean doEval)
     980CondF(doEval)
     981    Boolean doEval;
    958982{
    959983    Token   l, o;
     
    10021026 */
    10031027static Token
    1004 CondE(Boolean doEval)
     1028CondE(doEval)
     1029    Boolean doEval;
    10051030{
    10061031    Token   l, o;
     
    10571082 */
    10581083int
    1059 Cond_Eval (char *line)
     1084Cond_Eval (line)
     1085    char            *line;    /* Line to parse */
    10601086{
    10611087    struct If       *ifp;
     
    12381264 */
    12391265void
    1240 Cond_End(void)
     1266Cond_End()
    12411267{
    12421268    if (condTop != MAXIF) {
  • branches/FREEBSD/src/kmk/config.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)config.h    8.2 (Berkeley) 4/28/95
    40  * $FreeBSD: src/usr.bin/make/config.h,v 1.12 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)config.h      8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/config.h,v 1.9 1999/09/10 20:51:59 julian Exp $
    4140 */
     41
     42#define DEFSHELL        1                       /* Bourne shell */
    4243
    4344/*
     
    5051 *      to 0, nothing will ever happen...
    5152 */
    52 #define DEFMAXJOBS      4
    53 #define DEFMAXLOCAL     1
     53#define DEFMAXJOBS      4
     54#define DEFMAXLOCAL     1
    5455
    5556/*
     
    6263 *      See suff.c for more details.
    6364 */
    64 #define INCLUDES
    65 #define LIBRARIES
     65#define INCLUDES
     66#define LIBRARIES
    6667
    6768/*
     
    9091 *      - Allow empty command lines if starting with tab.
    9192 */
    92 #define POSIX
     93#define POSIX
    9394
    9495/*
     
    9899 *      Recognize system V like ${VAR:x=y} variable substitutions
    99100 */
    100 #define SYSVINCLUDE
    101 #define SYSVVARSUB
     101#define SYSVINCLUDE
     102#define SYSVVARSUB
    102103
    103104/*
     
    108109 *                              # of ${VAR}
    109110 */
    110 #define SUNSHCMD
     111#define SUNSHCMD
    111112
    112113#if !defined(__svr4__) && !defined(__SVR4) && !defined(__ELF__)
  • branches/FREEBSD/src/kmk/dir.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)dir.c    8.2 (Berkeley) 1/2/94
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/dir.c,v 1.30 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)dir.c       8.2 (Berkeley) 1/2/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/dir.c,v 1.10.2.1 2001/02/13 03:13:57 will Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/*-
     
    8891#include <stdio.h>
    8992#include <sys/types.h>
     93#include <dirent.h>
    9094#include <sys/stat.h>
    91 #include <dirent.h>
    92 #include <err.h>
    9395#include "make.h"
    9496#include "hash.h"
     
    190192
    191193
    192 static int DirFindName(void *, void *);
    193 static int DirMatchFiles(char *, Path *, Lst);
    194 static void DirExpandCurly(char *, char *, Lst, Lst);
    195 static void DirExpandInt(char *, Lst, Lst);
    196 static int DirPrintWord(void *, void *);
    197 static int DirPrintDir(void *, void *);
     194static int DirFindName __P((ClientData, ClientData));
     195static int DirMatchFiles __P((char *, Path *, Lst));
     196static void DirExpandCurly __P((char *, char *, Lst, Lst));
     197static void DirExpandInt __P((char *, Lst, Lst));
     198static int DirPrintWord __P((ClientData, ClientData));
     199static int DirPrintDir __P((ClientData, ClientData));
    198200
    199201/*-
     
    210212 */
    211213void
    212 Dir_Init (void)
     214Dir_Init ()
    213215{
    214216    dirSearchPath = Lst_Init (FALSE);
     
    247249 */
    248250void
    249 Dir_End(void)
     251Dir_End()
    250252{
    251253    dot->refCount -= 1;
    252     Dir_Destroy((void *) dot);
     254    Dir_Destroy((ClientData) dot);
    253255    Dir_ClearPath(dirSearchPath);
    254256    Lst_Destroy(dirSearchPath, NOFREE);
     
    273275 */
    274276static int
    275 DirFindName (void *p, void *dname)
     277DirFindName (p, dname)
     278    ClientData    p;          /* Current name */
     279    ClientData    dname;      /* Desired name */
    276280{
    277281    return (strcmp (((Path *)p)->name, (char *) dname));
     
    281285 *-----------------------------------------------------------------------
    282286 * Dir_HasWildcards  --
    283  *      See if the given name has any wildcard characters in it.
     287 *      see if the given name has any wildcard characters in it
    284288 *
    285289 * Results:
     
    291295 */
    292296Boolean
    293 Dir_HasWildcards (char *name)
    294 {
    295     char *cp;
    296     int wild = 0, brace = 0, bracket = 0;
     297Dir_HasWildcards (name)
     298    char          *name;        /* name to check */
     299{
     300    register char *cp;
    297301
    298302    for (cp = name; *cp; cp++) {
    299303        switch(*cp) {
    300304        case '{':
    301                 brace++;
    302                 wild = 1;
    303                 break;
    304         case '}':
    305                 brace--;
    306                 break;
    307305        case '[':
    308                 bracket++;
    309                 wild = 1;
    310                 break;
    311         case ']':
    312                 bracket--;
    313                 break;
    314306        case '?':
    315307        case '*':
    316                 wild = 1;
    317                 break;
    318         default:
    319                 break;
    320         }
    321     }
    322     return wild && bracket == 0 && brace == 0;
     308            return (TRUE);
     309        }
     310    }
     311    return (FALSE);
    323312}
    324313
     
    341330 */
    342331static int
    343 DirMatchFiles (char *pattern, Path *p, Lst expansions)
     332DirMatchFiles (pattern, p, expansions)
     333    char          *pattern;     /* Pattern to look for */
     334    Path          *p;           /* Directory to search */
     335    Lst           expansions;   /* Place to store the results */
    344336{
    345337    Hash_Search   search;       /* Index into the directory's table */
     
    378370 *      Note the special case: if after the piece of the curly brace is
    379371 *      done there are no wildcard characters in the result, the result is
    380  *      placed on the list WITHOUT CHECKING FOR ITS EXISTENCE.  The
    381  *      given arguments are the entire word to expand, the first curly
    382  *      brace in the word, the search path, and the list to store the
    383  *      expansions in.
     372 *      placed on the list WITHOUT CHECKING FOR ITS EXISTENCE.
    384373 *
    385374 * Results:
     
    392381 */
    393382static void
    394 DirExpandCurly(char *word, char *brace, Lst path, Lst expansions)
     383DirExpandCurly(word, brace, path, expansions)
     384    char          *word;        /* Entire word to expand */
     385    char          *brace;       /* First curly brace in it */
     386    Lst           path;         /* Search path to use */
     387    Lst           expansions;   /* Place to store the expansions */
    395388{
    396389    char          *end;         /* Character after the closing brace */
     
    466459                Dir_Expand(file, path, expansions);
    467460                goto next;
    468             default:
    469                 break;
    470461            }
    471462        }
     
    490481 *      Internal expand routine. Passes through the directories in the
    491482 *      path one by one, calling DirMatchFiles for each. NOTE: This still
    492  *      doesn't handle patterns in directories...  Works given a word to
    493  *      expand, a path to look in, and a list to store expansions in.
     483 *      doesn't handle patterns in directories...
    494484 *
    495485 * Results:
     
    502492 */
    503493static void
    504 DirExpandInt(char *word, Lst path, Lst expansions)
     494DirExpandInt(word, path, expansions)
     495    char          *word;        /* Word to expand */
     496    Lst           path;         /* Path on which to look */
     497    Lst           expansions;   /* Place to store the result */
    505498{
    506499    LstNode       ln;           /* Current node */
     
    508501
    509502    if (Lst_Open(path) == SUCCESS) {
    510         while ((ln = Lst_Next(path)) != NULL) {
     503        while ((ln = Lst_Next(path)) != NILLNODE) {
    511504            p = (Path *)Lst_Datum(ln);
    512505            DirMatchFiles(word, p, expansions);
     
    531524 */
    532525static int
    533 DirPrintWord(void *word, void *dummy __unused)
    534 {
    535     DEBUGF(DIR, ("%s ", (char *) word));
    536 
    537     return (0);
     526DirPrintWord(word, dummy)
     527    ClientData  word;
     528    ClientData  dummy;
     529{
     530    printf("%s ", (char *) word);
     531
     532    return(dummy ? 0 : 0);
    538533}
    539534
     
    546541 * Results:
    547542 *      A list of words consisting of the files which exist along the search
    548  *      path matching the given pattern is placed in expansions.
     543 *      path matching the given pattern.
    549544 *
    550545 * Side Effects:
     
    553548 */
    554549void
    555 Dir_Expand (char *word, Lst path, Lst expansions)
     550Dir_Expand (word, path, expansions)
     551    char    *word;      /* the word to expand */
     552    Lst     path;       /* the list of directories in which to find
     553                         * the resulting files */
     554    Lst     expansions; /* the list on which to place the results */
    556555{
    557556    char          *cp;
    558557
    559     DEBUGF(DIR, ("expanding \"%s\"...", word));
     558    if (DEBUG(DIR)) {
     559        printf("expanding \"%s\"...", word);
     560    }
    560561
    561562    cp = strchr(word, '{');
     
    640641    }
    641642    if (DEBUG(DIR)) {
    642         Lst_ForEach(expansions, DirPrintWord, (void *) 0);
    643         DEBUGF(DIR, ("\n"));
     643        Lst_ForEach(expansions, DirPrintWord, (ClientData) 0);
     644        fputc('\n', stdout);
    644645    }
    645646}
     
    664665 */
    665666char *
    666 Dir_FindFile (char *name, Lst path)
    667 {
    668     char          *p1;      /* pointer into p->name */
    669     char          *p2;      /* pointer into name */
     667Dir_FindFile (name, path)
     668    char          *name;    /* the file to find */
     669    Lst           path;     /* the Lst of directories to search */
     670{
     671    register char *p1;      /* pointer into p->name */
     672    register char *p2;      /* pointer into name */
    670673    LstNode       ln;       /* a list element */
    671     char          *file;    /* the current filename to check */
    672     Path          *p;       /* current path member */
    673     char          *cp;      /* index of first slash, if any */
     674    register char *file;    /* the current filename to check */
     675    register Path *p;       /* current path member */
     676    register char *cp;      /* index of first slash, if any */
    674677    Boolean       hasSlash; /* true if 'name' contains a / */
    675678    struct stat   stb;      /* Buffer for stat, if necessary */
     
    689692    }
    690693
    691     DEBUGF(DIR, ("Searching for %s...", name));
     694    if (DEBUG(DIR)) {
     695        printf("Searching for %s...", name);
     696    }
    692697    /*
    693698     * No matter what, we always look for the file in the current directory
     
    698703    if ((!hasSlash || (cp - name == 2 && *name == '.')) &&
    699704        (Hash_FindEntry (&dot->files, cp) != (Hash_Entry *)NULL)) {
    700             DEBUGF(DIR, ("in '.'\n"));
     705            if (DEBUG(DIR)) {
     706                printf("in '.'\n");
     707            }
    701708            hits += 1;
    702709            dot->hits += 1;
     
    705712
    706713    if (Lst_Open (path) == FAILURE) {
    707         DEBUGF(DIR, ("couldn't open path, file not found\n"));
     714        if (DEBUG(DIR)) {
     715            printf("couldn't open path, file not found\n");
     716        }
    708717        misses += 1;
    709718        return ((char *) NULL);
     
    718727     * we go on to phase two...
    719728     */
    720     while ((ln = Lst_Next (path)) != NULL) {
     729    while ((ln = Lst_Next (path)) != NILLNODE) {
    721730        p = (Path *) Lst_Datum (ln);
    722         DEBUGF(DIR, ("%s...", p->name));
     731        if (DEBUG(DIR)) {
     732            printf("%s...", p->name);
     733        }
    723734        if (Hash_FindEntry (&p->files, cp) != (Hash_Entry *)NULL) {
    724             DEBUGF(DIR, ("here..."));
     735            if (DEBUG(DIR)) {
     736                printf("here...");
     737            }
    725738            if (hasSlash) {
    726739                /*
     
    738751                }
    739752                if (p2 >= name || (p1 >= p->name && *p1 != '/')) {
    740                     DEBUGF(DIR, ("component mismatch -- continuing..."));
     753                    if (DEBUG(DIR)) {
     754                        printf("component mismatch -- continuing...");
     755                    }
    741756                    continue;
    742757                }
    743758            }
    744759            file = str_concat (p->name, cp, STR_ADDSLASH);
    745             DEBUGF(DIR, ("returning %s\n", file));
     760            if (DEBUG(DIR)) {
     761                printf("returning %s\n", file);
     762            }
    746763            Lst_Close (path);
    747764            p->hits += 1;
     
    758775            }
    759776            if (*p1 == '\0' && p2 == cp - 1) {
    760                 DEBUGF(DIR, ("must be here but isn't -- returing NULL\n"));
     777                if (DEBUG(DIR)) {
     778                    printf("must be here but isn't -- returing NULL\n");
     779                }
    761780                Lst_Close (path);
    762781                return ((char *) NULL);
     
    778797     */
    779798    if (!hasSlash) {
    780         DEBUGF(DIR, ("failed.\n"));
     799        if (DEBUG(DIR)) {
     800            printf("failed.\n");
     801        }
    781802        misses += 1;
    782803        return ((char *) NULL);
     
    786807        Boolean checkedDot = FALSE;
    787808
    788         DEBUGF(DIR, ("failed. Trying subdirectories..."));
     809        if (DEBUG(DIR)) {
     810            printf("failed. Trying subdirectories...");
     811        }
    789812        (void) Lst_Open (path);
    790         while ((ln = Lst_Next (path)) != NULL) {
     813        while ((ln = Lst_Next (path)) != NILLNODE) {
    791814            p = (Path *) Lst_Datum (ln);
    792815            if (p != dot) {
     
    799822                checkedDot = TRUE;
    800823            }
    801             DEBUGF(DIR, ("checking %s...", file));
     824            if (DEBUG(DIR)) {
     825                printf("checking %s...", file);
     826            }
     827
    802828
    803829            if (stat (file, &stb) == 0) {
    804                 DEBUGF(DIR, ("got it.\n"));
     830                if (DEBUG(DIR)) {
     831                    printf("got it.\n");
     832                }
    805833
    806834                Lst_Close (path);
     
    825853                 * to fetch it again.
    826854                 */
    827                 DEBUGF(DIR, ("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), file));
     855                if (DEBUG(DIR)) {
     856                    printf("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
     857                            file);
     858                }
    828859                entry = Hash_CreateEntry(&mtimes, (char *) file,
    829860                                         (Boolean *)NULL);
     
    836867        }
    837868
    838         DEBUGF(DIR, ("failed. "));
     869        if (DEBUG(DIR)) {
     870            printf("failed. ");
     871        }
    839872        Lst_Close (path);
    840873
     
    844877             * so no point in proceeding...
    845878             */
    846             DEBUGF(DIR, ("Checked . already, returning NULL\n"));
     879            if (DEBUG(DIR)) {
     880                printf("Checked . already, returning NULL\n");
     881            }
    847882            return(NULL);
    848883        }
     
    873908    bigmisses += 1;
    874909    ln = Lst_Last (path);
    875     if (ln == NULL) {
     910    if (ln == NILLNODE) {
    876911        return ((char *) NULL);
    877912    } else {
     
    885920    }
    886921#else /* !notdef */
    887     DEBUGF(DIR, ("Looking for \"%s\"...", name));
     922    if (DEBUG(DIR)) {
     923        printf("Looking for \"%s\"...", name);
     924    }
    888925
    889926    bigmisses += 1;
    890927    entry = Hash_FindEntry(&mtimes, name);
    891928    if (entry != (Hash_Entry *)NULL) {
    892         DEBUGF(DIR, ("got it (in mtime cache)\n"));
    893         return (estrdup(name));
     929        if (DEBUG(DIR)) {
     930            printf("got it (in mtime cache)\n");
     931        }
     932        return(estrdup(name));
    894933    } else if (stat (name, &stb) == 0) {
    895934        entry = Hash_CreateEntry(&mtimes, name, (Boolean *)NULL);
    896         DEBUGF(DIR, ("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), name));
     935        if (DEBUG(DIR)) {
     936            printf("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
     937                    name);
     938        }
    897939        Hash_SetValue(entry, (long)stb.st_mtime);
    898940        return (estrdup (name));
    899941    } else {
    900         DEBUGF(DIR, ("failed. Returning NULL\n"));
     942        if (DEBUG(DIR)) {
     943            printf("failed. Returning NULL\n");
     944        }
    901945        return ((char *)NULL);
    902946    }
     
    920964 */
    921965int
    922 Dir_MTime (GNode *gn)
     966Dir_MTime (gn)
     967    GNode         *gn;        /* the file whose modification time is
     968                               * desired */
    923969{
    924970    char          *fullName;  /* the full pathname of name */
     
    943989         * Only do this once -- the second time folks are checking to
    944990         * see if the file was actually updated, so we need to actually go
    945          * to the filesystem.
     991         * to the file system.
    946992         */
    947         DEBUGF(DIR, ("Using cached time %s for %s\n",
    948                Targ_FmtTime((time_t)(long)Hash_GetValue(entry)), fullName));
     993        if (DEBUG(DIR)) {
     994            printf("Using cached time %s for %s\n",
     995                    Targ_FmtTime((time_t)(long)Hash_GetValue(entry)), fullName);
     996        }
    949997        stb.st_mtime = (time_t)(long)Hash_GetValue(entry);
    950998        Hash_DeleteEntry(&mtimes, entry);
     
    9821030 */
    9831031void
    984 Dir_AddDir (Lst path, char *name)
     1032Dir_AddDir (path, name)
     1033    Lst           path;       /* the path to which the directory should be
     1034                               * added */
     1035    char          *name;      /* the name of the directory to add */
    9851036{
    9861037    LstNode       ln;         /* node in case Path structure is found */
    987     Path          *p;         /* pointer to new Path structure */
     1038    register Path *p;         /* pointer to new Path structure */
    9881039    DIR           *d;         /* for reading directory */
    989     struct dirent *dp;        /* entry in directory */
    990 
    991     ln = Lst_Find (openDirectories, (void *)name, DirFindName);
    992     if (ln != NULL) {
     1040    register struct dirent *dp; /* entry in directory */
     1041
     1042    ln = Lst_Find (openDirectories, (ClientData)name, DirFindName);
     1043    if (ln != NILLNODE) {
    9931044        p = (Path *)Lst_Datum (ln);
    994         if (Lst_Member(path, (void *)p) == NULL) {
     1045        if (Lst_Member(path, (ClientData)p) == NILLNODE) {
    9951046            p->refCount += 1;
    996             (void)Lst_AtEnd (path, (void *)p);
     1047            (void)Lst_AtEnd (path, (ClientData)p);
    9971048        }
    9981049    } else {
    999         DEBUGF(DIR, ("Caching %s...", name));
     1050        if (DEBUG(DIR)) {
     1051            printf("Caching %s...", name);
     1052            fflush(stdout);
     1053        }
    10001054
    10011055        if ((d = opendir (name)) != (DIR *) NULL) {
     
    10071061
    10081062            while ((dp = readdir (d)) != (struct dirent *) NULL) {
    1009 #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */
     1063#if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */
    10101064                /*
    10111065                 * The sun directory library doesn't check for a 0 inode
     
    10221076                 * that order when first going through a directory.  This is
    10231077                 * needed for XFS over NFS filesystems since SGI does not
    1024                  * guarantee that these are the first two entries returned
     1078                 * guarantee that these are * the first two entries returned
    10251079                 * from readdir().
    10261080                 */
     
    10311085            }
    10321086            (void) closedir (d);
    1033             (void)Lst_AtEnd (openDirectories, (void *)p);
    1034             (void)Lst_AtEnd (path, (void *)p);
    1035         }
    1036         DEBUGF(DIR, ("done\n"));
     1087            (void)Lst_AtEnd (openDirectories, (ClientData)p);
     1088            (void)Lst_AtEnd (path, (ClientData)p);
     1089        }
     1090        if (DEBUG(DIR)) {
     1091            printf("done\n");
     1092        }
    10371093    }
    10381094}
     
    10521108 *-----------------------------------------------------------------------
    10531109 */
    1054 void *
    1055 Dir_CopyDir(void *p)
     1110ClientData
     1111Dir_CopyDir(p)
     1112    ClientData p;
    10561113{
    10571114    ((Path *) p)->refCount += 1;
    10581115
    1059     return ((void *)p);
     1116    return ((ClientData)p);
    10601117}
    10611118
     
    10781135 */
    10791136char *
    1080 Dir_MakeFlags (char *flag, Lst path)
     1137Dir_MakeFlags (flag, path)
     1138    char          *flag;  /* flag which should precede each directory */
     1139    Lst           path;   /* list of directories */
    10811140{
    10821141    char          *str;   /* the string which will be returned */
     
    10881147
    10891148    if (Lst_Open (path) == SUCCESS) {
    1090         while ((ln = Lst_Next (path)) != NULL) {
     1149        while ((ln = Lst_Next (path)) != NILLNODE) {
    10911150            p = (Path *) Lst_Datum (ln);
    10921151            tstr = str_concat (flag, p->name, 0);
     
    11151174 */
    11161175void
    1117 Dir_Destroy (void *pp)
     1176Dir_Destroy (pp)
     1177    ClientData    pp;       /* The directory descriptor to nuke */
    11181178{
    11191179    Path          *p = (Path *) pp;
     
    11231183        LstNode ln;
    11241184
    1125         ln = Lst_Member (openDirectories, (void *)p);
     1185        ln = Lst_Member (openDirectories, (ClientData)p);
    11261186        (void) Lst_Remove (openDirectories, ln);
    11271187
    11281188        Hash_DeleteTable (&p->files);
    1129         free(p->name);
    1130         free(p);
     1189        free((Address)p->name);
     1190        free((Address)p);
    11311191    }
    11321192}
     
    11471207 */
    11481208void
    1149 Dir_ClearPath(Lst path)
     1209Dir_ClearPath(path)
     1210    Lst     path;       /* Path to clear */
    11501211{
    11511212    Path    *p;
    11521213    while (!Lst_IsEmpty(path)) {
    11531214        p = (Path *)Lst_DeQueue(path);
    1154         Dir_Destroy((void *) p);
     1215        Dir_Destroy((ClientData) p);
    11551216    }
    11561217}
     
    11721233 */
    11731234void
    1174 Dir_Concat(Lst path1, Lst path2)
     1235Dir_Concat(path1, path2)
     1236    Lst     path1;      /* Dest */
     1237    Lst     path2;      /* Source */
    11751238{
    11761239    LstNode ln;
    11771240    Path    *p;
    11781241
    1179     for (ln = Lst_First(path2); ln != NULL; ln = Lst_Succ(ln)) {
     1242    for (ln = Lst_First(path2); ln != NILLNODE; ln = Lst_Succ(ln)) {
    11801243        p = (Path *)Lst_Datum(ln);
    1181         if (Lst_Member(path1, (void *)p) == NULL) {
     1244        if (Lst_Member(path1, (ClientData)p) == NILLNODE) {
    11821245            p->refCount += 1;
    1183             (void)Lst_AtEnd(path1, (void *)p);
     1246            (void)Lst_AtEnd(path1, (ClientData)p);
    11841247        }
    11851248    }
     
    11881251/********** DEBUG INFO **********/
    11891252void
    1190 Dir_PrintDirectories(void)
     1253Dir_PrintDirectories()
    11911254{
    11921255    LstNode     ln;
     
    12001263    printf ("# %-20s referenced\thits\n", "directory");
    12011264    if (Lst_Open (openDirectories) == SUCCESS) {
    1202         while ((ln = Lst_Next (openDirectories)) != NULL) {
     1265        while ((ln = Lst_Next (openDirectories)) != NILLNODE) {
    12031266            p = (Path *) Lst_Datum (ln);
    12041267            printf ("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits);
     
    12081271}
    12091272
    1210 static int
    1211 DirPrintDir (void *p, void *dummy __unused)
     1273static int DirPrintDir (p, dummy)
     1274    ClientData  p;
     1275    ClientData  dummy;
    12121276{
    12131277    printf ("%s ", ((Path *) p)->name);
    1214 
    1215     return (0);
     1278    return (dummy ? 0 : 0);
    12161279}
    12171280
    12181281void
    1219 Dir_PrintPath (Lst path)
    1220 {
    1221     Lst_ForEach (path, DirPrintDir, (void *)0);
    1222 }
     1282Dir_PrintPath (path)
     1283    Lst path;
     1284{
     1285    Lst_ForEach (path, DirPrintDir, (ClientData)0);
     1286}
  • branches/FREEBSD/src/kmk/dir.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)dir.h       8.2 (Berkeley) 4/28/95
    40  * $FreeBSD: src/usr.bin/make/dir.h,v 1.10 2002/04/13 10:57:56 obrien Exp $
     38 *      from: @(#)dir.h 8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/dir.h,v 1.7 1999/08/28 01:03:29 peter Exp $
    4140 */
    4241
     
    5554} Path;
    5655
    57 void Dir_Init(void);
    58 void Dir_End(void);
    59 Boolean Dir_HasWildcards(char *);
    60 void Dir_Expand(char *, Lst, Lst);
    61 char *Dir_FindFile(char *, Lst);
    62 int Dir_MTime(GNode *);
    63 void Dir_AddDir(Lst, char *);
    64 char *Dir_MakeFlags(char *, Lst);
    65 void Dir_ClearPath(Lst);
    66 void Dir_Concat(Lst, Lst);
    67 void Dir_PrintDirectories(void);
    68 void Dir_PrintPath(Lst);
    69 void Dir_Destroy(void *);
    70 void * Dir_CopyDir(void *);
     56void Dir_Init __P((void));
     57void Dir_End __P((void));
     58Boolean Dir_HasWildcards __P((char *));
     59void Dir_Expand __P((char *, Lst, Lst));
     60char *Dir_FindFile __P((char *, Lst));
     61int Dir_MTime __P((GNode *));
     62void Dir_AddDir __P((Lst, char *));
     63char *Dir_MakeFlags __P((char *, Lst));
     64void Dir_ClearPath __P((Lst));
     65void Dir_Concat __P((Lst, Lst));
     66void Dir_PrintDirectories __P((void));
     67void Dir_PrintPath __P((Lst));
     68void Dir_Destroy __P((ClientData));
     69ClientData Dir_CopyDir __P((ClientData));
    7170
    7271#endif /* _DIR */
  • branches/FREEBSD/src/kmk/for.c

    r10 r24  
    11/*
    2  * Copyright (c) 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * This code is derived from software contributed to Berkeley by
    6  * Christos Zoulas.
     2 * Copyright (c) 1992, The Regents of the University of California.
     3 * All rights reserved.
    74 *
    85 * Redistribution and use in source and binary forms, with or without
     
    3330 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3431 * SUCH DAMAGE.
    35  *
    36  * @(#)for.c    8.1 (Berkeley) 6/6/93
    37  */
    38 
    39 #include <sys/cdefs.h>
    40 __FBSDID("$FreeBSD: src/usr.bin/make/for.c,v 1.19 2002/10/09 03:42:10 jmallett Exp $");
     32 */
     33
     34#ifndef lint
     35#if 0
     36static char sccsid[] = "@(#)for.c       8.1 (Berkeley) 6/6/93";
     37#else
     38static const char rcsid[] =
     39  "$FreeBSD: src/usr.bin/make/for.c,v 1.10 1999/09/11 13:08:01 hoek Exp $";
     40#endif
     41#endif /* not lint */
    4142
    4243/*-
     
    8485} For;
    8586
    86 static int ForExec(void *, void *);
     87static int ForExec      __P((ClientData, ClientData));
    8788
    8889
     
    108109 */
    109110int
    110 For_Eval (char *line)
     111For_Eval (line)
     112    char            *line;    /* Line to parse */
    111113{
    112114    char            *ptr = line, *sub, *wrd;
     
    176178        sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE);
    177179
    178 #define ADDWORD() \
     180#define ADDWORD() \
    179181        Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd), \
    180182        Buf_AddByte(buf, (Byte) '\0'), \
    181         Lst_AtFront(forLst, (void *) Buf_GetAll(buf, &varlen)), \
     183        Lst_AtFront(forLst, (ClientData) Buf_GetAll(buf, &varlen)), \
    182184        Buf_Destroy(buf, FALSE)
    183185
     
    193195                wrd = ptr--;
    194196            }
    195         DEBUGF(FOR, ("For: Iterator %s List %s\n", forVar, sub));
     197        if (DEBUG(FOR))
     198            (void) fprintf(stderr, "For: Iterator %s List %s\n", forVar, sub);
    196199        if (ptr - wrd > 0)
    197200            ADDWORD();
    198201        else
    199202            Buf_Destroy(buf, TRUE);
    200         free(sub);
     203        free((Address) sub);
    201204
    202205        forBuf = Buf_Init(0);
     
    211214        if (strncmp(ptr, "endfor", 6) == 0 &&
    212215            (isspace((unsigned char) ptr[6]) || !ptr[6])) {
    213             DEBUGF(FOR, ("For: end for %d\n", forLevel));
     216            if (DEBUG(FOR))
     217                (void) fprintf(stderr, "For: end for %d\n", forLevel);
    214218            if (--forLevel < 0) {
    215219                Parse_Error (level, "for-less endfor");
     
    220224                 isspace((unsigned char) ptr[3])) {
    221225            forLevel++;
    222             DEBUGF(FOR, ("For: new loop %d\n", forLevel));
     226            if (DEBUG(FOR))
     227                (void) fprintf(stderr, "For: new loop %d\n", forLevel);
    223228        }
    224229    }
     
    248253 */
    249254static int
    250 ForExec(void *namep, void *argp)
     255ForExec(namep, argp)
     256    ClientData namep;
     257    ClientData argp;
    251258{
    252259    char *name = (char *) namep;
     
    254261    int len;
    255262    Var_Set(arg->var, name, VAR_GLOBAL);
    256     DEBUGF(FOR, ("--- %s = %s\n", arg->var, name));
     263    if (DEBUG(FOR))
     264        (void) fprintf(stderr, "--- %s = %s\n", arg->var, name);
    257265    Parse_FromString(Var_Subst(arg->var, (char *) Buf_GetAll(arg->buf, &len),
    258266                               VAR_GLOBAL, FALSE));
     
    278286 */
    279287void
    280 For_Run(void)
     288For_Run()
    281289{
    282290    For arg;
     
    291299    forLst = NULL;
    292300
    293     Lst_ForEach(arg.lst, ForExec, (void *) &arg);
    294 
    295     free(arg.var);
    296     Lst_Destroy(arg.lst, (void (*)(void *)) free);
     301    Lst_ForEach(arg.lst, ForExec, (ClientData) &arg);
     302
     303    free((Address)arg.var);
     304    Lst_Destroy(arg.lst, (void (*) __P((ClientData))) free);
    297305    Buf_Destroy(arg.buf, TRUE);
    298306}
  • branches/FREEBSD/src/kmk/hash.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)hash.c   8.1 (Berkeley) 6/6/93
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/hash.c,v 1.18 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)hash.c      8.1 (Berkeley) 6/6/93";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/hash.c,v 1.9 1999/09/11 13:08:01 hoek Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/* hash.c --
     
    5053 *      information increases.
    5154 */
    52 #include <unistd.h>
    5355#include "sprite.h"
    5456#include "make.h"
     
    6062 */
    6163
    62 static void RebuildTable(Hash_Table *);
     64static void RebuildTable __P((Hash_Table *));
    6365
    6466/*
     
    6769 */
    6870
    69 #define rebuildLimit 8
     71#define rebuildLimit 8
    7072
    7173/*
     
    7375 *
    7476 * Hash_InitTable --
    75  *
    76  *      Set up the hash table t with a given number of buckets, or a
    77  *      reasonable default if the number requested is less than or
    78  *      equal to zero.  Hash tables will grow in size as needed.
    79  *
     77 *
     78 *      This routine just sets up the hash table.
    8079 *
    8180 * Results:
     
    8988
    9089void
    91 Hash_InitTable(Hash_Table *t, int numBuckets)
    92 {
    93         int i;
    94         struct Hash_Entry **hp;
     90Hash_InitTable(t, numBuckets)
     91        register Hash_Table *t; /* Structure to use to hold table. */
     92        int numBuckets;         /* How many buckets to create for starters.
     93                                 * This number is rounded up to a power of
     94                                 * two.   If <= 0, a reasonable default is
     95                                 * chosen. The table will grow in size later
     96                                 * as needed. */
     97{
     98        register int i;
     99        register struct Hash_Entry **hp;
    95100
    96101        /*
     
    130135
    131136void
    132 Hash_DeleteTable(Hash_Table *t)
    133 {
    134         struct Hash_Entry **hp, *h, *nexth = NULL;
    135         int i;
     137Hash_DeleteTable(t)
     138        Hash_Table *t;
     139{
     140        register struct Hash_Entry **hp, *h, *nexth = NULL;
     141        register int i;
    136142
    137143        for (hp = t->bucketPtr, i = t->size; --i >= 0;) {
     
    169175
    170176Hash_Entry *
    171 Hash_FindEntry(Hash_Table *t, char *key)
    172 {
    173         Hash_Entry *e;
    174         unsigned h;
    175         char *p;
     177Hash_FindEntry(t, key)
     178        Hash_Table *t;          /* Hash table to search. */
     179        char *key;              /* A hash key. */
     180{
     181        register Hash_Entry *e;
     182        register unsigned h;
     183        register char *p;
    176184
    177185        for (h = 0, p = key; *p;)
     
    204212
    205213Hash_Entry *
    206 Hash_CreateEntry(Hash_Table *t, char *key, Boolean *newPtr)
    207 {
    208         Hash_Entry *e;
    209         unsigned int h;
    210         char *p;
     214Hash_CreateEntry(t, key, newPtr)
     215        register Hash_Table *t; /* Hash table to search. */
     216        char *key;              /* A hash key. */
     217        Boolean *newPtr;        /* Filled in with TRUE if new entry created,
     218                                 * FALSE otherwise. */
     219{
     220        register Hash_Entry *e;
     221        register unsigned h;
     222        register char *p;
    211223        int keylen;
    212224        struct Hash_Entry **hp;
     
    267279
    268280void
    269 Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e)
    270 {
    271         Hash_Entry **hp, *p;
     281Hash_DeleteEntry(t, e)
     282        Hash_Table *t;
     283        Hash_Entry *e;
     284{
     285        register Hash_Entry **hp, *p;
    272286
    273287        if (e == NULL)
     
    282296                }
    283297        }
    284         (void) write(STDERR_FILENO, "bad call to Hash_DeleteEntry\n", 29);
     298        (void) write(2, "bad call to Hash_DeleteEntry\n", 29);
    285299        abort();
    286300}
     
    306320
    307321Hash_Entry *
    308 Hash_EnumFirst(Hash_Table *t, Hash_Search *searchPtr)
     322Hash_EnumFirst(t, searchPtr)
     323        Hash_Table *t;                  /* Table to be searched. */
     324        register Hash_Search *searchPtr;/* Area in which to keep state
     325                                         * about search.*/
    309326{
    310327        searchPtr->tablePtr = t;
     
    333350
    334351Hash_Entry *
    335 Hash_EnumNext(Hash_Search *searchPtr)
    336 {
    337         Hash_Entry *e;
     352Hash_EnumNext(searchPtr)
     353        register Hash_Search *searchPtr; /* Area used to keep state about
     354                                            search. */
     355{
     356        register Hash_Entry *e;
    338357        Hash_Table *t = searchPtr->tablePtr;
    339358
    340359        /*
    341360         * The hashEntryPtr field points to the most recently returned
    342          * entry, or is NULL if we are starting up.  If not NULL, we have
     361         * entry, or is nil if we are starting up.  If not nil, we have
    343362         * to start at the next one in the chain.
    344363         */
     
    377396
    378397static void
    379 RebuildTable(Hash_Table *t)
    380 {
    381         Hash_Entry *e, *next = NULL, **hp, **xp;
    382         int i, mask;
    383         Hash_Entry **oldhp;
     398RebuildTable(t)
     399        register Hash_Table *t;
     400{
     401        register Hash_Entry *e, *next = NULL, **hp, **xp;
     402        register int i, mask;
     403        register Hash_Entry **oldhp;
    384404        int oldsize;
    385405
  • branches/FREEBSD/src/kmk/hash.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)hash.h      8.1 (Berkeley) 6/6/93
    40  * $FreeBSD: src/usr.bin/make/hash.h,v 1.12 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)hash.h        8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/hash.h,v 1.8 1999/08/28 01:03:30 peter Exp $
    4140 */
    4241
     
    5857                                         * entries associated with the same
    5958                                         * bucket. */
    60     void *            clientData;       /* Arbitrary piece of data associated
     59    ClientData        clientData;       /* Arbitrary piece of data associated
    6160                                         * with key. */
    6261    unsigned          namehash;         /* hash value of key */
     
    8887
    8988/*
    90  * void * Hash_GetValue(h)
     89 * ClientData Hash_GetValue(h)
    9190 *     Hash_Entry *h;
    9291 */
    9392
    94 #define Hash_GetValue(h) ((h)->clientData)
     93#define Hash_GetValue(h) ((h)->clientData)
    9594
    9695/*
     
    10099 */
    101100
    102 #define Hash_SetValue(h, val) ((h)->clientData = (void *) (val))
     101#define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val))
    103102
    104103/*
     
    108107#define Hash_Size(n)    (((n) + sizeof (int) - 1) / sizeof (int))
    109108
    110 void Hash_InitTable(Hash_Table *, int);
    111 void Hash_DeleteTable(Hash_Table *);
    112 Hash_Entry *Hash_FindEntry(Hash_Table *, char *);
    113 Hash_Entry *Hash_CreateEntry(Hash_Table *, char *, Boolean *);
    114 void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
    115 Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
    116 Hash_Entry *Hash_EnumNext(Hash_Search *);
     109void Hash_InitTable __P((Hash_Table *, int));
     110void Hash_DeleteTable __P((Hash_Table *));
     111Hash_Entry *Hash_FindEntry __P((Hash_Table *, char *));
     112Hash_Entry *Hash_CreateEntry __P((Hash_Table *, char *, Boolean *));
     113void Hash_DeleteEntry __P((Hash_Table *, Hash_Entry *));
     114Hash_Entry *Hash_EnumFirst __P((Hash_Table *, Hash_Search *));
     115Hash_Entry *Hash_EnumNext __P((Hash_Search *));
    117116
    118117#endif /* _HASH */
  • branches/FREEBSD/src/kmk/job.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)job.c    8.2 (Berkeley) 3/19/94
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/job.c,v 1.45 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)job.c       8.2 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/job.c,v 1.17.2.2 2001/02/13 03:13:57 will Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548#ifndef OLD_JOKE
    46 #define OLD_JOKE 0
     49#define OLD_JOKE 0
    4750#endif /* OLD_JOKE */
    4851
     
    8487 *                              FAILURE if the spec was incorrect.
    8588 *
    86  *      Job_Finish                      Perform any final processing which needs doing.
     89 *      Job_End                 Perform any final processing which needs doing.
    8790 *                              This includes the execution of any commands
    8891 *                              which have been/were attached to the .END
     
    107110#include <sys/file.h>
    108111#include <sys/time.h>
    109 #include <sys/event.h>
    110112#include <sys/wait.h>
    111 #include <err.h>
     113#include <fcntl.h>
    112114#include <errno.h>
    113 #include <fcntl.h>
     115#include <utime.h>
    114116#include <stdio.h>
    115117#include <string.h>
    116118#include <signal.h>
    117 #include <unistd.h>
    118 #include <utime.h>
    119119#include "make.h"
    120120#include "hash.h"
     
    134134static int      errors = 0;         /* number of errors reported */
    135135static int      aborting = 0;       /* why is the make aborting? */
    136 #define ABORT_ERROR     1           /* Because of an error */
    137 #define ABORT_INTERRUPT 2           /* Because it was interrupted */
    138 #define ABORT_WAIT      3           /* Waiting for jobs to finish */
     136#define ABORT_ERROR     1           /* Because of an error */
     137#define ABORT_INTERRUPT 2           /* Because it was interrupted */
     138#define ABORT_WAIT      3           /* Waiting for jobs to finish */
    139139
    140140/*
     
    142142 * is a char! So when we go above 127 we turn negative!
    143143 */
    144 #define FILENO(a) ((unsigned) fileno(a))
     144#define FILENO(a) ((unsigned) fileno(a))
    145145
    146146/*
     
    158158 * Return values from JobStart.
    159159 */
    160 #define JOB_RUNNING     0       /* Job is running */
    161 #define JOB_ERROR       1       /* Error in starting the job */
    162 #define JOB_FINISHED    2       /* The job is already finished */
    163 #define JOB_STOPPED     3       /* The job is stopped */
     160#define JOB_RUNNING     0       /* Job is running */
     161#define JOB_ERROR       1       /* Error in starting the job */
     162#define JOB_FINISHED    2       /* The job is already finished */
     163#define JOB_STOPPED     3       /* The job is stopped */
    164164
    165165/*
     
    196196    FALSE, "echo \"%s\"\n", "sh -c '%s || exit 0'\n",
    197197#endif
    198     "v", "e",
    199 },
    200     /*
    201      * KSH description. The Korn shell has a superset of
    202      * the Bourne shell's functionality.
    203      */
    204 {
    205     "ksh",
    206     TRUE, "set -", "set -v", "set -", 5,
    207     TRUE, "set -e", "set +e",
    208198    "v", "e",
    209199},
     
    239229                                 * nLocal equals maxLocal */
    240230#ifndef RMT_WILL_WATCH
    241 #ifdef USE_KQUEUE
    242 static int      kqfd;           /* File descriptor obtained by kqueue() */
    243 #else
    244231static fd_set   outputs;        /* Set of descriptors of pipes connected to
    245232                                 * the output channels of children */
    246 #endif
    247233#endif
    248234
     
    290276 * really ugly, use dramamine sparingly. You have been warned.
    291277 */
    292 #define W_SETMASKED(st, val, fun)                               \
     278#define W_SETMASKED(st, val, fun)                               \
    293279        {                                                       \
    294280                int sh = (int) ~0;                              \
     
    300286        }
    301287
    302 #define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
    303 #define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
    304 
    305 
    306 static int JobCondPassSig(void *, void *);
    307 static void JobPassSig(int);
    308 static int JobCmpPid(void *, void *);
    309 static int JobPrintCommand(void *, void *);
    310 static int JobSaveCommand(void *, void *);
    311 static void JobClose(Job *);
     288#define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG)
     289#define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS)
     290
     291
     292static int JobCondPassSig __P((ClientData, ClientData));
     293static void JobPassSig __P((int));
     294static int JobCmpPid __P((ClientData, ClientData));
     295static int JobPrintCommand __P((ClientData, ClientData));
     296static int JobSaveCommand __P((ClientData, ClientData));
     297static void JobClose __P((Job *));
    312298#ifdef REMOTE
    313 static int JobCmpRmtID(Job *, int);
     299static int JobCmpRmtID __P((Job *, int));
    314300# ifdef RMT_WILL_WATCH
    315 static void JobLocalInput(int, Job *);
     301static void JobLocalInput __P((int, Job *));
    316302# endif
    317303#else
    318 static void JobFinish(Job *, int *);
    319 static void JobExec(Job *, char **);
    320 #endif
    321 static void JobMakeArgv(Job *, char **);
    322 static void JobRestart(Job *);
    323 static int JobStart(GNode *, int, Job *);
    324 static char *JobOutput(Job *, char *, char *, int);
    325 static void JobDoOutput(Job *, Boolean);
    326 static Shell *JobMatchShell(char *);
    327 static void JobInterrupt(int, int);
    328 static void JobRestartJobs(void);
     304static void JobFinish __P((Job *, int *));
     305static void JobExec __P((Job *, char **));
     306#endif
     307static void JobMakeArgv __P((Job *, char **));
     308static void JobRestart __P((Job *));
     309static int JobStart __P((GNode *, int, Job *));
     310static char *JobOutput __P((Job *, char *, char *, int));
     311static void JobDoOutput __P((Job *, Boolean));
     312static Shell *JobMatchShell __P((char *));
     313static void JobInterrupt __P((int, int));
     314static void JobRestartJobs __P((void));
    329315
    330316/*-
     
    343329 */
    344330static int
    345 JobCondPassSig(void *jobp, void *signop)
     331JobCondPassSig(jobp, signop)
     332    ClientData          jobp;       /* Job to biff */
     333    ClientData          signop;     /* Signal to send it */
    346334{
    347335    Job *job = (Job *) jobp;
     
    358346     * job as well.
    359347     */
    360     DEBUGF(JOB, ("JobCondPassSig passing signal %d to child %d.\n", signo, job->pid));
     348    if (DEBUG(JOB)) {
     349        (void) fprintf(stdout,
     350                       "JobCondPassSig passing signal %d to child %d.\n",
     351                       signo, job->pid);
     352        (void) fflush(stdout);
     353    }
    361354    KILL(job->pid, signo);
    362355#endif
     
    379372 */
    380373static void
    381 JobPassSig(int signo)
     374JobPassSig(signo)
     375    int     signo;      /* The signal number we've received */
    382376{
    383377    sigset_t nmask, omask;
    384378    struct sigaction act;
    385379
    386     DEBUGF(JOB, ("JobPassSig(%d) called.\n", signo));
    387     Lst_ForEach(jobs, JobCondPassSig, (void *) &signo);
     380    if (DEBUG(JOB)) {
     381        (void) fprintf(stdout, "JobPassSig(%d) called.\n", signo);
     382        (void) fflush(stdout);
     383    }
     384    Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
    388385
    389386    /*
     
    419416    sigaction(signo, &act, NULL);
    420417
    421     DEBUGF(JOB, ("JobPassSig passing signal to self, mask = %x.\n", ~0 & ~(1 << (signo-1))));
     418    if (DEBUG(JOB)) {
     419        (void) fprintf(stdout,
     420                       "JobPassSig passing signal to self, mask = %x.\n",
     421                       ~0 & ~(1 << (signo-1)));
     422        (void) fflush(stdout);
     423    }
    422424    (void) signal(signo, SIG_DFL);
    423425
     
    425427
    426428    signo = SIGCONT;
    427     Lst_ForEach(jobs, JobCondPassSig, (void *) &signo);
     429    Lst_ForEach(jobs, JobCondPassSig, (ClientData) &signo);
    428430
    429431    (void) sigprocmask(SIG_SETMASK, &omask, NULL);
     
    448450 */
    449451static int
    450 JobCmpPid(void *job, void *pid)
     452JobCmpPid(job, pid)
     453    ClientData        job;      /* job to examine */
     454    ClientData        pid;      /* process id desired */
    451455{
    452456    return *(int *) pid - ((Job *) job)->pid;
     
    468472 */
    469473static int
    470 JobCmpRmtID(void *job, void *rmtID)
     474JobCmpRmtID(job, rmtID)
     475    ClientData      job;        /* job to examine */
     476    ClientData      rmtID;      /* remote id desired */
    471477{
    472478    return(*(int *) rmtID - *(int *) job->rmtID);
     
    487493 *      made and return non-zero to signal that the end of the commands
    488494 *      was reached. These commands are later attached to the postCommands
    489  *      node and executed by Job_Finish when all things are done.
     495 *      node and executed by Job_End when all things are done.
    490496 *      This function is called from JobStart via Lst_ForEach.
    491497 *
     
    502508 */
    503509static int
    504 JobPrintCommand(void *cmdp, void *jobp)
     510JobPrintCommand(cmdp, jobp)
     511    ClientData    cmdp;             /* command string to print */
     512    ClientData    jobp;             /* job for which to print it */
    505513{
    506514    Boolean       noSpecials;       /* true if we shouldn't worry about
     
    525533        if ((job->flags & JOB_IGNDOTS) == 0) {
    526534            job->tailCmds = Lst_Succ(Lst_Member(job->node->commands,
    527                                                 (void *)cmd));
     535                                                (ClientData)cmd));
    528536            return 1;
    529537        }
     
    531539    }
    532540
    533 #define DBPRINTF(fmt, arg)                      \
    534    DEBUGF(JOB, (fmt, arg));                     \
     541#define DBPRINTF(fmt, arg) if (DEBUG(JOB)) {    \
     542        (void) fprintf(stdout, fmt, arg);       \
     543        (void) fflush(stdout);                  \
     544    }                                           \
    535545   (void) fprintf(job->cmdFILE, fmt, arg);      \
    536546   (void) fflush(job->cmdFILE);
     
    542552     * the variables in the command.
    543553     */
    544     cmdNode = Lst_Member(job->node->commands, (void *)cmd);
     554    cmdNode = Lst_Member(job->node->commands, (ClientData)cmd);
    545555    cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE);
    546     Lst_Replace(cmdNode, (void *)cmdStart);
     556    Lst_Replace(cmdNode, (ClientData)cmdStart);
    547557
    548558    cmdTemplate = "%s\n";
     
    659669 */
    660670static int
    661 JobSaveCommand(void *cmd, void *gn)
    662 {
    663     cmd = (void *) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE);
     671JobSaveCommand(cmd, gn)
     672    ClientData   cmd;
     673    ClientData   gn;
     674{
     675    cmd = (ClientData) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE);
    664676    (void) Lst_AtEnd(postCommands->commands, cmd);
    665677    return(0);
     
    681693 */
    682694static void
    683 JobClose(Job *job)
     695JobClose(job)
     696    Job *job;
    684697{
    685698    if (usePipes) {
    686699#ifdef RMT_WILL_WATCH
    687700        Rmt_Ignore(job->inPipe);
    688 #elif !defined(USE_KQUEUE)
     701#else
    689702        FD_CLR(job->inPipe, &outputs);
    690703#endif
     
    725738/*ARGSUSED*/
    726739static void
    727 JobFinish(Job *job, int *status)
     740JobFinish(job, status)
     741    Job         *job;             /* job to finish */
     742    int         *status;          /* sub-why job went away */
    728743{
    729744    Boolean      done;
     
    794809             */
    795810            out = fdopen(job->outFd, "w");
    796             if (out == NULL)
    797                 Punt("Cannot fdopen");
    798811        } else {
    799812            out = stdout;
     
    801814
    802815        if (WIFEXITED(*status)) {
    803             DEBUGF(JOB, ("Process %d exited.\n", job->pid));
     816            if (DEBUG(JOB)) {
     817                (void) fprintf(stdout, "Process %d exited.\n", job->pid);
     818                (void) fflush(stdout);
     819            }
    804820            if (WEXITSTATUS(*status) != 0) {
    805821                if (usePipes && job->node != lastNode) {
     
    822838            }
    823839        } else if (WIFSTOPPED(*status)) {
    824             DEBUGF(JOB, ("Process %d stopped.\n", job->pid));
     840            if (DEBUG(JOB)) {
     841                (void) fprintf(stdout, "Process %d stopped.\n", job->pid);
     842                (void) fflush(stdout);
     843            }
    825844            if (usePipes && job->node != lastNode) {
    826845                MESSAGE(out, job->node);
     
    832851            }
    833852            job->flags |= JOB_RESUME;
    834             (void)Lst_AtEnd(stoppedJobs, (void *)job);
     853            (void)Lst_AtEnd(stoppedJobs, (ClientData)job);
    835854#ifdef REMOTE
    836855            if (job->flags & JOB_REMIGRATE)
     
    853872            }
    854873            if (!(job->flags & JOB_CONTINUING)) {
    855                 DEBUGF(JOB, ("Warning: process %d was not continuing.\n", job->pid));
     874                if (DEBUG(JOB)) {
     875                    (void) fprintf(stdout,
     876                                   "Warning: process %d was not continuing.\n",
     877                                   job->pid);
     878                    (void) fflush(stdout);
     879                }
    856880#ifdef notdef
    857881                /*
     
    865889            }
    866890            job->flags &= ~JOB_CONTINUING;
    867             Lst_AtEnd(jobs, (void *)job);
     891            Lst_AtEnd(jobs, (ClientData)job);
    868892            nJobs += 1;
    869893            if (!(job->flags & JOB_REMOTE)) {
    870                 DEBUGF(JOB, ("Process %d is continuing locally.\n", job->pid));
     894                if (DEBUG(JOB)) {
     895                    (void) fprintf(stdout,
     896                                   "Process %d is continuing locally.\n",
     897                                   job->pid);
     898                    (void) fflush(stdout);
     899                }
    871900                nLocal += 1;
    872901            }
    873902            if (nJobs == maxJobs) {
    874903                jobFull = TRUE;
    875                 DEBUGF(JOB, ("Job queue is full.\n"));
     904                if (DEBUG(JOB)) {
     905                    (void) fprintf(stdout, "Job queue is full.\n");
     906                    (void) fflush(stdout);
     907                }
    876908            }
    877909            (void) fflush(out);
     
    913945            done = FALSE;
    914946            break;
    915         default:
    916             break;
    917947        }
    918948    } else {
     
    932962         * on the .END target.
    933963         */
    934         if (job->tailCmds != NULL) {
     964        if (job->tailCmds != NILLNODE) {
    935965            Lst_ForEachFrom(job->node->commands, job->tailCmds,
    936966                             JobSaveCommand,
    937                             (void *)job->node);
     967                            (ClientData)job->node);
    938968        }
    939969        job->node->made = MADE;
    940970        Make_Update(job->node);
    941         free(job);
     971        free((Address)job);
    942972    } else if (*status != 0) {
    943973        errors += 1;
    944         free(job);
     974        free((Address)job);
    945975    }
    946976
     
    9701000 * Job_Touch --
    9711001 *      Touch the given target. Called by JobStart when the -t flag was
    972  *      given.  Prints messages unless told to be silent.
     1002 *      given
    9731003 *
    9741004 * Results:
     
    9811011 */
    9821012void
    983 Job_Touch(GNode *gn, Boolean silent)
     1013Job_Touch(gn, silent)
     1014    GNode         *gn;          /* the node of the file to touch */
     1015    Boolean       silent;       /* TRUE if should not print messages */
    9841016{
    9851017    int           streamID;     /* ID of stream opened to do the touch */
     
    10221054                 */
    10231055                if (read(streamID, &c, 1) == 1) {
    1024                     (void) lseek(streamID, (off_t)0, SEEK_SET);
     1056                    (void) lseek(streamID, 0L, SEEK_SET);
    10251057                    (void) write(streamID, &c, 1);
    10261058                }
     
    10501082 */
    10511083Boolean
    1052 Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
     1084Job_CheckCommands(gn, abortProc)
     1085    GNode          *gn;             /* The target whose commands need
     1086                                     * verifying */
     1087    void         (*abortProc) __P((char *, ...));
     1088                        /* Function to abort with message */
    10531089{
    10541090    if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) &&
     
    10581094         * commands
    10591095         */
    1060         if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands)) {
     1096        if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands)) {
    10611097            char *p1;
    10621098            /*
     
    11181154/*ARGSUSED*/
    11191155static void
    1120 JobLocalInput(int stream, Job *job)
     1156JobLocalInput(stream, job)
     1157    int     stream;     /* Stream that's ready (ignored) */
     1158    Job     *job;       /* Job to which the stream belongs */
    11211159{
    11221160    JobDoOutput(job, FALSE);
     
    11401178 */
    11411179static void
    1142 JobExec(Job *job, char **argv)
     1180JobExec(job, argv)
     1181    Job           *job;         /* Job to execute */
     1182    char          **argv;
    11431183{
    11441184    int           cpid;         /* ID of new child */
     
    11471187        int       i;
    11481188
    1149         DEBUGF(JOB, ("Running %s %sly\n", job->node->name,
    1150                job->flags&JOB_REMOTE?"remote":"local"));
    1151         DEBUGF(JOB, ("\tCommand: "));
     1189        (void) fprintf(stdout, "Running %s %sly\n", job->node->name,
     1190                       job->flags&JOB_REMOTE?"remote":"local");
     1191        (void) fprintf(stdout, "\tCommand: ");
    11521192        for (i = 0; argv[i] != NULL; i++) {
    1153             DEBUGF(JOB, ("%s ", argv[i]));
    1154         }
    1155         DEBUGF(JOB, ("\n"));
     1193            (void) fprintf(stdout, "%s ", argv[i]);
     1194        }
     1195        (void) fprintf(stdout, "\n");
     1196        (void) fflush(stdout);
    11561197    }
    11571198
     
    11861227            Punt("Cannot dup2: %s", strerror(errno));
    11871228        (void) fcntl(0, F_SETFD, 0);
    1188         (void) lseek(0, (off_t)0, SEEK_SET);
     1229        (void) lseek(0, 0, SEEK_SET);
    11891230
    11901231        if (usePipes) {
     
    12341275           (void) execv(shellPath, argv);
    12351276
    1236         (void) write(STDERR_FILENO, "Could not execute shell\n",
     1277        (void) write(2, "Could not execute shell\n",
    12371278                     sizeof("Could not execute shell"));
    12381279        _exit(1);
     
    12491290             * stream to watch in the outputs mask
    12501291             */
    1251 #ifdef USE_KQUEUE
    1252             struct kevent       kev[2];
    1253 #endif
    12541292            job->curPos = 0;
    12551293
    12561294#ifdef RMT_WILL_WATCH
    12571295            Rmt_Watch(job->inPipe, JobLocalInput, job);
    1258 #elif defined(USE_KQUEUE)
    1259             EV_SET(&kev[0], job->inPipe, EVFILT_READ, EV_ADD, 0, 0, job);
    1260             EV_SET(&kev[1], job->pid, EVFILT_PROC, EV_ADD | EV_ONESHOT,
    1261                 NOTE_EXIT, 0, NULL);
    1262             if (kevent(kqfd, kev, 2, NULL, 0, NULL) != 0) {
    1263                 /* kevent() will fail if the job is already finished */
    1264                 if (errno != EBADF && errno != ESRCH)
    1265                     Punt("kevent: %s", strerror(errno));
    1266             }
    12671296#else
    12681297            FD_SET(job->inPipe, &outputs);
     
    12981327     */
    12991328    nJobs += 1;
    1300     (void) Lst_AtEnd(jobs, (void *)job);
     1329    (void) Lst_AtEnd(jobs, (ClientData)job);
    13011330    if (nJobs == maxJobs) {
    13021331        jobFull = TRUE;
     
    13171346 */
    13181347static void
    1319 JobMakeArgv(Job *job, char **argv)
     1348JobMakeArgv(job, argv)
     1349    Job           *job;
     1350    char          **argv;
    13201351{
    13211352    int           argc;
     
    13711402 */
    13721403static void
    1373 JobRestart(Job *job)
     1404JobRestart(job)
     1405    Job           *job;         /* Job to restart */
    13741406{
    13751407#ifdef REMOTE
     
    14301462                   (void) fflush(stdout);
    14311463                }
    1432                 (void)Lst_AtFront(stoppedJobs, (void *)job);
     1464                (void)Lst_AtFront(stoppedJobs, (ClientData)job);
    14331465                jobFull = TRUE;
    1434                 DEBUGF(JOB, ("Job queue is full.\n"));
     1466                if (DEBUG(JOB)) {
     1467                   (void) fprintf(stdout, "Job queue is full.\n");
     1468                   (void) fflush(stdout);
     1469                }
    14351470                return;
    14361471            }
     
    14481483#endif
    14491484
    1450         (void)Lst_AtEnd(jobs, (void *)job);
     1485        (void)Lst_AtEnd(jobs, (ClientData)job);
    14511486        nJobs += 1;
    14521487        if (nJobs == maxJobs) {
    14531488            jobFull = TRUE;
    1454             DEBUGF(JOB, ("Job queue is full.\n"));
     1489            if (DEBUG(JOB)) {
     1490                (void) fprintf(stdout, "Job queue is full.\n");
     1491                (void) fflush(stdout);
     1492            }
    14551493        }
    14561494    } else if (job->flags & JOB_RESTART) {
     
    14671505        JobMakeArgv(job, argv);
    14681506
    1469         DEBUGF(JOB, ("Restarting %s...", job->node->name));
     1507        if (DEBUG(JOB)) {
     1508            (void) fprintf(stdout, "Restarting %s...", job->node->name);
     1509            (void) fflush(stdout);
     1510        }
    14701511#ifdef REMOTE
    14711512        if ((job->node->type&OP_NOEXPORT) ||
     
    14831524                 * back on the hold queue and mark the table full
    14841525                 */
    1485                 DEBUGF(JOB, ("holding\n"));
    1486                 (void)Lst_AtFront(stoppedJobs, (void *)job);
     1526                if (DEBUG(JOB)) {
     1527                    (void) fprintf(stdout, "holding\n");
     1528                    (void) fflush(stdout);
     1529                }
     1530                (void)Lst_AtFront(stoppedJobs, (ClientData)job);
    14871531                jobFull = TRUE;
    1488                 DEBUGF(JOB, ("Job queue is full.\n"));
     1532                if (DEBUG(JOB)) {
     1533                    (void) fprintf(stdout, "Job queue is full.\n");
     1534                    (void) fflush(stdout);
     1535                }
    14891536                return;
    14901537            } else {
     
    14921539                 * Job may be run locally.
    14931540                 */
    1494                 DEBUGF(JOB, ("running locally\n"));
     1541                if (DEBUG(JOB)) {
     1542                    (void) fprintf(stdout, "running locally\n");
     1543                    (void) fflush(stdout);
     1544                }
    14951545                job->flags &= ~JOB_REMOTE;
    14961546            }
     
    15011551             * Can be exported. Hooray!
    15021552             */
    1503             DEBUGF(JOB, ("exporting\n"));
     1553            if (DEBUG(JOB)) {
     1554                (void) fprintf(stdout, "exporting\n");
     1555                (void) fflush(stdout);
     1556            }
    15041557            job->flags |= JOB_REMOTE;
    15051558        }
     
    15111564         * we don't know...
    15121565         */
    1513         DEBUGF(JOB, ("Resuming %s...", job->node->name));
     1566        if (DEBUG(JOB)) {
     1567           (void) fprintf(stdout, "Resuming %s...", job->node->name);
     1568           (void) fflush(stdout);
     1569        }
    15141570        if (((job->flags & JOB_REMOTE) ||
    15151571            (nLocal < maxLocal) ||
     
    15511607
    15521608                job->flags &= ~(JOB_RESUME|JOB_CONTINUING);
    1553                 DEBUGF(JOB, ("done\n"));
     1609                if (DEBUG(JOB)) {
     1610                   (void) fprintf(stdout, "done\n");
     1611                   (void) fflush(stdout);
     1612                }
    15541613            } else {
    15551614                Error("couldn't resume %s: %s",
     
    15641623             * place the job back on the list of stopped jobs.
    15651624             */
    1566             DEBUGF(JOB, ("table full\n"));
    1567             (void) Lst_AtFront(stoppedJobs, (void *)job);
     1625            if (DEBUG(JOB)) {
     1626                (void) fprintf(stdout, "table full\n");
     1627                (void) fflush(stdout);
     1628            }
     1629            (void) Lst_AtFront(stoppedJobs, (ClientData)job);
    15681630            jobFull = TRUE;
    1569             DEBUGF(JOB, ("Job queue is full.\n"));
     1631            if (DEBUG(JOB)) {
     1632                (void) fprintf(stdout, "Job queue is full.\n");
     1633                (void) fflush(stdout);
     1634            }
    15701635        }
    15711636    }
     
    15891654 */
    15901655static int
    1591 JobStart(GNode *gn, int flags, Job *previous)
    1592 {
    1593     Job           *job;       /* new job descriptor */
     1656JobStart(gn, flags, previous)
     1657    GNode         *gn;        /* target to create */
     1658    int            flags;      /* flags for the job to override normal ones.
     1659                               * e.g. JOB_SPECIAL or JOB_IGNDOTS */
     1660    Job           *previous;  /* The previous Job structure for this node,
     1661                               * if any. */
     1662{
     1663    register Job  *job;       /* new job descriptor */
    15941664    char          *argv[4];   /* Argument vector to shell */
    15951665    Boolean       cmdsOK;     /* true if the nodes commands were all right */
     
    16031673    } else {
    16041674        job = (Job *) emalloc(sizeof(Job));
     1675        if (job == NULL) {
     1676            Punt("JobStart out of memory");
     1677        }
    16051678        flags |= JOB_FIRST;
    16061679    }
    16071680
    16081681    job->node = gn;
    1609     job->tailCmds = NULL;
     1682    job->tailCmds = NILLNODE;
    16101683
    16111684    /*
     
    16821755                LstNode ln = Lst_Next(gn->commands);
    16831756
    1684                 if ((ln == NULL) ||
    1685                     JobPrintCommand((void *) Lst_Datum(ln),
    1686                                     (void *) job))
     1757                if ((ln == NILLNODE) ||
     1758                    JobPrintCommand((ClientData) Lst_Datum(ln),
     1759                                    (ClientData) job))
    16871760                {
    16881761                    noExec = TRUE;
     
    17091782             */
    17101783            numCommands = 0;
    1711             Lst_ForEach(gn->commands, JobPrintCommand, (void *)job);
     1784            Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
    17121785
    17131786            /*
     
    17351808         */
    17361809        if (cmdsOK) {
    1737             Lst_ForEach(gn->commands, JobPrintCommand, (void *)job);
     1810            Lst_ForEach(gn->commands, JobPrintCommand, (ClientData)job);
    17381811        }
    17391812        /*
     
    17731846        if (cmdsOK) {
    17741847            if (aborting == 0) {
    1775                 if (job->tailCmds != NULL) {
     1848                if (job->tailCmds != NILLNODE) {
    17761849                    Lst_ForEachFrom(job->node->commands, job->tailCmds,
    17771850                                    JobSaveCommand,
    1778                                    (void *)job->node);
     1851                                   (ClientData)job->node);
    17791852                }
    17801853                job->node->made = MADE;
    17811854                Make_Update(job->node);
    17821855            }
    1783             free(job);
     1856            free((Address)job);
    17841857            return(JOB_FINISHED);
    17851858        } else {
    1786             free(job);
     1859            free((Address)job);
    17871860            return(JOB_ERROR);
    17881861        }
     
    18551928        jobFull = TRUE;
    18561929
    1857         DEBUGF(JOB, ("Can only run job locally.\n"));
     1930        if (DEBUG(JOB)) {
     1931           (void) fprintf(stdout, "Can only run job locally.\n");
     1932           (void) fflush(stdout);
     1933        }
    18581934        job->flags |= JOB_RESTART;
    1859         (void) Lst_AtEnd(stoppedJobs, (void *)job);
     1935        (void) Lst_AtEnd(stoppedJobs, (ClientData)job);
    18601936    } else {
    18611937        if ((nLocal >= maxLocal) && local) {
     
    18651941             */
    18661942            jobFull = TRUE;
    1867             DEBUGF(JOB, ("Local job queue is full.\n"));
     1943            if (DEBUG(JOB)) {
     1944                (void) fprintf(stdout, "Local job queue is full.\n");
     1945                (void) fflush(stdout);
     1946            }
    18681947        }
    18691948        JobExec(job, argv);
     
    18731952
    18741953static char *
    1875 JobOutput(Job *job, char *cp, char *endp, int msg)
    1876 {
    1877     char *ecp;
     1954JobOutput(job, cp, endp, msg)
     1955    register Job *job;
     1956    register char *cp, *endp;
     1957    int msg;
     1958{
     1959    register char *ecp;
    18781960
    18791961    if (commandShell->noPrint) {
     
    19432025 */
    19442026STATIC void
    1945 JobDoOutput(Job *job, Boolean finish)
     2027JobDoOutput(job, finish)
     2028    register Job   *job;          /* the job whose output needs printing */
     2029    Boolean        finish;        /* TRUE if this is the last time we'll be
     2030                                   * called for this job */
    19462031{
    19472032    Boolean       gotNL = FALSE;  /* true if got a newline */
    19482033    Boolean       fbuf;           /* true if our buffer filled up */
    1949     int           nr;             /* number of bytes read */
    1950     int           i;              /* auxiliary index into outBuf */
    1951     int           max;            /* limit for i (end of current data) */
     2034    register int  nr;             /* number of bytes read */
     2035    register int  i;              /* auxiliary index into outBuf */
     2036    register int  max;            /* limit for i (end of current data) */
    19522037    int           nRead;          /* (Temporary) number of bytes read */
    19532038
     
    19672052                         JOB_BUFSIZE - job->curPos);
    19682053        if (nRead < 0) {
    1969             DEBUGF(JOB, ("JobDoOutput(piperead)"));
     2054            if (DEBUG(JOB)) {
     2055                perror("JobDoOutput(piperead)");
     2056            }
    19702057            nr = 0;
    19712058        } else {
     
    20212108             * first, overwriting the newline character if there was one.
    20222109             * So long as the line isn't one we should filter (according
    2023              * to the shell description), we print the line, preceded
     2110             * to the shell description), we print the line, preceeded
    20242111             * by a target banner if this target isn't the same as the
    20252112             * one for which we last printed something.
     
    20872174            (void) fflush(stdout);
    20882175            while (fgets(inLine, sizeof(inLine), oFILE) != NULL) {
    2089                 char    *cp, *endp, *oendp;
     2176                register char   *cp, *endp, *oendp;
    20902177
    20912178                cp = inLine;
     
    21342221 */
    21352222void
    2136 Job_CatchChildren(Boolean block)
     2223Job_CatchChildren(block)
     2224    Boolean       block;        /* TRUE if should block on the wait. */
    21372225{
    21382226    int           pid;          /* pid of dead child */
    2139     Job           *job;         /* job descriptor for dead child */
     2227    register Job  *job;         /* job descriptor for dead child */
    21402228    LstNode       jnode;        /* list element for finding job */
    21412229    int           status;       /* Exit/termination status */
     
    21512239                          (block?0:WNOHANG)|WUNTRACED)) > 0)
    21522240    {
    2153         DEBUGF(JOB, ("Process %d exited or stopped.\n", pid));
    2154 
    2155         jnode = Lst_Find(jobs, (void *)&pid, JobCmpPid);
    2156 
    2157         if (jnode == NULL) {
     2241        if (DEBUG(JOB)) {
     2242            (void) fprintf(stdout, "Process %d exited or stopped.\n", pid);
     2243            (void) fflush(stdout);
     2244        }
     2245
     2246
     2247        jnode = Lst_Find(jobs, (ClientData)&pid, JobCmpPid);
     2248
     2249        if (jnode == NILLNODE) {
    21582250            if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) {
    2159                 jnode = Lst_Find(stoppedJobs, (void *) &pid, JobCmpPid);
    2160                 if (jnode == NULL) {
     2251                jnode = Lst_Find(stoppedJobs, (ClientData) &pid, JobCmpPid);
     2252                if (jnode == NILLNODE) {
    21612253                    Error("Resumed child (%d) not in table", pid);
    21622254                    continue;
     
    21722264            (void) Lst_Remove(jobs, jnode);
    21732265            nJobs -= 1;
    2174             DEBUGF(JOB, ("Job queue is no longer full.\n"));
     2266            if (jobFull && DEBUG(JOB)) {
     2267                (void) fprintf(stdout, "Job queue is no longer full.\n");
     2268                (void) fflush(stdout);
     2269            }
    21752270            jobFull = FALSE;
    21762271#ifdef REMOTE
    21772272            if (!(job->flags & JOB_REMOTE)) {
    2178                 DEBUGF(JOB, ("Job queue has one fewer local process.\n"));
     2273                if (DEBUG(JOB)) {
     2274                    (void) fprintf(stdout,
     2275                                   "Job queue has one fewer local process.\n");
     2276                    (void) fflush(stdout);
     2277                }
    21792278                nLocal -= 1;
    21802279            }
     
    22052304 */
    22062305void
    2207 Job_CatchOutput(void)
     2306Job_CatchOutput()
    22082307{
    22092308    int                   nfds;
    2210 #ifdef USE_KQUEUE
    2211 #define KEV_SIZE        4
    2212     struct kevent         kev[KEV_SIZE];
    2213     int                   i;
    2214 #else
    22152309    struct timeval        timeout;
    22162310    fd_set                readfds;
    2217     LstNode               ln;
    2218     Job                   *job;
    2219 #endif
     2311    register LstNode      ln;
     2312    register Job          *job;
    22202313#ifdef RMT_WILL_WATCH
    22212314    int                   pnJobs;       /* Previous nJobs */
     
    22472340#else
    22482341    if (usePipes) {
    2249 #ifdef USE_KQUEUE
    2250         if ((nfds = kevent(kqfd, NULL, 0, kev, KEV_SIZE, NULL)) == -1) {
    2251             Punt("kevent: %s", strerror(errno));
    2252         } else {
    2253             for (i = 0; i < nfds; i++) {
    2254                 if (kev[i].flags & EV_ERROR) {
    2255                     warnc(kev[i].data, "kevent");
    2256                     continue;
    2257                 }
    2258                 switch (kev[i].filter) {
    2259                 case EVFILT_READ:
    2260                     JobDoOutput(kev[i].udata, FALSE);
    2261                     break;
    2262                 case EVFILT_PROC:
    2263                     /* Just wake up and let Job_CatchChildren() collect the
    2264                      * terminated job. */
    2265                     break;
    2266                 }
    2267             }
    2268         }
    2269 #else
    22702342        readfds = outputs;
    22712343        timeout.tv_sec = SEL_SEC;
     
    22792351                Punt("Cannot open job table");
    22802352            }
    2281             while (nfds && (ln = Lst_Next(jobs)) != NULL) {
     2353            while (nfds && (ln = Lst_Next(jobs)) != NILLNODE) {
    22822354                job = (Job *) Lst_Datum(ln);
    22832355                if (FD_ISSET(job->inPipe, &readfds)) {
     
    22882360            Lst_Close(jobs);
    22892361        }
    2290 #endif /* !USE_KQUEUE */
    22912362    }
    22922363#endif /* RMT_WILL_WATCH */
     
    23082379 */
    23092380void
    2310 Job_Make(GNode *gn)
     2381Job_Make(gn)
     2382    GNode   *gn;
    23112383{
    23122384    (void) JobStart(gn, 0, NULL);
     
    23162388 *-----------------------------------------------------------------------
    23172389 * Job_Init --
    2318  *      Initialize the process module, given a maximum number of jobs, and
    2319  *      a maximum number of local jobs.
     2390 *      Initialize the process module
    23202391 *
    23212392 * Results:
     
    23272398 */
    23282399void
    2329 Job_Init(int maxproc, int maxlocal)
     2400Job_Init(maxproc, maxlocal)
     2401    int           maxproc;  /* the greatest number of jobs which may be
     2402                             * running at one time */
     2403    int           maxlocal; /* the greatest number of local jobs which may
     2404                             * be running at once. */
    23302405{
    23312406    GNode         *begin;     /* node for commands to do at the very start */
     
    23422417    errors =      0;
    23432418
    2344     lastNode =    NULL;
     2419    lastNode =    NILGNODE;
    23452420
    23462421    if (maxJobs == 1 || beVerbose == 0
     
    24142489#endif
    24152490
    2416 #ifdef USE_KQUEUE
    2417     if ((kqfd = kqueue()) == -1) {
    2418         Punt("kqueue: %s", strerror(errno));
    2419     }
    2420 #endif
    2421 
    24222491    begin = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    24232492
    2424     if (begin != NULL) {
     2493    if (begin != NILGNODE) {
    24252494        JobStart(begin, JOB_SPECIAL, (Job *)0);
    24262495        while (nJobs) {
     
    24492518 */
    24502519Boolean
    2451 Job_Full(void)
     2520Job_Full()
    24522521{
    24532522    return(aborting || jobFull);
     
    24712540 */
    24722541Boolean
    2473 Job_Empty(void)
     2542Job_Empty()
    24742543{
    24752544    if (nJobs == 0) {
     
    25042573 */
    25052574static Shell *
    2506 JobMatchShell(char *name)
    2507 {
    2508     Shell         *sh;        /* Pointer into shells table */
    2509     Shell         *match;     /* Longest-matching shell */
    2510     char          *cp1,
     2575JobMatchShell(name)
     2576    char          *name;      /* Final component of shell path */
     2577{
     2578    register Shell *sh;       /* Pointer into shells table */
     2579    Shell          *match;    /* Longest-matching shell */
     2580    register char *cp1,
    25112581                  *cp2;
    25122582    char          *eoname;
     
    25752645 */
    25762646ReturnStatus
    2577 Job_ParseShell(char *line)
     2647Job_ParseShell(line)
     2648    char          *line;  /* The shell spec */
    25782649{
    25792650    char          **words;
    25802651    int           wordCount;
    2581     char          **argv;
    2582     int           argc;
     2652    register char **argv;
     2653    register int  argc;
    25832654    char          *path;
    25842655    Shell         newShell;
    25852656    Boolean       fullSpec = FALSE;
    25862657
    2587     while (isspace((unsigned char) *line)) {
     2658    while (isspace(*line)) {
    25882659        line++;
    25892660    }
    25902661    words = brk_string(line, &wordCount, TRUE);
    25912662
    2592     memset(&newShell, 0, sizeof(newShell));
     2663    memset((Address)&newShell, 0, sizeof(newShell));
    25932664
    25942665    /*
     
    26862757    }
    26872758
     2759    /*
     2760     * Do not free up the words themselves, since they might be in use by the
     2761     * shell specification...
     2762     */
     2763    free(words);
    26882764    return SUCCESS;
    26892765}
     
    27032779 */
    27042780static void
    2705 JobInterrupt(int runINTERRUPT, int signo)
     2781JobInterrupt(runINTERRUPT, signo)
     2782    int     runINTERRUPT;       /* Non-zero if commands for the .INTERRUPT
     2783                                 * target should be executed */
     2784    int     signo;              /* signal received */
    27062785{
    27072786    LstNode       ln;           /* element in job table */
     
    27112790    aborting = ABORT_INTERRUPT;
    27122791
    2713     (void) Lst_Open(jobs);
    2714     while ((ln = Lst_Next(jobs)) != NULL) {
     2792   (void) Lst_Open(jobs);
     2793    while ((ln = Lst_Next(jobs)) != NILLNODE) {
    27152794        job = (Job *) Lst_Datum(ln);
    27162795
     
    27442823#else
    27452824        if (job->pid) {
    2746             DEBUGF(JOB, ("JobInterrupt passing signal to child %d.\n",
    2747                    job->pid));
     2825            if (DEBUG(JOB)) {
     2826                (void) fprintf(stdout,
     2827                               "JobInterrupt passing signal to child %d.\n",
     2828                               job->pid);
     2829                (void) fflush(stdout);
     2830            }
    27482831            KILL(job->pid, signo);
    27492832        }
     
    27522835
    27532836#ifdef REMOTE
    2754     (void)Lst_Open(stoppedJobs);
    2755     while ((ln = Lst_Next(stoppedJobs)) != NULL) {
     2837   (void)Lst_Open(stoppedJobs);
     2838    while ((ln = Lst_Next(stoppedJobs)) != NILLNODE) {
    27562839        job = (Job *) Lst_Datum(ln);
    27572840
    27582841        if (job->flags & JOB_RESTART) {
    2759             DEBUGF(JOB, "JobInterrupt skipping job on stopped queue"
    2760                    "-- it was waiting to be restarted.\n");
     2842            if (DEBUG(JOB)) {
     2843                (void) fprintf(stdout, "%s%s",
     2844                               "JobInterrupt skipping job on stopped queue",
     2845                               "-- it was waiting to be restarted.\n");
     2846                (void) fflush(stdout);
     2847            }
    27612848            continue;
    27622849        }
     
    27722859         * Resume the thing so it will take the signal.
    27732860         */
    2774         DEBUGF(JOB, ("JobInterrupt passing CONT to stopped child %d.\n", job->pid));
     2861        if (DEBUG(JOB)) {
     2862            (void) fprintf(stdout,
     2863                           "JobInterrupt passing CONT to stopped child %d.\n",
     2864                           job->pid);
     2865            (void) fflush(stdout);
     2866        }
    27752867        KILL(job->pid, SIGCONT);
    27762868#ifdef RMT_WANTS_SIGNALS
     
    27902882            }
    27912883        } else if (job->pid) {
    2792             DEBUGF(JOB, "JobInterrupt passing interrupt to stopped child %d.\n",
    2793                    job->pid);
     2884            if (DEBUG(JOB)) {
     2885                (void) fprintf(stdout,
     2886                       "JobInterrupt passing interrupt to stopped child %d.\n",
     2887                               job->pid);
     2888                (void) fflush(stdout);
     2889            }
    27942890            KILL(job->pid, SIGINT);
    27952891        }
     
    28012897    if (runINTERRUPT && !touchFlag) {
    28022898        interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    2803         if (interrupt != NULL) {
     2899        if (interrupt != NILGNODE) {
    28042900            ignoreErrors = FALSE;
    28052901
     
    28172913/*
    28182914 *-----------------------------------------------------------------------
    2819  * Job_Finish --
     2915 * Job_End --
    28202916 *      Do final processing such as the running of the commands
    28212917 *      attached to the .END target.
     
    28262922 */
    28272923int
    2828 Job_Finish(void)
    2829 {
    2830     if (postCommands != NULL && !Lst_IsEmpty(postCommands->commands)) {
     2924Job_End()
     2925{
     2926    if (postCommands != NILGNODE && !Lst_IsEmpty(postCommands->commands)) {
    28312927        if (errors) {
    28322928            Error("Errors reported so .END ignored");
     
    28602956 */
    28612957void
    2862 Job_Wait(void)
     2958Job_Wait()
    28632959{
    28642960    aborting = ABORT_WAIT;
     
    28872983 */
    28882984void
    2889 Job_AbortAll(void)
     2985Job_AbortAll()
    28902986{
    28912987    LstNode             ln;     /* element in job table */
     
    28982994
    28992995        (void) Lst_Open(jobs);
    2900         while ((ln = Lst_Next(jobs)) != NULL) {
     2996        while ((ln = Lst_Next(jobs)) != NILLNODE) {
    29012997            job = (Job *) Lst_Datum(ln);
    29022998
     
    29323028 * JobFlagForMigration --
    29333029 *      Handle the eviction of a child. Called from RmtStatusChange.
    2934  *      Flags the child as remigratable and then suspends it.  Takes
    2935  *      the ID of the host we used, for matching children.
     3030 *      Flags the child as remigratable and then suspends it.
    29363031 *
    29373032 * Results:
     
    29443039 */
    29453040void
    2946 JobFlagForMigration(int hostID)
    2947 {
    2948     Job           *job;         /* job descriptor for dead child */
     3041JobFlagForMigration(hostID)
     3042    int           hostID;       /* ID of host we used, for matching children. */
     3043{
     3044    register Job  *job;         /* job descriptor for dead child */
    29493045    LstNode       jnode;        /* list element for finding job */
    29503046
    2951     DEBUGF(JOB, ("JobFlagForMigration(%d) called.\n", hostID));
    2952     jnode = Lst_Find(jobs, (void *)hostID, JobCmpRmtID);
    2953 
    2954     if (jnode == NULL) {
    2955         jnode = Lst_Find(stoppedJobs, (void *)hostID, JobCmpRmtID);
    2956                 if (jnode == NULL) {
     3047    if (DEBUG(JOB)) {
     3048        (void) fprintf(stdout, "JobFlagForMigration(%d) called.\n", hostID);
     3049        (void) fflush(stdout);
     3050    }
     3051    jnode = Lst_Find(jobs, (ClientData)hostID, JobCmpRmtID);
     3052
     3053    if (jnode == NILLNODE) {
     3054        jnode = Lst_Find(stoppedJobs, (ClientData)hostID, JobCmpRmtID);
     3055                if (jnode == NILLNODE) {
    29573056                    if (DEBUG(JOB)) {
    29583057                        Error("Evicting host(%d) not in table", hostID);
     
    29633062    job = (Job *) Lst_Datum(jnode);
    29643063
    2965     DEBUGF(JOB, ("JobFlagForMigration(%d) found job '%s'.\n", hostID, job->node->name));
     3064    if (DEBUG(JOB)) {
     3065        (void) fprintf(stdout,
     3066                       "JobFlagForMigration(%d) found job '%s'.\n", hostID,
     3067                       job->node->name);
     3068        (void) fflush(stdout);
     3069    }
    29663070
    29673071    KILL(job->pid, SIGSTOP);
     
    29893093 */
    29903094static void
    2991 JobRestartJobs(void)
     3095JobRestartJobs()
    29923096{
    29933097    while (!jobFull && !Lst_IsEmpty(stoppedJobs)) {
    2994         DEBUGF(JOB, ("Job queue is not full. Restarting a stopped job.\n"));
     3098        if (DEBUG(JOB)) {
     3099            (void) fprintf(stdout,
     3100                       "Job queue is not full. Restarting a stopped job.\n");
     3101            (void) fflush(stdout);
     3102        }
    29953103        JobRestart((Job *)Lst_DeQueue(stoppedJobs));
    29963104    }
  • branches/FREEBSD/src/kmk/job.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)job.h       8.1 (Berkeley) 6/6/93
    40  * $FreeBSD: src/usr.bin/make/job.h,v 1.20 2002/10/09 01:56:02 jmallett Exp $
     38 *      from: @(#)job.h 8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/job.h,v 1.11 2000/01/17 06:43:41 kris Exp $
    4140 */
    4241
     
    4746 */
    4847#ifndef _JOB_H_
    49 #define _JOB_H_
    50 
    51 #define TMPPAT  "/tmp/makeXXXXXXXXXX"
    52 
    53 #ifndef USE_KQUEUE
     48#define _JOB_H_
     49
     50#define TMPPAT  "/tmp/makeXXXXXXXXXX"
     51
    5452/*
    5553 * The SEL_ constants determine the maximum amount of time spent in select
     
    5755 * seconds and SEL_USEC is the number of micro-seconds
    5856 */
    59 #define SEL_SEC         0
    60 #define SEL_USEC        100000
    61 #endif /* !USE_KQUEUE */
     57#define SEL_SEC         0
     58#define SEL_USEC        100000
    6259
    6360
     
    7067 *      2) The graph node describing the target being made by this job
    7168 *      3) A LstNode for the first command to be saved after the job
    72  *         completes. This is NULL if there was no "..." in the job's
     69 *         completes. This is NILLNODE if there was no "..." in the job's
    7370 *         commands.
    7471 *      4) An FILE* for writing out the commands. This is only
     
    9592 * traversal of the dependency graph.
    9693 */
    97 #define JOB_BUFSIZE     1024
     94#define JOB_BUFSIZE     1024
    9895typedef struct Job {
    9996    int         pid;        /* The child's process ID */
     
    109106#define JOB_IGNERR      0x001   /* Ignore non-zero exits */
    110107#define JOB_SILENT      0x002   /* no output */
    111 #define JOB_SPECIAL     0x004   /* Target is a special one. i.e. run it locally
     108#define JOB_SPECIAL     0x004   /* Target is a special one. i.e. run it locally
    112109                                 * if we can't export it and maxLocal is 0 */
    113 #define JOB_IGNDOTS     0x008   /* Ignore "..." lines when processing
     110#define JOB_IGNDOTS     0x008   /* Ignore "..." lines when processing
    114111                                 * commands */
    115 #define JOB_REMOTE      0x010   /* Job is running remotely */
    116 #define JOB_FIRST       0x020   /* Job is first job for the node */
    117 #define JOB_REMIGRATE   0x040   /* Job needs to be remigrated */
    118 #define JOB_RESTART     0x080   /* Job needs to be completely restarted */
    119 #define JOB_RESUME      0x100   /* Job needs to be resumed b/c it stopped,
     112#define JOB_REMOTE      0x010   /* Job is running remotely */
     113#define JOB_FIRST       0x020   /* Job is first job for the node */
     114#define JOB_REMIGRATE   0x040   /* Job needs to be remigrated */
     115#define JOB_RESTART     0x080   /* Job needs to be completely restarted */
     116#define JOB_RESUME      0x100   /* Job needs to be resumed b/c it stopped,
    120117                                 * for some reason */
    121 #define JOB_CONTINUING  0x200   /* We are in the process of resuming this job.
     118#define JOB_CONTINUING  0x200   /* We are in the process of resuming this job.
    122119                                 * Used to avoid infinite recursion between
    123120                                 * JobFinish and JobRestart */
     
    148145} Job;
    149146
    150 #define outPipe         output.o_pipe.op_outPipe
    151 #define inPipe          output.o_pipe.op_inPipe
    152 #define outBuf          output.o_pipe.op_outBuf
    153 #define curPos          output.o_pipe.op_curPos
    154 #define outFile         output.o_file.of_outFile
    155 #define outFd           output.o_file.of_outFd
     147#define outPipe         output.o_pipe.op_outPipe
     148#define inPipe          output.o_pipe.op_inPipe
     149#define outBuf          output.o_pipe.op_outBuf
     150#define curPos          output.o_pipe.op_curPos
     151#define outFile         output.o_file.of_outFile
     152#define outFd           output.o_file.of_outFd
    156153
    157154
     
    208205}               Shell;
    209206
    210 /*
    211  * If REMOTE is defined then these things need exposed, otherwise they are
    212  * static to job.c!
    213  */
    214 #ifdef REMOTE
     207
    215208extern char     *targFmt;       /* Format string for banner that separates
    216209                                 * output from multiple jobs. Contains a
     
    227220                                 * quite get started */
    228221extern Boolean  jobFull;        /* Non-zero if no more jobs should/will start*/
    229 #endif
    230 
    231 extern int      maxJobs;        /* Number of jobs that may run */
    232 
    233 
    234 void Job_Touch(GNode *, Boolean);
    235 Boolean Job_CheckCommands(GNode *, void (*abortProc)(const char *, ...));
    236 void Job_CatchChildren(Boolean);
    237 void Job_CatchOutput(void);
    238 void Job_Make(GNode *);
    239 void Job_Init(int, int);
    240 Boolean Job_Full(void);
    241 Boolean Job_Empty(void);
    242 ReturnStatus Job_ParseShell(char *);
    243 int Job_Finish(void);
    244 void Job_Wait(void);
    245 void Job_AbortAll(void);
    246 void JobFlagForMigration(int);
     222
     223
     224void Job_Touch __P((GNode *, Boolean));
     225Boolean Job_CheckCommands __P((GNode *, void (*abortProc )(char *, ...)));
     226void Job_CatchChildren __P((Boolean));
     227void Job_CatchOutput __P((void));
     228void Job_Make __P((GNode *));
     229void Job_Init __P((int, int));
     230Boolean Job_Full __P((void));
     231Boolean Job_Empty __P((void));
     232ReturnStatus Job_ParseShell __P((char *));
     233int Job_End __P((void));
     234void Job_Wait __P((void));
     235void Job_AbortAll __P((void));
     236void JobFlagForMigration __P((int));
    247237
    248238#endif /* _JOB_H_ */
  • branches/FREEBSD/src/kmk/list.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)list.h      8.2 (Berkeley) 4/28/95
    40  * $FreeBSD: src/usr.bin/make/list.h,v 1.11 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)list.h        8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/list.h,v 1.8 1999/08/28 01:03:32 peter Exp $
    4140 */
    4241
     
    4847
    4948#ifndef _LIST
    50 #define _LIST
     49#define _LIST
    5150
    5251#ifndef _SPRITE
     
    131130 * ----------------------------------------------------------------------------
    132131 */
    133 #define List_InitElement(elementPtr) \
    134     (elementPtr)->prevPtr = (List_Links *) NULL; \
    135     (elementPtr)->nextPtr = (List_Links *) NULL;
     132#define List_InitElement(elementPtr) \
     133    (elementPtr)->prevPtr = (List_Links *) NIL; \
     134    (elementPtr)->nextPtr = (List_Links *) NIL;
    136135
    137136/*
     
    163162 */
    164163
    165 #define LIST_FORALL(headerPtr, itemPtr) \
     164#define LIST_FORALL(headerPtr, itemPtr) \
    166165        for (itemPtr = List_First(headerPtr); \
    167166             !List_IsAtEnd((headerPtr),itemPtr); \
     
    181180 */
    182181
    183 #define List_IsEmpty(headerPtr) \
     182#define List_IsEmpty(headerPtr) \
    184183        ((headerPtr) == (headerPtr)->nextPtr)
    185184
     
    198197
    199198
    200 #define List_IsAtEnd(headerPtr, itemPtr) \
     199#define List_IsAtEnd(headerPtr, itemPtr) \
    201200        ((itemPtr) == (headerPtr))
    202201
     
    216215 */
    217216
    218 #define List_First(headerPtr) ((headerPtr)->nextPtr)
     217#define List_First(headerPtr) ((headerPtr)->nextPtr)
    219218
    220219/*
     
    231230 */
    232231
    233 #define List_Last(headerPtr) ((headerPtr)->prevPtr)
     232#define List_Last(headerPtr) ((headerPtr)->prevPtr)
    234233
    235234/*
     
    247246 */
    248247
    249 #define List_Prev(itemPtr) ((itemPtr)->prevPtr)
     248#define List_Prev(itemPtr) ((itemPtr)->prevPtr)
    250249
    251250/*
     
    263262 */
    264263
    265 #define List_Next(itemPtr) ((itemPtr)->nextPtr)
     264#define List_Next(itemPtr) ((itemPtr)->nextPtr)
    266265
    267266
     
    294293 */
    295294
    296 #define LIST_AFTER(itemPtr) ((List_Links *) itemPtr)
    297 
    298 #define LIST_BEFORE(itemPtr) (((List_Links *) itemPtr)->prevPtr)
    299 
    300 #define LIST_ATFRONT(headerPtr) ((List_Links *) headerPtr)
    301 
    302 #define LIST_ATREAR(headerPtr) (((List_Links *) headerPtr)->prevPtr)
     295#define LIST_AFTER(itemPtr) ((List_Links *) itemPtr)
     296
     297#define LIST_BEFORE(itemPtr) (((List_Links *) itemPtr)->prevPtr)
     298
     299#define LIST_ATFRONT(headerPtr) ((List_Links *) headerPtr)
     300
     301#define LIST_ATREAR(headerPtr) (((List_Links *) headerPtr)->prevPtr)
    303302
    304303#endif /* _LIST */
  • branches/FREEBSD/src/kmk/lst.h

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3736 * SUCH DAMAGE.
    3837 *
    39  *      @(#)lst.h       8.2 (Berkeley) 4/28/95
    40  * $FreeBSD: src/usr.bin/make/lst.h,v 1.15 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)lst.h 8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/lst.h,v 1.9 1999/08/28 01:03:32 peter Exp $
    4140 */
    4241
     
    4645 */
    4746#ifndef _LST_H_
    48 #define _LST_H_
     47#define _LST_H_
    4948
    5049#include        <sys/param.h>
     50#ifdef __STDC__
    5151#include        <stdlib.h>
     52#endif
    5253#include        "sprite.h"
    5354
     
    5960typedef struct  LstNode *LstNode;
    6061
     62#define NILLST          ((Lst) NIL)
     63#define NILLNODE        ((LstNode) NIL)
     64
    6165/*
    6266 * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
     
    6468 * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
    6569 */
    66 #define NOFREE          ((void (*)(void *)) 0)
    67 #define NOCOPY          ((void * (*)(void *)) 0)
     70#define NOFREE          ((void (*) __P((ClientData))) 0)
     71#define NOCOPY          ((ClientData (*) __P((ClientData))) 0)
    6872
    69 #define LST_CONCNEW     0   /* create new LstNode's when using Lst_Concat */
    70 #define LST_CONCLINK    1   /* relink LstNode's when using Lst_Concat */
     73#define LST_CONCNEW     0   /* create new LstNode's when using Lst_Concat */
     74#define LST_CONCLINK    1   /* relink LstNode's when using Lst_Concat */
    7175
    7276/*
     
    7478 */
    7579/* Create a new list */
    76 Lst             Lst_Init(Boolean);
     80Lst             Lst_Init __P((Boolean));
    7781/* Duplicate an existing list */
    78 Lst             Lst_Duplicate(Lst, void * (*)(void *));
     82Lst             Lst_Duplicate __P((Lst, ClientData (*)(ClientData)));
    7983/* Destroy an old one */
    80 void            Lst_Destroy(Lst, void (*)(void *));
     84void            Lst_Destroy __P((Lst, void (*)(ClientData)));
    8185/* True if list is empty */
    82 Boolean         Lst_IsEmpty(Lst);
     86Boolean         Lst_IsEmpty __P((Lst));
    8387
    8488/*
     
    8690 */
    8791/* Insert an element before another */
    88 ReturnStatus    Lst_Insert(Lst, LstNode, void *);
     92ReturnStatus    Lst_Insert __P((Lst, LstNode, ClientData));
    8993/* Insert an element after another */
    90 ReturnStatus    Lst_Append(Lst, LstNode, void *);
     94ReturnStatus    Lst_Append __P((Lst, LstNode, ClientData));
    9195/* Place an element at the front of a lst. */
    92 ReturnStatus    Lst_AtFront(Lst, void *);
     96ReturnStatus    Lst_AtFront __P((Lst, ClientData));
    9397/* Place an element at the end of a lst. */
    94 ReturnStatus    Lst_AtEnd(Lst, void *);
     98ReturnStatus    Lst_AtEnd __P((Lst, ClientData));
    9599/* Remove an element */
    96 ReturnStatus    Lst_Remove(Lst, LstNode);
     100ReturnStatus    Lst_Remove __P((Lst, LstNode));
    97101/* Replace a node with a new value */
    98 ReturnStatus    Lst_Replace(LstNode, void *);
     102ReturnStatus    Lst_Replace __P((LstNode, ClientData));
    99103/* Concatenate two lists */
    100 ReturnStatus    Lst_Concat(Lst, Lst, int);
     104ReturnStatus    Lst_Concat __P((Lst, Lst, int));
    101105
    102106/*
     
    104108 */
    105109/* Return first element in list */
    106 LstNode         Lst_First(Lst);
     110LstNode         Lst_First __P((Lst));
    107111/* Return last element in list */
    108 LstNode         Lst_Last(Lst);
     112LstNode         Lst_Last __P((Lst));
    109113/* Return successor to given element */
    110 LstNode         Lst_Succ(LstNode);
     114LstNode         Lst_Succ __P((LstNode));
    111115/* Get datum from LstNode */
    112 void *  Lst_Datum(LstNode);
     116ClientData      Lst_Datum __P((LstNode));
    113117
    114118/*
     
    116120 */
    117121/* Find an element in a list */
    118 LstNode         Lst_Find(Lst, void *, int (*)(void *, void *));
     122LstNode         Lst_Find __P((Lst, ClientData,
     123                              int (*)(ClientData, ClientData)));
    119124/* Find an element starting from somewhere */
    120 LstNode         Lst_FindFrom(Lst, LstNode, void *, int (*cProc)(void *, void *));
     125LstNode         Lst_FindFrom __P((Lst, LstNode, ClientData,
     126                                  int (*cProc)(ClientData, ClientData)));
    121127/*
    122128 * See if the given datum is on the list. Returns the LstNode containing
    123129 * the datum
    124130 */
    125 LstNode         Lst_Member(Lst, void *);
     131LstNode         Lst_Member __P((Lst, ClientData));
    126132/* Apply a function to all elements of a lst */
    127 void            Lst_ForEach(Lst, int (*)(void *, void *), void *);
     133void            Lst_ForEach __P((Lst, int (*)(ClientData, ClientData),
     134                                 ClientData));
    128135/*
    129136 * Apply a function to all elements of a lst starting from a certain point.
     
    131138 * beginning of the list again.
    132139 */
    133 void            Lst_ForEachFrom(Lst, LstNode, int (*)(void *, void *), void *);
     140void            Lst_ForEachFrom __P((Lst, LstNode,
     141                                     int (*)(ClientData, ClientData),
     142                                     ClientData));
    134143/*
    135144 * these functions are for dealing with a list as a table, of sorts.
     
    138147 */
    139148/* Open the list */
    140 ReturnStatus    Lst_Open(Lst);
     149ReturnStatus    Lst_Open __P((Lst));
    141150/* Next element please */
    142 LstNode         Lst_Next(Lst);
     151LstNode         Lst_Next __P((Lst));
    143152/* Done yet? */
    144 Boolean         Lst_IsAtEnd(Lst);
     153Boolean         Lst_IsAtEnd __P((Lst));
    145154/* Finish table access */
    146 void            Lst_Close(Lst);
     155void            Lst_Close __P((Lst));
    147156
    148157/*
     
    150159 */
    151160/* Place an element at tail of queue */
    152 ReturnStatus    Lst_EnQueue(Lst, void *);
     161ReturnStatus    Lst_EnQueue __P((Lst, ClientData));
    153162/* Remove an element from head of queue */
    154 void *  Lst_DeQueue(Lst);
     163ClientData      Lst_DeQueue __P((Lst));
    155164
    156165#endif /* _LST_H_ */
  • branches/FREEBSD/src/kmk/lst.lib/lstAppend.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstAppend.c      8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstAppend.c,v 1.6 1999/08/28 01:03:45 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstAppend.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstAppend.c 8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6160 *      field of the List will be altered if ln is the last node in the
    6261 *      list. lastPtr and firstPtr will alter if the list was empty and
    63  *      ln was NULL.
     62 *      ln was NILLNODE.
    6463 *
    6564 *-----------------------------------------------------------------------
     
    6968    Lst         l;      /* affected list */
    7069    LstNode     ln;     /* node after which to append the datum */
    71     void *      d;      /* said datum */
     70    ClientData  d;      /* said datum */
    7271{
    7372    register List       list;
     
    7574    register ListNode   nLNode;
    7675
    77     if (LstValid (l) && (ln == NULL && LstIsEmpty (l))) {
     76    if (LstValid (l) && (ln == NILLNODE && LstIsEmpty (l))) {
    7877        goto ok;
    7978    }
     
    9190    nLNode->useCount = nLNode->flags = 0;
    9291
    93     if (lNode == NULL) {
     92    if (lNode == NilListNode) {
    9493        if (list->isCirc) {
    9594            nLNode->nextPtr = nLNode->prevPtr = nLNode;
    9695        } else {
    97             nLNode->nextPtr = nLNode->prevPtr = NULL;
     96            nLNode->nextPtr = nLNode->prevPtr = NilListNode;
    9897        }
    9998        list->firstPtr = list->lastPtr = nLNode;
     
    103102
    104103        lNode->nextPtr = nLNode;
    105         if (nLNode->nextPtr != NULL) {
     104        if (nLNode->nextPtr != NilListNode) {
    106105            nLNode->nextPtr->prevPtr = nLNode;
    107106        }
  • branches/FREEBSD/src/kmk/lst.lib/lstAtEnd.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstAtEnd.c       8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstAtEnd.c,v 1.6 1999/08/28 01:03:46 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstAtEnd.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstAtEnd.c  8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6564Lst_AtEnd (l, d)
    6665    Lst         l;      /* List to which to add the datum */
    67     void *      d;      /* Datum to add */
     66    ClientData  d;      /* Datum to add */
    6867{
    6968    register LstNode    end;
  • branches/FREEBSD/src/kmk/lst.lib/lstAtFront.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstAtFront.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstAtFront.c,v 1.6 1999/08/28 01:03:47 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstAtFront.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstAtFront.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6665Lst_AtFront (l, d)
    6766    Lst         l;
    68     void *      d;
     67    ClientData  d;
    6968{
    7069    register LstNode    front;
  • branches/FREEBSD/src/kmk/lst.lib/lstClose.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstClose.c       8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstClose.c,v 1.6 1999/08/28 01:03:47 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstClose.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstClose.c  8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
  • branches/FREEBSD/src/kmk/lst.lib/lstConcat.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstConcat.c      8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstConcat.c,v 1.7 1999/08/28 01:03:47 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstConcat.c,v 1.11 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstConcat.c 8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    8584
    8685    if (flags == LST_CONCLINK) {
    87         if (list2->firstPtr != NULL) {
     86        if (list2->firstPtr != NilListNode) {
    8887            /*
    8988             * We set the nextPtr of the
    90              * last element of list two to be NULL to make the loop easier and
     89             * last element of list two to be NIL to make the loop easier and
    9190             * so we don't need an extra case should the first list turn
    9291             * out to be non-circular -- the final element will already point
    93              * to NULL space and the first element will be untouched if it
    94              * existed before and will also point to NULL space if it didn't.
     92             * to NIL space and the first element will be untouched if it
     93             * existed before and will also point to NIL space if it didn't.
    9594             */
    96             list2->lastPtr->nextPtr = NULL;
     95            list2->lastPtr->nextPtr = NilListNode;
    9796            /*
    9897             * So long as the second list isn't empty, we just link the
     
    104103             */
    105104            list2->firstPtr->prevPtr = list1->lastPtr;
    106             if (list1->lastPtr != NULL) {
     105            if (list1->lastPtr != NilListNode) {
    107106                list1->lastPtr->nextPtr = list2->firstPtr;
    108107            } else {
     
    111110            list1->lastPtr = list2->lastPtr;
    112111        }
    113         if (list1->isCirc && list1->firstPtr != NULL) {
     112        if (list1->isCirc && list1->firstPtr != NilListNode) {
    114113            /*
    115114             * If the first list is supposed to be circular and it is (now)
     
    120119            list1->lastPtr->nextPtr = list1->firstPtr;
    121120        }
    122         free (l2);
    123     } else if (list2->firstPtr != NULL) {
     121        free ((Address)l2);
     122    } else if (list2->firstPtr != NilListNode) {
    124123        /*
    125          * We set the nextPtr of the last element of list 2 to be NULL to make
     124         * We set the nextPtr of the last element of list 2 to be nil to make
    126125         * the loop less difficult. The loop simply goes through the entire
    127126         * second list creating new LstNodes and filling in the nextPtr, and
     
    130129         * follows the last of the new nodes along until the entire l2 has
    131130         * been appended. Only then does the bookkeeping catch up with the
    132          * changes. During the first iteration of the loop, if 'last' is NULL,
     131         * changes. During the first iteration of the loop, if 'last' is nil,
    133132         * the first list must have been empty so the newly-created node is
    134133         * made the first node of the list.
    135134         */
    136         list2->lastPtr->nextPtr = NULL;
     135        list2->lastPtr->nextPtr = NilListNode;
    137136        for (last = list1->lastPtr, ln = list2->firstPtr;
    138              ln != NULL;
     137             ln != NilListNode;
    139138             ln = ln->nextPtr)
    140139        {
    141140            PAlloc (nln, ListNode);
    142141            nln->datum = ln->datum;
    143             if (last != NULL) {
     142            if (last != NilListNode) {
    144143                last->nextPtr = nln;
    145144            } else {
     
    167166            list1->firstPtr->prevPtr = list1->lastPtr;
    168167        } else {
    169             last->nextPtr = NULL;
     168            last->nextPtr = NilListNode;
    170169        }
    171170
  • branches/FREEBSD/src/kmk/lst.lib/lstDatum.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstDatum.c       8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstDatum.c,v 1.5 1999/08/28 01:03:48 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstDatum.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstDatum.c  8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5554 *
    5655 * Results:
    57  *      The datum or (ick!) NULL if the node is invalid.
     56 *      The datum or (ick!) NIL if the node is invalid.
    5857 *
    5958 * Side Effects:
     
    6261 *-----------------------------------------------------------------------
    6362 */
    64 void *
     63ClientData
    6564Lst_Datum (ln)
    6665    LstNode     ln;
    6766{
    68     if (ln != NULL) {
     67    if (ln != NILLNODE) {
    6968        return (((ListNode)ln)->datum);
    7069    } else {
    71         return ((void *) NULL);
     70        return ((ClientData) NIL);
    7271    }
    7372}
  • branches/FREEBSD/src/kmk/lst.lib/lstDeQueue.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstDeQueue.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstDeQueue.c,v 1.6 1999/08/28 01:03:48 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstDeQueue.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstDeQueue.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5554 *
    5655 * Results:
    57  *      The datum in the node at the head or (ick) NULL if the list
     56 *      The datum in the node at the head or (ick) NIL if the list
    5857 *      is empty.
    5958 *
     
    6362 *-----------------------------------------------------------------------
    6463 */
    65 void *
     64ClientData
    6665Lst_DeQueue (l)
    6766    Lst           l;
    6867{
    69     void *        rd;
     68    ClientData    rd;
    7069    register ListNode   tln;
    7170
    7271    tln = (ListNode) Lst_First (l);
    73     if (tln == NULL) {
    74         return ((void *) NULL);
     72    if (tln == NilListNode) {
     73        return ((ClientData) NIL);
    7574    }
    7675
    7776    rd = tln->datum;
    7877    if (Lst_Remove (l, (LstNode)tln) == FAILURE) {
    79         return ((void *) NULL);
     78        return ((ClientData) NIL);
    8079    } else {
    8180        return (rd);
  • branches/FREEBSD/src/kmk/lst.lib/lstDestroy.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstDestroy.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstDestroy.c,v 1.7 1999/08/28 01:03:49 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstDestroy.c,v 1.12 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstDestroy.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6766Lst_Destroy (l, freeProc)
    6867    Lst                 l;
    69     register void       (*freeProc)(void *);
     68    register void       (*freeProc) __P((ClientData));
    7069{
    7170    register ListNode   ln;
    72     register ListNode   tln = NULL;
     71    register ListNode   tln = NilListNode;
    7372    register List       list = (List)l;
    7473
    75     if (l == NULL || ! l) {
     74    if (l == NILLST || ! l) {
    7675        /*
    7776         * Note the check for l == (Lst)0 to catch uninitialized static Lst's.
     
    8281
    8382    /* To ease scanning */
    84     if (list->lastPtr != NULL)
    85         list->lastPtr->nextPtr = NULL;
     83    if (list->lastPtr != NilListNode)
     84        list->lastPtr->nextPtr = NilListNode;
    8685    else {
    87         free (l);
     86        free ((Address)l);
    8887        return;
    8988    }
    9089
    9190    if (freeProc) {
    92         for (ln = list->firstPtr; ln != NULL; ln = tln) {
     91        for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
    9392             tln = ln->nextPtr;
    9493             (*freeProc) (ln->datum);
    95              free (ln);
     94             free ((Address)ln);
    9695        }
    9796    } else {
    98         for (ln = list->firstPtr; ln != NULL; ln = tln) {
     97        for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
    9998             tln = ln->nextPtr;
    100              free (ln);
     99             free ((Address)ln);
    101100        }
    102101    }
    103102
    104     free (l);
     103    free ((Address)l);
    105104}
  • branches/FREEBSD/src/kmk/lst.lib/lstDupl.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstDupl.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstDupl.c,v 1.7 1999/08/28 01:03:49 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstDupl.c,v 1.12 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstDupl.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5352 *-----------------------------------------------------------------------
    5453 * Lst_Duplicate --
    55  *      Duplicate an entire list. If a function to copy a void * is
     54 *      Duplicate an entire list. If a function to copy a ClientData is
    5655 *      given, the individual client elements will be duplicated as well.
    5756 *
    5857 * Results:
    59  *      The new Lst structure or NULL if failure.
     58 *      The new Lst structure or NILLST if failure.
    6059 *
    6160 * Side Effects:
     
    6665Lst_Duplicate (l, copyProc)
    6766    Lst           l;             /* the list to duplicate */
    68     /* A function to duplicate each void * */
    69     void *        (*copyProc)(void *);
     67    /* A function to duplicate each ClientData */
     68    ClientData    (*copyProc) __P((ClientData));
    7069{
    7170    register Lst        nl;
     
    7473
    7574    if (!LstValid (l)) {
    76         return (NULL);
     75        return (NILLST);
    7776    }
    7877
    7978    nl = Lst_Init (list->isCirc);
    80     if (nl == NULL) {
    81         return (NULL);
     79    if (nl == NILLST) {
     80        return (NILLST);
    8281    }
    8382
    8483    ln = list->firstPtr;
    85     while (ln != NULL) {
     84    while (ln != NilListNode) {
    8685        if (copyProc != NOCOPY) {
    8786            if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) {
    88                 return (NULL);
     87                return (NILLST);
    8988            }
    9089        } else if (Lst_AtEnd (nl, ln->datum) == FAILURE) {
    91             return (NULL);
     90            return (NILLST);
    9291        }
    9392
    9493        if (list->isCirc && ln == list->lastPtr) {
    95             ln = NULL;
     94            ln = NilListNode;
    9695        } else {
    9796            ln = ln->nextPtr;
  • branches/FREEBSD/src/kmk/lst.lib/lstEnQueue.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstEnQueue.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstEnQueue.c,v 1.6 1999/08/28 01:03:50 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstEnQueue.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstEnQueue.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6665Lst_EnQueue (l, d)
    6766    Lst           l;
    68     void *        d;
     67    ClientData    d;
    6968{
    7069    if (LstValid (l) == FALSE) {
  • branches/FREEBSD/src/kmk/lst.lib/lstFind.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstFind.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstFind.c,v 1.6 1999/08/28 01:03:50 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstFind.c,v 1.11 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstFind.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5655 *
    5756 * Results:
    58  *      The found node or NULL if none matches.
     57 *      The found node or NILLNODE if none matches.
    5958 *
    6059 * Side Effects:
     
    6665Lst_Find (l, d, cProc)
    6766    Lst         l;
    68     void *      d;
    69     int         (*cProc)(void *, void *);
     67    ClientData  d;
     68    int         (*cProc) __P((ClientData, ClientData));
    7069{
    7170    return (Lst_FindFrom (l, Lst_First(l), d, cProc));
  • branches/FREEBSD/src/kmk/lst.lib/lstFindFrom.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstFindFrom.c    8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstFindFrom.c,v 1.7 1999/08/28 01:03:50 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstFindFrom.c,v 1.12 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstFindFrom.c       8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5756 *
    5857 * Results:
    59  *      The found node or NULL
     58 *      The found node or NILLNODE
    6059 *
    6160 * Side Effects:
     
    6867    Lst                 l;
    6968    register LstNode    ln;
    70     register void * d;
    71     register int        (*cProc)(void *, void *);
     69    register ClientData d;
     70    register int        (*cProc) __P((ClientData, ClientData));
    7271{
    7372    register ListNode   tln;
     
    7574
    7675    if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
    77         return (NULL);
     76        return (NILLNODE);
    7877    }
    7978
     
    8786            tln = tln->nextPtr;
    8887        }
    89     } while (tln != (ListNode)ln && tln != NULL);
     88    } while (tln != (ListNode)ln && tln != NilListNode);
    9089
    9190    if (found) {
    9291        return ((LstNode)tln);
    9392    } else {
    94         return (NULL);
     93        return (NILLNODE);
    9594    }
    9695}
  • branches/FREEBSD/src/kmk/lst.lib/lstFirst.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstFirst.c       8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstFirst.c,v 1.5 1999/08/28 01:03:51 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstFirst.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstFirst.c  8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5554 *
    5655 * Results:
    57  *      The first node or NULL if the list is empty.
     56 *      The first node or NILLNODE if the list is empty.
    5857 *
    5958 * Side Effects:
     
    6766{
    6867    if (!LstValid (l) || LstIsEmpty (l)) {
    69         return (NULL);
     68        return (NILLNODE);
    7069    } else {
    7170        return ((LstNode)((List)l)->firstPtr);
  • branches/FREEBSD/src/kmk/lst.lib/lstForEach.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstForEach.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstForEach.c,v 1.6 1999/08/28 01:03:51 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstForEach.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstForEach.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6867Lst_ForEach (l, proc, d)
    6968    Lst                 l;
    70     register int        (*proc)(void *, void *);
    71     register void *     d;
     69    register int        (*proc) __P((ClientData, ClientData));
     70    register ClientData d;
    7271{
    7372    Lst_ForEachFrom(l, Lst_First(l), proc, d);
  • branches/FREEBSD/src/kmk/lst.lib/lstForEachFrom.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstForEachFrom.c 8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstForEachFrom.c,v 1.7 1999/08/28 01:03:52 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstForEachFrom.c,v 1.12 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstForEachFrom.c    8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    7069    Lst                 l;
    7170    LstNode             ln;
    72     register int        (*proc)(void *, void *);
    73     register void *     d;
     71    register int        (*proc) __P((ClientData, ClientData));
     72    register ClientData d;
    7473{
    7574    register ListNode   tln = (ListNode)ln;
     
    102101         */
    103102        done = (next == tln->nextPtr &&
    104                 (next == NULL || next == list->firstPtr));
     103                (next == NilListNode || next == list->firstPtr));
    105104
    106105        next = tln->nextPtr;
  • branches/FREEBSD/src/kmk/lst.lib/lstInit.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstInit.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstInit.c,v 1.6 1999/08/28 01:03:52 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstInit.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstInit.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    7069    PAlloc (nList, List);
    7170
    72     nList->firstPtr = NULL;
    73     nList->lastPtr = NULL;
     71    nList->firstPtr = NilListNode;
     72    nList->lastPtr = NilListNode;
    7473    nList->isOpen = FALSE;
    7574    nList->isCirc = circ;
  • branches/FREEBSD/src/kmk/lst.lib/lstInsert.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstInsert.c      8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstInsert.c,v 1.6 1999/08/28 01:03:52 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstInsert.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstInsert.c 8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6867    Lst                 l;      /* list to manipulate */
    6968    LstNode             ln;     /* node before which to insert d */
    70     void *              d;      /* datum to be inserted */
     69    ClientData          d;      /* datum to be inserted */
    7170{
    7271    register ListNode   nLNode; /* new lnode for d */
     
    7877     * check validity of arguments
    7978     */
    80     if (LstValid (l) && (LstIsEmpty (l) && ln == NULL))
     79    if (LstValid (l) && (LstIsEmpty (l) && ln == NILLNODE))
    8180        goto ok;
    8281
     
    9190    nLNode->useCount = nLNode->flags = 0;
    9291
    93     if (ln == NULL) {
     92    if (ln == NILLNODE) {
    9493        if (list->isCirc) {
    9594            nLNode->prevPtr = nLNode->nextPtr = nLNode;
    9695        } else {
    97             nLNode->prevPtr = nLNode->nextPtr = NULL;
     96            nLNode->prevPtr = nLNode->nextPtr = NilListNode;
    9897        }
    9998        list->firstPtr = list->lastPtr = nLNode;
     
    102101        nLNode->nextPtr = lNode;
    103102
    104         if (nLNode->prevPtr != NULL) {
     103        if (nLNode->prevPtr != NilListNode) {
    105104            nLNode->prevPtr->nextPtr = nLNode;
    106105        }
  • branches/FREEBSD/src/kmk/lst.lib/lstInt.h

    r9 r24  
    3535 *
    3636 *      from: @(#)lstInt.h      8.1 (Berkeley) 6/6/93
    37  * $FreeBSD: src/usr.bin/make/lst.lib/lstInt.h,v 1.10 2002/07/15 06:57:25 jmallett Exp $
     37 * $FreeBSD: src/usr.bin/make/lst.lib/lstInt.h,v 1.7 1999/08/28 01:03:53 peter Exp $
    3838 */
    3939
     
    5151        struct ListNode *prevPtr;   /* previous element in list */
    5252        struct ListNode *nextPtr;   /* next in list */
    53         int             useCount:8, /* Count of functions using the node.
     53        short           useCount:8, /* Count of functions using the node.
    5454                                     * node may not be deleted until count
    5555                                     * goes to 0 */
    5656                        flags:8;    /* Node status flags */
    57         void *  datum;      /* datum associated with this element */
     57        ClientData      datum;      /* datum associated with this element */
    5858} *ListNode;
    5959/*
     
    6161 */
    6262#define LN_DELETED      0x0001      /* List node should be removed when done */
     63
     64#define NilListNode     ((ListNode)-1)
    6365
    6466typedef enum {
     
    7678        Where           atEnd;    /* Where in the list the last access was */
    7779        Boolean         isOpen;   /* true if list has been Lst_Open'ed */
    78         ListNode        curPtr;   /* current node, if open. NULL if
     80        ListNode        curPtr;   /* current node, if open. NilListNode if
    7981                                   * *just* opened */
    8082        ListNode        prevPtr;  /* Previous node, if open. Used by
    8183                                   * Lst_Remove */
    8284} *List;
     85
     86#define NilList         ((List)-1)
    8387
    8488/*
     
    9296 *      Return TRUE if the list l is valid
    9397 */
    94 #define LstValid(l)     (((Lst)l == NULL) ? FALSE : TRUE)
     98#define LstValid(l)     (((Lst)l == NILLST) ? FALSE : TRUE)
    9599
    96100/*
     
    98102 *      Return TRUE if the LstNode ln is valid with respect to l
    99103 */
    100 #define LstNodeValid(ln, l)     ((((LstNode)ln) == NULL) ? FALSE : TRUE)
     104#define LstNodeValid(ln, l)     ((((LstNode)ln) == NILLNODE) ? FALSE : TRUE)
    101105
    102106/*
     
    104108 *      TRUE if the list l is empty.
    105109 */
    106 #define LstIsEmpty(l)   (((List)l)->firstPtr == NULL)
     110#define LstIsEmpty(l)   (((List)l)->firstPtr == NilListNode)
    107111
    108112#endif /* _LSTINT_H_ */
  • branches/FREEBSD/src/kmk/lst.lib/lstIsAtEnd.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstIsAtEnd.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstIsAtEnd.c,v 1.5 1999/08/28 01:03:53 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstIsAtEnd.c,v 1.7 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstIsAtEnd.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
  • branches/FREEBSD/src/kmk/lst.lib/lstIsEmpty.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstIsEmpty.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstIsEmpty.c,v 1.5 1999/08/28 01:03:54 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstIsEmpty.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstIsEmpty.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6059 *      None.
    6160 *
    62  *      A list is considered empty if its firstPtr == NULL (or if
    63  *      the list itself is NULLLIST).
     61 *      A list is considered empty if its firstPtr == NilListNode (or if
     62 *      the list itself is NILLIST).
    6463 *-----------------------------------------------------------------------
    6564 */
  • branches/FREEBSD/src/kmk/lst.lib/lstLast.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstLast.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstLast.c,v 1.5 1999/08/28 01:03:55 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstLast.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstLast.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5554 *
    5655 * Results:
    57  *      The requested node or NULL if the list is empty.
     56 *      The requested node or NILLNODE if the list is empty.
    5857 *
    5958 * Side Effects:
     
    6766{
    6867    if (!LstValid(l) || LstIsEmpty (l)) {
    69         return (NULL);
     68        return (NILLNODE);
    7069    } else {
    7170        return ((LstNode)((List)l)->lastPtr);
  • branches/FREEBSD/src/kmk/lst.lib/lstMember.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstMember.c      8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstMember.c,v 1.6 1999/08/28 01:03:55 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstMember.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstMember.c 8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5251Lst_Member (l, d)
    5352    Lst                 l;
    54     void *              d;
     53    ClientData          d;
    5554{
    5655    List                list = (List) l;
     
    5857
    5958    lNode = list->firstPtr;
    60     if (lNode == NULL) {
    61         return NULL;
     59    if (lNode == NilListNode) {
     60        return NILLNODE;
    6261    }
    6362
     
    6766        }
    6867        lNode = lNode->nextPtr;
    69     } while (lNode != NULL && lNode != list->firstPtr);
     68    } while (lNode != NilListNode && lNode != list->firstPtr);
    7069
    71     return NULL;
     70    return NILLNODE;
    7271}
  • branches/FREEBSD/src/kmk/lst.lib/lstNext.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstNext.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstNext.c,v 1.6 1999/08/28 01:03:55 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstNext.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstNext.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6059 *
    6160 * Results:
    62  *      The next node or NULL if the list has yet to be opened. Also
    63  *      if the list is non-circular and the end has been reached, NULL
     61 *      The next node or NILLNODE if the list has yet to be opened. Also
     62 *      if the list is non-circular and the end has been reached, NILLNODE
    6463 *      is returned.
    6564 *
     
    7877    if ((LstValid (l) == FALSE) ||
    7978        (list->isOpen == FALSE)) {
    80             return (NULL);
     79            return (NILLNODE);
    8180    }
    8281
    8382    list->prevPtr = list->curPtr;
    8483
    85     if (list->curPtr == NULL) {
     84    if (list->curPtr == NilListNode) {
    8685        if (list->atEnd == Unknown) {
    8786            /*
     
    9392            list->atEnd = Middle;
    9493        } else {
    95             tln = NULL;
     94            tln = NilListNode;
    9695            list->atEnd = Tail;
    9796        }
     
    10099        list->curPtr = tln;
    101100
    102         if (tln == list->firstPtr || tln == NULL) {
     101        if (tln == list->firstPtr || tln == NilListNode) {
    103102            /*
    104103             * If back at the front, then we've hit the end...
  • branches/FREEBSD/src/kmk/lst.lib/lstOpen.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstOpen.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstOpen.c,v 1.5 1999/08/28 01:03:56 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstOpen.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstOpen.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6362 *
    6463 * Side Effects:
    65  *      isOpen is set TRUE and curPtr is set to NULL so the
     64 *      isOpen is set TRUE and curPtr is set to NilListNode so the
    6665 *      other sequential functions no it was just opened and can choose
    6766 *      the first element accessed based on this.
     
    7877        ((List) l)->isOpen = TRUE;
    7978        ((List) l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
    80         ((List) l)->curPtr = NULL;
     79        ((List) l)->curPtr = NilListNode;
    8180
    8281        return (SUCCESS);
  • branches/FREEBSD/src/kmk/lst.lib/lstRemove.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstRemove.c      8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstRemove.c,v 1.6 1999/08/28 01:03:56 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstRemove.c,v 1.10 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstRemove.c 8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    5857 *
    5958 * Side Effects:
    60  *      The list's firstPtr will be set to NULL if ln is the last
     59 *      The list's firstPtr will be set to NilListNode if ln is the last
    6160 *      node on the list. firsPtr and lastPtr will be altered if ln is
    6261 *      either the first or last node, respectively, on the list.
     
    8079     * unlink it from the list
    8180     */
    82     if (lNode->nextPtr != NULL) {
     81    if (lNode->nextPtr != NilListNode) {
    8382        lNode->nextPtr->prevPtr = lNode->prevPtr;
    8483    }
    85     if (lNode->prevPtr != NULL) {
     84    if (lNode->prevPtr != NilListNode) {
    8685        lNode->prevPtr->nextPtr = lNode->nextPtr;
    8786    }
     
    101100     * Sequential access stuff. If the node we're removing is the current
    102101     * node in the list, reset the current node to the previous one. If the
    103      * previous one was non-existent (prevPtr == NULL), we set the
     102     * previous one was non-existent (prevPtr == NilListNode), we set the
    104103     * end to be Unknown, since it is.
    105104     */
    106105    if (list->isOpen && (list->curPtr == lNode)) {
    107106        list->curPtr = list->prevPtr;
    108         if (list->curPtr == NULL) {
     107        if (list->curPtr == NilListNode) {
    109108            list->atEnd = Unknown;
    110109        }
     
    117116     */
    118117    if (list->firstPtr == lNode) {
    119         list->firstPtr = NULL;
     118        list->firstPtr = NilListNode;
    120119    }
    121120
     
    125124     */
    126125    if (lNode->useCount == 0) {
    127         free (ln);
     126        free ((Address)ln);
    128127    } else {
    129128        lNode->flags |= LN_DELETED;
  • branches/FREEBSD/src/kmk/lst.lib/lstReplace.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstReplace.c     8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstReplace.c,v 1.5 1999/08/28 01:03:56 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstReplace.c,v 1.9 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstReplace.c        8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6564Lst_Replace (ln, d)
    6665    register LstNode    ln;
    67     void *              d;
     66    ClientData          d;
    6867{
    69     if (ln == NULL) {
     68    if (ln == NILLNODE) {
    7069        return (FAILURE);
    7170    } else {
  • branches/FREEBSD/src/kmk/lst.lib/lstSucc.c

    r9 r24  
    3434 * SUCH DAMAGE.
    3535 *
    36  * @(#)lstSucc.c        8.1 (Berkeley) 6/6/93
     36 * $FreeBSD: src/usr.bin/make/lst.lib/lstSucc.c,v 1.5 1999/08/28 01:03:57 peter Exp $
    3737 */
    3838
    3939#ifndef lint
    40 #include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/usr.bin/make/lst.lib/lstSucc.c,v 1.8 2002/10/09 02:00:22 jmallett Exp $");
     40static char sccsid[] = "@(#)lstSucc.c   8.1 (Berkeley) 6/6/93";
    4241#endif /* not lint */
    4342
     
    6867    LstNode     ln;
    6968{
    70     if (ln == NULL) {
    71         return (NULL);
     69    if (ln == NILLNODE) {
     70        return (NILLNODE);
    7271    } else {
    7372        return ((LstNode) ((ListNode) ln)->nextPtr);
  • branches/FREEBSD/src/kmk/main.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)main.c      8.3 (Berkeley) 3/19/94
    39  */
     37 */
     38
     39#ifndef lint
     40static const char copyright[] =
     41"@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
     42        The Regents of the University of California.  All rights reserved.\n";
     43#endif /* not lint */
    4044
    4145#ifndef lint
    4246#if 0
    43 static char copyright[] =
    44 "@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
    45         The Regents of the University of California.  All rights reserved.\n";
     47static char sccsid[] = "@(#)main.c      8.3 (Berkeley) 3/19/94";
     48#else
     49static const char rcsid[] =
     50  "$FreeBSD: src/usr.bin/make/main.c,v 1.35.2.6 2002/07/24 16:50:18 ru Exp $";
    4651#endif
    4752#endif /* not lint */
    48 #include <sys/cdefs.h>
    49 __FBSDID("$FreeBSD: src/usr.bin/make/main.c,v 1.79 2002/10/10 19:27:48 jmallett Exp $");
    5053
    5154/*-
     
    5962 *                              invoked. Used by the parse module to implement
    6063 *                              the .MFLAGS target.
     64 *
     65 *      Error                   Print a tagged error message. The global
     66 *                              MAKE variable must have been defined. This
     67 *                              takes a format string and two optional
     68 *                              arguments for it.
     69 *
     70 *      Fatal                   Print an error message and exit. Also takes
     71 *                              a format string and two arguments.
     72 *
     73 *      Punt                    Aborts all jobs and exits with a message. Also
     74 *                              takes a format string and two arguments.
     75 *
     76 *      Finish                  Finish things up by printing the number of
     77 *                              errors which occured, as passed to it, and
     78 *                              exiting.
    6179 */
    6280
     
    8098#include <stdio.h>
    8199#include <sysexits.h>
     100#ifdef __STDC__
    82101#include <stdarg.h>
    83 #include <unistd.h>
     102#else
     103#include <varargs.h>
     104#endif
    84105#include "make.h"
    85106#include "hash.h"
     
    88109#include "pathnames.h"
    89110
    90 #define WANT_ENV_MKLVL  1
    91 
    92111#ifndef DEFMAXLOCAL
    93112#define DEFMAXLOCAL DEFMAXJOBS
     
    103122static Boolean          noBuiltins;     /* -r flag */
    104123static Lst              makefiles;      /* ordered list of makefiles to read */
     124static Boolean          printVars;      /* print value of one or more vars */
    105125static Boolean          expandVars;     /* fully expand printed variables */
    106126static Lst              variables;      /* list of variables to print */
     
    121141Boolean                 checkEnvFirst;  /* -e flag */
    122142Lst                     envFirstVars;   /* (-E) vars to override from env */
    123 Boolean                 jobsRunning;    /* TRUE if the jobs might be running */
    124 
    125 static void             MainParseArgs(int, char **);
    126 char *                  chdir_verify_path(char *, char *);
    127 static int              ReadMakefile(void *, void *);
    128 static void             usage(void);
     143static Boolean          jobsRunning;    /* TRUE if the jobs might be running */
     144
     145static void             MainParseArgs __P((int, char **));
     146char *                  chdir_verify_path __P((char *, char *));
     147static int              ReadMakefile __P((ClientData, ClientData));
     148static void             usage __P((void));
    129149
    130150static char *curdir;                    /* startup directory */
     
    146166 */
    147167static void
    148 MainParseArgs(int argc, char **argv)
    149 {
     168MainParseArgs(argc, argv)
     169        int argc;
     170        char **argv;
     171{
     172        extern int optind;
     173        extern char *optarg;
    150174        char *p;
    151175        int c;
     
    153177        optind = 1;     /* since we're called more than once */
    154178#ifdef REMOTE
    155 # define OPTFLAGS "BC:D:E:I:L:PSV:Xd:ef:ij:km:nqrstv"
     179# define OPTFLAGS "BD:E:I:L:PSV:Xd:ef:ij:km:nqrstv"
    156180#else
    157 # define OPTFLAGS "BC:D:E:I:PSV:Xd:ef:ij:km:nqrstv"
     181# define OPTFLAGS "BD:E:I:PSV:Xd:ef:ij:km:nqrstv"
    158182#endif
    159183rearg:  while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
    160184                switch(c) {
    161                 case 'C':
    162                         chdir(optarg);
    163                         break;
    164185                case 'D':
    165186                        Var_Set(optarg, "1", VAR_GLOBAL);
     
    173194                        break;
    174195                case 'V':
    175                         (void)Lst_AtEnd(variables, (void *)optarg);
     196                        printVars = TRUE;
     197                        (void)Lst_AtEnd(variables, (ClientData)optarg);
    176198                        Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
    177199                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
     
    264286                }
    265287                case 'E':
    266                         p = emalloc(strlen(optarg) + 1);
     288                        p = malloc(strlen(optarg) + 1);
     289                        if (!p)
     290                                Punt("make: cannot allocate memory.");
    267291                        (void)strcpy(p, optarg);
    268                         (void)Lst_AtEnd(envFirstVars, (void *)p);
     292                        (void)Lst_AtEnd(envFirstVars, (ClientData)p);
    269293                        Var_Append(MAKEFLAGS, "-E", VAR_GLOBAL);
    270294                        Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL);
     
    275299                        break;
    276300                case 'f':
    277                         (void)Lst_AtEnd(makefiles, (void *)optarg);
     301                        (void)Lst_AtEnd(makefiles, (ClientData)optarg);
    278302                        break;
    279303                case 'i':
     
    358382                                goto rearg;
    359383                        }
    360                         (void)Lst_AtEnd(create, (void *)estrdup(*argv));
     384                        (void)Lst_AtEnd(create, (ClientData)estrdup(*argv));
    361385                }
    362386}
     
    378402 */
    379403void
    380 Main_ParseArgLine(char *line)
     404Main_ParseArgLine(line)
     405        char *line;                     /* Line to fracture */
    381406{
    382407        char **argv;                    /* Manufactured argument vector */
     
    395420
    396421char *
    397 chdir_verify_path(char *path, char *obpath)
     422chdir_verify_path(path, obpath)
     423        char *path;
     424        char *obpath;
    398425{
    399426        struct stat sb;
    400427
    401428        if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
    402                 if (chdir(path) == -1 || getcwd(obpath, MAXPATHLEN) == NULL) {
     429                if (chdir(path)) {
    403430                        warn("warning: %s", path);
    404431                        return 0;
    405432                }
    406                 return obpath;
     433                else {
     434                        if (path[0] != '/') {
     435                                (void) snprintf(obpath, MAXPATHLEN, "%s/%s",
     436                                                curdir, path);
     437                                return obpath;
     438                        }
     439                        else
     440                                return path;
     441                }
    407442        }
    408443
     
    429464 */
    430465int
    431 main(int argc, char **argv)
     466main(argc, argv)
     467        int argc;
     468        char **argv;
    432469{
    433470        Lst targs;      /* target nodes to create -- passed to Make_Init */
     
    435472        struct stat sa;
    436473        char *p, *p1, *path, *pathp;
    437 #ifdef WANT_ENV_MKLVL
    438 #define MKLVL_MAXVAL    500
    439 #define MKLVL_ENVVAR    "__MKLVL__"
    440         int iMkLvl = 0;
    441         char *szMkLvl = getenv(MKLVL_ENVVAR);
    442 #endif  /* WANT_ENV_MKLVL */
    443         char mdpath[MAXPATHLEN];
    444         char obpath[MAXPATHLEN];
    445         char cdpath[MAXPATHLEN];
     474#ifdef WANT_ENV_PWD
     475        struct stat sb;
     476        char *pwd;
     477#endif
     478        char mdpath[MAXPATHLEN + 1];
     479        char obpath[MAXPATHLEN + 1];
     480        char cdpath[MAXPATHLEN + 1];
    446481        char *machine = getenv("MACHINE");
    447482        char *machine_arch = getenv("MACHINE_ARCH");
     
    452487        static char syspath[] = _PATH_DEFSYSPATH;
    453488
    454 #ifdef WANT_ENV_MKLVL
    455         if ((iMkLvl = szMkLvl ? atoi(szMkLvl) : 0) < 0) {
    456           iMkLvl = 0;
    457         }
    458         if (iMkLvl++ > MKLVL_MAXVAL) {
    459           errc(2, EAGAIN,
    460                "Max recursion level (%d) exceeded.", MKLVL_MAXVAL);
    461         }
    462         bzero(szMkLvl = emalloc(32), 32);
    463         sprintf(szMkLvl, "%d", iMkLvl);
    464         setenv(MKLVL_ENVVAR, szMkLvl, 1);
    465 #endif /* WANT_ENV_MKLVL */
    466 
    467 #if DEFSHELL == 2
    468         /*
    469          * Turn off ENV to make ksh happier.
    470          */
    471         unsetenv("ENV");
    472 #endif
    473 
    474489#ifdef RLIMIT_NOFILE
    475490        /*
     
    486501#endif
    487502        /*
    488          * Find where we are...
     503         * Find where we are and take care of PWD for the automounter...
    489504         * All this code is so that we know where we are when we start up
    490505         * on a different machine with pmake.
     
    496511        if (stat(curdir, &sa) == -1)
    497512            err(2, "%s", curdir);
     513
     514#ifdef WANT_ENV_PWD
     515        if ((pwd = getenv("PWD")) != NULL) {
     516            if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
     517                sa.st_dev == sb.st_dev)
     518                (void) strcpy(curdir, pwd);
     519        }
     520#endif
    498521
    499522#if defined(__i386__) && defined(__FreeBSD_version) && \
     
    532555            struct utsname utsname;
    533556
    534             if (uname(&utsname) == -1)
    535                     err(2, "uname");
     557            if (uname(&utsname) == -1) {
     558                    perror("make: uname");
     559                    exit(2);
     560            }
    536561            machine = utsname.machine;
    537562#else
     
    603628        }
    604629
     630#ifdef WANT_ENV_PWD
     631        setenv("PWD", objdir, 1);
     632#endif
     633
    605634        create = Lst_Init(FALSE);
    606635        makefiles = Lst_Init(FALSE);
    607636        envFirstVars = Lst_Init(FALSE);
     637        printVars = FALSE;
    608638        expandVars = TRUE;
    609639        variables = Lst_Init(FALSE);
     
    659689        Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
    660690        Var_Set("MACHINE_CPU", machine_cpu, VAR_GLOBAL);
    661 #ifdef MAKE_VERSION
    662         Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL);
    663 #endif
    664691
    665692        /*
     
    691718        Suff_Init();
    692719
    693         DEFAULT = NULL;
     720        DEFAULT = NILGNODE;
    694721        (void)time(&now);
    695722
     
    702729                LstNode ln;
    703730
    704                 for (ln = Lst_First(create); ln != NULL;
     731                for (ln = Lst_First(create); ln != NILLNODE;
    705732                    ln = Lst_Succ(ln)) {
    706733                        char *name = (char *)Lst_Datum(ln);
     
    742769                if (Lst_IsEmpty(sysMkPath))
    743770                        Fatal("make: no system rules (%s).", _PATH_DEFSYSMK);
    744                 ln = Lst_Find(sysMkPath, (void *)NULL, ReadMakefile);
    745                 if (ln != NULL)
     771                ln = Lst_Find(sysMkPath, (ClientData)NULL, ReadMakefile);
     772                if (ln != NILLNODE)
    746773                        Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
    747774        }
     
    750777                LstNode ln;
    751778
    752                 ln = Lst_Find(makefiles, (void *)NULL, ReadMakefile);
    753                 if (ln != NULL)
     779                ln = Lst_Find(makefiles, (ClientData)NULL, ReadMakefile);
     780                if (ln != NILLNODE)
    754781                        Fatal("make: cannot open %s.", (char *)Lst_Datum(ln));
    755         } else if (!ReadMakefile("BSDmakefile", NULL))
    756             if (!ReadMakefile("makefile", NULL))
     782        } else if (!ReadMakefile("makefile", NULL))
    757783                (void)ReadMakefile("Makefile", NULL);
    758784
     
    778804         */
    779805        if (Var_Exists("VPATH", VAR_CMD)) {
    780                 char *vpath, savec;
     806                char *vpath, *path, *cp, savec;
    781807                /*
    782808                 * GCC stores string constants in read-only memory, but
     
    800826                        path = cp + 1;
    801827                } while (savec == ':');
    802                 (void)free(vpath);
     828                (void)free((Address)vpath);
    803829        }
    804830
     
    814840
    815841        /* print the values of any variables requested by the user */
    816         if (!Lst_IsEmpty(variables)) {
     842        if (printVars) {
    817843                LstNode ln;
    818844
    819                 for (ln = Lst_First(variables); ln != NULL;
     845                for (ln = Lst_First(variables); ln != NILLNODE;
    820846                    ln = Lst_Succ(ln)) {
    821847                        char *value;
    822848                        if (expandVars) {
    823                                 p1 = emalloc(strlen((char *)Lst_Datum(ln)) + 1 + 3);
     849                                p1 = malloc(strlen((char *)Lst_Datum(ln)) + 1 + 3);
     850                                if (!p1)
     851                                        Punt("make: cannot allocate memory.");
    824852                                /* This sprintf is safe, because of the malloc above */
    825853                                (void)sprintf(p1, "${%s}", (char *)Lst_Datum(ln));
     
    833861                                free(p1);
    834862                }
    835         } else {
    836 
     863        }
     864
     865        /*
     866         * Have now read the entire graph and need to make a list of targets
     867         * to create. If none was given on the command line, we consult the
     868         * parsing module to find the main target(s) to create.
     869         */
     870        if (Lst_IsEmpty(create))
     871                targs = Parse_MainName();
     872        else
     873                targs = Targ_FindList(create, TARG_CREATE);
     874
     875        if (!compatMake && !printVars) {
    837876                /*
    838                  * Have now read the entire graph and need to make a list of targets
    839                  * to create. If none was given on the command line, we consult the
    840                  * parsing module to find the main target(s) to create.
     877                 * Initialize job module before traversing the graph, now that
     878                 * any .BEGIN and .END targets have been read.  This is done
     879                 * only if the -q flag wasn't given (to prevent the .BEGIN from
     880                 * being executed should it exist).
    841881                 */
    842                 if (Lst_IsEmpty(create))
    843                         targs = Parse_MainName();
    844                 else
    845                         targs = Targ_FindList(create, TARG_CREATE);
    846 
    847                 if (!compatMake) {
    848                         /*
    849                          * Initialize job module before traversing the graph, now that
    850                          * any .BEGIN and .END targets have been read.  This is done
    851                          * only if the -q flag wasn't given (to prevent the .BEGIN from
    852                          * being executed should it exist).
    853                          */
    854                         if (!queryFlag) {
    855                                 if (maxLocal == -1)
    856                                         maxLocal = maxJobs;
    857                                 Job_Init(maxJobs, maxLocal);
    858                                 jobsRunning = TRUE;
    859                         }
    860 
    861                         /* Traverse the graph, checking on all the targets */
    862                         outOfDate = Make_Run(targs);
    863                 } else {
    864                         /*
    865                          * Compat_Init will take care of creating all the targets as
    866                          * well as initializing the module.
    867                          */
    868                         Compat_Run(targs);
    869                 }
    870                 Lst_Destroy(targs, NOFREE);
    871         }
    872 
     882                if (!queryFlag) {
     883                        if (maxLocal == -1)
     884                                maxLocal = maxJobs;
     885                        Job_Init(maxJobs, maxLocal);
     886                        jobsRunning = TRUE;
     887                }
     888
     889                /* Traverse the graph, checking on all the targets */
     890                outOfDate = Make_Run(targs);
     891        } else if (!printVars) {
     892                /*
     893                 * Compat_Init will take care of creating all the targets as
     894                 * well as initializing the module.
     895                 */
     896                Compat_Run(targs);
     897        }
     898
     899        Lst_Destroy(targs, NOFREE);
    873900        Lst_Destroy(variables, NOFREE);
    874901        Lst_Destroy(makefiles, NOFREE);
    875         Lst_Destroy(create, (void (*)(void *)) free);
     902        Lst_Destroy(create, (void (*) __P((ClientData))) free);
    876903
    877904        /* print the graph now it's been processed if the user requested it */
     
    904931 */
    905932static Boolean
    906 ReadMakefile(void *p, void *q __unused)
    907 {
    908         char *fname;                    /* makefile to read */
     933ReadMakefile(p, q)
     934        ClientData p, q;
     935{
     936        char *fname = p;                /* makefile to read */
     937        extern Lst parseIncPath;
    909938        FILE *stream;
    910         char *name, path[MAXPATHLEN];
     939        char *name, path[MAXPATHLEN + 1];
    911940        char *MAKEFILE;
    912941        int setMAKEFILE;
    913 
    914         fname = p;
    915942
    916943        if (!strcmp(fname, "-")) {
     
    923950                if (curdir != objdir && *fname != '/') {
    924951                        (void)snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname);
    925                         /*
    926                          * XXX The realpath stuff breaks relative includes
    927                          * XXX in some cases.   The problem likely is in
    928                          * XXX parse.c where it does special things in
    929                          * XXX ParseDoInclude if the file is relateive
    930                          * XXX or absolute and not a system file.  There
    931                          * XXX it assumes that if the current file that's
    932                          * XXX being included is absolute, that any files
    933                          * XXX that it includes shouldn't do the -I path
    934                          * XXX stuff, which is inconsistant with historical
    935                          * XXX behavior.  However, I can't pentrate the mists
    936                          * XXX further, so I'm putting this workaround in
    937                          * XXX here until such time as the underlying bug
    938                          * XXX can be fixed.
    939                          */
    940 #if THIS_BREAKS_THINGS
    941952                        if (realpath(path, path) != NULL &&
    942953                            (stream = fopen(path, "r")) != NULL) {
     
    951962                                goto found;
    952963                }
    953 #else
    954                         if ((stream = fopen(path, "r")) != NULL) {
    955                                 MAKEFILE = fname;
    956                                 fname = path;
    957                                 goto found;
    958                         }
    959                 } else {
    960                         MAKEFILE = fname;
    961                         if ((stream = fopen(fname, "r")) != NULL)
    962                                 goto found;
    963                 }
    964 #endif
    965964                /* look in -I and system include directories. */
    966965                name = Dir_FindFile(fname, parseIncPath);
     
    991990 * Results:
    992991 *      A string containing the output of the command, or the empty string
    993  *      If error is not NULL, it contains the reason for the command failure
     992 *      If err is not NULL, it contains the reason for the command failure
    994993 *
    995994 * Side Effects:
     
    997996 */
    998997char *
    999 Cmd_Exec(char *cmd, char **error)
     998Cmd_Exec(cmd, err)
     999    char *cmd;
     1000    char **err;
    10001001{
    10011002    char        *args[4];       /* Args for invoking the shell */
     
    10091010    int         cc;
    10101011
    1011     *error = NULL;
     1012
     1013    *err = NULL;
    10121014
    10131015    /*
     
    10231025     */
    10241026    if (pipe(fds) == -1) {
    1025         *error = "Couldn't create pipe for \"%s\"";
     1027        *err = "Couldn't create pipe for \"%s\"";
    10261028        goto bad;
    10271029    }
     
    10451047        (void) close(fds[1]);
    10461048
    1047 #if defined(DEFSHELL) && DEFSHELL == 0
    1048         (void) execv("/bin/csh", args);
    1049 #elif DEFSHELL == 1
    10501049        (void) execv("/bin/sh", args);
    1051 #elif DEFSHELL == 2
    1052         (void) execv("/bin/ksh", args);
    1053 #else
    1054 #error "DEFSHELL must be 1 or 2."
    1055 #endif
    10561050        _exit(1);
    10571051        /*NOTREACHED*/
    10581052
    10591053    case -1:
    1060         *error = "Couldn't exec \"%s\"";
     1054        *err = "Couldn't exec \"%s\"";
    10611055        goto bad;
    10621056
     
    10891083
    10901084        if (cc == -1)
    1091             *error = "Error reading shell's output for \"%s\"";
     1085            *err = "Error reading shell's output for \"%s\"";
    10921086
    10931087        res = (char *)Buf_GetAll (buf, &cc);
     
    10951089
    10961090        if (status)
    1097             *error = "\"%s\" returned non-zero status";
     1091            *err = "\"%s\" returned non-zero status";
    10981092
    10991093        /*
     
    11251119}
    11261120
     1121/*-
     1122 * Error --
     1123 *      Print an error message given its format.
     1124 *
     1125 * Results:
     1126 *      None.
     1127 *
     1128 * Side Effects:
     1129 *      The message is printed.
     1130 */
     1131/* VARARGS */
     1132void
     1133#ifdef __STDC__
     1134Error(char *fmt, ...)
     1135#else
     1136Error(va_alist)
     1137        va_dcl
     1138#endif
     1139{
     1140        va_list ap;
     1141#ifdef __STDC__
     1142        va_start(ap, fmt);
     1143#else
     1144        char *fmt;
     1145
     1146        va_start(ap);
     1147        fmt = va_arg(ap, char *);
     1148#endif
     1149        (void)vfprintf(stderr, fmt, ap);
     1150        va_end(ap);
     1151        (void)fprintf(stderr, "\n");
     1152        (void)fflush(stderr);
     1153}
     1154
     1155/*-
     1156 * Fatal --
     1157 *      Produce a Fatal error message. If jobs are running, waits for them
     1158 *      to finish.
     1159 *
     1160 * Results:
     1161 *      None
     1162 *
     1163 * Side Effects:
     1164 *      The program exits
     1165 */
     1166/* VARARGS */
     1167void
     1168#ifdef __STDC__
     1169Fatal(char *fmt, ...)
     1170#else
     1171Fatal(va_alist)
     1172        va_dcl
     1173#endif
     1174{
     1175        va_list ap;
     1176#ifdef __STDC__
     1177        va_start(ap, fmt);
     1178#else
     1179        char *fmt;
     1180
     1181        va_start(ap);
     1182        fmt = va_arg(ap, char *);
     1183#endif
     1184        if (jobsRunning)
     1185                Job_Wait();
     1186
     1187        (void)vfprintf(stderr, fmt, ap);
     1188        va_end(ap);
     1189        (void)fprintf(stderr, "\n");
     1190        (void)fflush(stderr);
     1191
     1192        if (DEBUG(GRAPH2))
     1193                Targ_PrintGraph(2);
     1194        exit(2);                /* Not 1 so -q can distinguish error */
     1195}
     1196
     1197/*
     1198 * Punt --
     1199 *      Major exception once jobs are being created. Kills all jobs, prints
     1200 *      a message and exits.
     1201 *
     1202 * Results:
     1203 *      None
     1204 *
     1205 * Side Effects:
     1206 *      All children are killed indiscriminately and the program Lib_Exits
     1207 */
     1208/* VARARGS */
     1209void
     1210#ifdef __STDC__
     1211Punt(char *fmt, ...)
     1212#else
     1213Punt(va_alist)
     1214        va_dcl
     1215#endif
     1216{
     1217        va_list ap;
     1218#if __STDC__
     1219        va_start(ap, fmt);
     1220#else
     1221        char *fmt;
     1222
     1223        va_start(ap);
     1224        fmt = va_arg(ap, char *);
     1225#endif
     1226
     1227        (void)fprintf(stderr, "make: ");
     1228        (void)vfprintf(stderr, fmt, ap);
     1229        va_end(ap);
     1230        (void)fprintf(stderr, "\n");
     1231        (void)fflush(stderr);
     1232
     1233        DieHorribly();
     1234}
     1235
     1236/*-
     1237 * DieHorribly --
     1238 *      Exit without giving a message.
     1239 *
     1240 * Results:
     1241 *      None
     1242 *
     1243 * Side Effects:
     1244 *      A big one...
     1245 */
     1246void
     1247DieHorribly()
     1248{
     1249        if (jobsRunning)
     1250                Job_AbortAll();
     1251        if (DEBUG(GRAPH2))
     1252                Targ_PrintGraph(2);
     1253        exit(2);                /* Not 1, so -q can distinguish error */
     1254}
     1255
     1256/*
     1257 * Finish --
     1258 *      Called when aborting due to errors in child shell to signal
     1259 *      abnormal exit.
     1260 *
     1261 * Results:
     1262 *      None
     1263 *
     1264 * Side Effects:
     1265 *      The program exits
     1266 */
     1267void
     1268Finish(errors)
     1269        int errors;     /* number of errors encountered in Make_Make */
     1270{
     1271        Fatal("%d error%s", errors, errors == 1 ? "" : "s");
     1272}
     1273
     1274/*
     1275 * emalloc --
     1276 *      malloc, but die on error.
     1277 */
     1278void *
     1279emalloc(len)
     1280        size_t len;
     1281{
     1282        void *p;
     1283
     1284        if ((p = malloc(len)) == NULL)
     1285                enomem();
     1286        return(p);
     1287}
     1288
     1289/*
     1290 * estrdup --
     1291 *      strdup, but die on error.
     1292 */
     1293char *
     1294estrdup(str)
     1295        const char *str;
     1296{
     1297        char *p;
     1298
     1299        if ((p = strdup(str)) == NULL)
     1300                enomem();
     1301        return(p);
     1302}
     1303
     1304/*
     1305 * erealloc --
     1306 *      realloc, but die on error.
     1307 */
     1308void *
     1309erealloc(ptr, size)
     1310        void *ptr;
     1311        size_t size;
     1312{
     1313        if ((ptr = realloc(ptr, size)) == NULL)
     1314                enomem();
     1315        return(ptr);
     1316}
     1317
     1318/*
     1319 * enomem --
     1320 *      die when out of memory.
     1321 */
     1322void
     1323enomem()
     1324{
     1325        err(2, NULL);
     1326}
     1327
     1328/*
     1329 * enunlink --
     1330 *      Remove a file carefully, avoiding directories.
     1331 */
     1332int
     1333eunlink(file)
     1334        const char *file;
     1335{
     1336        struct stat st;
     1337
     1338        if (lstat(file, &st) == -1)
     1339                return -1;
     1340
     1341        if (S_ISDIR(st.st_mode)) {
     1342                errno = EISDIR;
     1343                return -1;
     1344        }
     1345        return unlink(file);
     1346}
     1347
    11271348/*
    11281349 * usage --
     
    11301351 */
    11311352static void
    1132 usage(void)
     1353usage()
    11331354{
    11341355        (void)fprintf(stderr, "%s\n%s\n%s\n",
     
    11381359        exit(2);
    11391360}
     1361
     1362
     1363int
     1364PrintAddr(a, b)
     1365    ClientData a;
     1366    ClientData b;
     1367{
     1368    printf("%lx ", (unsigned long) a);
     1369    return b ? 0 : 0;
     1370}
  • branches/FREEBSD/src/kmk/make.1

    r10 r24  
    3030.\" SUCH DAMAGE.
    3131.\"
    32 .\"     @(#)make.1      8.8 (Berkeley) 6/13/95
    33 .\" $FreeBSD: src/usr.bin/make/make.1,v 1.59 2002/09/27 09:21:07 ru Exp $
     32.\"     from: @(#)make.1        8.4 (Berkeley) 3/19/94
     33.\" $FreeBSD: src/usr.bin/make/make.1,v 1.29.2.14 2002/09/09 19:06:16 archie Exp $
    3434.\"
    35 .Dd June 13, 1995
     35.Dd March 19, 1994
    3636.Dt MAKE 1
    3737.Os
     
    4242.Nm
    4343.Op Fl BPSXeiknqrstv
    44 .Op Fl C Ar directory
    4544.Op Fl D Ar variable
    4645.Op Fl d Ar flags
     
    6362files and programs.
    6463The first of
    65 .Ql Pa BSDmakefile ,
    6664.Ql Pa makefile
    6765and
     
    9088.Fl j
    9189is used.
    92 .It Fl C Ar directory
    93 Change to
    94 .Ar directory
    95 while running.
    9690.It Fl D Ar variable
    9791Define
     
    178172that do not depend on the target whose creation caused the error.
    179173.It Fl m Ar directory
    180 Specify a directory in which to search for
    181 .Pa sys.mk
    182 and makefiles included via the <...> style.
     174Specify a directory in which to search for sys.mk and makefiles included
     175via the <...> style.
    183176Multiple directories can be added to form a search path.
    184177This path will override the default system include path:
     
    519512is unable to change into any of the remaining three directories,
    520513then the current directory is used.
    521 .Pp
    522 The
    523 .Nm
    524 utility sets
    525 .Va .OBJDIR
    526 to the canonical path given by
    527 .Xr getcwd 3 .
    528514.It Va .MAKEFLAGS
    529515The environment variable
     
    551537.Va .MAKEFLAGS
    552538provided for backward compatibility.
     539.It Ev PWD
     540Alternate path to the current directory.
     541Supported if built with WANT_ENV_PWD defined.
     542.Nm
     543normally sets
     544.Ql Va .CURDIR
     545to the canonical path given by
     546.Xr getcwd 3 .
     547However, if the environment variable
     548.Ev PWD
     549is set and gives a path to the current directory, then
     550.Nm
     551sets
     552.Ql Va .CURDIR
     553to the value of
     554.Ev PWD
     555instead.
     556.Ev PWD
     557is always set to the value of
     558.Ql Va .OBJDIR
     559for all programs which
     560.Nm
     561executes.
    553562.It Va .TARGETS
    554563List of targets
     
    580589These directories will be searched for source files by
    581590.Nm
    582 after it has finished parsing all input makefiles.
     591after
     592.Nm
     593has finished parsing all input makefiles.
    583594.El
    584595.Pp
     
    700711.Pq Ql \&$ ,
    701712not a preceding dollar sign as is usual.
     713.It Cm T
     714Replaces each word in the variable with its last component.
    702715.It Ar old_string=new_string
    703716This is the
     
    720733to be replaced in
    721734.Ar new_string
    722 .It Cm T
    723 Replaces each word in the variable with its last component.
    724735.It Cm U
    725736Converts variable to upper-case letters.
     
    853864.Bl -tag -width "Cm XX"
    854865.It Cm \&|\&|
    855 logical
    856 .Tn OR
     866logical OR
    857867.It Cm \&&&
    858868Logical
     
    11071117Disable parallel mode.
    11081118.It Ic .NO_PARALLEL
    1109 Same as above, for compatibility with other
    1110 .Nm pmake
    1111 variants.
     1119Same as above, for compatibility with other pmake variants.
    11121120.It Ic .ORDER
    11131121The named targets are made in sequence.
     
    11911199.Ev MAKEFLAGS ,
    11921200.Ev MAKEOBJDIR ,
     1201.Ev MAKEOBJDIRPREFIX ,
    11931202and
    1194 .Ev MAKEOBJDIRPREFIX .
     1203.Ev PWD .
    11951204.Sh FILES
    11961205.Bl -tag -width /usr/share/doc/psd/12.make -compact
     
    12451254.Pp
    12461255For loops are expanded before tests, so a fragment such as:
    1247 .Bd -literal -offset indent
     1256.Bd -literal
    12481257\&.for TMACHINE in ${SHARED_ARCHS}
    12491258\&.if ${TMACHINE} = ${MACHINE}
     
    12521261\&.endfor
    12531262.Ed
    1254 .Pp
    12551263won't work, and should be rewritten the other way around.
    1256 .Pp
    1257 The parsing code is broken with respect to handling a semicolon
    1258 after a colon, so a fragment like this will fail:
    1259 .Bd -literal -offset indent
    1260 HDRS=   foo.h bar.h
    1261 
    1262 all:
    1263 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
    1264      ...
    1265 \&.endfor
    1266 .Ed
    12671264.Sh SEE ALSO
    12681265.Xr mkdep 1 ,
     
    12761273A
    12771274.Nm
    1278 command appeared in PWB UNIX.
     1275command appeared in
     1276.At v7 .
  • branches/FREEBSD/src/kmk/make.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)make.c   8.1 (Berkeley) 6/6/93
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/make.c,v 1.23 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)make.c      8.1 (Berkeley) 6/6/93";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/make.c,v 1.11 1999/09/11 13:08:01 hoek Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    8892                                 * TRUE, there's a cycle in the graph */
    8993
    90 static int MakeAddChild(void *, void *);
    91 static int MakeAddAllSrc(void *, void *);
    92 static int MakeTimeStamp(void *, void *);
    93 static int MakeHandleUse(void *, void *);
    94 static Boolean MakeStartJobs(void);
    95 static int MakePrintStatus(void *, void *);
     94static int MakeAddChild __P((ClientData, ClientData));
     95static int MakeAddAllSrc __P((ClientData, ClientData));
     96static int MakeTimeStamp __P((ClientData, ClientData));
     97static int MakeHandleUse __P((ClientData, ClientData));
     98static Boolean MakeStartJobs __P((void));
     99static int MakePrintStatus __P((ClientData, ClientData));
    96100/*-
    97101 *-----------------------------------------------------------------------
     
    109113 */
    110114int
    111 Make_TimeStamp (GNode *pgn, GNode *cgn)
     115Make_TimeStamp (pgn, cgn)
     116    GNode *pgn; /* the current parent */
     117    GNode *cgn; /* the child we've just examined */
    112118{
    113119    if (cgn->mtime > pgn->cmtime) {
     
    118124
    119125static int
    120 MakeTimeStamp (void *pgn, void *cgn)
     126MakeTimeStamp (pgn, cgn)
     127    ClientData pgn;     /* the current parent */
     128    ClientData cgn;     /* the child we've just examined */
    121129{
    122130    return Make_TimeStamp((GNode *) pgn, (GNode *) cgn);
     
    143151 */
    144152Boolean
    145 Make_OODate (GNode *gn)
     153Make_OODate (gn)
     154    register GNode *gn;       /* the node to check */
    146155{
    147156    Boolean         oodate;
     
    153162    if ((gn->type & (OP_JOIN|OP_USE|OP_EXEC)) == 0) {
    154163        (void) Dir_MTime (gn);
    155         if (gn->mtime != 0) {
    156             DEBUGF(MAKE, ("modified %s...", Targ_FmtTime(gn->mtime)));
    157         } else {
    158             DEBUGF(MAKE, ("non-existent..."));
     164        if (DEBUG(MAKE)) {
     165            if (gn->mtime != 0) {
     166                printf ("modified %s...", Targ_FmtTime(gn->mtime));
     167            } else {
     168                printf ("non-existent...");
     169            }
    159170        }
    160171    }
     
    179190         * no matter *what*.
    180191         */
    181         DEBUGF(MAKE, (".USE node..."));
     192        if (DEBUG(MAKE)) {
     193            printf(".USE node...");
     194        }
    182195        oodate = FALSE;
    183196    } else if (gn->type & OP_LIB) {
    184         DEBUGF(MAKE, ("library..."));
     197        if (DEBUG(MAKE)) {
     198            printf("library...");
     199        }
    185200
    186201        /*
     
    195210         * out-of-date if any of its children was out-of-date.
    196211         */
    197         DEBUGF(MAKE, (".JOIN node..."));
     212        if (DEBUG(MAKE)) {
     213            printf(".JOIN node...");
     214        }
    198215        oodate = gn->childMade;
    199216    } else if (gn->type & (OP_FORCE|OP_EXEC|OP_PHONY)) {
     
    202219         * the .EXEC attribute is always considered out-of-date.
    203220         */
    204         if (gn->type & OP_FORCE) {
    205             DEBUGF(MAKE, ("! operator..."));
    206         } else if (gn->type & OP_PHONY) {
    207             DEBUGF(MAKE, (".PHONY node..."));
    208         } else {
    209             DEBUGF(MAKE, (".EXEC node..."));
     221        if (DEBUG(MAKE)) {
     222            if (gn->type & OP_FORCE) {
     223                printf("! operator...");
     224            } else if (gn->type & OP_PHONY) {
     225                printf(".PHONY node...");
     226            } else {
     227                printf(".EXEC node...");
     228            }
    210229        }
    211230        oodate = TRUE;
     
    221240         * it.
    222241         */
    223         if (gn->mtime < gn->cmtime) {
    224             DEBUGF(MAKE, ("modified before source..."));
    225         } else if (gn->mtime == 0) {
    226             DEBUGF(MAKE, ("non-existent and no sources..."));
    227         } else {
    228             DEBUGF(MAKE, (":: operator and no sources..."));
     242        if (DEBUG(MAKE)) {
     243            if (gn->mtime < gn->cmtime) {
     244                printf("modified before source...");
     245            } else if (gn->mtime == 0) {
     246                printf("non-existent and no sources...");
     247            } else {
     248                printf(":: operator and no sources...");
     249            }
    229250        }
    230251        oodate = TRUE;
    231     } else
     252    } else {
     253#if 0
     254        /* WHY? */
     255        if (DEBUG(MAKE)) {
     256            printf("source %smade...", gn->childMade ? "" : "not ");
     257        }
     258        oodate = gn->childMade;
     259#else
    232260        oodate = FALSE;
     261#endif /* 0 */
     262    }
    233263
    234264    /*
     
    240270     */
    241271    if (!oodate) {
    242         Lst_ForEach (gn->parents, MakeTimeStamp, (void *)gn);
     272        Lst_ForEach (gn->parents, MakeTimeStamp, (ClientData)gn);
    243273    }
    244274
     
    261291 */
    262292static int
    263 MakeAddChild (void *gnp, void *lp)
     293MakeAddChild (gnp, lp)
     294    ClientData     gnp;         /* the node to add */
     295    ClientData     lp;          /* the list to which to add it */
    264296{
    265297    GNode          *gn = (GNode *) gnp;
     
    267299
    268300    if (!gn->make && !(gn->type & OP_USE)) {
    269         (void)Lst_EnQueue (l, (void *)gn);
     301        (void)Lst_EnQueue (l, (ClientData)gn);
    270302    }
    271303    return (0);
     
    297329 */
    298330int
    299 Make_HandleUse (GNode *cgn, GNode *pgn)
    300 {
    301     GNode       *gn;            /* A child of the .USE node */
    302     LstNode     ln;             /* An element in the children list */
     331Make_HandleUse (cgn, pgn)
     332    register GNode      *cgn;   /* The .USE node */
     333    register GNode      *pgn;   /* The target of the .USE node */
     334{
     335    register GNode      *gn;    /* A child of the .USE node */
     336    register LstNode    ln;     /* An element in the children list */
    303337
    304338    if (cgn->type & (OP_USE|OP_TRANSFORM)) {
     
    312346
    313347        if (Lst_Open (cgn->children) == SUCCESS) {
    314             while ((ln = Lst_Next (cgn->children)) != NULL) {
     348            while ((ln = Lst_Next (cgn->children)) != NILLNODE) {
    315349                gn = (GNode *)Lst_Datum (ln);
    316350
    317                 if (Lst_Member (pgn->children, gn) == NULL) {
     351                if (Lst_Member (pgn->children, gn) == NILLNODE) {
    318352                    (void) Lst_AtEnd (pgn->children, gn);
    319353                    (void) Lst_AtEnd (gn->parents, pgn);
     
    340374}
    341375static int
    342 MakeHandleUse (void *pgn, void *cgn)
     376MakeHandleUse (pgn, cgn)
     377    ClientData pgn;     /* the current parent */
     378    ClientData cgn;     /* the child we've just examined */
    343379{
    344380    return Make_HandleUse((GNode *) pgn, (GNode *) cgn);
     
    372408 */
    373409void
    374 Make_Update (GNode *cgn)
    375 {
    376     GNode       *pgn;           /* the parent node */
    377     char        *cname;         /* the child's name */
    378     LstNode     ln;             /* Element in parents and iParents lists */
    379     char        *p1;
     410Make_Update (cgn)
     411    register GNode *cgn;        /* the child node */
     412{
     413    register GNode      *pgn;   /* the parent node */
     414    register char       *cname; /* the child's name */
     415    register LstNode    ln;     /* Element in parents and iParents lists */
     416    char *p1;
    380417
    381418    cname = Var_Value (TARGET, cgn, &p1);
     
    443480            cgn->mtime = now;
    444481        }
    445         DEBUGF(MAKE, ("update time: %s\n", Targ_FmtTime(cgn->mtime)));
     482        if (DEBUG(MAKE)) {
     483            printf("update time: %s\n", Targ_FmtTime(cgn->mtime));
     484        }
    446485#endif
    447486    }
    448487
    449488    if (Lst_Open (cgn->parents) == SUCCESS) {
    450         while ((ln = Lst_Next (cgn->parents)) != NULL) {
     489        while ((ln = Lst_Next (cgn->parents)) != NILLNODE) {
    451490            pgn = (GNode *)Lst_Datum (ln);
    452491            if (pgn->make) {
     
    468507                     * be dealt with in MakeStartJobs.
    469508                     */
    470                     (void)Lst_EnQueue (toBeMade, (void *)pgn);
     509                    (void)Lst_EnQueue (toBeMade, (ClientData)pgn);
    471510                } else if (pgn->unmade < 0) {
    472511                    Error ("Graph cycles through %s", pgn->name);
     
    482521     * before.
    483522     */
    484     for (ln = Lst_First(cgn->successors); ln != NULL; ln = Lst_Succ(ln)) {
     523    for (ln = Lst_First(cgn->successors); ln != NILLNODE; ln = Lst_Succ(ln)) {
    485524        GNode   *succ = (GNode *)Lst_Datum(ln);
    486525
    487526        if (succ->make && succ->unmade == 0 && succ->made == UNMADE &&
    488             Lst_Member(toBeMade, (void *)succ) == NULL)
     527            Lst_Member(toBeMade, (ClientData)succ) == NILLNODE)
    489528        {
    490             (void)Lst_EnQueue(toBeMade, (void *)succ);
     529            (void)Lst_EnQueue(toBeMade, (ClientData)succ);
    491530        }
    492531    }
     
    497536     */
    498537    if (Lst_Open (cgn->iParents) == SUCCESS) {
    499         char    *ptr;
    500         char    *cpref = Var_Value(PREFIX, cgn, &ptr);
    501 
    502         while ((ln = Lst_Next (cgn->iParents)) != NULL) {
     538        char    *p1;
     539        char    *cpref = Var_Value(PREFIX, cgn, &p1);
     540
     541        while ((ln = Lst_Next (cgn->iParents)) != NILLNODE) {
    503542            pgn = (GNode *)Lst_Datum (ln);
    504543            if (pgn->make) {
     
    507546            }
    508547        }
    509         efree(ptr);
     548        efree(p1);
    510549        Lst_Close (cgn->iParents);
    511550    }
     
    534573 */
    535574static int
    536 MakeAddAllSrc (void *cgnp, void *pgnp)
     575MakeAddAllSrc (cgnp, pgnp)
     576    ClientData  cgnp;   /* The child to add */
     577    ClientData  pgnp;   /* The parent to whose ALLSRC variable it should be */
     578                        /* added */
    537579{
    538580    GNode       *cgn = (GNode *) cgnp;
     
    605647 */
    606648void
    607 Make_DoAllVar (GNode *gn)
    608 {
    609     Lst_ForEach (gn->children, MakeAddAllSrc, (void *) gn);
     649Make_DoAllVar (gn)
     650    GNode       *gn;
     651{
     652    Lst_ForEach (gn->children, MakeAddAllSrc, (ClientData) gn);
    610653
    611654    if (!Var_Exists (OODATE, gn)) {
     
    641684 */
    642685static Boolean
    643 MakeStartJobs (void)
    644 {
    645     GNode       *gn;
     686MakeStartJobs ()
     687{
     688    register GNode      *gn;
    646689
    647690    while (!Job_Full() && !Lst_IsEmpty (toBeMade)) {
    648691        gn = (GNode *) Lst_DeQueue (toBeMade);
    649         DEBUGF(MAKE, ("Examining %s...", gn->name));
     692        if (DEBUG(MAKE)) {
     693            printf ("Examining %s...", gn->name);
     694        }
    650695        /*
    651696         * Make sure any and all predecessors that are going to be made,
     
    655700            LstNode ln;
    656701
    657             for (ln = Lst_First(gn->preds); ln != NULL; ln = Lst_Succ(ln)){
     702            for (ln = Lst_First(gn->preds); ln != NILLNODE; ln = Lst_Succ(ln)){
    658703                GNode   *pgn = (GNode *)Lst_Datum(ln);
    659704
    660705                if (pgn->make && pgn->made == UNMADE) {
    661                     DEBUGF(MAKE, ("predecessor %s not made yet.\n", pgn->name));
     706                    if (DEBUG(MAKE)) {
     707                        printf("predecessor %s not made yet.\n", pgn->name);
     708                    }
    662709                    break;
    663710                }
    664711            }
    665712            /*
    666              * If ln isn't NULL, there's a predecessor as yet unmade, so we
     713             * If ln isn't nil, there's a predecessor as yet unmade, so we
    667714             * just drop this node on the floor. When the node in question
    668715             * has been made, it will notice this node as being ready to
    669716             * make but as yet unmade and will place the node on the queue.
    670717             */
    671             if (ln != NULL) {
     718            if (ln != NILLNODE) {
    672719                continue;
    673720            }
     
    676723        numNodes--;
    677724        if (Make_OODate (gn)) {
    678             DEBUGF(MAKE, ("out-of-date\n"));
     725            if (DEBUG(MAKE)) {
     726                printf ("out-of-date\n");
     727            }
    679728            if (queryFlag) {
    680729                return (TRUE);
     
    683732            Job_Make (gn);
    684733        } else {
    685             DEBUGF(MAKE, ("up-to-date\n"));
     734            if (DEBUG(MAKE)) {
     735                printf ("up-to-date\n");
     736            }
    686737            gn->made = UPTODATE;
    687738            if (gn->type & OP_JOIN) {
     
    707758 *      Print the status of a top-level node, viz. it being up-to-date
    708759 *      already or not created due to an error in a lower level.
    709  *      Callback function for Make_Run via Lst_ForEach.  If gn->unmade is
    710  *      nonzero and that is meant to imply a cycle in the graph, then
    711  *      cycle is TRUE.
     760 *      Callback function for Make_Run via Lst_ForEach.
    712761 *
    713762 * Results:
     
    720769 */
    721770static int
    722 MakePrintStatus(void *gnp, void *cyclep)
     771MakePrintStatus(gnp, cyclep)
     772    ClientData  gnp;        /* Node to examine */
     773    ClientData  cyclep;     /* True if gn->unmade being non-zero implies
     774                             * a cycle in the graph, not an error in an
     775                             * inferior */
    723776{
    724777    GNode       *gn = (GNode *) gnp;
     
    742795                Error("Graph cycles through `%s'", gn->name);
    743796                gn->made = ENDCYCLE;
    744                 Lst_ForEach(gn->children, MakePrintStatus, (void *) &t);
     797                Lst_ForEach(gn->children, MakePrintStatus, (ClientData) &t);
    745798                gn->made = UNMADE;
    746799            } else if (gn->made != ENDCYCLE) {
    747800                gn->made = CYCLE;
    748                 Lst_ForEach(gn->children, MakePrintStatus, (void *) &t);
     801                Lst_ForEach(gn->children, MakePrintStatus, (ClientData) &t);
    749802            }
    750803        } else {
     
    778831 */
    779832Boolean
    780 Make_Run (Lst targs)
    781 {
    782     GNode           *gn;        /* a temporary pointer */
    783     Lst             examine;    /* List of targets to examine */
     833Make_Run (targs)
     834    Lst             targs;      /* the initial list of targets */
     835{
     836    register GNode  *gn;        /* a temporary pointer */
     837    register Lst    examine;    /* List of targets to examine */
    784838    int             errors;     /* Number of errors the Job module reports */
    785839
     
    808862             * to make sure everything has commands that should...
    809863             */
    810             Lst_ForEach (gn->children, MakeHandleUse, (void *)gn);
     864            Lst_ForEach (gn->children, MakeHandleUse, (ClientData)gn);
    811865            Suff_FindDeps (gn);
    812866
    813867            if (gn->unmade != 0) {
    814                 Lst_ForEach (gn->children, MakeAddChild, (void *)examine);
     868                Lst_ForEach (gn->children, MakeAddChild, (ClientData)examine);
    815869            } else {
    816                 (void)Lst_EnQueue (toBeMade, (void *)gn);
     870                (void)Lst_EnQueue (toBeMade, (ClientData)gn);
    817871            }
    818872        }
     
    855909    }
    856910
    857     errors = Job_Finish();
     911    errors = Job_End();
    858912
    859913    /*
     
    862916     */
    863917    errors = ((errors == 0) && (numNodes != 0));
    864     Lst_ForEach(targs, MakePrintStatus, (void *) &errors);
     918    Lst_ForEach(targs, MakePrintStatus, (ClientData) &errors);
    865919
    866920    return (TRUE);
  • branches/FREEBSD/src/kmk/make.h

    r10 r24  
    3636 * SUCH DAMAGE.
    3737 *
    38  *      @(#)make.h      8.3 (Berkeley) 6/13/95
    39  * $FreeBSD: src/usr.bin/make/make.h,v 1.23 2002/10/10 19:27:48 jmallett Exp $
     38 *      from: @(#)make.h        8.3 (Berkeley) 6/13/95
     39 * $FreeBSD: src/usr.bin/make/make.h,v 1.12.2.2 2001/02/13 03:13:58 will Exp $
    4040 */
    4141
     
    4646
    4747#ifndef _MAKE_H_
    48 #define _MAKE_H_
     48#define _MAKE_H_
    4949
    5050#include <sys/types.h>
     
    5252#include <string.h>
    5353#include <ctype.h>
    54 
     54#include <err.h>
     55
     56#if !defined(MAKE_BOOTSTRAP) && defined(BSD4_4)
     57# include <sys/cdefs.h>
     58#else
     59# ifndef __P
     60#  if defined(__STDC__) || defined(__cplusplus)
     61#   define      __P(protos)     protos          /* full-blown ANSI C */
     62#  else
     63#   define      __P(protos)     ()              /* traditional C preprocessor */
     64#  endif
     65# endif
     66# ifndef __STDC__
     67#  ifndef const
     68#   define const
     69#  endif
     70#  ifndef volatile
     71#   define volatile
     72#  endif
     73# endif
     74#endif
     75
     76#ifdef __STDC__
    5577#include <stdlib.h>
    5678#include <unistd.h>
     79#endif
    5780#include "sprite.h"
    5881#include "lst.h"
     
    6487 * pieces of data associated with it.
    6588 *      1) the name of the target it describes
    66  *      2) the location of the target file in the filesystem.
     89 *      2) the location of the target file in the file system.
    6790 *      3) the type of operator used to define its sources (qv. parse.c)
    6891 *      4) whether it is involved in this invocation of make
     
    143166
    144167/*
     168 * Manifest constants
     169 */
     170#define NILGNODE        ((GNode *) NIL)
     171
     172/*
    145173 * The OP_ constants are used when parsing a dependency line as a way of
    146174 * communicating to other parts of the program the way in which a target
     
    151179 * righthand side...
    152180 */
    153 #define OP_DEPENDS      0x00000001  /* Execution of commands depends on
     181#define OP_DEPENDS      0x00000001  /* Execution of commands depends on
    154182                                     * kids (:) */
    155 #define OP_FORCE        0x00000002  /* Always execute commands (!) */
    156 #define OP_DOUBLEDEP    0x00000004  /* Execution of commands depends on kids
     183#define OP_FORCE        0x00000002  /* Always execute commands (!) */
     184#define OP_DOUBLEDEP    0x00000004  /* Execution of commands depends on kids
    157185                                     * per line (::) */
    158 #define OP_OPMASK       (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
    159 
    160 #define OP_OPTIONAL     0x00000008  /* Don't care if the target doesn't
     186#define OP_OPMASK       (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
     187
     188#define OP_OPTIONAL     0x00000008  /* Don't care if the target doesn't
    161189                                     * exist and can't be created */
    162 #define OP_USE          0x00000010  /* Use associated commands for parents */
    163 #define OP_EXEC         0x00000020  /* Target is never out of date, but always
     190#define OP_USE          0x00000010  /* Use associated commands for parents */
     191#define OP_EXEC         0x00000020  /* Target is never out of date, but always
    164192                                     * execute commands anyway. Its time
    165193                                     * doesn't matter, so it has none...sort
    166194                                     * of */
    167 #define OP_IGNORE       0x00000040  /* Ignore errors when creating the node */
    168 #define OP_PRECIOUS     0x00000080  /* Don't remove the target when
     195#define OP_IGNORE       0x00000040  /* Ignore errors when creating the node */
     196#define OP_PRECIOUS     0x00000080  /* Don't remove the target when
    169197                                     * interrupted */
    170 #define OP_SILENT       0x00000100  /* Don't echo commands when executed */
    171 #define OP_MAKE         0x00000200  /* Target is a recurrsive make so its
     198#define OP_SILENT       0x00000100  /* Don't echo commands when executed */
     199#define OP_MAKE         0x00000200  /* Target is a recurrsive make so its
    172200                                     * commands should always be executed when
    173201                                     * it is out of date, regardless of the
    174202                                     * state of the -n or -t flags */
    175 #define OP_JOIN         0x00000400  /* Target is out-of-date only if any of its
     203#define OP_JOIN         0x00000400  /* Target is out-of-date only if any of its
    176204                                     * children was out-of-date */
    177 #define OP_INVISIBLE    0x00004000  /* The node is invisible to its parents.
     205#define OP_INVISIBLE    0x00004000  /* The node is invisible to its parents.
    178206                                     * I.e. it doesn't show up in the parents's
    179207                                     * local variables. */
    180 #define OP_NOTMAIN      0x00008000  /* The node is exempt from normal 'main
     208#define OP_NOTMAIN      0x00008000  /* The node is exempt from normal 'main
    181209                                     * target' processing in parse.c */
    182 #define OP_PHONY        0x00010000  /* Not a file target; run always */
     210#define OP_PHONY        0x00010000  /* Not a file target; run always */
    183211/* Attributes applied by PMake */
    184 #define OP_TRANSFORM    0x80000000  /* The node is a transformation rule */
    185 #define OP_MEMBER       0x40000000  /* Target is a member of an archive */
    186 #define OP_LIB          0x20000000  /* Target is a library */
    187 #define OP_ARCHV        0x10000000  /* Target is an archive construct */
    188 #define OP_HAS_COMMANDS 0x08000000  /* Target has all the commands it should.
     212#define OP_TRANSFORM    0x80000000  /* The node is a transformation rule */
     213#define OP_MEMBER       0x40000000  /* Target is a member of an archive */
     214#define OP_LIB          0x20000000  /* Target is a library */
     215#define OP_ARCHV        0x10000000  /* Target is an archive construct */
     216#define OP_HAS_COMMANDS 0x08000000  /* Target has all the commands it should.
    189217                                     * Used when parsing to catch multiple
    190218                                     * commands for a target */
    191 #define OP_SAVE_CMDS    0x04000000  /* Saving commands on .END (Compat) */
    192 #define OP_DEPS_FOUND   0x02000000  /* Already processed by Suff_FindDeps */
     219#define OP_SAVE_CMDS    0x04000000  /* Saving commands on .END (Compat) */
     220#define OP_DEPS_FOUND   0x02000000  /* Already processed by Suff_FindDeps */
    193221
    194222/*
     
    196224 * object of a dependency operator
    197225 */
    198 #define OP_NOP(t)       (((t) & OP_OPMASK) == 0x00000000)
     226#define OP_NOP(t)       (((t) & OP_OPMASK) == 0x00000000)
    199227
    200228/*
     
    204232 * is given, a new, empty node will be created for the target, placed in the
    205233 * table of all targets and its address returned. If TARG_NOCREATE is given,
    206  * a NULL pointer will be returned.
    207  */
    208 #define TARG_CREATE     0x01      /* create node if not found */
    209 #define TARG_NOCREATE   0x00      /* don't create it */
     234 * a NIL pointer will be returned.
     235 */
     236#define TARG_CREATE     0x01      /* create node if not found */
     237#define TARG_NOCREATE   0x00      /* don't create it */
    210238
    211239/*
     
    218246 * schemes allocate in powers of two.
    219247 */
    220 #define MAKE_BSIZE              256     /* starting size for expandable buffers */
     248#define MAKE_BSIZE              256     /* starting size for expandable buffers */
    221249
    222250/*
     
    229257 * Str_Concat returns.
    230258 */
    231 #define STR_ADDSPACE    0x01    /* add a space when Str_Concat'ing */
    232 #define STR_DOFREE      0x02    /* free source strings after concatenation */
    233 #define STR_ADDSLASH    0x04    /* add a slash when Str_Concat'ing */
     259#define STR_ADDSPACE    0x01    /* add a space when Str_Concat'ing */
     260#define STR_DOFREE      0x02    /* free source strings after concatenation */
     261#define STR_ADDSLASH    0x04    /* add a slash when Str_Concat'ing */
    234262
    235263/*
     
    238266 * as the first argument to Parse_Error.
    239267 */
    240 #define PARSE_WARNING   2
    241 #define PARSE_FATAL     1
     268#define PARSE_WARNING   2
     269#define PARSE_FATAL     1
    242270
    243271/*
    244272 * Values returned by Cond_Eval.
    245273 */
    246 #define COND_PARSE      0       /* Parse the next lines */
    247 #define COND_SKIP       1       /* Skip the next lines */
    248 #define COND_INVALID    2       /* Not a conditional statement */
     274#define COND_PARSE      0       /* Parse the next lines */
     275#define COND_SKIP       1       /* Skip the next lines */
     276#define COND_INVALID    2       /* Not a conditional statement */
    249277
    250278/*
    251279 * Definitions for the "local" variables. Used only for clarity.
    252280 */
    253 #define TARGET            "@"   /* Target of dependency */
    254 #define OODATE            "?"   /* All out-of-date sources */
    255 #define ALLSRC            ">"   /* All sources */
    256 #define IMPSRC            "<"   /* Source implied by transformation */
    257 #define PREFIX            "*"   /* Common prefix */
    258 #define ARCHIVE           "!"   /* Archive in "archive(member)" syntax */
    259 #define MEMBER            "%"   /* Member in "archive(member)" syntax */
    260 
    261 #define FTARGET           "@F"  /* file part of TARGET */
    262 #define DTARGET           "@D"  /* directory part of TARGET */
    263 #define FIMPSRC           "<F"  /* file part of IMPSRC */
    264 #define DIMPSRC           "<D"  /* directory part of IMPSRC */
    265 #define FPREFIX           "*F"  /* file part of PREFIX */
    266 #define DPREFIX           "*D"  /* directory part of PREFIX */
     281#define TARGET            "@"   /* Target of dependency */
     282#define OODATE            "?"   /* All out-of-date sources */
     283#define ALLSRC            ">"   /* All sources */
     284#define IMPSRC            "<"   /* Source implied by transformation */
     285#define PREFIX            "*"   /* Common prefix */
     286#define ARCHIVE           "!"   /* Archive in "archive(member)" syntax */
     287#define MEMBER            "%"   /* Member in "archive(member)" syntax */
     288
     289#define FTARGET           "@F"  /* file part of TARGET */
     290#define DTARGET           "@D"  /* directory part of TARGET */
     291#define FIMPSRC           "<F"  /* file part of IMPSRC */
     292#define DIMPSRC           "<D"  /* directory part of IMPSRC */
     293#define FPREFIX           "*F"  /* file part of PREFIX */
     294#define DPREFIX           "*D"  /* directory part of PREFIX */
    267295
    268296/*
     
    274302extern Lst      dirSearchPath;  /* The list of directories to search when
    275303                                 * looking for targets */
    276 extern Lst      parseIncPath;   /* The list of directories to search when
    277                                  * looking for includes */
    278 
    279 extern Boolean  jobsRunning;    /* True if jobs are running */
     304
    280305extern Boolean  compatMake;     /* True if we are make compatible */
    281306extern Boolean  ignoreErrors;   /* True if should ignore all errors */
     
    336361#define DEBUG_TARG      0x0100
    337362#define DEBUG_VAR       0x0200
    338 #define DEBUG_FOR       0x0400
    339 #define DEBUG_LOUD      0x0800
    340 
    341 #define CONCAT(a,b)     a##b
     363#define DEBUG_FOR       0x0400
     364#define DEBUG_LOUD      0x0800
     365
     366#ifdef __STDC__
     367#define CONCAT(a,b)     a##b
     368#else
     369#define I(a)            a
     370#define CONCAT(a,b)     I(a)b
     371#endif /* __STDC__ */
    342372
    343373#define DEBUG(module)   (debug & CONCAT(DEBUG_,module))
    344 #define DEBUGF(module,args)             \
    345 do {                                            \
    346         if (DEBUG(module)) {                    \
    347                 Debug args ;                    \
    348         }                                       \
    349 } while (0)
    350 #define ISDOT(c) ((c)[0] == '.' && (((c)[1] == '\0') || ((c)[1] == '/')))
    351 #define ISDOTDOT(c) ((c)[0] == '.' && ISDOT(&((c)[1])))
     374#define ISDOT(c) ((c)[0] == '.' && (((c)[1] == '\0') || ((c)[1] == '/')))
     375#define ISDOTDOT(c) ((c)[0] == '.' && ISDOT(&((c)[1])))
    352376
    353377/*
     
    357381#include "nonints.h"
    358382
    359 int Make_TimeStamp(GNode *, GNode *);
    360 Boolean Make_OODate(GNode *);
    361 int Make_HandleUse(GNode *, GNode *);
    362 void Make_Update(GNode *);
    363 void Make_DoAllVar(GNode *);
    364 Boolean Make_Run(Lst);
     383int Make_TimeStamp __P((GNode *, GNode *));
     384Boolean Make_OODate __P((GNode *));
     385int Make_HandleUse __P((GNode *, GNode *));
     386void Make_Update __P((GNode *));
     387void Make_DoAllVar __P((GNode *));
     388Boolean Make_Run __P((Lst));
    365389
    366390#endif /* _MAKE_H_ */
  • branches/FREEBSD/src/kmk/nonints.h

    r10 r24  
    3636 * SUCH DAMAGE.
    3737 *
    38  *      @(#)nonints.h   8.4 (Berkeley) 4/28/95
    39  * $FreeBSD: src/usr.bin/make/nonints.h,v 1.17 2002/09/18 16:13:03 jmallett Exp $
     38 *      from: @(#)nonints.h     8.3 (Berkeley) 3/19/94
     39 * $FreeBSD: src/usr.bin/make/nonints.h,v 1.8 1999/08/28 01:03:35 peter Exp $
    4040 */
    4141
    4242/* arch.c */
    43 ReturnStatus Arch_ParseArchive(char **, Lst, GNode *);
    44 void Arch_Touch(GNode *);
    45 void Arch_TouchLib(GNode *);
    46 int Arch_MTime(GNode *);
    47 int Arch_MemMTime(GNode *);
    48 void Arch_FindLib(GNode *, Lst);
    49 Boolean Arch_LibOODate(GNode *);
    50 void Arch_Init(void);
    51 void Arch_End(void);
     43ReturnStatus Arch_ParseArchive __P((char **, Lst, GNode *));
     44void Arch_Touch __P((GNode *));
     45void Arch_TouchLib __P((GNode *));
     46int Arch_MTime __P((GNode *));
     47int Arch_MemMTime __P((GNode *));
     48void Arch_FindLib __P((GNode *, Lst));
     49Boolean Arch_LibOODate __P((GNode *));
     50void Arch_Init __P((void));
     51void Arch_End __P((void));
    5252
    5353/* compat.c */
    54 void Compat_Run(Lst);
     54void Compat_Run __P((Lst));
    5555
    5656/* cond.c */
    57 int Cond_Eval(char *);
    58 void Cond_End(void);
     57int Cond_Eval __P((char *));
     58void Cond_End __P((void));
    5959
    6060/* for.c */
    61 int For_Eval(char *);
    62 void For_Run(void);
     61int For_Eval __P((char *));
     62void For_Run  __P((void));
    6363
    6464/* main.c */
    65 void Main_ParseArgLine(char *);
    66 char *Cmd_Exec(char *, char **);
    67 void Debug(const char *, ...);
    68 void Error(const char *, ...);
    69 void Fatal(const char *, ...);
    70 void Punt(const char *, ...);
    71 void DieHorribly(void);
    72 int PrintAddr(void *, void *);
    73 void Finish(int);
    74 char *estrdup(const char *);
    75 void *emalloc(size_t);
     65void Main_ParseArgLine __P((char *));
     66int main __P((int, char **));
     67char *Cmd_Exec __P((char *, char **));
     68void Error __P((char *, ...));
     69void Fatal __P((char *, ...));
     70void Punt __P((char *, ...));
     71void DieHorribly __P((void));
     72int PrintAddr __P((ClientData, ClientData));
     73void Finish __P((int));
     74char *estrdup __P((const char *));
     75void *emalloc __P((size_t));
    7676/* efree(x) works when x==NULL. STDC behavior, may need some different
    7777 * definition for cross-builds on deficient systems */
    78 #define efree   free
    79 void *erealloc(void *, size_t);
    80 void enomem(void);
    81 int eunlink(const char *);
     78#define efree   free
     79void *erealloc __P((void *, size_t));
     80void enomem __P((void));
     81int eunlink __P((const char *));
    8282
    8383/* parse.c */
    84 void Parse_Error(int, const char *, ...);
    85 Boolean Parse_AnyExport(void);
    86 Boolean Parse_IsVar(char *);
    87 void Parse_DoVar(char *, GNode *);
    88 void Parse_AddIncludeDir(char *);
    89 void Parse_File(char *, FILE *);
    90 void Parse_Init(void);
    91 void Parse_End(void);
    92 void Parse_FromString(char *);
    93 Lst Parse_MainName(void);
     84void Parse_Error __P((int, char *, ...));
     85Boolean Parse_AnyExport __P((void));
     86Boolean Parse_IsVar __P((char *));
     87void Parse_DoVar __P((char *, GNode *));
     88void Parse_AddIncludeDir __P((char *));
     89void Parse_File __P((char *, FILE *));
     90void Parse_Init __P((void));
     91void Parse_End __P((void));
     92void Parse_FromString __P((char *));
     93Lst Parse_MainName __P((void));
    9494
    9595/* str.c */
    96 void str_init(void);
    97 void str_end(void);
    98 char *str_concat(char *, char *, int);
    99 char **brk_string(char *, int *, Boolean);
    100 char *Str_FindSubstring(char *, char *);
    101 int Str_Match(char *, char *);
    102 char *Str_SYSVMatch(char *, char *, int *len);
    103 void Str_SYSVSubst(Buffer, char *, char *, int);
     96void str_init __P((void));
     97void str_end __P((void));
     98char *str_concat __P((char *, char *, int));
     99char **brk_string __P((char *, int *, Boolean));
     100char *Str_FindSubstring __P((char *, char *));
     101int Str_Match __P((char *, char *));
     102char *Str_SYSVMatch __P((char *, char *, int *len));
     103void Str_SYSVSubst __P((Buffer, char *, char *, int));
    104104
    105105/* suff.c */
    106 void Suff_ClearSuffixes(void);
    107 Boolean Suff_IsTransform(char *);
    108 GNode *Suff_AddTransform(char *);
    109 int Suff_EndTransform(void *, void *);
    110 void Suff_AddSuffix(char *);
    111 Lst Suff_GetPath(char *);
    112 void Suff_DoPaths(void);
    113 void Suff_AddInclude(char *);
    114 void Suff_AddLib(char *);
    115 void Suff_FindDeps(GNode *);
    116 void Suff_SetNull(char *);
    117 void Suff_Init(void);
    118 void Suff_End(void);
    119 void Suff_PrintAll(void);
     106void Suff_ClearSuffixes __P((void));
     107Boolean Suff_IsTransform __P((char *));
     108GNode *Suff_AddTransform __P((char *));
     109int Suff_EndTransform __P((ClientData, ClientData));
     110void Suff_AddSuffix __P((char *));
     111Lst Suff_GetPath __P((char *));
     112void Suff_DoPaths __P((void));
     113void Suff_AddInclude __P((char *));
     114void Suff_AddLib __P((char *));
     115void Suff_FindDeps __P((GNode *));
     116void Suff_SetNull __P((char *));
     117void Suff_Init __P((void));
     118void Suff_End __P((void));
     119void Suff_PrintAll __P((void));
    120120
    121121/* targ.c */
    122 void Targ_Init(void);
    123 void Targ_End(void);
    124 GNode *Targ_NewGN(char *);
    125 GNode *Targ_FindNode(char *, int);
    126 Lst Targ_FindList(Lst, int);
    127 Boolean Targ_Ignore(GNode *);
    128 Boolean Targ_Silent(GNode *);
    129 Boolean Targ_Precious(GNode *);
    130 void Targ_SetMain(GNode *);
    131 int Targ_PrintCmd(void *, void *);
    132 char *Targ_FmtTime(time_t);
    133 void Targ_PrintType(int);
    134 void Targ_PrintGraph(int);
     122void Targ_Init __P((void));
     123void Targ_End __P((void));
     124GNode *Targ_NewGN __P((char *));
     125GNode *Targ_FindNode __P((char *, int));
     126Lst Targ_FindList __P((Lst, int));
     127Boolean Targ_Ignore __P((GNode *));
     128Boolean Targ_Silent __P((GNode *));
     129Boolean Targ_Precious __P((GNode *));
     130void Targ_SetMain __P((GNode *));
     131int Targ_PrintCmd __P((ClientData, ClientData));
     132char *Targ_FmtTime __P((time_t));
     133void Targ_PrintType __P((int));
     134void Targ_PrintGraph __P((int));
    135135
    136136/* var.c */
    137 void Var_Delete(char *, GNode *);
    138 void Var_Set(char *, char *, GNode *);
    139 void Var_Append(char *, char *, GNode *);
    140 Boolean Var_Exists(char *, GNode *);
    141 char *Var_Value(char *, GNode *, char **);
    142 char *Var_Parse(char *, GNode *, Boolean, int *, Boolean *);
    143 char *Var_Subst(char *, char *, GNode *, Boolean);
    144 char *Var_GetTail(char *);
    145 char *Var_GetHead(char *);
    146 void Var_Init(void);
    147 void Var_End(void);
    148 void Var_Dump(GNode *);
     137void Var_Delete __P((char *, GNode *));
     138void Var_Set __P((char *, char *, GNode *));
     139void Var_Append __P((char *, char *, GNode *));
     140Boolean Var_Exists __P((char *, GNode *));
     141char *Var_Value __P((char *, GNode *, char **));
     142char *Var_Parse __P((char *, GNode *, Boolean, int *, Boolean *));
     143char *Var_Subst __P((char *, char *, GNode *, Boolean));
     144char *Var_GetTail __P((char *));
     145char *Var_GetHead __P((char *));
     146void Var_Init __P((void));
     147void Var_End __P((void));
     148void Var_Dump __P((GNode *));
  • branches/FREEBSD/src/kmk/parse.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)parse.c  8.3 (Berkeley) 3/19/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/parse.c,v 1.48 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)parse.c     8.3 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/parse.c,v 1.22 1999/08/28 01:03:35 peter Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    8488 */
    8589
     90#ifdef __STDC__
    8691#include <stdarg.h>
     92#else
     93#include <varargs.h>
     94#endif
    8795#include <ctype.h>
    8896#include <err.h>
     
    178186
    179187/*
    180  * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
     188 * Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER
    181189 * seen, then set to each successive source on the line.
    182190 */
     
    231239};
    232240
    233 static int ParseFindKeyword(char *);
    234 static int ParseLinkSrc(void *, void *);
    235 static int ParseDoOp(void *, void *);
    236 static int ParseAddDep(void *, void *);
    237 static void ParseDoSrc(int, char *, Lst);
    238 static int ParseFindMain(void *, void *);
    239 static int ParseAddDir(void *, void *);
    240 static int ParseClearPath(void *, void *);
    241 static void ParseDoDependency(char *);
    242 static int ParseAddCmd(void *, void *);
    243 static int ParseReadc(void);
    244 static void ParseUnreadc(int);
    245 static void ParseHasCommands(void *);
    246 static void ParseDoInclude(char *);
    247 static void ParseDoError(char *);
     241static int ParseFindKeyword __P((char *));
     242static int ParseLinkSrc __P((ClientData, ClientData));
     243static int ParseDoOp __P((ClientData, ClientData));
     244static int ParseAddDep __P((ClientData, ClientData));
     245static void ParseDoSrc __P((int, char *, Lst));
     246static int ParseFindMain __P((ClientData, ClientData));
     247static int ParseAddDir __P((ClientData, ClientData));
     248static int ParseClearPath __P((ClientData, ClientData));
     249static void ParseDoDependency __P((char *));
     250static int ParseAddCmd __P((ClientData, ClientData));
     251static int ParseReadc __P((void));
     252static void ParseUnreadc __P((int));
     253static void ParseHasCommands __P((ClientData));
     254static void ParseDoInclude __P((char *));
     255static void ParseDoError __P((char *));
    248256#ifdef SYSVINCLUDE
    249 static void ParseTraditionalInclude(char *);
     257static void ParseTraditionalInclude __P((char *));
    250258#endif
    251 static int ParseEOF(int);
    252 static char *ParseReadLine(void);
    253 static char *ParseSkipLine(int);
    254 static void ParseFinishLine(void);
     259static int ParseEOF __P((int));
     260static char *ParseReadLine __P((void));
     261static char *ParseSkipLine __P((int));
     262static void ParseFinishLine __P((void));
    255263
    256264/*-
     
    267275 */
    268276static int
    269 ParseFindKeyword (char *str)
    270 {
    271     int             start,
     277ParseFindKeyword (str)
     278    char            *str;               /* String to find */
     279{
     280    register int    start,
    272281                    end,
    273282                    cur;
    274     int             diff;
     283    register int    diff;
    275284
    276285    start = 0;
     
    306315/* VARARGS */
    307316void
    308 Parse_Error(int type, const char *fmt, ...)
     317#ifdef __STDC__
     318Parse_Error(int type, char *fmt, ...)
     319#else
     320Parse_Error(va_alist)
     321        va_dcl
     322#endif
    309323{
    310324        va_list ap;
    311 
     325#ifdef __STDC__
    312326        va_start(ap, fmt);
     327#else
     328        int type;               /* Error type (PARSE_WARNING, PARSE_FATAL) */
     329        char *fmt;
     330
     331        va_start(ap);
     332        type = va_arg(ap, int);
     333        fmt = va_arg(ap, char *);
     334#endif
     335
    313336        (void)fprintf(stderr, "\"%s\", line %d: ", fname, lineno);
    314337        if (type == PARSE_WARNING)
     
    339362 */
    340363static int
    341 ParseLinkSrc (void *pgnp, void *cgnp)
     364ParseLinkSrc (pgnp, cgnp)
     365    ClientData     pgnp;        /* The parent node */
     366    ClientData     cgnp;        /* The child node */
    342367{
    343368    GNode          *pgn = (GNode *) pgnp;
    344369    GNode          *cgn = (GNode *) cgnp;
    345     if (Lst_Member (pgn->children, (void *)cgn) == NULL) {
    346         (void)Lst_AtEnd (pgn->children, (void *)cgn);
     370    if (Lst_Member (pgn->children, (ClientData)cgn) == NILLNODE) {
     371        (void)Lst_AtEnd (pgn->children, (ClientData)cgn);
    347372        if (specType == Not) {
    348             (void)Lst_AtEnd (cgn->parents, (void *)pgn);
     373            (void)Lst_AtEnd (cgn->parents, (ClientData)pgn);
    349374        }
    350375        pgn->unmade += 1;
     
    370395 */
    371396static int
    372 ParseDoOp (void *gnp, void *opp)
     397ParseDoOp (gnp, opp)
     398    ClientData     gnp;         /* The node to which the operator is to be
     399                                 * applied */
     400    ClientData     opp;         /* The operator to apply */
    373401{
    374402    GNode          *gn = (GNode *) gnp;
     
    395423         * instance.
    396424         */
    397         GNode           *cohort;
     425        register GNode  *cohort;
    398426        LstNode         ln;
    399427
     
    408436         * sorry.
    409437         */
    410         Lst_ForEach(gn->parents, ParseLinkSrc, (void *)cohort);
     438        Lst_ForEach(gn->parents, ParseLinkSrc, (ClientData)cohort);
    411439        cohort->type = OP_DOUBLEDEP|OP_INVISIBLE;
    412         (void)Lst_AtEnd(gn->cohorts, (void *)cohort);
     440        (void)Lst_AtEnd(gn->cohorts, (ClientData)cohort);
    413441
    414442        /*
    415443         * Replace the node in the targets list with the new copy
    416444         */
    417         ln = Lst_Member(targets, (void *)gn);
    418         Lst_Replace(ln, (void *)cohort);
     445        ln = Lst_Member(targets, (ClientData)gn);
     446        Lst_Replace(ln, (ClientData)cohort);
    419447        gn = cohort;
    420448    }
     
    445473 */
    446474static int
    447 ParseAddDep(void *pp, void *sp)
     475ParseAddDep(pp, sp)
     476    ClientData pp;
     477    ClientData sp;
    448478{
    449479    GNode *p = (GNode *) pp;
     
    456486         * problem
    457487         */
    458         (void)Lst_AtEnd(p->successors, (void *)s);
    459         (void)Lst_AtEnd(s->preds, (void *)p);
     488        (void)Lst_AtEnd(p->successors, (ClientData)s);
     489        (void)Lst_AtEnd(s->preds, (ClientData)p);
    460490        return 0;
    461491    }
     
    483513 */
    484514static void
    485 ParseDoSrc (int tOp, char *src, Lst allsrc)
     515ParseDoSrc (tOp, src, allsrc)
     516    int         tOp;    /* operator (if any) from special targets */
     517    char        *src;   /* name of the source to handle */
     518    Lst         allsrc; /* List of all sources to wait for */
    486519{
    487520    GNode       *gn = NULL;
    488521
    489     if (*src == '.' && isupper ((unsigned char) src[1])) {
     522    if (*src == '.' && isupper (src[1])) {
    490523        int keywd = ParseFindKeyword(src);
    491524        if (keywd != -1) {
    492525            int op = parseKeywords[keywd].op;
    493526            if (op != 0) {
    494                 Lst_ForEach (targets, ParseDoOp, (void *)&op);
     527                Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
    495528                return;
    496529            }
     
    512545         * line. This is to allow #ifmake's to succeed, or something...
    513546         */
    514         (void) Lst_AtEnd (create, (void *)estrdup(src));
     547        (void) Lst_AtEnd (create, (ClientData)estrdup(src));
    515548        /*
    516549         * Add the name to the .TARGETS variable as well, so the user cna
     
    526559         */
    527560        gn = Targ_FindNode(src, TARG_CREATE);
    528         if (predecessor != NULL) {
    529             (void)Lst_AtEnd(predecessor->successors, (void *)gn);
    530             (void)Lst_AtEnd(gn->preds, (void *)predecessor);
     561        if (predecessor != NILGNODE) {
     562            (void)Lst_AtEnd(predecessor->successors, (ClientData)gn);
     563            (void)Lst_AtEnd(gn->preds, (ClientData)predecessor);
    531564        }
    532565        /*
     
    552585            gn->type |= tOp;
    553586        } else {
    554             Lst_ForEach (targets, ParseLinkSrc, (void *)gn);
     587            Lst_ForEach (targets, ParseLinkSrc, (ClientData)gn);
    555588        }
    556589        if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
    557             GNode       *cohort;
    558             LstNode     ln;
    559 
    560             for (ln=Lst_First(gn->cohorts); ln != NULL; ln = Lst_Succ(ln)){
     590            register GNode      *cohort;
     591            register LstNode    ln;
     592
     593            for (ln=Lst_First(gn->cohorts); ln != NILLNODE; ln = Lst_Succ(ln)){
    561594                cohort = (GNode *)Lst_Datum(ln);
    562595                if (tOp) {
    563596                    cohort->type |= tOp;
    564597                } else {
    565                     Lst_ForEach(targets, ParseLinkSrc, (void *)cohort);
     598                    Lst_ForEach(targets, ParseLinkSrc, (ClientData)cohort);
    566599                }
    567600            }
     
    571604
    572605    gn->order = waiting;
    573     (void)Lst_AtEnd(allsrc, (void *)gn);
     606    (void)Lst_AtEnd(allsrc, (ClientData)gn);
    574607    if (waiting) {
    575         Lst_ForEach(allsrc, ParseAddDep, (void *)gn);
     608        Lst_ForEach(allsrc, ParseAddDep, (ClientData)gn);
    576609    }
    577610}
     
    593626 */
    594627static int
    595 ParseFindMain(void *gnp, void *dummy __unused)
     628ParseFindMain(gnp, dummy)
     629    ClientData    gnp;      /* Node to examine */
     630    ClientData    dummy;
    596631{
    597632    GNode         *gn = (GNode *) gnp;
     
    599634        mainNode = gn;
    600635        Targ_SetMain(gn);
    601         return (1);
     636        return (dummy ? 1 : 1);
    602637    } else {
    603         return (0);
     638        return (dummy ? 0 : 0);
    604639    }
    605640}
     
    619654 */
    620655static int
    621 ParseAddDir(void *path, void *name)
     656ParseAddDir(path, name)
     657    ClientData    path;
     658    ClientData    name;
    622659{
    623660    Dir_AddDir((Lst) path, (char *) name);
     
    639676 */
    640677static int
    641 ParseClearPath(void *path, void *dummy __unused)
     678ParseClearPath(path, dummy)
     679    ClientData path;
     680    ClientData dummy;
    642681{
    643682    Dir_ClearPath((Lst) path);
    644     return (0);
     683    return(dummy ? 0 : 0);
    645684}
    646685
     
    680719 */
    681720static void
    682 ParseDoDependency (char *line)
     721ParseDoDependency (line)
     722    char           *line;       /* the line to parse */
    683723{
    684724    char           *cp;         /* our current position */
     
    706746    do {
    707747        for (cp = line;
    708              *cp && !isspace ((unsigned char) *cp) && *cp != '(';
     748             *cp && !isspace (*cp) &&
     749             (*cp != '!') && (*cp != ':') && (*cp != '(');
    709750             cp++)
    710751        {
     
    727768                }
    728769                cp += length-1;
    729             } else if (*cp == '!' || *cp == ':') {
    730                 /*
    731                  * We don't want to end a word on ':' or '!' if there is a
    732                  * better match later on in the string.  By "better" I mean
    733                  * one that is followed by whitespace.  This allows the user
    734                  * to have targets like:
    735                  *    fie::fi:fo: fum
    736                  * where "fie::fi:fo" is the target.  In real life this is used
    737                  * for perl5 library man pages where "::" separates an object
    738                  * from its class.  Ie: "File::Spec::Unix".  This behaviour
    739                  * is also consistent with other versions of make.
    740                  */
    741                 char *p = cp + 1;
    742 
    743                 if (*cp == ':' && *p == ':')
    744                     p++;
    745 
    746                 /* Found the best match already. */
    747                 if (*p == '\0' || isspace(*p))
    748                     break;
    749 
    750                 do {
    751                     p += strcspn(p, "!:");
    752                     if (*p == '\0')
    753                         break;
    754                 } while (!isspace(*++p));
    755 
    756                 /* No better match later on... */
    757                 if (*p == '\0')
    758                     break;
    759770            }
    760771            continue;
     
    784795            /*
    785796             * Ending a dependency line without an operator is a Bozo
    786              * no-no.  As a heuristic, this is also often triggered by
    787              * undetected conflicts from cvs/rcs merges.
     797             * no-no
    788798             */
    789             if ((strncmp(line, "<<<<<<", 6) == 0) ||
    790                 (strncmp(line, "======", 6) == 0) ||
    791                 (strncmp(line, ">>>>>>", 6) == 0))
    792                 Parse_Error (PARSE_FATAL,
    793                     "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
    794             else
    795                 Parse_Error (PARSE_FATAL, "Need an operator");
     799            Parse_Error (PARSE_FATAL, "Need an operator");
    796800            return;
    797801        }
     
    801805         * specType to match it.
    802806         */
    803         if (*line == '.' && isupper ((unsigned char) line[1])) {
     807        if (*line == '.' && isupper (line[1])) {
    804808            /*
    805809             * See if the target is a special target that must have it
     
    842846                 *      .NOTPARALLEL    Make only one target at a time.
    843847                 *      .SINGLESHELL    Create a shell for each command.
    844                  *      .ORDER          Must set initial predecessor to NULL
     848                 *      .ORDER          Must set initial predecessor to NIL
    845849                 */
    846850                switch (specType) {
     
    849853                            paths = Lst_Init(FALSE);
    850854                        }
    851                         (void)Lst_AtEnd(paths, (void *)dirSearchPath);
     855                        (void)Lst_AtEnd(paths, (ClientData)dirSearchPath);
    852856                        break;
    853857                    case Main:
     
    861865                        gn = Targ_FindNode(line, TARG_CREATE);
    862866                        gn->type |= OP_NOTMAIN;
    863                         (void)Lst_AtEnd(targets, (void *)gn);
     867                        (void)Lst_AtEnd(targets, (ClientData)gn);
    864868                        break;
    865869                    case Default:
    866870                        gn = Targ_NewGN(".DEFAULT");
    867871                        gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
    868                         (void)Lst_AtEnd(targets, (void *)gn);
     872                        (void)Lst_AtEnd(targets, (ClientData)gn);
    869873                        DEFAULT = gn;
    870874                        break;
    871875                    case NotParallel:
    872876                    {
     877                        extern int  maxJobs;
     878
    873879                        maxJobs = 1;
    874880                        break;
     
    878884                        break;
    879885                    case Order:
    880                         predecessor = NULL;
     886                        predecessor = NILGNODE;
    881887                        break;
    882888                    default:
     
    893899                specType = ExPath;
    894900                path = Suff_GetPath (&line[5]);
    895                 if (path == NULL) {
     901                if (path == NILLST) {
    896902                    Parse_Error (PARSE_FATAL,
    897903                                 "Suffix '%s' not defined (yet)",
     
    902908                        paths = Lst_Init(FALSE);
    903909                    }
    904                     (void)Lst_AtEnd(paths, (void *)path);
     910                    (void)Lst_AtEnd(paths, (ClientData)path);
    905911                }
    906912            }
     
    929935                 * so create a list with the word on it.
    930936                 */
    931                 (void)Lst_AtEnd(curTargs, (void *)line);
     937                (void)Lst_AtEnd(curTargs, (ClientData)line);
    932938            }
    933939
     
    941947                }
    942948
    943                 (void)Lst_AtEnd (targets, (void *)gn);
     949                (void)Lst_AtEnd (targets, (ClientData)gn);
    944950            }
    945951        } else if (specType == ExPath && *line != '.' && *line != '\0') {
     
    965971            }
    966972        } else {
    967             while (*cp && isspace ((unsigned char) *cp)) {
     973            while (*cp && isspace (*cp)) {
    968974                cp++;
    969975            }
     
    10181024    cp++;                       /* Advance beyond operator */
    10191025
    1020     Lst_ForEach (targets, ParseDoOp, (void *)&op);
     1026    Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
    10211027
    10221028    /*
    10231029     * Get to the first source
    10241030     */
    1025     while (*cp && isspace ((unsigned char) *cp)) {
     1031    while (*cp && isspace (*cp)) {
    10261032        cp++;
    10271033    }
     
    10521058                break;
    10531059            case ExPath:
    1054                 Lst_ForEach(paths, ParseClearPath, (void *)NULL);
     1060                Lst_ForEach(paths, ParseClearPath, (ClientData)NULL);
    10551061                break;
    10561062#ifdef POSIX
     
    11121118             * has no valid suffix.
    11131119             */
    1114             char  savech;
    1115             while (*cp && !isspace ((unsigned char) *cp)) {
     1120            char  savec;
     1121            while (*cp && !isspace (*cp)) {
    11161122                cp++;
    11171123            }
    1118             savech = *cp;
     1124            savec = *cp;
    11191125            *cp = '\0';
    11201126            switch (specType) {
     
    11231129                    break;
    11241130                case ExPath:
    1125                     Lst_ForEach(paths, ParseAddDir, (void *)line);
     1131                    Lst_ForEach(paths, ParseAddDir, (ClientData)line);
    11261132                    break;
    11271133                case Includes:
     
    11371143                    break;
    11381144            }
    1139             *cp = savech;
    1140             if (savech != '\0') {
     1145            *cp = savec;
     1146            if (savec != '\0') {
    11411147                cp++;
    11421148            }
    1143             while (*cp && isspace ((unsigned char) *cp)) {
     1149            while (*cp && isspace (*cp)) {
    11441150                cp++;
    11451151            }
     
    11561162             * and handle them accordingly.
    11571163             */
    1158             while (*cp && !isspace ((unsigned char) *cp)) {
     1164            while (*cp && !isspace (*cp)) {
    11591165                if ((*cp == '(') && (cp > line) && (cp[-1] != '$')) {
    11601166                    /*
     
    11711177
    11721178            if (*cp == '(') {
    1173                 GNode     *gnp;
     1179                GNode     *gn;
    11741180
    11751181                sources = Lst_Init (FALSE);
     
    11811187
    11821188                while (!Lst_IsEmpty (sources)) {
    1183                     gnp = (GNode *) Lst_DeQueue (sources);
    1184                     ParseDoSrc (tOp, gnp->name, curSrcs);
     1189                    gn = (GNode *) Lst_DeQueue (sources);
     1190                    ParseDoSrc (tOp, gn->name, curSrcs);
    11851191                }
    11861192                Lst_Destroy (sources, NOFREE);
     
    11941200                ParseDoSrc (tOp, line, curSrcs);
    11951201            }
    1196             while (*cp && isspace ((unsigned char) *cp)) {
     1202            while (*cp && isspace (*cp)) {
    11971203                cp++;
    11981204            }
     
    12011207    }
    12021208
    1203     if (mainNode == NULL) {
     1209    if (mainNode == NILGNODE) {
    12041210        /*
    12051211         * If we have yet to decide on a main target to make, in the
     
    12081214         * (i.e. isn't a .USE or .EXEC rule) to be made.
    12091215         */
    1210         Lst_ForEach (targets, ParseFindMain, (void *)0);
     1216        Lst_ForEach (targets, ParseFindMain, (ClientData)0);
    12111217    }
    12121218
     
    12341240 */
    12351241Boolean
    1236 Parse_IsVar (char *line)
    1237 {
    1238     Boolean wasSpace = FALSE;   /* set TRUE if found a space */
    1239     Boolean haveName = FALSE;   /* Set TRUE if have a variable name */
     1242Parse_IsVar (line)
     1243    register char  *line;       /* the line to check */
     1244{
     1245    register Boolean wasSpace = FALSE;  /* set TRUE if found a space */
     1246    register Boolean haveName = FALSE;  /* Set TRUE if have a variable name */
    12401247    int level = 0;
    1241 #define ISEQOPERATOR(c) \
     1248#define ISEQOPERATOR(c) \
    12421249        (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
    12431250
     
    13351342 */
    13361343void
    1337 Parse_DoVar (char *line, GNode *ctxt)
     1344Parse_DoVar (line, ctxt)
     1345    char            *line;      /* a line guaranteed to be a variable
     1346                                 * assignment. This reduces error checks */
     1347    GNode           *ctxt;      /* Context in which to do the assignment */
    13381348{
    13391349    char           *cp; /* pointer into line */
     
    13631373     */
    13641374    for (cp = line + 1; *cp != '='; cp++) {
    1365         if (isspace ((unsigned char) *cp)) {
     1375        if (isspace (*cp)) {
    13661376            *cp = '\0';
    13671377        }
     
    14191429    }
    14201430
    1421     while (isspace ((unsigned char) *cp)) {
     1431    while (isspace (*cp)) {
    14221432        cp++;
    14231433    }
     
    14401450
    14411451        oldVars = FALSE;
    1442 
    1443         /*
    1444          * make sure that we set the variable the first time to nothing
    1445          * so that it gets substituted!
    1446          */
    1447         if (!Var_Exists(line, ctxt))
    1448             Var_Set(line, "", ctxt);
    1449 
    14501452        cp = Var_Subst(NULL, cp, ctxt, FALSE);
    14511453        oldVars = oldOldVars;
     
    14561458        Boolean freeCmd = FALSE; /* TRUE if the command needs to be freed, i.e.
    14571459                                  * if any variable expansion was performed */
    1458         char *res, *error;
     1460        char *res, *err;
    14591461
    14601462        if (strchr(cp, '$') != NULL) {
     
    14681470        }
    14691471
    1470         res = Cmd_Exec(cp, &error);
     1472        res = Cmd_Exec(cp, &err);
    14711473        Var_Set(line, res, ctxt);
    14721474        free(res);
    14731475
    1474         if (error)
    1475             Parse_Error(PARSE_WARNING, error, cp);
     1476        if (err)
     1477            Parse_Error(PARSE_WARNING, err, cp);
    14761478
    14771479        if (freeCmd)
     
    14971499 */
    14981500static int
    1499 ParseAddCmd(void *gnp, void *cmd)
     1501ParseAddCmd(gnp, cmd)
     1502    ClientData gnp;     /* the node to which the command is to be added */
     1503    ClientData cmd;     /* the command to add */
    15001504{
    15011505    GNode *gn = (GNode *) gnp;
     
    15031507    if (!(gn->type & OP_HAS_COMMANDS))
    15041508        (void)Lst_AtEnd(gn->commands, cmd);
    1505     else
    1506         Parse_Error(PARSE_WARNING,
    1507                     "duplicate script for target \"%s\" ignored",
    1508                     gn->name);
    15091509    return(0);
    15101510}
     
    15271527 */
    15281528static void
    1529 ParseHasCommands(void *gnp)
     1529ParseHasCommands(gnp)
     1530    ClientData    gnp;      /* Node to examine */
    15301531{
    15311532    GNode *gn = (GNode *) gnp;
     
    15501551 */
    15511552void
    1552 Parse_AddIncludeDir (char *dir)
     1553Parse_AddIncludeDir (dir)
     1554    char          *dir;     /* The name of the directory to add */
    15531555{
    15541556    Dir_AddDir (parseIncPath, dir);
     
    15661568 */
    15671569static void
    1568 ParseDoError(char *errmsg)
    1569 {
    1570         if (!isspace((unsigned char) *errmsg)) {
     1570ParseDoError(errmsg)
     1571    char          *errmsg;      /* error message */
     1572{
     1573        if (!isspace(*errmsg)) {
    15711574                Parse_Error(PARSE_WARNING, "invalid syntax: .error%s", errmsg);
    15721575                return;
    15731576        }
    15741577       
    1575         while (isspace((unsigned char) *errmsg))
     1578        while (isspace(*errmsg))
    15761579                errmsg++;
    15771580       
     
    16021605 */
    16031606static void
    1604 ParseDoInclude (char *file)
     1607ParseDoInclude (file)
     1608    char          *file;        /* file specification */
    16051609{
    16061610    char          *fullname;    /* full pathname of file */
     
    17411745    oldFile->lineno = lineno;
    17421746
    1743     (void) Lst_AtFront (includes, (void *)oldFile);
     1747    (void) Lst_AtFront (includes, (ClientData)oldFile);
    17441748
    17451749    /*
     
    17791783 */
    17801784void
    1781 Parse_FromString(char *str)
     1785Parse_FromString(str)
     1786    char *str;
    17821787{
    17831788    IFile         *oldFile;     /* state associated with this file */
    17841789
    1785     DEBUGF(FOR, ("%s\n----\n", str));
     1790    if (DEBUG(FOR))
     1791        (void) fprintf(stderr, "%s\n----\n", str);
    17861792
    17871793    oldFile = (IFile *) emalloc (sizeof (IFile));
     
    17911797    oldFile->p = curPTR;
    17921798
    1793     (void) Lst_AtFront (includes, (void *)oldFile);
     1799    (void) Lst_AtFront (includes, (ClientData)oldFile);
    17941800
    17951801    curFILE = NULL;
     
    18191825 */
    18201826static void
    1821 ParseTraditionalInclude (char *file)
     1827ParseTraditionalInclude (file)
     1828    char          *file;        /* file specification */
    18221829{
    18231830    char          *fullname;    /* full pathname of file */
     
    19211928    oldFile->lineno = lineno;
    19221929
    1923     (void) Lst_AtFront (includes, (void *)oldFile);
     1930    (void) Lst_AtFront (includes, (ClientData)oldFile);
    19241931
    19251932    /*
     
    19601967 */
    19611968static int
    1962 ParseEOF (int opened)
     1969ParseEOF (opened)
     1970    int opened;
    19631971{
    19641972    IFile     *ifile;   /* the state on the top of the includes stack */
     
    19691977
    19701978    ifile = (IFile *) Lst_DeQueue (includes);
    1971     free (fname);
     1979    free ((Address) fname);
    19721980    fname = ifile->fname;
    19731981    lineno = ifile->lineno;
     
    19751983        (void) fclose (curFILE);
    19761984    if (curPTR) {
    1977         free(curPTR->str);
    1978         free(curPTR);
     1985        free((Address) curPTR->str);
     1986        free((Address) curPTR);
    19791987    }
    19801988    curFILE = ifile->F;
    19811989    curPTR = ifile->p;
    1982     free (ifile);
     1990    free ((Address)ifile);
    19831991    return (CONTINUE);
    19841992}
     
    19962004 */
    19972005static int
    1998 ParseReadc(void)
     2006ParseReadc()
    19992007{
    20002008    if (curFILE)
     
    20192027 */
    20202028static void
    2021 ParseUnreadc(int c)
     2029ParseUnreadc(c)
     2030    int c;
    20222031{
    20232032    if (curFILE) {
     
    20332042
    20342043/* ParseSkipLine():
    2035  *      Grab the next line unless it begins with a dot (`.') and we're told to
    2036  *      ignore such lines.
     2044 *      Grab the next line
    20372045 */
    20382046static char *
    2039 ParseSkipLine(int skip)
     2047ParseSkipLine(skip)
     2048    int skip;           /* Skip lines that don't start with . */
    20402049{
    20412050    char *line;
     
    20552064                lineno++;
    20562065
    2057                 while ((c = ParseReadc()) == ' ' || c == '\t')
    2058                     continue;
     2066                while ((c = ParseReadc()) == ' ' || c == '\t');
    20592067
    20602068                if (c == EOF)
     
    21002108 */
    21012109static char *
    2102 ParseReadLine (void)
     2110ParseReadLine ()
    21032111{
    21042112    Buffer        buf;          /* Buffer for current line */
    2105     int           c;            /* the current character */
    2106     int           lastc;        /* The most-recent character */
     2113    register int  c;            /* the current character */
     2114    register int  lastc;        /* The most-recent character */
    21072115    Boolean       semiNL;       /* treat semi-colons as newlines */
    21082116    Boolean       ignDepOp;     /* TRUE if should ignore dependency operators
     
    22212229            case '#':
    22222230                if (!ignComment) {
    2223                     if (lastc != '\\') {
     2231                    if (
     2232#if 0
     2233                    compatMake &&
     2234#endif
     2235                    (lastc != '\\')) {
    22242236                        /*
    22252237                         * If the character is a hash mark and it isn't escaped
     
    22522264                }
    22532265                break;
    2254             default:
    2255                 break;
    22562266            }
    22572267            /*
     
    22742284        /*
    22752285         * Strip trailing blanks and tabs from the line.
    2276          * Do not strip a blank or tab that is preceded by
     2286         * Do not strip a blank or tab that is preceeded by
    22772287         * a '\'
    22782288         */
     
    23052315                /*FALLTHRU*/
    23062316            case COND_PARSE:
    2307                 free (line);
     2317                free ((Address) line);
    23082318                line = ParseReadLine();
    23092319                break;
     
    23312341                }
    23322342                break;
    2333             default:
    2334                 break;
    23352343            }
    23362344        }
     
    23592367 */
    23602368static void
    2361 ParseFinishLine(void)
     2369ParseFinishLine()
    23622370{
    23632371    if (inLine) {
    2364         Lst_ForEach(targets, Suff_EndTransform, (void *)NULL);
     2372        Lst_ForEach(targets, Suff_EndTransform, (ClientData)NULL);
    23652373        Lst_Destroy (targets, ParseHasCommands);
    23662374        targets = NULL;
     
    23862394 */
    23872395void
    2388 Parse_File(char *name, FILE *stream)
    2389 {
    2390     char          *cp,          /* pointer into the line */
     2396Parse_File(name, stream)
     2397    char          *name;        /* the name of the file being read */
     2398    FILE *        stream;       /* Stream open to makefile to parse */
     2399{
     2400    register char *cp,          /* pointer into the line */
    23912401                  *line;        /* the line we're working on */
    23922402
     
    24042414                 * include or undef directives.
    24052415                 */
    2406                 for (cp = line + 1; isspace ((unsigned char) *cp); cp++) {
     2416                for (cp = line + 1; isspace (*cp); cp++) {
    24072417                    continue;
    24082418                }
     
    24432453            shellCommand:
    24442454#endif
    2445                 for (cp = line + 1; isspace ((unsigned char) *cp); cp++) {
     2455                for (cp = line + 1; isspace (*cp); cp++) {
    24462456                    continue;
    24472457                }
     
    24542464                         */
    24552465                        Lst_ForEach (targets, ParseAddCmd, cp);
    2456                         Lst_AtEnd(targCmds, (void *) line);
     2466                        Lst_AtEnd(targCmds, (ClientData) line);
    24572467                        continue;
    24582468                    } else {
     
    25692579 */
    25702580void
    2571 Parse_Init (void)
    2572 {
    2573     mainNode = NULL;
     2581Parse_Init ()
     2582{
     2583    mainNode = NILGNODE;
    25742584    parseIncPath = Lst_Init (FALSE);
    25752585    sysIncPath = Lst_Init (FALSE);
     
    25792589
    25802590void
    2581 Parse_End (void)
    2582 {
    2583     Lst_Destroy(targCmds, (void (*)(void *)) free);
     2591Parse_End()
     2592{
     2593    Lst_Destroy(targCmds, (void (*) __P((ClientData))) free);
    25842594    if (targets)
    25852595        Lst_Destroy(targets, NOFREE);
     
    26052615 */
    26062616Lst
    2607 Parse_MainName(void)
     2617Parse_MainName()
    26082618{
    26092619    Lst           listmain;     /* result list */
     
    26112621    listmain = Lst_Init (FALSE);
    26122622
    2613     if (mainNode == NULL) {
     2623    if (mainNode == NILGNODE) {
    26142624        Punt ("no target to make.");
    26152625        /*NOTREACHED*/
    26162626    } else if (mainNode->type & OP_DOUBLEDEP) {
    2617         (void) Lst_AtEnd (listmain, (void *)mainNode);
     2627        (void) Lst_AtEnd (listmain, (ClientData)mainNode);
    26182628        Lst_Concat(listmain, mainNode->cohorts, LST_CONCNEW);
    26192629    }
    26202630    else
    2621         (void) Lst_AtEnd (listmain, (void *)mainNode);
     2631        (void) Lst_AtEnd (listmain, (ClientData)mainNode);
    26222632    return (listmain);
    26232633}
  • branches/FREEBSD/src/kmk/pathnames.h

    r10 r24  
    3131 * SUCH DAMAGE.
    3232 *
    33  *      @(#)pathnames.h 8.2 (Berkeley) 4/28/95
    34  * $FreeBSD: src/usr.bin/make/pathnames.h,v 1.12 2002/05/24 15:51:27 ru Exp $
     33 *      from: @(#)pathnames.h   5.2 (Berkeley) 6/1/90
     34 * $FreeBSD: src/usr.bin/make/pathnames.h,v 1.9 1999/08/28 01:03:36 peter Exp $
    3535 */
    3636
  • branches/FREEBSD/src/kmk/sprite.h

    r10 r24  
    3636 * SUCH DAMAGE.
    3737 *
    38  *      @(#)sprite.h    8.2 (Berkeley) 4/28/95
    39  * $FreeBSD: src/usr.bin/make/sprite.h,v 1.13 2002/09/17 21:29:06 jmallett Exp $
     38 *      from: @(#)sprite.h      8.1 (Berkeley) 6/6/93
     39 * $FreeBSD: src/usr.bin/make/sprite.h,v 1.9 1999/08/28 01:03:36 peter Exp $
    4040 */
    4141
     
    4747
    4848#ifndef _SPRITE
    49 #define _SPRITE
     49#define _SPRITE
     50
    5051
    5152/*
     
    5657typedef int Boolean;
    5758#ifndef TRUE
    58 #define TRUE    1
     59#define TRUE    1
    5960#endif /* TRUE */
    6061#ifndef FALSE
    61 #define FALSE   0
     62#define FALSE   0
    6263#endif /* FALSE */
     64
     65/*
     66 * Functions that must return a status can return a ReturnStatus to
     67 * indicate success or type of failure.
     68 */
    6369
    6470typedef int  ReturnStatus;
    6571
    66 #define SUCCESS         0
    67 #define FAILURE         1
     72/*
     73 * The following statuses overlap with the first 2 generic statuses
     74 * defined in status.h:
     75 *
     76 * SUCCESS                      There was no error.
     77 * FAILURE                      There was a general error.
     78 */
     79
     80#define SUCCESS                 0x00000000
     81#define FAILURE                 0x00000001
     82
     83
     84/*
     85 * A nil pointer must be something that will cause an exception if
     86 * referenced.  There are two nils: the kernels nil and the nil used
     87 * by user processes.
     88 */
     89
     90#define NIL             ~0
     91#define USER_NIL        0
     92#ifndef NULL
     93#define NULL            0
     94#endif /* NULL */
     95
     96/*
     97 * An address is just a pointer in C.  It is defined as a character pointer
     98 * so that address arithmetic will work properly, a byte at a time.
     99 */
     100
     101typedef char *Address;
     102
     103/*
     104 * ClientData is an uninterpreted word.  It is defined as an int so that
     105 * kdbx will not interpret client data as a string.  Unlike an "Address",
     106 * client data will generally not be used in arithmetic.
     107 * But we don't have kdbx anymore so we define it as void (christos)
     108 */
     109
     110typedef void *ClientData;
    68111
    69112#endif /* _SPRITE */
  • branches/FREEBSD/src/kmk/str.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)str.c    5.8 (Berkeley) 6/1/90
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/str.c,v 1.25 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)str.c       5.8 (Berkeley) 6/1/90";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/str.c,v 1.12.2.1 2002/06/17 04:30:48 jmallett Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448#include "make.h"
     
    5357 */
    5458void
    55 str_init(void)
     59str_init()
    5660{
    5761    char *p1;
     
    6771 */
    6872void
    69 str_end(void)
     73str_end()
    7074{
    7175    if (argv) {
    7276        if (argv[0])
    7377            free(argv[0]);
    74         free(argv);
     78        free((Address) argv);
    7579    }
    7680    if (buffer)
     
    8791 */
    8892char *
    89 str_concat(char *s1, char *s2, int flags)
    90 {
    91         int len1, len2;
    92         char *result;
     93str_concat(s1, s2, flags)
     94        char *s1, *s2;
     95        int flags;
     96{
     97        register int len1, len2;
     98        register char *result;
    9399
    94100        /* get the length of both strings */
     
    116122        /* free original strings */
    117123        if (flags & STR_DOFREE) {
    118                 (void)efree(s1);
    119                 (void)efree(s2);
     124                (void)free(s1);
     125                (void)free(s2);
    120126        }
    121127        return(result);
     
    133139 */
    134140char **
    135 brk_string(char *str, int *store_argc, Boolean expand)
    136 {
    137         int argc, ch;
    138         char inquote, *p, *start, *t;
     141brk_string(str, store_argc, expand)
     142        register char *str;
     143        int *store_argc;
     144        Boolean expand;
     145{
     146        register int argc, ch;
     147        register char inquote, *p, *start, *t;
    139148        int len;
    140149
     
    237246                                ch = '\t';
    238247                                break;
    239                         default:
    240                                 break;
    241                         }
    242                         break;
    243                 default:
     248                        }
    244249                        break;
    245250                }
     
    262267 *
    263268 * Side effects: None.
    264  *
    265  * XXX should be strstr(3).
    266269 */
    267270char *
    268 Str_FindSubstring(char *string, char *substring)
    269 {
    270         char *a, *b;
     271Str_FindSubstring(string, substring)
     272        register char *string;          /* String to search. */
     273        char *substring;                /* Substring to find in string */
     274{
     275        register char *a, *b;
    271276
    272277        /*
     
    303308 */
    304309int
    305 Str_Match(char *string, char *pattern)
     310Str_Match(string, pattern)
     311        register char *string;          /* String */
     312        register char *pattern;         /* Pattern */
    306313{
    307314        char c2;
     
    406413 */
    407414char *
    408 Str_SYSVMatch(char *word, char *pattern, int *len)
     415Str_SYSVMatch(word, pattern, len)
     416    char        *word;          /* Word to examine */
     417    char        *pattern;       /* Pattern to examine against */
     418    int         *len;           /* Number of characters to substitute */
    409419{
    410420    char *p = pattern;
     
    469479 */
    470480void
    471 Str_SYSVSubst(Buffer buf, char *pat, char *src, int len)
     481Str_SYSVSubst(buf, pat, src, len)
     482    Buffer buf;
     483    char *pat;
     484    char *src;
     485    int   len;
    472486{
    473487    char *m;
  • branches/FREEBSD/src/kmk/suff.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)suff.c   8.4 (Berkeley) 3/21/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/suff.c,v 1.26 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)suff.c      8.4 (Berkeley) 3/21/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/suff.c,v 1.12.2.1 2001/03/09 01:13:24 tmm Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    8993 *      Suff_FindDeps           Find implicit sources for and the location of
    9094 *                              a target based on its suffix. Returns the
    91  *                              bottom-most node added to the graph or NULL
     95 *                              bottom-most node added to the graph or NILGNODE
    9296 *                              if the target had no implicit sources.
    9397 */
     
    112116    int          nameLen;       /* Length of the suffix */
    113117    short        flags;         /* Type of suffix */
    114 #define SUFF_INCLUDE      0x01      /* One which is #include'd */
    115 #define SUFF_LIBRARY      0x02      /* One which contains a library */
    116 #define SUFF_NULL         0x04      /* The empty suffix */
     118#define SUFF_INCLUDE      0x01      /* One which is #include'd */
     119#define SUFF_LIBRARY      0x02      /* One which contains a library */
     120#define SUFF_NULL         0x04      /* The empty suffix */
    117121    Lst          searchPath;    /* The path along which files of this suffix
    118122                                 * may be found */
     
    154158
    155159
    156 static char *SuffStrIsPrefix(char *, char *);
    157 static char *SuffSuffIsSuffix(Suff *, char *);
    158 static int SuffSuffIsSuffixP(void *, void *);
    159 static int SuffSuffHasNameP(void *, void *);
    160 static int SuffSuffIsPrefix(void *, void *);
    161 static int SuffGNHasNameP(void *, void *);
    162 static void SuffFree(void *);
    163 static void SuffInsert(Lst, Suff *);
    164 static void SuffRemove(Lst, Suff *);
    165 static Boolean SuffParseTransform(char *, Suff **, Suff **);
    166 static int SuffRebuildGraph(void *, void *);
    167 static int SuffAddSrc(void *, void *);
    168 static int SuffRemoveSrc(Lst);
    169 static void SuffAddLevel(Lst, Src *);
    170 static Src *SuffFindThem(Lst, Lst);
    171 static Src *SuffFindCmds(Src *, Lst);
    172 static int SuffExpandChildren(void *, void *);
    173 static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
    174 static void SuffFindDeps(GNode *, Lst);
    175 static void SuffFindArchiveDeps(GNode *, Lst);
    176 static void SuffFindNormalDeps(GNode *, Lst);
    177 static int SuffPrintName(void *, void *);
    178 static int SuffPrintSuff(void *, void *);
    179 static int SuffPrintTrans(void *, void *);
     160static char *SuffStrIsPrefix __P((char *, char *));
     161static char *SuffSuffIsSuffix __P((Suff *, char *));
     162static int SuffSuffIsSuffixP __P((ClientData, ClientData));
     163static int SuffSuffHasNameP __P((ClientData, ClientData));
     164static int SuffSuffIsPrefix __P((ClientData, ClientData));
     165static int SuffGNHasNameP __P((ClientData, ClientData));
     166static void SuffFree __P((ClientData));
     167static void SuffInsert __P((Lst, Suff *));
     168static void SuffRemove __P((Lst, Suff *));
     169static Boolean SuffParseTransform __P((char *, Suff **, Suff **));
     170static int SuffRebuildGraph __P((ClientData, ClientData));
     171static int SuffAddSrc __P((ClientData, ClientData));
     172static int SuffRemoveSrc __P((Lst));
     173static void SuffAddLevel __P((Lst, Src *));
     174static Src *SuffFindThem __P((Lst, Lst));
     175static Src *SuffFindCmds __P((Src *, Lst));
     176static int SuffExpandChildren __P((ClientData, ClientData));
     177static Boolean SuffApplyTransform __P((GNode *, GNode *, Suff *, Suff *));
     178static void SuffFindDeps __P((GNode *, Lst));
     179static void SuffFindArchiveDeps __P((GNode *, Lst));
     180static void SuffFindNormalDeps __P((GNode *, Lst));
     181static int SuffPrintName __P((ClientData, ClientData));
     182static int SuffPrintSuff __P((ClientData, ClientData));
     183static int SuffPrintTrans __P((ClientData, ClientData));
    180184
    181185        /*************** Lst Predicates ****************/
     
    193197 */
    194198static char    *
    195 SuffStrIsPrefix (char *pref, char *str)
     199SuffStrIsPrefix (pref, str)
     200    register char  *pref;       /* possible prefix */
     201    register char  *str;        /* string to check */
    196202{
    197203    while (*str && *pref == *str) {
     
    218224 */
    219225static char *
    220 SuffSuffIsSuffix (Suff *s, char *str)
    221 {
    222     char           *p1;         /* Pointer into suffix name */
    223     char           *p2;         /* Pointer into string being examined */
     226SuffSuffIsSuffix (s, str)
     227    register Suff  *s;          /* possible suffix */
     228    char           *str;        /* string to examine */
     229{
     230    register char  *p1;         /* Pointer into suffix name */
     231    register char  *p2;         /* Pointer into string being examined */
    224232
    225233    p1 = s->name + s->nameLen;
     
    249257 */
    250258static int
    251 SuffSuffIsSuffixP(void *s, void *str)
     259SuffSuffIsSuffixP(s, str)
     260    ClientData   s;
     261    ClientData   str;
    252262{
    253263    return(!SuffSuffIsSuffix((Suff *) s, (char *) str));
     
    268278 */
    269279static int
    270 SuffSuffHasNameP (void *s, void *sname)
     280SuffSuffHasNameP (s, sname)
     281    ClientData    s;                /* Suffix to check */
     282    ClientData    sname;            /* Desired name */
    271283{
    272284    return (strcmp ((char *) sname, ((Suff *) s)->name));
     
    289301 */
    290302static int
    291 SuffSuffIsPrefix (void *s, void *str)
     303SuffSuffIsPrefix (s, str)
     304    ClientData   s;             /* suffix to compare */
     305    ClientData   str;   /* string to examine */
    292306{
    293307    return (SuffStrIsPrefix (((Suff *) s)->name, (char *) str) == NULL ? 1 : 0);
     
    307321 */
    308322static int
    309 SuffGNHasNameP (void *gn, void *name)
     323SuffGNHasNameP (gn, name)
     324    ClientData      gn;         /* current node we're looking at */
     325    ClientData      name;       /* name we're looking for */
    310326{
    311327    return (strcmp ((char *) name, ((GNode *) gn)->name));
     
    327343 */
    328344static void
    329 SuffFree (void *sp)
     345SuffFree (sp)
     346    ClientData sp;
    330347{
    331348    Suff           *s = (Suff *) sp;
     
    342359    Lst_Destroy (s->searchPath, Dir_Destroy);
    343360
    344     free (s->name);
    345     free (s);
     361    free ((Address)s->name);
     362    free ((Address)s);
    346363}
    347364
     
    359376 */
    360377static void
    361 SuffRemove(Lst l, Suff *s)
    362 {
    363     LstNode ln = Lst_Member(l, (void *)s);
    364     if (ln != NULL) {
     378SuffRemove(l, s)
     379    Lst l;
     380    Suff *s;
     381{
     382    LstNode ln = Lst_Member(l, (ClientData)s);
     383    if (ln != NILLNODE) {
    365384        Lst_Remove(l, ln);
    366385        s->refCount--;
     
    383402 */
    384403static void
    385 SuffInsert (Lst l, Suff *s)
     404SuffInsert (l, s)
     405    Lst           l;            /* the list where in s should be inserted */
     406    Suff          *s;           /* the suffix to insert */
    386407{
    387408    LstNode       ln;           /* current element in l we're examining */
     
    391412        return;
    392413    }
    393     while ((ln = Lst_Next (l)) != NULL) {
     414    while ((ln = Lst_Next (l)) != NILLNODE) {
    394415        s2 = (Suff *) Lst_Datum (ln);
    395416        if (s2->sNum >= s->sNum) {
     
    397418        }
    398419    }
    399     if (s2 == NULL) {
    400             DEBUGF(SUFF, ("inserting an empty list?..."));
    401     }
    402420
    403421    Lst_Close (l);
    404     DEBUGF(SUFF, ("inserting %s(%d)...", s->name, s->sNum));
    405     if (ln == NULL) {
    406         DEBUGF(SUFF, ("at end of list\n"));
    407         (void)Lst_AtEnd (l, (void *)s);
     422    if (DEBUG(SUFF)) {
     423        printf("inserting %s(%d)...", s->name, s->sNum);
     424    }
     425    if (ln == NILLNODE) {
     426        if (DEBUG(SUFF)) {
     427            printf("at end of list\n");
     428        }
     429        (void)Lst_AtEnd (l, (ClientData)s);
    408430        s->refCount++;
    409         (void)Lst_AtEnd(s->ref, (void *) l);
     431        (void)Lst_AtEnd(s->ref, (ClientData) l);
    410432    } else if (s2->sNum != s->sNum) {
    411         DEBUGF(SUFF, ("before %s(%d)\n", s2->name, s2->sNum));
    412         (void)Lst_Insert (l, ln, (void *)s);
     433        if (DEBUG(SUFF)) {
     434            printf("before %s(%d)\n", s2->name, s2->sNum);
     435        }
     436        (void)Lst_Insert (l, ln, (ClientData)s);
    413437        s->refCount++;
    414         (void)Lst_AtEnd(s->ref, (void *) l);
    415     } else {
    416         DEBUGF(SUFF, ("already there\n"));
     438        (void)Lst_AtEnd(s->ref, (ClientData) l);
     439    } else if (DEBUG(SUFF)) {
     440        printf("already there\n");
    417441    }
    418442}
     
    436460 */
    437461void
    438 Suff_ClearSuffixes (void)
     462Suff_ClearSuffixes ()
    439463{
    440464    Lst_Concat (suffClean, sufflist, LST_CONCLINK);
     
    448472     * suffNull should not have parents.
    449473     */
    450     Lst_Destroy(suffNull->children, NOFREE); 
     474    Lst_Destroy(suffNull->children, NOFREE);
    451475    suffNull->children = Lst_Init(FALSE);
    452476}
     
    466490 */
    467491static Boolean
    468 SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
    469 {
    470     LstNode             srcLn;      /* element in suffix list of trans source*/
    471     Suff                *src;       /* Source of transformation */
    472     LstNode             targLn;     /* element in suffix list of trans target*/
    473     char                *str2;      /* Extra pointer (maybe target suffix) */
     492SuffParseTransform(str, srcPtr, targPtr)
     493    char                *str;           /* String being parsed */
     494    Suff                **srcPtr;       /* Place to store source of trans. */
     495    Suff                **targPtr;      /* Place to store target of trans. */
     496{
     497    register LstNode    srcLn;      /* element in suffix list of trans source*/
     498    register Suff       *src;       /* Source of transformation */
     499    register LstNode    targLn;     /* element in suffix list of trans target*/
     500    register char       *str2;      /* Extra pointer (maybe target suffix) */
    474501    LstNode             singleLn;   /* element in suffix list of any suffix
    475502                                     * that exactly matches str */
     
    477504                                     * null suffix */
    478505
    479     srcLn = NULL;
    480     singleLn = NULL;
     506    srcLn = NILLNODE;
     507    singleLn = NILLNODE;
    481508
    482509    /*
     
    487514     */
    488515    for (;;) {
    489         if (srcLn == NULL) {
    490             srcLn = Lst_Find(sufflist, (void *)str, SuffSuffIsPrefix);
     516        if (srcLn == NILLNODE) {
     517            srcLn = Lst_Find(sufflist, (ClientData)str, SuffSuffIsPrefix);
    491518        } else {
    492             srcLn = Lst_FindFrom (sufflist, Lst_Succ(srcLn), (void *)str,
     519            srcLn = Lst_FindFrom (sufflist, Lst_Succ(srcLn), (ClientData)str,
    493520                                  SuffSuffIsPrefix);
    494521        }
    495         if (srcLn == NULL) {
     522        if (srcLn == NILLNODE) {
    496523            /*
    497524             * Ran out of source suffixes -- no such rule
    498525             */
    499             if (singleLn != NULL) {
     526            if (singleLn != NILLNODE) {
    500527                /*
    501528                 * Not so fast Mr. Smith! There was a suffix that encompassed
     
    519546            singleLn = srcLn;
    520547        } else {
    521             targLn = Lst_Find(sufflist, (void *)str2, SuffSuffHasNameP);
    522             if (targLn != NULL) {
     548            targLn = Lst_Find(sufflist, (ClientData)str2, SuffSuffHasNameP);
     549            if (targLn != NILLNODE) {
    523550                *srcPtr = src;
    524551                *targPtr = (Suff *)Lst_Datum(targLn);
     
    544571 */
    545572Boolean
    546 Suff_IsTransform (char *str)
     573Suff_IsTransform (str)
     574    char          *str;         /* string to check */
    547575{
    548576    Suff          *src, *targ;
     
    566594 */
    567595GNode *
    568 Suff_AddTransform (char *line)
     596Suff_AddTransform (line)
     597    char          *line;        /* name of transformation to add */
    569598{
    570599    GNode         *gn;          /* GNode of transformation rule */
     
    573602    LstNode       ln;           /* Node for existing transformation */
    574603
    575     ln = Lst_Find (transforms, (void *)line, SuffGNHasNameP);
    576     if (ln == NULL) {
     604    ln = Lst_Find (transforms, (ClientData)line, SuffGNHasNameP);
     605    if (ln == NILLNODE) {
    577606        /*
    578607         * Make a new graph node for the transformation. It will be filled in
     
    580609         */
    581610        gn = Targ_NewGN (line);
    582         (void)Lst_AtEnd (transforms, (void *)gn);
     611        (void)Lst_AtEnd (transforms, (ClientData)gn);
    583612    } else {
    584613        /*
     
    602631     * link the two together in the proper relationship and order
    603632     */
    604     DEBUGF(SUFF, ("defining transformation from `%s' to `%s'\n",
    605            s->name, t->name));
     633    if (DEBUG(SUFF)) {
     634        printf("defining transformation from `%s' to `%s'\n",
     635                s->name, t->name);
     636    }
    606637    SuffInsert (t->children, s);
    607638    SuffInsert (s->parents, t);
     
    628659 */
    629660int
    630 Suff_EndTransform(void *gnp, void *dummy __unused)
     661Suff_EndTransform(gnp, dummy)
     662    ClientData   gnp;           /* Node for transformation */
     663    ClientData   dummy;         /* Node for transformation */
    631664{
    632665    GNode *gn = (GNode *) gnp;
     
    639672        (void)SuffParseTransform(gn->name, &s, &t);
    640673
    641         DEBUGF(SUFF, ("deleting transformation from `%s' to `%s'\n",
    642                s->name, t->name));
     674        if (DEBUG(SUFF)) {
     675            printf("deleting transformation from `%s' to `%s'\n",
     676                    s->name, t->name);
     677        }
    643678
    644679        /*
    645680         * Remove the source from the target's children list. We check for a
    646          * NULL return to handle a beanhead saying something like
     681         * nil return to handle a beanhead saying something like
    647682         *  .c.o .c.o:
    648683         *
     
    656691         */
    657692        SuffRemove(s->parents, t);
    658     } else if (gn->type & OP_TRANSFORM) {
    659         DEBUGF(SUFF, ("transformation %s complete\n", gn->name));
    660     }
    661 
    662     return (0);
     693    } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
     694        printf("transformation %s complete\n", gn->name);
     695    }
     696
     697    return(dummy ? 0 : 0);
    663698}
    664699
     
    683718 */
    684719static int
    685 SuffRebuildGraph(void *transformp, void *sp)
     720SuffRebuildGraph(transformp, sp)
     721    ClientData  transformp; /* Transformation to test */
     722    ClientData  sp;         /* Suffix to rebuild */
    686723{
    687724    GNode       *transform = (GNode *) transformp;
     
    696733    cp = SuffStrIsPrefix(s->name, transform->name);
    697734    if (cp != (char *)NULL) {
    698         if (cp[0] == '\0')  /* null rule */
     735        if (cp[0] == '\0')  /* null rule */
    699736            s2 = suffNull;
    700737        else {
    701             ln = Lst_Find(sufflist, (void *)cp, SuffSuffHasNameP);
    702             if (ln != NULL)
    703                 s2 = (Suff *)Lst_Datum(ln);
     738            ln = Lst_Find(sufflist, (ClientData)cp, SuffSuffHasNameP);
     739            if (ln != NILLNODE)
     740                s2 = (Suff *)Lst_Datum(ln);
    704741        }
    705742        if (s2 != NULL) {
     
    723760         */
    724761        cp[1] = '\0';
    725         ln = Lst_Find(sufflist, (void *)transform->name, SuffSuffHasNameP);
     762        ln = Lst_Find(sufflist, (ClientData)transform->name, SuffSuffHasNameP);
    726763        /*
    727764         * Replace the start of the target suffix
    728765         */
    729766        cp[1] = s->name[0];
    730         if (ln != NULL) {
     767        if (ln != NILLNODE) {
    731768            /*
    732769             * Found it -- establish the proper relationship
     
    755792 */
    756793void
    757 Suff_AddSuffix (char *str)
     794Suff_AddSuffix (str)
     795    char          *str;     /* the name of the suffix to add */
    758796{
    759797    Suff          *s;       /* new suffix descriptor */
    760798    LstNode       ln;
    761799
    762     ln = Lst_Find (sufflist, (void *)str, SuffSuffHasNameP);
    763     if (ln == NULL) {
     800    ln = Lst_Find (sufflist, (ClientData)str, SuffSuffHasNameP);
     801    if (ln == NILLNODE) {
    764802        s = (Suff *) emalloc (sizeof (Suff));
    765803
     
    774812        s->refCount =   0;
    775813
    776         (void)Lst_AtEnd (sufflist, (void *)s);
     814        (void)Lst_AtEnd (sufflist, (ClientData)s);
    777815        /*
    778816         * Look for any existing transformations from or to this suffix.
    779817         * XXX: Only do this after a Suff_ClearSuffixes?
    780818         */
    781         Lst_ForEach (transforms, SuffRebuildGraph, (void *)s);
     819        Lst_ForEach (transforms, SuffRebuildGraph, (ClientData)s);
    782820    }
    783821}
     
    789827 *
    790828 * Results:
    791  *      The searchPath for the desired suffix or NULL if the suffix isn't
     829 *      The searchPath for the desired suffix or NILLST if the suffix isn't
    792830 *      defined.
    793831 *
     
    797835 */
    798836Lst
    799 Suff_GetPath (char *sname)
     837Suff_GetPath (sname)
     838    char          *sname;
    800839{
    801840    LstNode       ln;
    802841    Suff          *s;
    803842
    804     ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP);
    805     if (ln == NULL) {
    806         return (NULL);
     843    ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
     844    if (ln == NILLNODE) {
     845        return (NILLST);
    807846    } else {
    808847        s = (Suff *) Lst_Datum (ln);
     
    824863 *      directories in dirSearchPath. If paths were specified for the
    825864 *      ".h" suffix, the directories are stuffed into a global variable
    826  *      called ".INCLUDES" with each directory preceded by a -I. The same
     865 *      called ".INCLUDES" with each directory preceeded by a -I. The same
    827866 *      is done for the ".a" suffix, except the variable is called
    828867 *      ".LIBS" and the flag is -L.
     
    830869 */
    831870void
    832 Suff_DoPaths(void)
    833 {
    834     Suff                *s;
    835     LstNode             ln;
     871Suff_DoPaths()
     872{
     873    register Suff       *s;
     874    register LstNode    ln;
    836875    char                *ptr;
    837876    Lst                 inIncludes; /* Cumulative .INCLUDES path */
     
    845884    inLibs = Lst_Init(FALSE);
    846885
    847     while ((ln = Lst_Next (sufflist)) != NULL) {
     886    while ((ln = Lst_Next (sufflist)) != NILLNODE) {
    848887        s = (Suff *) Lst_Datum (ln);
    849888        if (!Lst_IsEmpty (s->searchPath)) {
     
    892931 */
    893932void
    894 Suff_AddInclude (char *sname)
     933Suff_AddInclude (sname)
     934    char          *sname;     /* Name of suffix to mark */
    895935{
    896936    LstNode       ln;
    897937    Suff          *s;
    898938
    899     ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP);
    900     if (ln != NULL) {
     939    ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
     940    if (ln != NILLNODE) {
    901941        s = (Suff *) Lst_Datum (ln);
    902942        s->flags |= SUFF_INCLUDE;
     
    921961 */
    922962void
    923 Suff_AddLib (char *sname)
     963Suff_AddLib (sname)
     964    char          *sname;     /* Name of suffix to mark */
    924965{
    925966    LstNode       ln;
    926967    Suff          *s;
    927968
    928     ln = Lst_Find (sufflist, (void *)sname, SuffSuffHasNameP);
    929     if (ln != NULL) {
     969    ln = Lst_Find (sufflist, (ClientData)sname, SuffSuffHasNameP);
     970    if (ln != NILLNODE) {
    930971        s = (Suff *) Lst_Datum (ln);
    931972        s->flags |= SUFF_LIBRARY;
     
    950991 */
    951992static int
    952 SuffAddSrc (void *sp, void *lsp)
     993SuffAddSrc (sp, lsp)
     994    ClientData  sp;         /* suffix for which to create a Src structure */
     995    ClientData  lsp;        /* list and parent for the new Src */
    953996{
    954997    Suff        *s = (Suff *) sp;
     
    9691012        s2->pref =      targ->pref;
    9701013        s2->parent =    targ;
    971         s2->node =      NULL;
     1014        s2->node =      NILGNODE;
    9721015        s2->suff =      s;
    9731016        s->refCount++;
    9741017        s2->children =  0;
    9751018        targ->children += 1;
    976         (void)Lst_AtEnd (ls->l, (void *)s2);
     1019        (void)Lst_AtEnd (ls->l, (ClientData)s2);
    9771020#ifdef DEBUG_SRC
    9781021        s2->cp = Lst_Init(FALSE);
    979         Lst_AtEnd(targ->cp, (void *) s2);
     1022        Lst_AtEnd(targ->cp, (ClientData) s2);
    9801023        printf("1 add %x %x to %x:", targ, s2, ls->l);
    981         Lst_ForEach(ls->l, PrintAddr, (void *) 0);
     1024        Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
    9821025        printf("\n");
    9831026#endif
     
    9871030    s2->pref =      targ->pref;
    9881031    s2->parent =    targ;
    989     s2->node =      NULL;
     1032    s2->node =      NILGNODE;
    9901033    s2->suff =      s;
    9911034    s->refCount++;
    9921035    s2->children =  0;
    9931036    targ->children += 1;
    994     (void)Lst_AtEnd (ls->l, (void *)s2);
     1037    (void)Lst_AtEnd (ls->l, (ClientData)s2);
    9951038#ifdef DEBUG_SRC
    9961039    s2->cp = Lst_Init(FALSE);
    997     Lst_AtEnd(targ->cp, (void *) s2);
     1040    Lst_AtEnd(targ->cp, (ClientData) s2);
    9981041    printf("2 add %x %x to %x:", targ, s2, ls->l);
    999     Lst_ForEach(ls->l, PrintAddr, (void *) 0);
     1042    Lst_ForEach(ls->l, PrintAddr, (ClientData) 0);
    10001043    printf("\n");
    10011044#endif
     
    10171060 */
    10181061static void
    1019 SuffAddLevel (Lst l, Src *targ)
     1062SuffAddLevel (l, targ)
     1063    Lst            l;           /* list to which to add the new level */
     1064    Src            *targ;       /* Src structure to use as the parent */
    10201065{
    10211066    LstSrc         ls;
     
    10241069    ls.l = l;
    10251070
    1026     Lst_ForEach (targ->suff->children, SuffAddSrc, (void *)&ls);
     1071    Lst_ForEach (targ->suff->children, SuffAddSrc, (ClientData)&ls);
    10271072}
    10281073
     
    10401085 */
    10411086static int
    1042 SuffRemoveSrc (Lst l)
     1087SuffRemoveSrc (l)
     1088    Lst l;
    10431089{
    10441090    LstNode ln;
     
    10511097#ifdef DEBUG_SRC
    10521098    printf("cleaning %lx: ", (unsigned long) l);
    1053     Lst_ForEach(l, PrintAddr, (void *) 0);
     1099    Lst_ForEach(l, PrintAddr, (ClientData) 0);
    10541100    printf("\n");
    10551101#endif
    10561102
    10571103
    1058     while ((ln = Lst_Next (l)) != NULL) {
     1104    while ((ln = Lst_Next (l)) != NILLNODE) {
    10591105        s = (Src *) Lst_Datum (ln);
    10601106        if (s->children == 0) {
    1061             free (s->file);
     1107            free ((Address)s->file);
    10621108            if (!s->parent)
    1063                 free(s->pref);
     1109                free((Address)s->pref);
    10641110            else {
    10651111#ifdef DEBUG_SRC
    1066                 LstNode ln = Lst_Member(s->parent->cp, (void *)s);
    1067                 if (ln != NULL)
     1112                LstNode ln = Lst_Member(s->parent->cp, (ClientData)s);
     1113                if (ln != NILLNODE)
    10681114                    Lst_Remove(s->parent->cp, ln);
    10691115#endif
     
    10751121#endif
    10761122            Lst_Remove(l, ln);
    1077             free (s);
     1123            free ((Address)s);
    10781124            t |= 1;
    10791125            Lst_Close(l);
     
    10831129        else {
    10841130            printf("keep: [l=%x] p=%x %d: ", l, s, s->children);
    1085             Lst_ForEach(s->cp, PrintAddr, (void *) 0);
     1131            Lst_ForEach(s->cp, PrintAddr, (ClientData) 0);
    10861132            printf("\n");
    10871133        }
     
    11071153 */
    11081154static Src *
    1109 SuffFindThem (Lst srcs, Lst slst)
     1155SuffFindThem (srcs, slst)
     1156    Lst            srcs;        /* list of Src structures to search through */
     1157    Lst            slst;
    11101158{
    11111159    Src            *s;          /* current Src */
     
    11181166        s = (Src *) Lst_DeQueue (srcs);
    11191167
    1120         DEBUGF(SUFF, ("\ttrying %s...", s->file));
     1168        if (DEBUG(SUFF)) {
     1169            printf ("\ttrying %s...", s->file);
     1170        }
    11211171
    11221172        /*
     
    11241174         * graph for it or the file actually exists.
    11251175         */
    1126         if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) {
     1176        if (Targ_FindNode(s->file, TARG_NOCREATE) != NILGNODE) {
    11271177#ifdef DEBUG_SRC
    11281178            printf("remove %x from %x\n", s, srcs);
     
    11411191        }
    11421192
    1143         DEBUGF(SUFF, ("not there\n"));
     1193        if (DEBUG(SUFF)) {
     1194            printf ("not there\n");
     1195        }
    11441196
    11451197        SuffAddLevel (srcs, s);
    1146         Lst_AtEnd(slst, (void *) s);
    1147     }
    1148 
    1149     if (rs) {
    1150         DEBUGF(SUFF, ("got it\n"));
     1198        Lst_AtEnd(slst, (ClientData) s);
     1199    }
     1200
     1201    if (DEBUG(SUFF) && rs) {
     1202        printf ("got it\n");
    11511203    }
    11521204    return (rs);
     
    11611213 *
    11621214 * Results:
    1163  *      The Src structure of the "winning" child, or NULL if no such beast.
     1215 *      The Src structure of the "winning" child, or NIL if no such beast.
    11641216 *
    11651217 * Side Effects:
     
    11691221 */
    11701222static Src *
    1171 SuffFindCmds (Src *targ, Lst slst)
     1223SuffFindCmds (targ, slst)
     1224    Src         *targ;  /* Src structure to play with */
     1225    Lst         slst;
    11721226{
    11731227    LstNode             ln;     /* General-purpose list node */
    1174     GNode               *t,     /* Target GNode */
     1228    register GNode      *t,     /* Target GNode */
    11751229                        *s;     /* Source GNode */
    11761230    int                 prefLen;/* The length of the defined prefix */
     
    11831237    prefLen = strlen (targ->pref);
    11841238
    1185     while ((ln = Lst_Next (t->children)) != NULL) {
     1239    while ((ln = Lst_Next (t->children)) != NILLNODE) {
    11861240        s = (GNode *)Lst_Datum (ln);
    11871241
     
    11971251             * suffix.
    11981252             */
    1199             ln = Lst_Find (sufflist, (void *)&cp[prefLen],
     1253            ln = Lst_Find (sufflist, (ClientData)&cp[prefLen],
    12001254                           SuffSuffHasNameP);
    1201             if (ln != NULL) {
     1255            if (ln != NILLNODE) {
    12021256                /*
    12031257                 * It even has a known suffix, see if there's a transformation
     
    12091263
    12101264                if (Lst_Member (suff->parents,
    1211                                 (void *)targ->suff) != NULL)
     1265                                (ClientData)targ->suff) != NILLNODE)
    12121266                {
    12131267                    /*
     
    12291283                    ret->cp = Lst_Init(FALSE);
    12301284                    printf("3 add %x %x\n", targ, ret);
    1231                     Lst_AtEnd(targ->cp, (void *) ret);
     1285                    Lst_AtEnd(targ->cp, (ClientData) ret);
    12321286#endif
    1233                     Lst_AtEnd(slst, (void *) ret);
    1234                     DEBUGF(SUFF, ("\tusing existing source %s\n", s->name));
     1287                    Lst_AtEnd(slst, (ClientData) ret);
     1288                    if (DEBUG(SUFF)) {
     1289                        printf ("\tusing existing source %s\n", s->name);
     1290                    }
    12351291                    return (ret);
    12361292                }
     
    12591315 */
    12601316static int
    1261 SuffExpandChildren(void *cgnp, void *pgnp)
     1317SuffExpandChildren(cgnp, pgnp)
     1318    ClientData  cgnp;       /* Child to examine */
     1319    ClientData  pgnp;       /* Parent node being processed */
    12621320{
    12631321    GNode       *cgn = (GNode *) cgnp;
     
    12721330     * after the child
    12731331     */
    1274     prevLN = Lst_Member(pgn->children, (void *)cgn);
     1332    prevLN = Lst_Member(pgn->children, (ClientData)cgn);
    12751333
    12761334    /*
     
    12811339     */
    12821340    if (strchr(cgn->name, '$') != (char *)NULL) {
    1283         DEBUGF(SUFF, ("Expanding \"%s\"...", cgn->name));
     1341        if (DEBUG(SUFF)) {
     1342            printf("Expanding \"%s\"...", cgn->name);
     1343        }
    12841344        cp = Var_Subst(NULL, cgn->name, pgn, TRUE);
    12851345
     
    13171377                        *cp++ = '\0';
    13181378                        gn = Targ_FindNode(start, TARG_CREATE);
    1319                         (void)Lst_AtEnd(members, (void *)gn);
     1379                        (void)Lst_AtEnd(members, (ClientData)gn);
    13201380                        while (*cp == ' ' || *cp == '\t') {
    13211381                            cp++;
     
    13561416                     */
    13571417                    gn = Targ_FindNode(start, TARG_CREATE);
    1358                     (void)Lst_AtEnd(members, (void *)gn);
     1418                    (void)Lst_AtEnd(members, (ClientData)gn);
    13591419                }
    13601420                /*
     
    13701430                gn = (GNode *)Lst_DeQueue(members);
    13711431
    1372                 DEBUGF(SUFF, ("%s...", gn->name));
    1373                 if (Lst_Member(pgn->children, (void *)gn) == NULL) {
    1374                     (void)Lst_Append(pgn->children, prevLN, (void *)gn);
     1432                if (DEBUG(SUFF)) {
     1433                    printf("%s...", gn->name);
     1434                }
     1435                if (Lst_Member(pgn->children, (ClientData)gn) == NILLNODE) {
     1436                    (void)Lst_Append(pgn->children, prevLN, (ClientData)gn);
    13751437                    prevLN = Lst_Succ(prevLN);
    1376                     (void)Lst_AtEnd(gn->parents, (void *)pgn);
     1438                    (void)Lst_AtEnd(gn->parents, (ClientData)pgn);
    13771439                    pgn->unmade++;
    13781440                }
     
    13881450         * keep it from being processed.
    13891451         */
    1390         ln = Lst_Member(pgn->children, (void *)cgn);
     1452        ln = Lst_Member(pgn->children, (ClientData)cgn);
    13911453        pgn->unmade--;
    13921454        Lst_Remove(pgn->children, ln);
    1393         DEBUGF(SUFF, ("\n"));
     1455        if (DEBUG(SUFF)) {
     1456            printf("\n");
     1457        }
    13941458    } else if (Dir_HasWildcards(cgn->name)) {
    13951459        Lst     exp;        /* List of expansions */
     
    14051469         */
    14061470        cp = cgn->name + strlen(cgn->name);
    1407         ln = Lst_Find(sufflist, (void *)cp, SuffSuffIsSuffixP);
    1408 
    1409         DEBUGF(SUFF, ("Wildcard expanding \"%s\"...", cgn->name));
    1410 
    1411         if (ln != NULL) {
     1471        ln = Lst_Find(sufflist, (ClientData)cp, SuffSuffIsSuffixP);
     1472
     1473        if (DEBUG(SUFF)) {
     1474            printf("Wildcard expanding \"%s\"...", cgn->name);
     1475        }
     1476
     1477        if (ln != NILLNODE) {
    14121478            Suff    *s = (Suff *)Lst_Datum(ln);
    14131479
    1414             DEBUGF(SUFF, ("suffix is \"%s\"...", s->name));
     1480            if (DEBUG(SUFF)) {
     1481                printf("suffix is \"%s\"...", s->name);
     1482            }
    14151483            path = s->searchPath;
    14161484        } else {
     
    14331501            cp = (char *)Lst_DeQueue(exp);
    14341502
    1435             DEBUGF(SUFF, ("%s...", cp));
     1503            if (DEBUG(SUFF)) {
     1504                printf("%s...", cp);
     1505            }
    14361506            gn = Targ_FindNode(cp, TARG_CREATE);
    14371507
     
    14401510             * up the parent's count of unmade children.
    14411511             */
    1442             if (Lst_Member(pgn->children, (void *)gn) == NULL) {
    1443                 (void)Lst_Append(pgn->children, prevLN, (void *)gn);
     1512            if (Lst_Member(pgn->children, (ClientData)gn) == NILLNODE) {
     1513                (void)Lst_Append(pgn->children, prevLN, (ClientData)gn);
    14441514                prevLN = Lst_Succ(prevLN);
    1445                 (void)Lst_AtEnd(gn->parents, (void *)pgn);
     1515                (void)Lst_AtEnd(gn->parents, (ClientData)pgn);
    14461516                pgn->unmade++;
    14471517            }
     
    14571527         * keep it from being processed.
    14581528         */
    1459         ln = Lst_Member(pgn->children, (void *)cgn);
     1529        ln = Lst_Member(pgn->children, (ClientData)cgn);
    14601530        pgn->unmade--;
    14611531        Lst_Remove(pgn->children, ln);
    1462         DEBUGF(SUFF, ("\n"));
     1532        if (DEBUG(SUFF)) {
     1533            printf("\n");
     1534        }
    14631535    }
    14641536
     
    14851557 */
    14861558static Boolean
    1487 SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
     1559SuffApplyTransform(tGn, sGn, t, s)
     1560    GNode       *tGn;       /* Target node */
     1561    GNode       *sGn;       /* Source node */
     1562    Suff        *t;         /* Target suffix */
     1563    Suff        *s;         /* Source suffix */
    14881564{
    14891565    LstNode     ln;         /* General node */
     
    14911567    GNode       *gn;        /* Node for same */
    14921568
    1493     if (Lst_Member(tGn->children, (void *)sGn) == NULL) {
     1569    if (Lst_Member(tGn->children, (ClientData)sGn) == NILLNODE) {
    14941570        /*
    14951571         * Not already linked, so form the proper links between the
    14961572         * target and source.
    14971573         */
    1498         (void)Lst_AtEnd(tGn->children, (void *)sGn);
    1499         (void)Lst_AtEnd(sGn->parents, (void *)tGn);
     1574        (void)Lst_AtEnd(tGn->children, (ClientData)sGn);
     1575        (void)Lst_AtEnd(sGn->parents, (ClientData)tGn);
    15001576        tGn->unmade += 1;
    15011577    }
     
    15081584         * will be sufficient to get the .IMPSRC variable set for tGn
    15091585         */
    1510         for (ln=Lst_First(sGn->cohorts); ln != NULL; ln=Lst_Succ(ln)) {
     1586        for (ln=Lst_First(sGn->cohorts); ln != NILLNODE; ln=Lst_Succ(ln)) {
    15111587            gn = (GNode *)Lst_Datum(ln);
    15121588
    1513             if (Lst_Member(tGn->children, (void *)gn) == NULL) {
     1589            if (Lst_Member(tGn->children, (ClientData)gn) == NILLNODE) {
    15141590                /*
    15151591                 * Not already linked, so form the proper links between the
    15161592                 * target and source.
    15171593                 */
    1518                 (void)Lst_AtEnd(tGn->children, (void *)gn);
    1519                 (void)Lst_AtEnd(gn->parents, (void *)tGn);
     1594                (void)Lst_AtEnd(tGn->children, (ClientData)gn);
     1595                (void)Lst_AtEnd(gn->parents, (ClientData)tGn);
    15201596                tGn->unmade += 1;
    15211597            }
     
    15261602     */
    15271603    tname = str_concat(s->name, t->name, 0);
    1528     ln = Lst_Find(transforms, (void *)tname, SuffGNHasNameP);
     1604    ln = Lst_Find(transforms, (ClientData)tname, SuffGNHasNameP);
    15291605    free(tname);
    15301606
    1531     if (ln == NULL) {
     1607    if (ln == NILLNODE) {
    15321608        /*
    15331609         * Not really such a transformation rule (can happen when we're
     
    15401616    gn = (GNode *)Lst_Datum(ln);
    15411617
    1542     DEBUGF(SUFF, ("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name));
     1618    if (DEBUG(SUFF)) {
     1619        printf("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
     1620    }
    15431621
    15441622    /*
     
    15561634     */
    15571635    ln = Lst_Succ(ln);
    1558     if (ln != NULL) {
     1636    if (ln != NILLNODE) {
    15591637        Lst_ForEachFrom(tGn->children, ln,
    1560                         SuffExpandChildren, (void *)tGn);
     1638                        SuffExpandChildren, (ClientData)tGn);
    15611639    }
    15621640
     
    15651643     * the .IMPSRC variable can be set correctly for the parent.
    15661644     */
    1567     (void)Lst_AtEnd(sGn->iParents, (void *)tGn);
     1645    (void)Lst_AtEnd(sGn->iParents, (ClientData)tGn);
    15681646
    15691647    return(TRUE);
     
    15851663 */
    15861664static void
    1587 SuffFindArchiveDeps(GNode *gn, Lst slst)
     1665SuffFindArchiveDeps(gn, slst)
     1666    GNode       *gn;        /* Node for which to locate dependencies */
     1667    Lst         slst;
    15881668{
    15891669    char        *eoarch;    /* End of archive portion */
     
    16231703     * Create the link between the two nodes right off
    16241704     */
    1625     if (Lst_Member(gn->children, (void *)mem) == NULL) {
    1626         (void)Lst_AtEnd(gn->children, (void *)mem);
    1627         (void)Lst_AtEnd(mem->parents, (void *)gn);
     1705    if (Lst_Member(gn->children, (ClientData)mem) == NILLNODE) {
     1706        (void)Lst_AtEnd(gn->children, (ClientData)mem);
     1707        (void)Lst_AtEnd(mem->parents, (ClientData)gn);
    16281708        gn->unmade += 1;
    16291709    }
     
    16441724         * Didn't know what it was -- use .NULL suffix if not in make mode
    16451725         */
    1646         DEBUGF(SUFF, ("using null suffix\n"));
     1726        if (DEBUG(SUFF)) {
     1727            printf("using null suffix\n");
     1728        }
    16471729        ms = suffNull;
    16481730    }
     
    16691751        ln = Lst_Find(ms->parents, eoarch, SuffSuffIsSuffixP);
    16701752
    1671         if (ln != NULL) {
     1753        if (ln != NILLNODE) {
    16721754            /*
    16731755             * Got one -- apply it
    16741756             */
    1675             if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms)) {
    1676                 DEBUGF(SUFF, ("\tNo transformation from %s -> %s\n",
    1677                        ms->name, ((Suff *)Lst_Datum(ln))->name));
     1757            if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
     1758                DEBUG(SUFF))
     1759            {
     1760                printf("\tNo transformation from %s -> %s\n",
     1761                       ms->name, ((Suff *)Lst_Datum(ln))->name);
    16781762            }
    16791763        }
     
    17161800 */
    17171801static void
    1718 SuffFindNormalDeps(GNode *gn, Lst slst)
     1802SuffFindNormalDeps(gn, slst)
     1803    GNode       *gn;        /* Node for which to find sources */
     1804    Lst         slst;
    17191805{
    17201806    char        *eoname;    /* End of name */
     
    17611847     */
    17621848
    1763     while (ln != NULL) {
     1849    while (ln != NILLNODE) {
    17641850        /*
    17651851         * Look for next possible suffix...
     
    17671853        ln = Lst_FindFrom(sufflist, ln, eoname, SuffSuffIsSuffixP);
    17681854
    1769         if (ln != NULL) {
     1855        if (ln != NILLNODE) {
    17701856            int     prefLen;        /* Length of the prefix */
    1771             Src     *target;
     1857            Src     *targ;
    17721858
    17731859            /*
    17741860             * Allocate a Src structure to which things can be transformed
    17751861             */
    1776             target = (Src *)emalloc(sizeof (Src));
    1777             target->file = estrdup(gn->name);
    1778             target->suff = (Suff *)Lst_Datum(ln);
    1779             target->suff->refCount++;
    1780             target->node = gn;
    1781             target->parent = (Src *)NULL;
    1782             target->children = 0;
     1862            targ = (Src *)emalloc(sizeof (Src));
     1863            targ->file = estrdup(gn->name);
     1864            targ->suff = (Suff *)Lst_Datum(ln);
     1865            targ->suff->refCount++;
     1866            targ->node = gn;
     1867            targ->parent = (Src *)NULL;
     1868            targ->children = 0;
    17831869#ifdef DEBUG_SRC
    1784             target->cp = Lst_Init(FALSE);
     1870            targ->cp = Lst_Init(FALSE);
    17851871#endif
    17861872
     
    17891875             * the length of the suffix from the end of the name.
    17901876             */
    1791             prefLen = (eoname - target->suff->nameLen) - sopref;
    1792             target->pref = emalloc(prefLen + 1);
    1793             memcpy(target->pref, sopref, prefLen);
    1794             target->pref[prefLen] = '\0';
     1877            prefLen = (eoname - targ->suff->nameLen) - sopref;
     1878            targ->pref = emalloc(prefLen + 1);
     1879            memcpy(targ->pref, sopref, prefLen);
     1880            targ->pref[prefLen] = '\0';
    17951881
    17961882            /*
    17971883             * Add nodes from which the target can be made
    17981884             */
    1799             SuffAddLevel(srcs, target);
     1885            SuffAddLevel(srcs, targ);
    18001886
    18011887            /*
    18021888             * Record the target so we can nuke it
    18031889             */
    1804             (void)Lst_AtEnd(targs, (void *)target);
     1890            (void)Lst_AtEnd(targs, (ClientData)targ);
    18051891
    18061892            /*
     
    18151901     */
    18161902    if (Lst_IsEmpty(targs) && suffNull != NULL) {
    1817         DEBUGF(SUFF, ("\tNo known suffix on %s. Using .NULL suffix\n", gn->name));
     1903        if (DEBUG(SUFF)) {
     1904            printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
     1905        }
    18181906
    18191907        targ = (Src *)emalloc(sizeof (Src));
     
    18361924            SuffAddLevel(srcs, targ);
    18371925        else {
    1838             DEBUGF(SUFF, ("not "));
    1839         }
    1840 
    1841         DEBUGF(SUFF, ("adding suffix rules\n"));
    1842 
    1843         (void)Lst_AtEnd(targs, (void *)targ);
     1926            if (DEBUG(SUFF))
     1927                printf("not ");
     1928        }
     1929
     1930        if (DEBUG(SUFF))
     1931            printf("adding suffix rules\n");
     1932
     1933        (void)Lst_AtEnd(targs, (ClientData)targ);
    18441934    }
    18451935
     
    18841974     * that still contain variables or wildcards in their names.
    18851975     */
    1886     Lst_ForEach(gn->children, SuffExpandChildren, (void *)gn);
     1976    Lst_ForEach(gn->children, SuffExpandChildren, (ClientData)gn);
    18871977
    18881978    if (targ == NULL) {
    1889         DEBUGF(SUFF, ("\tNo valid suffix on %s\n", gn->name));
     1979        if (DEBUG(SUFF)) {
     1980            printf("\tNo valid suffix on %s\n", gn->name);
     1981        }
    18901982
    18911983sfnd_abort:
     
    19842076             */
    19852077            while (bottom && bottom->parent != NULL) {
    1986                 if (Lst_Member(slst, (void *) bottom) == NULL) {
    1987                     Lst_AtEnd(slst, (void *) bottom);
     2078                if (Lst_Member(slst, (ClientData) bottom) == NILLNODE) {
     2079                    Lst_AtEnd(slst, (ClientData) bottom);
    19882080                }
    19892081                bottom = bottom->parent;
     
    20122104     * Etc.
    20132105     */
    2014     if (bottom->node == NULL) {
     2106    if (bottom->node == NILGNODE) {
    20152107        bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);
    20162108    }
     
    20242116        src->node->suffix->refCount++;
    20252117
    2026         if (targ->node == NULL) {
     2118        if (targ->node == NILGNODE) {
    20272119            targ->node = Targ_FindNode(targ->file, TARG_CREATE);
    20282120        }
     
    20662158sfnd_return:
    20672159    if (bottom)
    2068         if (Lst_Member(slst, (void *) bottom) == NULL)
    2069             Lst_AtEnd(slst, (void *) bottom);
     2160        if (Lst_Member(slst, (ClientData) bottom) == NILLNODE)
     2161            Lst_AtEnd(slst, (ClientData) bottom);
    20702162
    20712163    while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
     
    21062198
    21072199void
    2108 Suff_FindDeps(GNode *gn)
     2200Suff_FindDeps(gn)
     2201    GNode *gn;
    21092202{
    21102203
     
    21162209
    21172210static void
    2118 SuffFindDeps (GNode *gn, Lst slst)
     2211SuffFindDeps (gn, slst)
     2212    GNode         *gn;          /* node we're dealing with */
     2213    Lst           slst;
    21192214{
    21202215    if (gn->type & OP_DEPS_FOUND) {
     
    21272222    }
    21282223
    2129     DEBUGF(SUFF, ("SuffFindDeps (%s)\n", gn->name));
     2224    if (DEBUG(SUFF)) {
     2225        printf ("SuffFindDeps (%s)\n", gn->name);
     2226    }
    21302227
    21312228    if (gn->type & OP_ARCHV) {
     
    21432240        Suff    *s;
    21442241
    2145         ln = Lst_Find (sufflist, (void *)LIBSUFF, SuffSuffHasNameP);
     2242        ln = Lst_Find (sufflist, (ClientData)LIBSUFF, SuffSuffHasNameP);
    21462243        if (gn->suffix)
    21472244            gn->suffix->refCount--;
    2148         if (ln != NULL) {
     2245        if (ln != NILLNODE) {
    21492246            gn->suffix = s = (Suff *) Lst_Datum (ln);
    21502247            gn->suffix->refCount++;
     
    21832280 */
    21842281void
    2185 Suff_SetNull(char *name)
     2282Suff_SetNull(name)
     2283    char    *name;          /* Name of null suffix */
    21862284{
    21872285    Suff    *s;
    21882286    LstNode ln;
    21892287
    2190     ln = Lst_Find(sufflist, (void *)name, SuffSuffHasNameP);
    2191     if (ln != NULL) {
     2288    ln = Lst_Find(sufflist, (ClientData)name, SuffSuffHasNameP);
     2289    if (ln != NILLNODE) {
    21922290        s = (Suff *)Lst_Datum(ln);
    21932291        if (suffNull != (Suff *)NULL) {
     
    22182316 */
    22192317void
    2220 Suff_Init (void)
     2318Suff_Init ()
    22212319{
    22222320    sufflist = Lst_Init (FALSE);
     
    22612359
    22622360void
    2263 Suff_End(void)
     2361Suff_End()
    22642362{
    22652363    Lst_Destroy(sufflist, SuffFree);
     
    22742372/********************* DEBUGGING FUNCTIONS **********************/
    22752373
     2374static int SuffPrintName(s, dummy)
     2375    ClientData s;
     2376    ClientData dummy;
     2377{
     2378    printf ("`%s' ", ((Suff *) s)->name);
     2379    return (dummy ? 0 : 0);
     2380}
     2381
    22762382static int
    2277 SuffPrintName(void *s, void *dummy __unused)
    2278 {
    2279     printf ("`%s' ", ((Suff *) s)->name);
    2280     return (0);
    2281 }
    2282 
    2283 static int
    2284 SuffPrintSuff (void *sp, void *dummy __unused)
     2383SuffPrintSuff (sp, dummy)
     2384    ClientData sp;
     2385    ClientData dummy;
    22852386{
    22862387    Suff    *s = (Suff *) sp;
     
    23062407                    printf ("LIBRARY");
    23072408                    break;
    2308                 default:
    2309                     break;
    23102409            }
    23112410            fputc(flags ? '|' : ')', stdout);
     
    23142413    fputc ('\n', stdout);
    23152414    printf ("#\tTo: ");
    2316     Lst_ForEach (s->parents, SuffPrintName, (void *)0);
     2415    Lst_ForEach (s->parents, SuffPrintName, (ClientData)0);
    23172416    fputc ('\n', stdout);
    23182417    printf ("#\tFrom: ");
    2319     Lst_ForEach (s->children, SuffPrintName, (void *)0);
     2418    Lst_ForEach (s->children, SuffPrintName, (ClientData)0);
    23202419    fputc ('\n', stdout);
    23212420    printf ("#\tSearch Path: ");
    23222421    Dir_PrintPath (s->searchPath);
    23232422    fputc ('\n', stdout);
    2324     return (0);
     2423    return (dummy ? 0 : 0);
    23252424}
    23262425
    23272426static int
    2328 SuffPrintTrans (void *tp, void *dummy __unused)
     2427SuffPrintTrans (tp, dummy)
     2428    ClientData tp;
     2429    ClientData dummy;
    23292430{
    23302431    GNode   *t = (GNode *) tp;
     
    23332434    Targ_PrintType (t->type);
    23342435    fputc ('\n', stdout);
    2335     Lst_ForEach (t->commands, Targ_PrintCmd, (void *)0);
     2436    Lst_ForEach (t->commands, Targ_PrintCmd, (ClientData)0);
    23362437    fputc ('\n', stdout);
    2337     return (0);
     2438    return(dummy ? 0 : 0);
    23382439}
    23392440
    23402441void
    2341 Suff_PrintAll(void)
     2442Suff_PrintAll()
    23422443{
    23432444    printf ("#*** Suffixes:\n");
    2344     Lst_ForEach (sufflist, SuffPrintSuff, (void *)0);
     2445    Lst_ForEach (sufflist, SuffPrintSuff, (ClientData)0);
    23452446
    23462447    printf ("#*** Transformations:\n");
    2347     Lst_ForEach (transforms, SuffPrintTrans, (void *)0);
    2348 }
     2448    Lst_ForEach (transforms, SuffPrintTrans, (ClientData)0);
     2449}
  • branches/FREEBSD/src/kmk/targ.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)targ.c   8.2 (Berkeley) 3/19/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/targ.c,v 1.25 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)targ.c      8.2 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/targ.c,v 1.10 1999/09/11 13:08:02 hoek Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    9397static Hash_Table targets;      /* a hash table of same */
    9498
    95 #define HTSIZE  191             /* initial size of hash table */
    96 
    97 static int TargPrintOnlySrc(void *, void *);
    98 static int TargPrintName(void *, void *);
    99 static int TargPrintNode(void *, void *);
    100 static void TargFreeGN(void *);
     99#define HTSIZE  191             /* initial size of hash table */
     100
     101static int TargPrintOnlySrc __P((ClientData, ClientData));
     102static int TargPrintName __P((ClientData, ClientData));
     103static int TargPrintNode __P((ClientData, ClientData));
     104static void TargFreeGN __P((ClientData));
    101105
    102106/*-
     
    113117 */
    114118void
    115 Targ_Init (void)
     119Targ_Init ()
    116120{
    117121    allTargets = Lst_Init (FALSE);
     
    132136 */
    133137void
    134 Targ_End (void)
     138Targ_End ()
    135139{
    136140    Lst_Destroy(allTargets, NOFREE);
     
    154158 */
    155159GNode *
    156 Targ_NewGN (char *name)
    157 {
    158     GNode *gn;
     160Targ_NewGN (name)
     161    char           *name;       /* the name to stick in the new node */
     162{
     163    register GNode *gn;
    159164
    160165    gn = (GNode *) emalloc (sizeof (GNode));
     
    184189    if (allGNs == NULL)
    185190        allGNs = Lst_Init(FALSE);
    186     Lst_AtEnd(allGNs, (void *) gn);
     191    Lst_AtEnd(allGNs, (ClientData) gn);
    187192
    188193    return (gn);
     
    202207 */
    203208static void
    204 TargFreeGN (void *gnp)
     209TargFreeGN (gnp)
     210    ClientData gnp;
    205211{
    206212    GNode *gn = (GNode *) gnp;
     
    218224    Lst_Destroy(gn->context, NOFREE);
    219225    Lst_Destroy(gn->commands, NOFREE);
    220     free(gn);
     226    free((Address)gn);
    221227}
    222228
     
    228234 *
    229235 * Results:
    230  *      The node in the list if it was. If it wasn't, return NULL of
     236 *      The node in the list if it was. If it wasn't, return NILGNODE of
    231237 *      flags was TARG_NOCREATE or the newly created and initialized node
    232238 *      if it was TARG_CREATE
     
    237243 */
    238244GNode *
    239 Targ_FindNode (char *name, int flags)
     245Targ_FindNode (name, flags)
     246    char           *name;       /* the name to find */
     247    int             flags;      /* flags governing events when target not
     248                                 * found */
    240249{
    241250    GNode         *gn;        /* node in that element */
     
    250259            gn = Targ_NewGN (name);
    251260            Hash_SetValue (he, gn);
    252             (void) Lst_AtEnd (allTargets, (void *)gn);
     261            (void) Lst_AtEnd (allTargets, (ClientData)gn);
    253262        }
    254263    } else {
     
    257266
    258267    if (he == (Hash_Entry *) NULL) {
    259         return (NULL);
     268        return (NILGNODE);
    260269    } else {
    261270        return ((GNode *) Hash_GetValue (he));
     
    279288 */
    280289Lst
    281 Targ_FindList (Lst names, int flags)
     290Targ_FindList (names, flags)
     291    Lst            names;       /* list of names to find */
     292    int            flags;       /* flags used if no node is found for a given
     293                                 * name */
    282294{
    283295    Lst            nodes;       /* result list */
    284     LstNode        ln;          /* name list element */
    285     GNode          *gn;         /* node in tLn */
    286     char           *name;
     296    register LstNode  ln;               /* name list element */
     297    register GNode *gn;         /* node in tLn */
     298    char          *name;
    287299
    288300    nodes = Lst_Init (FALSE);
     
    291303        return (nodes);
    292304    }
    293     while ((ln = Lst_Next (names)) != NULL) {
     305    while ((ln = Lst_Next (names)) != NILLNODE) {
    294306        name = (char *)Lst_Datum(ln);
    295307        gn = Targ_FindNode (name, flags);
    296         if (gn != NULL) {
     308        if (gn != NILGNODE) {
    297309            /*
    298310             * Note: Lst_AtEnd must come before the Lst_Concat so the nodes
     
    300312             * encountered in the makefile.
    301313             */
    302             (void) Lst_AtEnd (nodes, (void *)gn);
     314            (void) Lst_AtEnd (nodes, (ClientData)gn);
    303315            if (gn->type & OP_DOUBLEDEP) {
    304316                (void)Lst_Concat (nodes, gn->cohorts, LST_CONCNEW);
     
    325337 */
    326338Boolean
    327 Targ_Ignore (GNode *gn)
     339Targ_Ignore (gn)
     340    GNode          *gn;         /* node to check for */
    328341{
    329342    if (ignoreErrors || gn->type & OP_IGNORE) {
     
    347360 */
    348361Boolean
    349 Targ_Silent (GNode *gn)
     362Targ_Silent (gn)
     363    GNode          *gn;         /* node to check for */
    350364{
    351365    if (beSilent || gn->type & OP_SILENT) {
     
    369383 */
    370384Boolean
    371 Targ_Precious (GNode *gn)
     385Targ_Precious (gn)
     386    GNode          *gn;         /* the node to check */
    372387{
    373388    if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) {
     
    395410 */
    396411void
    397 Targ_SetMain (GNode *gn)
     412Targ_SetMain (gn)
     413    GNode   *gn;        /* The main target we'll create */
    398414{
    399415    mainTarg = gn;
     
    401417
    402418static int
    403 TargPrintName (void *gnp, void *ppath)
     419TargPrintName (gnp, ppath)
     420    ClientData     gnp;
     421    ClientData      ppath;
    404422{
    405423    GNode *gn = (GNode *) gnp;
     
    420438
    421439int
    422 Targ_PrintCmd (void *cmd, void *dummy __unused)
     440Targ_PrintCmd (cmd, dummy)
     441    ClientData cmd;
     442    ClientData dummy;
    423443{
    424444    printf ("\t%s\n", (char *) cmd);
    425     return (0);
     445    return (dummy ? 0 : 0);
    426446}
    427447
     
    441461 */
    442462char *
    443 Targ_FmtTime (time_t modtime)
     463Targ_FmtTime (time)
     464    time_t    time;
    444465{
    445466    struct tm           *parts;
    446467    static char         buf[128];
    447468
    448     parts = localtime(&modtime);
    449 
    450     strftime(buf, sizeof buf, "%H:%M:%S %b %d, %Y", parts);
     469    parts = localtime(&time);
     470
     471    strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
    451472    buf[sizeof(buf) - 1] = '\0';
    452473    return(buf);
     
    466487 */
    467488void
    468 Targ_PrintType (int type)
    469 {
    470     int    tbit;
    471 
    472 #define PRINTBIT(attr)  case CONCAT(OP_,attr): printf("." #attr " "); break
    473 #define PRINTDBIT(attr) case CONCAT(OP_,attr): DEBUGF(TARG, ("." #attr " ")); break
     489Targ_PrintType (type)
     490    register int    type;
     491{
     492    register int    tbit;
     493
     494#ifdef __STDC__
     495#define PRINTBIT(attr)  case CONCAT(OP_,attr): printf("." #attr " "); break
     496#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG)) printf("." #attr " "); break
     497#else
     498#define PRINTBIT(attr)  case CONCAT(OP_,attr): printf(".attr "); break
     499#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG)) printf(".attr "); break
     500#endif /* __STDC__ */
    474501
    475502    type &= ~OP_OPMASK;
     
    492519            PRINTDBIT(LIB);
    493520            /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
    494             case OP_MEMBER: DEBUGF(TARG, (".MEMBER ")); break;
     521            case OP_MEMBER: if (DEBUG(TARG)) printf(".MEMBER "); break;
    495522            PRINTDBIT(ARCHV);
    496523        }
     
    505532 */
    506533static int
    507 TargPrintNode (void *gnp, void *passp)
     534TargPrintNode (gnp, passp)
     535    ClientData   gnp;
     536    ClientData   passp;
    508537{
    509538    GNode         *gn = (GNode *) gnp;
     
    540569            if (!Lst_IsEmpty (gn->iParents)) {
    541570                printf("# implicit parents: ");
    542                 Lst_ForEach (gn->iParents, TargPrintName, (void *)0);
     571                Lst_ForEach (gn->iParents, TargPrintName, (ClientData)0);
    543572                fputc ('\n', stdout);
    544573            }
     
    546575        if (!Lst_IsEmpty (gn->parents)) {
    547576            printf("# parents: ");
    548             Lst_ForEach (gn->parents, TargPrintName, (void *)0);
     577            Lst_ForEach (gn->parents, TargPrintName, (ClientData)0);
    549578            fputc ('\n', stdout);
    550579        }
     
    558587            case OP_DOUBLEDEP:
    559588                printf(":: "); break;
    560             default:
    561                 break;
    562589        }
    563590        Targ_PrintType (gn->type);
    564         Lst_ForEach (gn->children, TargPrintName, (void *)0);
     591        Lst_ForEach (gn->children, TargPrintName, (ClientData)0);
    565592        fputc ('\n', stdout);
    566         Lst_ForEach (gn->commands, Targ_PrintCmd, (void *)0);
     593        Lst_ForEach (gn->commands, Targ_PrintCmd, (ClientData)0);
    567594        printf("\n\n");
    568595        if (gn->type & OP_DOUBLEDEP) {
    569             Lst_ForEach (gn->cohorts, TargPrintNode, (void *)&pass);
     596            Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)&pass);
    570597        }
    571598    }
     
    582609 *
    583610 * Side Effects:
    584  *      The name of each file is printed preceded by #\t
     611 *      The name of each file is printed preceeded by #\t
    585612 *
    586613 *-----------------------------------------------------------------------
    587614 */
    588615static int
    589 TargPrintOnlySrc(void *gnp, void *dummy __unused)
     616TargPrintOnlySrc(gnp, dummy)
     617    ClientData    gnp;
     618    ClientData    dummy;
    590619{
    591620    GNode         *gn = (GNode *) gnp;
     
    593622        printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name);
    594623
    595     return (0);
     624    return (dummy ? 0 : 0);
    596625}
    597626
     
    599628 *-----------------------------------------------------------------------
    600629 * Targ_PrintGraph --
    601  *      Print the entire graph.
     630 *      print the entire graph. heh heh
    602631 *
    603632 * Results:
     
    609638 */
    610639void
    611 Targ_PrintGraph (int pass)
     640Targ_PrintGraph (pass)
     641    int     pass;       /* Which pass this is. 1 => no processing
     642                         * 2 => processing done */
    612643{
    613644    printf("#*** Input graph:\n");
    614     Lst_ForEach (allTargets, TargPrintNode, (void *)&pass);
     645    Lst_ForEach (allTargets, TargPrintNode, (ClientData)&pass);
    615646    printf("\n\n");
    616647    printf("#\n#   Files that are only sources:\n");
    617     Lst_ForEach (allTargets, TargPrintOnlySrc, (void *) 0);
     648    Lst_ForEach (allTargets, TargPrintOnlySrc, (ClientData) 0);
    618649    printf("#*** Global Variables:\n");
    619650    Var_Dump (VAR_GLOBAL);
  • branches/FREEBSD/src/kmk/util.c

    r10 r24  
    11/*
    2  * Copyright (c) 2002 Juli Mallett.  All rights reserved.
    3  * Copyright (c) 1988, 1989, 1990, 1993
    4  *      The Regents of the University of California.  All rights reserved.
    5  * Copyright (c) 1989 by Berkeley Softworks
    6  * All rights reserved.
     2 * Missing stuff from OS's
     3 */
     4
     5#ifndef lint
     6static char rcsid[] = "$FreeBSD: src/usr.bin/make/util.c,v 1.5.2.2 2001/02/13 03:13:58 will Exp $";
     7#endif
     8
     9#include <stdio.h>
     10#include <errno.h>
     11#include "make.h"
     12
     13#if !__STDC__
     14# ifndef const
     15#  define const
     16# endif
     17#endif
     18
     19#ifdef sun
     20extern int errno, sys_nerr;
     21extern char *sys_errlist[];
     22
     23char *
     24strerror(e)
     25    int e;
     26{
     27    static char buf[100];
     28    if (e < 0 || e >= sys_nerr) {
     29        sprintf(buf, "Unknown error %d", e);
     30        return buf;
     31    }
     32    else
     33        return sys_errlist[e];
     34}
     35#endif
     36
     37#ifdef ultrix
     38#include <string.h>
     39
     40/* strdup
    741 *
    8  * This code is derived from software contributed to Berkeley by
    9  * Adam de Boor.
    10  *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. All advertising materials mentioning features or use of this software
    20  *    must display the following acknowledgement:
    21  *      This product includes software developed by the University of
    22  *      California, Berkeley and its contributors.
    23  * 4. Neither the name of the University nor the names of its contributors
    24  *    may be used to endorse or promote products derived from this software
    25  *    without specific prior written permission.
    26  *
    27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    37  * SUCH DAMAGE.
    38  *
    39  * @(#)main.c      8.3 (Berkeley) 3/19/94
    40  */
    41 
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/util.c,v 1.12 2002/10/10 19:27:48 jmallett Exp $");
    44 
    45 /*-
    46  * util.c --
    47  *      General utilitarian routines for make(1).
    48  */
    49 
    50 #include <sys/types.h>
    51 #include <sys/stat.h>
    52 #include <err.h>
    53 #include <stdlib.h>
    54 #include <errno.h>
    55 #include <fcntl.h>
    56 #include <stdio.h>
    57 #include <sysexits.h>
    58 #include <stdarg.h>
    59 #include <unistd.h>
    60 
    61 #include "make.h"
    62 #include "hash.h"
    63 #include "dir.h"
    64 #include "job.h"
    65 #include "pathnames.h"
    66 
    67 /*-
    68  * Debug --
    69  *      Print a debugging message given its format.
    70  *
    71  * Results:
    72  *      None.
    73  *
    74  * Side Effects:
    75  *      The message is printed.
    76  */
    77 /* VARARGS */
    78 void
    79 Debug(const char *fmt, ...)
    80 {
    81         va_list ap;
    82 
    83         va_start(ap, fmt);
    84         (void)vfprintf(stderr, fmt, ap);
    85         va_end(ap);
    86         (void)fflush(stderr);
    87 }
    88 
    89 /*-
    90  * Error --
    91  *      Print an error message given its format.
    92  *
    93  * Results:
    94  *      None.
    95  *
    96  * Side Effects:
    97  *      The message is printed.
    98  */
    99 /* VARARGS */
    100 void
    101 Error(const char *fmt, ...)
    102 {
    103         va_list ap;
    104 
    105         va_start(ap, fmt);
    106         (void)vfprintf(stderr, fmt, ap);
    107         va_end(ap);
    108         (void)fprintf(stderr, "\n");
    109         (void)fflush(stderr);
    110 }
    111 
    112 /*-
    113  * Fatal --
    114  *      Produce a Fatal error message. If jobs are running, waits for them
    115  *      to finish.
    116  *
    117  * Results:
    118  *      None
    119  *
    120  * Side Effects:
    121  *      The program exits
    122  */
    123 /* VARARGS */
    124 void
    125 Fatal(const char *fmt, ...)
    126 {
    127         va_list ap;
    128 
    129         va_start(ap, fmt);
    130         if (jobsRunning)
    131                 Job_Wait();
    132 
    133         (void)vfprintf(stderr, fmt, ap);
    134         va_end(ap);
    135         (void)fprintf(stderr, "\n");
    136         (void)fflush(stderr);
    137 
    138         if (DEBUG(GRAPH2))
    139                 Targ_PrintGraph(2);
    140         exit(2);                /* Not 1 so -q can distinguish error */
    141 }
    142 
    143 /*
    144  * Punt --
    145  *      Major exception once jobs are being created. Kills all jobs, prints
    146  *      a message and exits.
    147  *
    148  * Results:
    149  *      None
    150  *
    151  * Side Effects:
    152  *      All children are killed indiscriminately and the program Lib_Exits
    153  */
    154 /* VARARGS */
    155 void
    156 Punt(const char *fmt, ...)
    157 {
    158         va_list ap;
    159 
    160         va_start(ap, fmt);
    161         (void)fprintf(stderr, "make: ");
    162         (void)vfprintf(stderr, fmt, ap);
    163         va_end(ap);
    164         (void)fprintf(stderr, "\n");
    165         (void)fflush(stderr);
    166 
    167         DieHorribly();
    168 }
    169 
    170 /*-
    171  * DieHorribly --
    172  *      Exit without giving a message.
    173  *
    174  * Results:
    175  *      None
    176  *
    177  * Side Effects:
    178  *      A big one...
    179  */
    180 void
    181 DieHorribly(void)
    182 {
    183         if (jobsRunning)
    184                 Job_AbortAll();
    185         if (DEBUG(GRAPH2))
    186                 Targ_PrintGraph(2);
    187         exit(2);                /* Not 1, so -q can distinguish error */
    188 }
    189 
    190 /*
    191  * Finish --
    192  *      Called when aborting due to errors in child shell to signal
    193  *      abnormal exit, with the number of errors encountered in Make_Make.
    194  *
    195  * Results:
    196  *      None
    197  *
    198  * Side Effects:
    199  *      The program exits
    200  */
    201 void
    202 Finish(int errors)
    203 {
    204         Fatal("%d error%s", errors, errors == 1 ? "" : "s");
    205 }
    206 
    207 /*
    208  * emalloc --
    209  *      malloc, but die on error.
    210  */
    211 void *
    212 emalloc(size_t len)
    213 {
    214         void *p;
    215 
    216         if ((p = malloc(len)) == NULL)
    217                 enomem();
    218         return(p);
    219 }
    220 
    221 /*
    222  * estrdup --
    223  *      strdup, but die on error.
     42 * Make a duplicate of a string.
     43 * For systems which lack this function.
    22444 */
    22545char *
    226 estrdup(const char *str)
    227 {
    228         char *p;
    229 
    230         if ((p = strdup(str)) == NULL)
    231                 enomem();
    232         return(p);
    233 }
    234 
    235 /*
    236  * erealloc --
    237  *      realloc, but die on error.
     46strdup(str)
     47    const char *str;
     48{
     49    size_t len;
     50
     51    if (str == NULL)
     52        return NULL;
     53    len = strlen(str) + 1;
     54    if ((p = malloc(len)) == NULL)
     55        return NULL;
     56
     57    return memcpy(p, str, len);
     58}
     59
     60#endif
     61
     62#if defined(sun) || defined(__hpux) || defined(__sgi)
     63
     64int
     65setenv(name, value, dum)
     66    const char *name;
     67    const char *value;
     68    int dum;
     69{
     70    register char *p;
     71    int len = strlen(name) + strlen(value) + 2; /* = \0 */
     72    char *ptr = (char*) malloc(len);
     73
     74    (void) dum;
     75
     76    if (ptr == NULL)
     77        return -1;
     78
     79    p = ptr;
     80
     81    while (*name)
     82        *p++ = *name++;
     83
     84    *p++ = '=';
     85
     86    while (*value)
     87        *p++ = *value++;
     88
     89    *p = '\0';
     90
     91    len = putenv(ptr);
     92/*    free(ptr); */
     93    return len;
     94}
     95#endif
     96
     97#ifdef __hpux
     98#include <sys/types.h>
     99#include <sys/param.h>
     100#include <sys/syscall.h>
     101#include <sys/signal.h>
     102#include <sys/stat.h>
     103#include <stdio.h>
     104#include <dirent.h>
     105#include <sys/time.h>
     106#include <time.h>
     107#include <unistd.h>
     108
     109
     110int
     111killpg(pid, sig)
     112    int pid, sig;
     113{
     114    return kill(-pid, sig);
     115}
     116
     117void
     118srandom(seed)
     119    long seed;
     120{
     121    srand48(seed);
     122}
     123
     124long
     125random()
     126{
     127    return lrand48();
     128}
     129
     130/* turn into bsd signals */
     131void (*
     132signal(s, a)) ()
     133    int     s;
     134    void (*a)();
     135{
     136    struct sigvec osv, sv;
     137
     138    (void) sigvector(s, (struct sigvec *) 0, &osv);
     139    sv = osv;
     140    sv.sv_handler = a;
     141#ifdef SV_BSDSIG
     142    sv.sv_flags = SV_BSDSIG;
     143#endif
     144
     145    if (sigvector(s, &sv, (struct sigvec *) 0) == -1)
     146        return (BADSIG);
     147    return (osv.sv_handler);
     148}
     149
     150#if !defined(BSD) && !defined(d_fileno)
     151# define d_fileno d_ino
     152#endif
     153
     154#ifndef DEV_DEV_COMPARE
     155# define DEV_DEV_COMPARE(a, b) ((a) == (b))
     156#endif
     157
     158/* strrcpy():
     159 *      Like strcpy, going backwards and returning the new pointer
    238160 */
    239 void *
    240 erealloc(void *ptr, size_t size)
    241 {
    242         if ((ptr = realloc(ptr, size)) == NULL)
    243                 enomem();
    244         return(ptr);
    245 }
    246 
    247 /*
    248  * enomem --
    249  *      die when out of memory.
    250  */
    251 void
    252 enomem(void)
    253 {
    254         err(2, NULL);
    255 }
    256 
    257 /*
    258  * enunlink --
    259  *      Remove a file carefully, avoiding directories.
    260  */
     161static char *
     162strrcpy(ptr, str)
     163    register char *ptr, *str;
     164{
     165    register int len = strlen(str);
     166
     167    while (len)
     168        *--ptr = str[--len];
     169
     170    return (ptr);
     171} /* end strrcpy */
     172
     173
     174char   *
     175getwd(pathname)
     176    char   *pathname;
     177{
     178    DIR    *dp;
     179    struct dirent *d;
     180
     181    struct stat st_root, st_cur, st_next, st_dotdot;
     182    char    pathbuf[MAXPATHLEN], nextpathbuf[MAXPATHLEN * 2];
     183    char   *pathptr, *nextpathptr, *cur_name_add;
     184
     185    /* find the inode of root */
     186    if (stat("/", &st_root) == -1) {
     187        (void) sprintf(pathname,
     188                        "getwd: Cannot stat \"/\" (%s)", strerror(errno));
     189        return (NULL);
     190    }
     191    pathbuf[MAXPATHLEN - 1] = '\0';
     192    pathptr = &pathbuf[MAXPATHLEN - 1];
     193    nextpathbuf[MAXPATHLEN - 1] = '\0';
     194    cur_name_add = nextpathptr = &nextpathbuf[MAXPATHLEN - 1];
     195
     196    /* find the inode of the current directory */
     197    if (lstat(".", &st_cur) == -1) {
     198        (void) sprintf(pathname,
     199                        "getwd: Cannot stat \".\" (%s)", strerror(errno));
     200        return (NULL);
     201    }
     202    nextpathptr = strrcpy(nextpathptr, "../");
     203
     204    /* Descend to root */
     205    for (;;) {
     206
     207        /* look if we found root yet */
     208        if (st_cur.st_ino == st_root.st_ino &&
     209            DEV_DEV_COMPARE(st_cur.st_dev, st_root.st_dev)) {
     210            (void) strcpy(pathname, *pathptr != '/' ? "/" : pathptr);
     211            return (pathname);
     212        }
     213
     214        /* open the parent directory */
     215        if (stat(nextpathptr, &st_dotdot) == -1) {
     216            snprintf(pathname, sizeof(pathname),
     217                            "getwd: Cannot stat directory \"%s\" (%s)",
     218                            nextpathptr, strerror(errno));
     219            return (NULL);
     220        }
     221        if ((dp = opendir(nextpathptr)) == NULL) {
     222             snprintf(pathname, sizeof(pathname),
     223                            "getwd: Cannot open directory \"%s\" (%s)",
     224                            nextpathptr, strerror(errno));
     225            return (NULL);
     226        }
     227
     228        /* look in the parent for the entry with the same inode */
     229        if (DEV_DEV_COMPARE(st_dotdot.st_dev, st_cur.st_dev)) {
     230            /* Parent has same device. No need to stat every member */
     231            for (d = readdir(dp); d != NULL; d = readdir(dp))
     232                if (d->d_fileno == st_cur.st_ino)
     233                    break;
     234        }
     235        else {
     236            /*
     237             * Parent has a different device. This is a mount point so we
     238             * need to stat every member
     239             */
     240            for (d = readdir(dp); d != NULL; d = readdir(dp)) {
     241                if (ISDOT(d->d_name) || ISDOTDOT(d->d_name))
     242                    continue;
     243                (void) strcpy(cur_name_add, d->d_name);
     244                if (lstat(nextpathptr, &st_next) == -1) {
     245                    snprintf(pathname, sizeof(pathname), "getwd: Cannot stat \"%s\" (%s)",
     246                                    d->d_name, strerror(errno));
     247                    (void) closedir(dp);
     248                    return (NULL);
     249                }
     250                /* check if we found it yet */
     251                if (st_next.st_ino == st_cur.st_ino &&
     252                    DEV_DEV_COMPARE(st_next.st_dev, st_cur.st_dev))
     253                    break;
     254            }
     255        }
     256        if (d == NULL) {
     257            (void) sprintf(pathname, "getwd: Cannot find \".\" in \"..\"");
     258            (void) closedir(dp);
     259            return (NULL);
     260        }
     261        st_cur = st_dotdot;
     262        pathptr = strrcpy(pathptr, d->d_name);
     263        pathptr = strrcpy(pathptr, "/");
     264        nextpathptr = strrcpy(nextpathptr, "../");
     265        (void) closedir(dp);
     266        *cur_name_add = '\0';
     267    }
     268} /* end getwd */
     269
     270
     271char    *sys_siglist[] = {
     272        "Signal 0",
     273        "Hangup",                       /* SIGHUP    */
     274        "Interrupt",                    /* SIGINT    */
     275        "Quit",                         /* SIGQUIT   */
     276        "Illegal instruction",          /* SIGILL    */
     277        "Trace/BPT trap",               /* SIGTRAP   */
     278        "IOT trap",                     /* SIGIOT    */
     279        "EMT trap",                     /* SIGEMT    */
     280        "Floating point exception",     /* SIGFPE    */
     281        "Killed",                       /* SIGKILL   */
     282        "Bus error",                    /* SIGBUS    */
     283        "Segmentation fault",           /* SIGSEGV   */
     284        "Bad system call",              /* SIGSYS    */
     285        "Broken pipe",                  /* SIGPIPE   */
     286        "Alarm clock",                  /* SIGALRM   */
     287        "Terminated",                   /* SIGTERM   */
     288        "User defined signal 1",        /* SIGUSR1   */
     289        "User defined signal 2",        /* SIGUSR2   */
     290        "Child exited",                 /* SIGCLD    */
     291        "Power-fail restart",           /* SIGPWR    */
     292        "Virtual timer expired",        /* SIGVTALRM */
     293        "Profiling timer expired",      /* SIGPROF   */
     294        "I/O possible",                 /* SIGIO     */
     295        "Window size changes",          /* SIGWINDOW */
     296        "Stopped (signal)",             /* SIGSTOP   */
     297        "Stopped",                      /* SIGTSTP   */
     298        "Continued",                    /* SIGCONT   */
     299        "Stopped (tty input)",          /* SIGTTIN   */
     300        "Stopped (tty output)",         /* SIGTTOU   */
     301        "Urgent I/O condition",         /* SIGURG    */
     302        "Remote lock lost (NFS)",       /* SIGLOST   */
     303        "Signal 31",                    /* reserved  */
     304        "DIL signal"                    /* SIGDIL    */
     305};
     306
    261307int
    262 eunlink(const char *file)
    263 {
    264         struct stat st;
    265 
    266         if (lstat(file, &st) == -1)
    267                 return -1;
    268 
    269         if (S_ISDIR(st.st_mode)) {
    270                 errno = EISDIR;
    271                 return -1;
    272         }
    273         return unlink(file);
    274 }
    275 
    276 /*
    277  * Printaddr --
    278  *      Print the address of a node, used as an interative function.
    279  */
    280 int
    281 PrintAddr(void *a, void *b __unused)
    282 {
    283     printf("%p ", a);
    284     return 0;
    285 }
     308utimes(file, tvp)
     309    char *file;
     310    struct timeval tvp[2];
     311{
     312    struct utimbuf t;
     313
     314    t.actime  = tvp[0].tv_sec;
     315    t.modtime = tvp[1].tv_sec;
     316    return(utime(file, &t));
     317}
     318
     319
     320#endif /* __hpux */
     321
     322#if defined(sun) && defined(__svr4__)
     323#include <signal.h>
     324
     325/* turn into bsd signals */
     326void (*
     327signal(s, a)) ()
     328    int     s;
     329    void (*a)();
     330{
     331    struct sigaction sa, osa;
     332
     333    sa.sa_handler = a;
     334    sigemptyset(&sa.sa_mask);
     335    sa.sa_flags = SA_RESTART;
     336
     337    if (sigaction(s, &sa, &osa) == -1)
     338        return SIG_ERR;
     339    else
     340        return osa.sa_handler;
     341}
     342
     343#endif
  • branches/FREEBSD/src/kmk/var.c

    r10 r24  
    3535 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3636 * SUCH DAMAGE.
    37  *
    38  * @(#)var.c    8.3 (Berkeley) 3/19/94
    39  */
    40 
    41 #include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/usr.bin/make/var.c,v 1.35 2002/10/09 03:42:10 jmallett Exp $");
     37 */
     38
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)var.c       8.3 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/var.c,v 1.16.2.3 2002/02/27 14:18:57 cjc Exp $";
     45#endif
     46#endif /* not lint */
    4347
    4448/*-
     
    126130static Lst      allVars;      /* List of all variables */
    127131
    128 #define FIND_CMD        0x1   /* look in VAR_CMD when searching */
    129 #define FIND_GLOBAL     0x2   /* look in VAR_GLOBAL as well */
    130 #define FIND_ENV        0x4   /* look in the environment also */
     132#define FIND_CMD        0x1   /* look in VAR_CMD when searching */
     133#define FIND_GLOBAL     0x2   /* look in VAR_GLOBAL as well */
     134#define FIND_ENV        0x4   /* look in the environment also */
    131135
    132136typedef struct Var {
     
    134138    Buffer        val;          /* its value */
    135139    int           flags;        /* miscellaneous status flags */
    136 #define VAR_IN_USE      1           /* Variable's value currently being used.
     140#define VAR_IN_USE      1           /* Variable's value currently being used.
    137141                                     * Used to avoid recursion */
    138 #define VAR_FROM_ENV    2           /* Variable comes from the environment */
    139 #define VAR_JUNK        4           /* Variable is a junk variable that
     142#define VAR_FROM_ENV    2           /* Variable comes from the environment */
     143#define VAR_JUNK        4           /* Variable is a junk variable that
    140144                                     * should be destroyed when done with
    141145                                     * it. Used by Var_Parse for undefined,
     
    144148
    145149/* Var*Pattern flags */
    146 #define VAR_SUB_GLOBAL  0x01    /* Apply substitution globally */
    147 #define VAR_SUB_ONE     0x02    /* Apply substitution to one word */
    148 #define VAR_SUB_MATCHED 0x04    /* There was a match */
    149 #define VAR_MATCH_START 0x08    /* Match at start of word */
    150 #define VAR_MATCH_END   0x10    /* Match at end of word */
    151 #define VAR_NOSUBST     0x20    /* don't expand vars in VarGetPattern */
     150#define VAR_SUB_GLOBAL  0x01    /* Apply substitution globally */
     151#define VAR_SUB_ONE     0x02    /* Apply substitution to one word */
     152#define VAR_SUB_MATCHED 0x04    /* There was a match */
     153#define VAR_MATCH_START 0x08    /* Match at start of word */
     154#define VAR_MATCH_END   0x10    /* Match at end of word */
     155#define VAR_NOSUBST     0x20    /* don't expand vars in VarGetPattern */
    152156
    153157typedef struct {
     
    167171} VarREPattern;
    168172
    169 static int VarCmp(void *, void *);
    170 static void VarPossiblyExpand(char **, GNode *);
    171 static Var *VarFind(char *, GNode *, int);
    172 static void VarAdd(char *, char *, GNode *);
    173 static void VarDelete(void *);
    174 static Boolean VarHead(char *, Boolean, Buffer, void *);
    175 static Boolean VarTail(char *, Boolean, Buffer, void *);
    176 static Boolean VarSuffix(char *, Boolean, Buffer, void *);
    177 static Boolean VarRoot(char *, Boolean, Buffer, void *);
    178 static Boolean VarMatch(char *, Boolean, Buffer, void *);
     173static int VarCmp __P((ClientData, ClientData));
     174static Var *VarFind __P((char *, GNode *, int));
     175static void VarAdd __P((char *, char *, GNode *));
     176static void VarDelete __P((ClientData));
     177static Boolean VarHead __P((char *, Boolean, Buffer, ClientData));
     178static Boolean VarTail __P((char *, Boolean, Buffer, ClientData));
     179static Boolean VarSuffix __P((char *, Boolean, Buffer, ClientData));
     180static Boolean VarRoot __P((char *, Boolean, Buffer, ClientData));
     181static Boolean VarMatch __P((char *, Boolean, Buffer, ClientData));
    179182#ifdef SYSVVARSUB
    180 static Boolean VarSYSVMatch(char *, Boolean, Buffer, void *);
     183static Boolean VarSYSVMatch __P((char *, Boolean, Buffer, ClientData));
    181184#endif
    182 static Boolean VarNoMatch(char *, Boolean, Buffer, void *);
    183 static void VarREError(int, regex_t *, const char *);
    184 static Boolean VarRESubstitute(char *, Boolean, Buffer, void *);
    185 static Boolean VarSubstitute(char *, Boolean, Buffer, void *);
    186 static char *VarGetPattern(GNode *, int, char **, int, int *, int *,
    187                            VarPattern *);
    188 static char *VarQuote(char *);
    189 static char *VarModify(char *, Boolean (*)(char *, Boolean, Buffer, void *),
    190                        void *);
    191 static int VarPrintVar(void *, void *);
     185static Boolean VarNoMatch __P((char *, Boolean, Buffer, ClientData));
     186static void VarREError __P((int, regex_t *, const char *));
     187static Boolean VarRESubstitute __P((char *, Boolean, Buffer, ClientData));
     188static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData));
     189static char *VarGetPattern __P((GNode *, int, char **, int, int *, int *,
     190                                VarPattern *));
     191static char *VarQuote __P((char *));
     192static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer,
     193                                                ClientData),
     194                            ClientData));
     195static int VarPrintVar __P((ClientData, ClientData));
    192196
    193197/*-
     
    205209 */
    206210static int
    207 VarCmp (void *v, void *name)
     211VarCmp (v, name)
     212    ClientData     v;           /* VAR structure to compare */
     213    ClientData     name;        /* name to look for */
    208214{
    209215    return (strcmp ((char *) name, ((Var *) v)->name));
    210 }
    211 
    212 /*-
    213  *-----------------------------------------------------------------------
    214  * VarPossiblyExpand --
    215  *      Expand a variable name's embedded variables in the given context.
    216  *
    217  * Results:
    218  *      The contents of name, possibly expanded.
    219  *
    220  * Side Effects:
    221  *      The caller must free the new contents or old contents of name.
    222  *-----------------------------------------------------------------------
    223  */
    224 static void
    225 VarPossiblyExpand(char **name, GNode *ctxt)
    226 {
    227     if (strchr(*name, '$') != NULL)
    228         *name = Var_Subst(NULL, *name, ctxt, 0);
    229     else
    230         *name = estrdup(*name);
    231216}
    232217
     
    237222 *      indicated.
    238223 *
    239  *      Flags:
    240  *              FIND_GLOBAL     set means look in the VAR_GLOBAL context too
    241  *              FIND_CMD        set means to look in the VAR_CMD context too
    242  *              FIND_ENV        set means to look in the environment
    243  *
    244224 * Results:
    245225 *      A pointer to the structure describing the desired variable or
    246  *      NULL if the variable does not exist.
     226 *      NIL if the variable does not exist.
    247227 *
    248228 * Side Effects:
     
    251231 */
    252232static Var *
    253 VarFind (char *name, GNode *ctxt, int flags)
     233VarFind (name, ctxt, flags)
     234    char                *name;  /* name to find */
     235    GNode               *ctxt;  /* context in which to find it */
     236    int                 flags;  /* FIND_GLOBAL set means to look in the
     237                                 * VAR_GLOBAL context as well.
     238                                 * FIND_CMD set means to look in the VAR_CMD
     239                                 * context also.
     240                                 * FIND_ENV set means to look in the
     241                                 * environment */
    254242{
    255243    Boolean             localCheckEnvFirst;
     
    297285     * the -E flag to use environment-variable-override for.
    298286     */
    299     if (Lst_Find (envFirstVars, (void *)name,
    300                   (int (*)(void *, void *)) strcmp) != NULL)
     287    if (Lst_Find (envFirstVars, (ClientData)name,
     288                  (int (*)(ClientData, ClientData)) strcmp) != NILLNODE)
    301289    {
    302290        localCheckEnvFirst = TRUE;
     
    310298     * depending on the FIND_* flags in 'flags'
    311299     */
    312     var = Lst_Find (ctxt->context, (void *)name, VarCmp);
    313 
    314     if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
    315         var = Lst_Find (VAR_CMD->context, (void *)name, VarCmp);
    316     }
    317     if ((var == NULL) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) &&
     300    var = Lst_Find (ctxt->context, (ClientData)name, VarCmp);
     301
     302    if ((var == NILLNODE) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
     303        var = Lst_Find (VAR_CMD->context, (ClientData)name, VarCmp);
     304    }
     305    if ((var == NILLNODE) && (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL) &&
    318306        !checkEnvFirst && !localCheckEnvFirst)
    319307    {
    320         var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp);
    321     }
    322     if ((var == NULL) && (flags & FIND_ENV)) {
     308        var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
     309    }
     310    if ((var == NILLNODE) && (flags & FIND_ENV)) {
    323311        char *env;
    324312
     
    339327                   (flags & FIND_GLOBAL) && (ctxt != VAR_GLOBAL))
    340328        {
    341             var = Lst_Find (VAR_GLOBAL->context, (void *)name, VarCmp);
    342             if (var == NULL) {
    343                 return ((Var *) NULL);
     329            var = Lst_Find (VAR_GLOBAL->context, (ClientData)name, VarCmp);
     330            if (var == NILLNODE) {
     331                return ((Var *) NIL);
    344332            } else {
    345333                return ((Var *)Lst_Datum(var));
    346334            }
    347335        } else {
    348             return((Var *)NULL);
     336            return((Var *)NIL);
    349337        }
    350     } else if (var == NULL) {
    351         return ((Var *) NULL);
     338    } else if (var == NILLNODE) {
     339        return ((Var *) NIL);
    352340    } else {
    353341        return ((Var *) Lst_Datum (var));
     
    358346 *-----------------------------------------------------------------------
    359347 * VarAdd  --
    360  *      Add a new variable of name name and value val to the given context.
     348 *      Add a new variable of name name and value val to the given context
    361349 *
    362350 * Results:
     
    370358 */
    371359static void
    372 VarAdd (char *name, char *val, GNode *ctxt)
    373 {
    374     Var           *v;
     360VarAdd (name, val, ctxt)
     361    char           *name;       /* name of variable to add */
     362    char           *val;        /* value to set it to */
     363    GNode          *ctxt;       /* context in which to set it */
     364{
     365    register Var   *v;
    375366    int           len;
    376367
     
    385376    v->flags = 0;
    386377
    387     (void) Lst_AtFront (ctxt->context, (void *)v);
    388     (void) Lst_AtEnd (allVars, (void *) v);
    389     DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
     378    (void) Lst_AtFront (ctxt->context, (ClientData)v);
     379    (void) Lst_AtEnd (allVars, (ClientData) v);
     380    if (DEBUG(VAR)) {
     381        printf("%s:%s = %s\n", ctxt->name, name, val);
     382    }
    390383}
    391384
     
    404397 */
    405398static void
    406 VarDelete(void *vp)
     399VarDelete(vp)
     400    ClientData vp;
    407401{
    408402    Var *v = (Var *) vp;
    409403    free(v->name);
    410404    Buf_Destroy(v->val, TRUE);
    411     free(v);
     405    free((Address) v);
    412406}
    413407
     
    428422 */
    429423void
    430 Var_Delete(char *name, GNode *ctxt)
     424Var_Delete(name, ctxt)
     425    char          *name;
     426    GNode         *ctxt;
    431427{
    432428    LstNode       ln;
    433429
    434     DEBUGF(VAR, ("%s:delete %s\n", ctxt->name, name));
    435     ln = Lst_Find(ctxt->context, (void *)name, VarCmp);
    436     if (ln != NULL) {
    437         Var       *v;
     430    if (DEBUG(VAR)) {
     431        printf("%s:delete %s\n", ctxt->name, name);
     432    }
     433    ln = Lst_Find(ctxt->context, (ClientData)name, VarCmp);
     434    if (ln != NILLNODE) {
     435        register Var      *v;
    438436
    439437        v = (Var *)Lst_Datum(ln);
     
    441439        ln = Lst_Member(allVars, v);
    442440        Lst_Remove(allVars, ln);
    443         VarDelete((void *) v);
     441        VarDelete((ClientData) v);
    444442    }
    445443}
     
    467465 */
    468466void
    469 Var_Set (char *name, char *val, GNode *ctxt)
    470 {
    471     Var            *v;
     467Var_Set (name, val, ctxt)
     468    char           *name;       /* name of variable to set */
     469    char           *val;        /* value to give to the variable */
     470    GNode          *ctxt;       /* context in which to set it */
     471{
     472    register Var   *v;
    472473
    473474    /*
     
    476477     * point in searching them all just to save a bit of memory...
    477478     */
    478     VarPossiblyExpand(&name, ctxt);
    479479    v = VarFind (name, ctxt, 0);
    480     if (v == (Var *) NULL) {
     480    if (v == (Var *) NIL) {
    481481        VarAdd (name, val, ctxt);
    482482    } else {
     
    484484        Buf_AddBytes(v->val, strlen(val), (Byte *)val);
    485485
    486         DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name, val));
     486        if (DEBUG(VAR)) {
     487            printf("%s:%s = %s\n", ctxt->name, name, val);
     488        }
    487489    }
    488490    /*
     
    493495        setenv(name, val, 1);
    494496    }
    495     free(name);
    496497}
    497498
     
    519520 */
    520521void
    521 Var_Append (char *name, char *val, GNode *ctxt)
    522 {
    523     Var            *v;
    524 
    525     VarPossiblyExpand(&name, ctxt);
     522Var_Append (name, val, ctxt)
     523    char           *name;       /* Name of variable to modify */
     524    char           *val;        /* String to append to it */
     525    GNode          *ctxt;       /* Context in which this should occur */
     526{
     527    register Var   *v;
     528
    526529    v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
    527530
    528     if (v == (Var *) NULL) {
     531    if (v == (Var *) NIL) {
    529532        VarAdd (name, val, ctxt);
    530533    } else {
     
    532535        Buf_AddBytes(v->val, strlen(val), (Byte *)val);
    533536
    534         DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, name,
    535                (char *) Buf_GetAll(v->val, (int *)NULL)));
     537        if (DEBUG(VAR)) {
     538            printf("%s:%s = %s\n", ctxt->name, name,
     539                   (char *) Buf_GetAll(v->val, (int *)NULL));
     540        }
    536541
    537542        if (v->flags & VAR_FROM_ENV) {
     
    543548             */
    544549            v->flags &= ~VAR_FROM_ENV;
    545             Lst_AtFront(ctxt->context, (void *)v);
     550            Lst_AtFront(ctxt->context, (ClientData)v);
    546551        }
    547552    }
    548     free(name);
    549553}
    550554
     
    563567 */
    564568Boolean
    565 Var_Exists(char *name, GNode *ctxt)
     569Var_Exists(name, ctxt)
     570    char          *name;        /* Variable to find */
     571    GNode         *ctxt;        /* Context in which to start search */
    566572{
    567573    Var           *v;
    568574
    569     VarPossiblyExpand(&name, ctxt);
    570575    v = VarFind(name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV);
    571     free(name);
    572 
    573     if (v == (Var *)NULL) {
     576
     577    if (v == (Var *)NIL) {
    574578        return(FALSE);
    575579    } else if (v->flags & VAR_FROM_ENV) {
     
    594598 */
    595599char *
    596 Var_Value (char *name, GNode *ctxt, char **frp)
     600Var_Value (name, ctxt, frp)
     601    char           *name;       /* name to find */
     602    GNode          *ctxt;       /* context in which to search for it */
     603    char           **frp;
    597604{
    598605    Var            *v;
    599606
    600     VarPossiblyExpand(&name, ctxt);
    601607    v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    602     free(name);
    603608    *frp = NULL;
    604     if (v != (Var *) NULL) {
     609    if (v != (Var *) NIL) {
    605610        char *p = ((char *)Buf_GetAll(v->val, (int *)NULL));
    606611        if (v->flags & VAR_FROM_ENV) {
    607612            Buf_Destroy(v->val, FALSE);
    608             free(v);
     613            free((Address) v);
    609614            *frp = p;
    610615        }
     
    631636 */
    632637static Boolean
    633 VarHead (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    634 {
    635     char *slash;
     638VarHead (word, addSpace, buf, dummy)
     639    char          *word;        /* Word to trim */
     640    Boolean       addSpace;     /* True if need to add a space to the buffer
     641                                 * before sticking in the head */
     642    Buffer        buf;          /* Buffer in which to store it */
     643    ClientData    dummy;
     644{
     645    register char *slash;
    636646
    637647    slash = strrchr (word, '/');
     
    654664        }
    655665    }
    656     return (TRUE);
     666    return(dummy ? TRUE : TRUE);
    657667}
    658668
     
    673683 */
    674684static Boolean
    675 VarTail (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    676 {
    677     char *slash;
     685VarTail (word, addSpace, buf, dummy)
     686    char          *word;        /* Word to trim */
     687    Boolean       addSpace;     /* TRUE if need to stick a space in the
     688                                 * buffer before adding the tail */
     689    Buffer        buf;          /* Buffer in which to store it */
     690    ClientData    dummy;
     691{
     692    register char *slash;
    678693
    679694    if (addSpace) {
     
    689704        Buf_AddBytes (buf, strlen(word), (Byte *)word);
    690705    }
    691     return (TRUE);
     706    return (dummy ? TRUE : TRUE);
    692707}
    693708
     
    707722 */
    708723static Boolean
    709 VarSuffix (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    710 {
    711     char *dot;
     724VarSuffix (word, addSpace, buf, dummy)
     725    char          *word;        /* Word to trim */
     726    Boolean       addSpace;     /* TRUE if need to add a space before placing
     727                                 * the suffix in the buffer */
     728    Buffer        buf;          /* Buffer in which to store it */
     729    ClientData    dummy;
     730{
     731    register char *dot;
    712732
    713733    dot = strrchr (word, '.');
     
    721741        addSpace = TRUE;
    722742    }
    723     return (addSpace);
     743    return (dummy ? addSpace : addSpace);
    724744}
    725745
     
    740760 */
    741761static Boolean
    742 VarRoot (char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
    743 {
    744     char *dot;
     762VarRoot (word, addSpace, buf, dummy)
     763    char          *word;        /* Word to trim */
     764    Boolean       addSpace;     /* TRUE if need to add a space to the buffer
     765                                 * before placing the root in it */
     766    Buffer        buf;          /* Buffer in which to store it */
     767    ClientData    dummy;
     768{
     769    register char *dot;
    745770
    746771    if (addSpace) {
     
    756781        Buf_AddBytes (buf, strlen(word), (Byte *)word);
    757782    }
    758     return (TRUE);
     783    return (dummy ? TRUE : TRUE);
    759784}
    760785
     
    764789 *      Place the word in the buffer if it matches the given pattern.
    765790 *      Callback function for VarModify to implement the :M modifier.
    766  *      A space will be added if requested.  A pattern is supplied
    767  *      which the word must match.
    768791 *
    769792 * Results:
     
    777800 */
    778801static Boolean
    779 VarMatch (char *word, Boolean addSpace, Buffer buf, void *pattern)
     802VarMatch (word, addSpace, buf, pattern)
     803    char          *word;        /* Word to examine */
     804    Boolean       addSpace;     /* TRUE if need to add a space to the
     805                                 * buffer before adding the word, if it
     806                                 * matches */
     807    Buffer        buf;          /* Buffer in which to store it */
     808    ClientData    pattern;      /* Pattern the word must match */
    780809{
    781810    if (Str_Match(word, (char *) pattern)) {
     
    795824 *      Place the word in the buffer if it matches the given pattern.
    796825 *      Callback function for VarModify to implement the System V %
    797  *      modifiers.  A space is added if requested.
     826 *      modifiers.
    798827 *
    799828 * Results:
     
    807836 */
    808837static Boolean
    809 VarSYSVMatch (char *word, Boolean addSpace, Buffer buf, void *patp)
     838VarSYSVMatch (word, addSpace, buf, patp)
     839    char          *word;        /* Word to examine */
     840    Boolean       addSpace;     /* TRUE if need to add a space to the
     841                                 * buffer before adding the word, if it
     842                                 * matches */
     843    Buffer        buf;          /* Buffer in which to store it */
     844    ClientData    patp;         /* Pattern the word must match */
    810845{
    811846    int len;
     
    832867 * VarNoMatch --
    833868 *      Place the word in the buffer if it doesn't match the given pattern.
    834  *      Callback function for VarModify to implement the :N modifier.  A
    835  *      space is added if requested.
     869 *      Callback function for VarModify to implement the :N modifier.
    836870 *
    837871 * Results:
     
    845879 */
    846880static Boolean
    847 VarNoMatch (char *word, Boolean addSpace, Buffer buf, void *pattern)
     881VarNoMatch (word, addSpace, buf, pattern)
     882    char          *word;        /* Word to examine */
     883    Boolean       addSpace;     /* TRUE if need to add a space to the
     884                                 * buffer before adding the word, if it
     885                                 * matches */
     886    Buffer        buf;          /* Buffer in which to store it */
     887    ClientData    pattern;      /* Pattern the word must match */
    848888{
    849889    if (!Str_Match(word, (char *) pattern)) {
     
    862902 * VarSubstitute --
    863903 *      Perform a string-substitution on the given word, placing the
    864  *      result in the passed buffer.  A space is added if requested.
     904 *      result in the passed buffer.
    865905 *
    866906 * Results:
     
    873913 */
    874914static Boolean
    875 VarSubstitute (char *word, Boolean addSpace, Buffer buf, void *patternp)
    876 {
    877     int                 wordLen;    /* Length of word */
    878     char                *cp;        /* General pointer */
     915VarSubstitute (word, addSpace, buf, patternp)
     916    char                *word;      /* Word to modify */
     917    Boolean             addSpace;   /* True if space should be added before
     918                                     * other characters */
     919    Buffer              buf;        /* Buffer for result */
     920    ClientData          patternp;   /* Pattern for substitution */
     921{
     922    register int        wordLen;    /* Length of word */
     923    register char       *cp;        /* General pointer */
    879924    VarPattern  *pattern = (VarPattern *) patternp;
    880925
     
    9711016             * buffer.
    9721017             */
    973             Boolean done;
     1018            register Boolean done;
    9741019            int origSize;
    9751020
     
    10351080 */
    10361081static void
    1037 VarREError(int err, regex_t *pat, const char *str)
     1082VarREError(err, pat, str)
     1083    int err;
     1084    regex_t *pat;
     1085    const char *str;
    10381086{
    10391087    char *errbuf;
     
    10521100 * VarRESubstitute --
    10531101 *      Perform a regex substitution on the given word, placing the
    1054  *      result in the passed buffer.  A space is added if requested.
     1102 *      result in the passed buffer.
    10551103 *
    10561104 * Results:
     
    10631111 */
    10641112static Boolean
    1065 VarRESubstitute(char *word, Boolean addSpace, Buffer buf, void *patternp)
     1113VarRESubstitute(word, addSpace, buf, patternp)
     1114    char *word;
     1115    Boolean addSpace;
     1116    Buffer buf;
     1117    ClientData patternp;
    10661118{
    10671119    VarREPattern *pat;
     
    10721124    int flags = 0;
    10731125
    1074 #define MAYBE_ADD_SPACE()               \
     1126#define MAYBE_ADD_SPACE()               \
    10751127        if (addSpace && !added)         \
    10761128            Buf_AddByte(buf, ' ');      \
     
    11911243 */
    11921244static char *
    1193 VarModify (char *str, Boolean (*modProc)(char *, Boolean, Buffer, void *),
    1194     void *datum)
     1245VarModify (str, modProc, datum)
     1246    char          *str;             /* String whose words should be trimmed */
     1247                                    /* Function to use to modify them */
     1248    Boolean       (*modProc) __P((char *, Boolean, Buffer, ClientData));
     1249    ClientData    datum;            /* Datum to pass it */
    11951250{
    11961251    Buffer        buf;              /* Buffer for the new string */
     
    12381293 */
    12391294static char *
    1240 VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
    1241     int *length, VarPattern *pattern)
     1295VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern)
     1296    GNode *ctxt;
     1297    int err;
     1298    char **tstr;
     1299    int delim;
     1300    int *flags;
     1301    int *length;
     1302    VarPattern *pattern;
    12421303{
    12431304    char *cp;
     
    12471308        length = &junk;
    12481309
    1249 #define IS_A_MATCH(cp, delim) \
     1310#define IS_A_MATCH(cp, delim) \
    12501311    ((cp[0] == '\\') && ((cp[1] == delim) ||  \
    12511312     (cp[1] == '\\') || (cp[1] == '$') || (pattern && (cp[1] == '&'))))
     
    13521413 */
    13531414static char *
    1354 VarQuote(char *str)
     1415VarQuote(str)
     1416        char *str;
    13551417{
    13561418
     
    13921454 */
    13931455char *
    1394 Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
    1395 {
    1396     char            *tstr;      /* Pointer into str */
     1456Var_Parse (str, ctxt, err, lengthPtr, freePtr)
     1457    char          *str;         /* The string to parse */
     1458    GNode         *ctxt;        /* The context for the variable */
     1459    Boolean         err;        /* TRUE if undefined variables are an error */
     1460    int             *lengthPtr; /* OUT: The length of the specification */
     1461    Boolean         *freePtr;   /* OUT: TRUE if caller should free result */
     1462{
     1463    register char   *tstr;      /* Pointer into str */
    13971464    Var             *v;         /* Variable in invocation */
    13981465    char            *cp;        /* Secondary pointer into str (place marker
    13991466                                 * for tstr) */
    14001467    Boolean         haveModifier;/* TRUE if have modifiers for the variable */
    1401     char            endc;       /* Ending character when variable in parens
     1468    register char   endc;       /* Ending character when variable in parens
    14021469                                 * or braces */
    1403     char            startc=0;   /* Starting character when variable in parens
     1470    register char   startc=0;   /* Starting character when variable in parens
    14041471                                 * or braces */
    14051472    int             cnt;        /* Used to count brace pairs when variable in
     
    14301497
    14311498        v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    1432         if (v == (Var *)NULL) {
     1499        if (v == (Var *)NIL) {
    14331500            *lengthPtr = 2;
    14341501
     
    14531520                    case '!':
    14541521                        return("$(.MEMBER)");
    1455                     default:
    1456                         break;
    14571522                }
    14581523            }
     
    15121577
    15131578        v = VarFind (str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
    1514         if ((v == (Var *)NULL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) &&
     1579        if ((v == (Var *)NIL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) &&
    15151580            (vlen == 2) && (str[1] == 'F' || str[1] == 'D'))
    15161581        {
     
    15371602                    v = VarFind(vname, ctxt, 0);
    15381603
    1539                     if (v != (Var *)NULL && !haveModifier) {
     1604                    if (v != (Var *)NIL && !haveModifier) {
    15401605                        /*
    15411606                         * No need for nested expansion or anything, as we're
     
    15461611
    15471612                        if (str[1] == 'D') {
    1548                             val = VarModify(val, VarHead, (void *)0);
     1613                            val = VarModify(val, VarHead, (ClientData)0);
    15491614                        } else {
    1550                             val = VarModify(val, VarTail, (void *)0);
     1615                            val = VarModify(val, VarTail, (ClientData)0);
    15511616                        }
    15521617                        /*
     
    15611626                    }
    15621627                    break;
    1563                 default:
    1564                     break;
    15651628                }
    15661629            }
    15671630        }
    15681631
    1569         if (v == (Var *)NULL) {
     1632        if (v == (Var *)NIL) {
    15701633            if (((vlen == 1) ||
    15711634                 (((vlen == 2) && (str[1] == 'F' ||
     
    15881651                    case '!':
    15891652                        dynamic = TRUE;
    1590                         break;
    1591                     default:
    15921653                        break;
    15931654                }
     
    16931754            char        termc;      /* Character which terminated scan */
    16941755
    1695             DEBUGF(VAR, ("Applying :%c to \"%s\"\n", *tstr, str));
     1756            if (DEBUG(VAR)) {
     1757                printf("Applying :%c to \"%s\"\n", *tstr, str);
     1758            }
    16961759            switch (*tstr) {
    16971760                case 'U':
     
    17701833                    }
    17711834                    if (*tstr == 'M' || *tstr == 'm') {
    1772                         newStr = VarModify(str, VarMatch, (void *)pattern);
     1835                        newStr = VarModify(str, VarMatch, (ClientData)pattern);
    17731836                    } else {
    17741837                        newStr = VarModify(str, VarNoMatch,
    1775                                            (void *)pattern);
     1838                                           (ClientData)pattern);
    17761839                    }
    17771840                    if (copy) {
     
    17831846                {
    17841847                    VarPattern      pattern;
    1785                     char            del;
     1848                    register char   delim;
    17861849                    Buffer          buf;        /* Buffer for patterns */
    17871850
    17881851                    pattern.flags = 0;
    1789                     del = tstr[1];
     1852                    delim = tstr[1];
    17901853                    tstr += 2;
    17911854
     
    18081871                     * The result is left in the Buffer buf.
    18091872                     */
    1810                     for (cp = tstr; *cp != '\0' && *cp != del; cp++) {
     1873                    for (cp = tstr; *cp != '\0' && *cp != delim; cp++) {
    18111874                        if ((*cp == '\\') &&
    1812                             ((cp[1] == del) ||
     1875                            ((cp[1] == delim) ||
    18131876                             (cp[1] == '$') ||
    18141877                             (cp[1] == '\\')))
     
    18171880                            cp++;
    18181881                        } else if (*cp == '$') {
    1819                             if (cp[1] != del) {
     1882                            if (cp[1] != delim) {
    18201883                                /*
    18211884                                 * If unescaped dollar sign not before the
     
    18511914                     * return NULL
    18521915                     */
    1853                     if (*cp != del) {
     1916                    if (*cp != delim) {
    18541917                        *lengthPtr = cp - start + 1;
    18551918                        if (*freePtr) {
     
    18581921                        Buf_Destroy(buf, TRUE);
    18591922                        Error("Unclosed substitution for %s (%c missing)",
    1860                               v->name, del);
     1923                              v->name, delim);
    18611924                        return (var_Error);
    18621925                    }
     
    18831946
    18841947                    tstr = cp + 1;
    1885                     for (cp = tstr; *cp != '\0' && *cp != del; cp++) {
     1948                    for (cp = tstr; *cp != '\0' && *cp != delim; cp++) {
    18861949                        if ((*cp == '\\') &&
    1887                             ((cp[1] == del) ||
     1950                            ((cp[1] == delim) ||
    18881951                             (cp[1] == '&') ||
    18891952                             (cp[1] == '\\') ||
     
    18921955                            Buf_AddByte(buf, (Byte)cp[1]);
    18931956                            cp++;
    1894                         } else if ((*cp == '$') && (cp[1] != del)) {
     1957                        } else if ((*cp == '$') && (cp[1] != delim)) {
    18951958                            char    *cp2;
    18961959                            int     len;
     
    19161979                     * If didn't end in delimiter character, complain
    19171980                     */
    1918                     if (*cp != del) {
     1981                    if (*cp != delim) {
    19191982                        *lengthPtr = cp - start + 1;
    19201983                        if (*freePtr) {
     
    19231986                        Buf_Destroy(buf, TRUE);
    19241987                        Error("Unclosed substitution for %s (%c missing)",
    1925                               v->name, del);
     1988                              v->name, delim);
    19261989                        return (var_Error);
    19271990                    }
     
    19442007                    termc = *cp;
    19452008                    newStr = VarModify(str, VarSubstitute,
    1946                                        (void *)&pattern);
     2009                                       (ClientData)&pattern);
    19472010                    /*
    19482011                     * Free the two strings.
     
    19982061                            pattern.flags |= VAR_SUB_ONE;
    19992062                            continue;
    2000                         default:
    2001                             break;
    20022063                        }
    20032064                        break;
     
    20232084                                              sizeof(regmatch_t));
    20242085                    newStr = VarModify(str, VarRESubstitute,
    2025                                        (void *) &pattern);
     2086                                       (ClientData) &pattern);
    20262087                    regfree(&pattern.re);
    20272088                    free(pattern.replace);
     
    20392100                case 'T':
    20402101                    if (tstr[1] == endc || tstr[1] == ':') {
    2041                         newStr = VarModify (str, VarTail, (void *)0);
     2102                        newStr = VarModify (str, VarTail, (ClientData)0);
    20422103                        cp = tstr + 1;
    20432104                        termc = *cp;
     
    20472108                case 'H':
    20482109                    if (tstr[1] == endc || tstr[1] == ':') {
    2049                         newStr = VarModify (str, VarHead, (void *)0);
     2110                        newStr = VarModify (str, VarHead, (ClientData)0);
    20502111                        cp = tstr + 1;
    20512112                        termc = *cp;
     
    20552116                case 'E':
    20562117                    if (tstr[1] == endc || tstr[1] == ':') {
    2057                         newStr = VarModify (str, VarSuffix, (void *)0);
     2118                        newStr = VarModify (str, VarSuffix, (ClientData)0);
    20582119                        cp = tstr + 1;
    20592120                        termc = *cp;
     
    20632124                case 'R':
    20642125                    if (tstr[1] == endc || tstr[1] == ':') {
    2065                         newStr = VarModify (str, VarRoot, (void *)0);
     2126                        newStr = VarModify (str, VarRoot, (ClientData)0);
    20662127                        cp = tstr + 1;
    20672128                        termc = *cp;
     
    20722133                case 's':
    20732134                    if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
    2074                         char *error;
    2075                         newStr = Cmd_Exec (str, &error);
    2076                         if (error)
    2077                             Error (error, str);
     2135                        char *err;
     2136                        newStr = Cmd_Exec (str, &err);
     2137                        if (err)
     2138                            Error (err, str);
    20782139                        cp = tstr + 2;
    20792140                        termc = *cp;
     
    21432204                         */
    21442205                        newStr = VarModify(str, VarSYSVMatch,
    2145                                            (void *)&pattern);
     2206                                           (ClientData)&pattern);
    21462207
    21472208                        /*
     
    21642225                }
    21652226            }
    2166             DEBUGF(VAR, ("Result is \"%s\"\n", newStr));
     2227            if (DEBUG(VAR)) {
     2228                printf("Result is \"%s\"\n", newStr);
     2229            }
    21672230
    21682231            if (*freePtr) {
     
    22032266        }
    22042267        Buf_Destroy(v->val, destroy);
    2205         free(v);
     2268        free((Address)v);
    22062269    } else if (v->flags & VAR_JUNK) {
    22072270        /*
     
    22142277        *freePtr = FALSE;
    22152278        Buf_Destroy(v->val, TRUE);
    2216         free(v);
     2279        free((Address)v);
    22172280        if (dynamic) {
    22182281            str = emalloc(*lengthPtr + 1);
     
    22422305 */
    22432306char *
    2244 Var_Subst (char *var, char *str, GNode *ctxt, Boolean undefErr)
     2307Var_Subst (var, str, ctxt, undefErr)
     2308    char          *var;             /* Named variable || NULL for all */
     2309    char          *str;             /* the string in which to substitute */
     2310    GNode         *ctxt;            /* the context wherein to find variables */
     2311    Boolean       undefErr;         /* TRUE if undefineds are an error */
    22452312{
    22462313    Buffer        buf;              /* Buffer for forming things */
     
    23772444                Buf_AddBytes (buf, strlen (val), (Byte *)val);
    23782445                if (doFree) {
    2379                     free (val);
     2446                    free ((Address)val);
    23802447                }
    23812448            }
     
    24042471 */
    24052472char *
    2406 Var_GetTail(char *file)
    2407 {
    2408     return(VarModify(file, VarTail, (void *)0));
     2473Var_GetTail(file)
     2474    char        *file;      /* Filename to modify */
     2475{
     2476    return(VarModify(file, VarTail, (ClientData)0));
    24092477}
    24102478
     
    24252493 */
    24262494char *
    2427 Var_GetHead(char *file)
    2428 {
    2429     return(VarModify(file, VarHead, (void *)0));
     2495Var_GetHead(file)
     2496    char        *file;      /* Filename to manipulate */
     2497{
     2498    return(VarModify(file, VarHead, (ClientData)0));
    24302499}
    24312500
     
    24432512 */
    24442513void
    2445 Var_Init (void)
     2514Var_Init ()
    24462515{
    24472516    VAR_GLOBAL = Targ_NewGN ("Global");
     
    24532522
    24542523void
    2455 Var_End (void)
     2524Var_End ()
    24562525{
    24572526    Lst_Destroy(allVars, VarDelete);
     
    24612530/****************** PRINT DEBUGGING INFO *****************/
    24622531static int
    2463 VarPrintVar (void *vp, void *dummy __unused)
     2532VarPrintVar (vp, dummy)
     2533    ClientData vp;
     2534    ClientData dummy;
    24642535{
    24652536    Var    *v = (Var *) vp;
    24662537    printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL));
    2467     return (0);
     2538    return (dummy ? 0 : 0);
    24682539}
    24692540
     
    24752546 */
    24762547void
    2477 Var_Dump (GNode *ctxt)
    2478 {
    2479     Lst_ForEach (ctxt->context, VarPrintVar, (void *) 0);
    2480 }
     2548Var_Dump (ctxt)
     2549    GNode          *ctxt;
     2550{
     2551    Lst_ForEach (ctxt->context, VarPrintVar, (ClientData) 0);
     2552}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette