diff options
author | joerg <joerg> | 2009-09-18 21:27:25 +0000 |
---|---|---|
committer | joerg <joerg> | 2009-09-18 21:27:25 +0000 |
commit | ef2c7a77a87c4962868da3ddf42ef1047e1cddcd (patch) | |
tree | 9f85b0675b6430d91feb47f1fcbbe95577efbec7 /devel/bmake | |
parent | d48273424898724da3dc3a42ee28981b1ec72418 (diff) | |
download | pkgsrc-ef2c7a77a87c4962868da3ddf42ef1047e1cddcd.tar.gz |
Update to bmake-20090909
Diffstat (limited to 'devel/bmake')
66 files changed, 2755 insertions, 2483 deletions
diff --git a/devel/bmake/Makefile b/devel/bmake/Makefile index ce2f1c08948..5f3d66e109b 100644 --- a/devel/bmake/Makefile +++ b/devel/bmake/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.47 2009/04/09 00:48:07 joerg Exp $ +# $NetBSD: Makefile,v 1.48 2009/09/18 21:27:25 joerg Exp $ # -DISTNAME= bmake-20081111 +DISTNAME= bmake-20090909 CATEGORIES= devel MASTER_SITES= # empty DISTFILES= # empty diff --git a/devel/bmake/files/ChangeLog b/devel/bmake/files/ChangeLog index 3df404347e4..4087db887b7 100644 --- a/devel/bmake/files/ChangeLog +++ b/devel/bmake/files/ChangeLog @@ -1,3 +1,58 @@ +2009-09-09 Simon J. Gerraty <sjg@void.crufty.net> + + * Makefile.in (MAKE_VERSION): bump version to 20090909 + * Merge with NetBSD make, pick up: + o fix for -C, .CURDIR and .OBJDIR + * boot-strap: + o allow share_dir to be set independent of prefix. + o select default share_dir better when prefix ends in $HOST_TARGET + o if FORCE_BSD_MK etc were set, include them in the suggested + install-mk command. + +2009-09-08 Simon J. Gerraty <sjg@void.crufty.net> + + * Makefile.in (MAKE_VERSION): bump version to 20090908 + * Merge with NetBSD make, pick up: + o .MAKE.LEVEL for recursion tracking + o fix for :M scanning \: + +2009-09-03 Simon J. Gerraty <sjg@void.crufty.net> + + * configure.in: Don't -D__EXTENSIONS__ if + AC_USE_SYSTEM_EXTENSIONS says "no". + +2009-08-26 Simon J. Gerraty <sjg@void.crufty.net> + + * Makefile.in (MAKE_VERSION): bump version to 20090826 + Simplify MAKE_VERSION to just the bare date. + * Merge with NetBSD make, pick up: + o -C directory support. + o support for SIGINFO + o use $TMPDIR for temp files. + o child of vfork should be careful about modifying parent's state. + + +2009-03-26 Simon J. Gerraty <sjg@void.crufty.net> + + * Appy some patches for MiNT from David Brownlee + +2009-02-26 Simon J. Gerraty <sjg@void.crufty.net> + + * Makefile.in (BMAKE_VERSION): bump version to 20090222 + * Merge with NetBSD make, pick up: + o Possible null pointer de-ref in Var_Set. + +2009-02-08 Simon J. Gerraty <sjg@void.crufty.net> + + * Makefile.in (BMAKE_VERSION): bump version to 20090204 + * Merge with NetBSD make, pick up: + o bmake_malloc et al moved to their own .c + o Count both () and {} when looking for the end of a :M pattern + o Change 'Buffer' so that it is the actual struct, not a pointer to it. + o strlist.c - functions for processing extendable arrays of pointers to strings. + o ClientData replaced with void *, so const void * can be used. + o New debug flag C for DEBUG_CWD + 2008-11-11 Simon J. Gerraty <sjg@void.crufty.net> * Makefile.in (BMAKE_VERSION): bump version to 20081111 diff --git a/devel/bmake/files/FILES b/devel/bmake/files/FILES index 94b0a8e2f2c..91abe3f6d1a 100644 --- a/devel/bmake/files/FILES +++ b/devel/bmake/files/FILES @@ -13,6 +13,8 @@ buf.h compat.c cond.c make-conf.h +make_malloc.c +make_malloc.h config.h.in configure aclocal.m4 @@ -28,6 +30,8 @@ hash.h install-sh job.c job.h +strlist.c +strlist.h trace.c trace.h lst.h diff --git a/devel/bmake/files/Makefile.in b/devel/bmake/files/Makefile.in index 3f9ed804466..77f1f6305c2 100644 --- a/devel/bmake/files/Makefile.in +++ b/devel/bmake/files/Makefile.in @@ -1,11 +1,13 @@ -# $NetBSD: Makefile.in,v 1.12 2008/11/11 19:47:38 joerg Exp $ +# $NetBSD: Makefile.in,v 1.13 2009/09/18 21:27:25 joerg Exp $ # @(#)Makefile 5.2 (Berkeley) 12/28/90 -# $Id: Makefile.in,v 1.12 2008/11/11 19:47:38 joerg Exp $ +# $Id: Makefile.in,v 1.13 2009/09/18 21:27:25 joerg Exp $ PROG= bmake SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \ make.c parse.c str.c suff.c targ.c trace.c var.c util.c +SRCS+= strlist.c +SRCS+= make_malloc.c SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \ lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \ @@ -19,10 +21,7 @@ srcdir= @srcdir@ CC?= @CC@ # Base version on src date -BMAKE_VERSION= 20081111 -# knowing when it was built is also handy -BUILD_DATE!= date +%Y%m%d -MAKE_VERSION:= bmake-${BMAKE_VERSION} build-${BUILD_DATE} +MAKE_VERSION= 20090909 MACHINE=@machine@ MACHINE_ARCH=@machine_arch@ DEFAULT_SYS_PATH = @default_sys_path@ @@ -122,6 +121,7 @@ install-mk: .else @echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false .endif +CFLAGS_var.o += -Wno-cast-qual .ifdef TOOLDIR # this is a native netbsd build, diff --git a/devel/bmake/files/PSD.doc/tutorial.ms b/devel/bmake/files/PSD.doc/tutorial.ms index 52741084514..f10a0fa5383 100644 --- a/devel/bmake/files/PSD.doc/tutorial.ms +++ b/devel/bmake/files/PSD.doc/tutorial.ms @@ -1,4 +1,4 @@ -.\" $NetBSD: tutorial.ms,v 1.2 2008/03/09 19:54:29 joerg Exp $ +.\" $NetBSD: tutorial.ms,v 1.3 2009/09/18 21:27:25 joerg Exp $ .\" Copyright (c) 1988, 1989, 1993 .\" The Regents of the University of California. All rights reserved. .\" diff --git a/devel/bmake/files/arch.c b/devel/bmake/files/arch.c index ea699adc7af..ff9b6728ff1 100644 --- a/devel/bmake/files/arch.c +++ b/devel/bmake/files/arch.c @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: arch.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: arch.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: arch.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: arch.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: arch.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -173,9 +173,9 @@ typedef struct Arch { size_t fnamesize; /* Size of the string table */ } Arch; -static int ArchFindArchive(ClientData, ClientData); +static int ArchFindArchive(const void *, const void *); #ifdef CLEANUP -static void ArchFree(ClientData); +static void ArchFree(void *); #endif static struct ar_hdr *ArchStatMember(char *, char *, Boolean); static FILE *ArchFindMember(char *, char *, struct ar_hdr *, const char *); @@ -222,7 +222,7 @@ static int ArchSVR4Entry(Arch *, char *, size_t, FILE *); *----------------------------------------------------------------------- */ static void -ArchFree(ClientData ap) +ArchFree(void *ap) { Arch *a = (Arch *)ap; Hash_Search search; @@ -405,7 +405,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) */ gn = Targ_FindNode(buf, TARG_CREATE); - if (gn == NILGNODE) { + if (gn == NULL) { free(buf); return(FAILURE); } else { @@ -440,7 +440,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) snprintf(nameBuf, sz, "%s(%s)", libName, member); free(member); gn = Targ_FindNode(nameBuf, TARG_CREATE); - if (gn == NILGNODE) { + if (gn == NULL) { free(nameBuf); return (FAILURE); } else { @@ -455,7 +455,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) (void)Lst_AtEnd(nodeLst, gn); } } - Lst_Destroy(members, NOFREE); + Lst_Destroy(members, NULL); free(nameBuf); } else { size_t sz = strlen(libName) + strlen(memName) + 3; @@ -463,7 +463,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) snprintf(nameBuf, sz, "%s(%s)", libName, memName); gn = Targ_FindNode(nameBuf, TARG_CREATE); free(nameBuf); - if (gn == NILGNODE) { + if (gn == NULL) { return (FAILURE); } else { /* @@ -523,9 +523,9 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt) *----------------------------------------------------------------------- */ static int -ArchFindArchive(ClientData ar, ClientData archName) +ArchFindArchive(const void *ar, const void *archName) { - return (strcmp((char *)archName, ((Arch *)ar)->name)); + return (strcmp(archName, ((const Arch *)ar)->name)); } /*- @@ -577,7 +577,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) } ln = Lst_Find(archives, archive, ArchFindArchive); - if (ln != NILLNODE) { + if (ln != NULL) { ar = (Arch *)Lst_Datum(ln); he = Hash_FindEntry(&ar->members, member); @@ -596,7 +596,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) } if ((he = Hash_FindEntry(&ar->members, copy)) != NULL) return ((struct ar_hdr *)Hash_GetValue(he)); - return (NULL); + return NULL; } } @@ -613,7 +613,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) arch = ArchFindMember(archive, member, &sarh, "r"); if (arch == NULL) { - return (NULL); + return NULL; } else { fclose(arch); return (&sarh); @@ -626,7 +626,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) */ arch = fopen(archive, "r"); if (arch == NULL) { - return (NULL); + return NULL; } /* @@ -636,7 +636,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) if ((fread(magic, SARMAG, 1, arch) != 1) || (strncmp(magic, ARMAG, SARMAG) != 0)) { fclose(arch); - return (NULL); + return NULL; } ar = bmake_malloc(sizeof(Arch)); @@ -734,7 +734,7 @@ ArchStatMember(char *archive, char *member, Boolean hash) if (he != NULL) { return ((struct ar_hdr *)Hash_GetValue(he)); } else { - return (NULL); + return NULL; } badarch: @@ -743,7 +743,7 @@ badarch: if (ar->fnametab) free(ar->fnametab); free(ar); - return (NULL); + return NULL; } #ifdef SVR4ARCHIVES @@ -884,7 +884,7 @@ ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, arch = fopen(archive, mode); if (arch == NULL) { - return (NULL); + return NULL; } /* @@ -894,7 +894,7 @@ ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, if ((fread(magic, SARMAG, 1, arch) != 1) || (strncmp(magic, ARMAG, SARMAG) != 0)) { fclose(arch); - return (NULL); + return NULL; } /* @@ -919,7 +919,7 @@ ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, * and there's no way we can recover... */ fclose(arch); - return (NULL); + return NULL; } else if (strncmp(member, arhPtr->AR_NAME, tlen) == 0) { /* * If the member's name doesn't take up the entire 'name' field, @@ -995,7 +995,7 @@ skip: * archive and return NULL -- an error. */ fclose(arch); - return (NULL); + return NULL; } /*- @@ -1149,7 +1149,7 @@ Arch_MemMTime(GNode *gn) gn->mtime = 0; return (0); } - while ((ln = Lst_Next(gn->parents)) != NILLNODE) { + while ((ln = Lst_Next(gn->parents)) != NULL) { pgn = (GNode *)Lst_Datum(ln); if (pgn->type & OP_ARCHV) { diff --git a/devel/bmake/files/bmake.1 b/devel/bmake/files/bmake.1 index 50908ded1b9..74071f6beb0 100644 --- a/devel/bmake/files/bmake.1 +++ b/devel/bmake/files/bmake.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: bmake.1,v 1.2 2008/03/09 19:54:29 joerg Exp $ +.\" $NetBSD: bmake.1,v 1.3 2009/09/18 21:27:25 joerg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd November 19, 2006 +.Dd September 7, 2009 .Dt MAKE 1 .Os .Sh NAME @@ -39,6 +39,9 @@ .Nm .Op Fl BeikNnqrstWX .Bk -words +.Op Fl C Ar directory +.Ek +.Bk -words .Op Fl D Ar variable .Ek .Bk -words @@ -104,6 +107,16 @@ The options are as follows: .It Fl B Try to be backwards compatible by executing a single shell per command and by executing the commands to make the sources of a dependency line in sequence. +.It Fl C Ar directory +Change to +.Ar directory +before reading the makefiles or doing anything else. +If multiple +.Fl C +options are specified, each is interpreted relative to the previous one: +.Fl C Pa / Fl C Pa etc +is equivalent to +.Fl C Pa /etc . .It Fl D Ar variable Define .Ar variable @@ -117,6 +130,13 @@ Unless the flags are preceded by they are added to the .Va MAKEFLAGS environment variable and will be processed by any child make processes. +By default, debugging information is printed to standard error, +but this can be changed using the +.Ar F +debugging flag. +The debugging output is always unbuffered; in addition, if debugging +is enabled but debugging output is not directed to standard output, +then the standard output is line buffered. .Ar Flags is one or more of the following: .Bl -tag -width Ds @@ -125,17 +145,35 @@ Print all possible debugging information; equivalent to specifying all of the debugging flags. .It Ar a Print debugging information about archive searching and caching. +.It Ar C +Print debugging information about current working directory. .It Ar c Print debugging information about conditional evaluation. .It Ar d Print debugging information about directory searching and caching. .It Ar e Print debugging information about failed commands and targets. -.It Ar F -Use the rest of -.Ql flags -as the name of the file to which the debug output is written. -If the filename ends +.It Ar F Ns Oo Sy \&+ Oc Ns Ar filename +Specify where debugging output is written. +This must be the last flag, because it consumes the remainder of +the argument. +If the character immediately after the +.Ql F +flag is +.Ql \&+ , +then the file will be opened in append mode; +otherwise the file will be overwritten. +If the file name is +.Ql stdout +or +.Ql stderr +then debugging output will be written to the +standard output or standard error output file descriptors respectively +(and the +.Ql \&+ +option has no effect). +Otherwise, the output will be written to the named file. +If the file name ends .Ql .%d then the .Ql %d @@ -153,23 +191,31 @@ Print the input graph before exiting on error. Print debugging information about running multiple shells. .It Ar l Print commands in Makefiles regardless of whether or not they are prefixed by -.Ql @ +.Ql @ or other "quiet" flags. Also known as "loud" behavior. .It Ar m Print debugging information about making targets, including modification dates. .It Ar n -Don't delete the temporary command scripts created in +Don't delete the temporary command scripts created when running commands. +These temporary scripts are created in the directory +referred to by the +.Ev TMPDIR +environment variable, or in .Pa /tmp -when running commands. -These are created via -.Xr mkstemp 3 +if +.Ev TMPDIR +is unset or set to the empty string. +The temporary scripts are created by +.Xr mkstemp 3 , and have names of the form -.Pa /tmp/makeXXXXX . +.Pa makeXXXXXX . .Em NOTE : -This can create many file in -.Pa /tmp +This can create many files in +.Ev TMPDIR +or +.Pa /tmp , so use with care. .It Ar p Print debugging information about makefile parsing. @@ -223,6 +269,14 @@ may have running at any one time. Turns compatibility mode off, unless the .Ar B flag is also specified. +When compatibility mode is off, all commands associated with a +target are executed in a single shell invocation as opposed to the +traditional one shell invocation per line. +This can break traditional scripts which change directories on each +command invocation and then expect to start with a fresh environment +on the next line. +It is more efficient to correct the scripts rather than turn backwards +compatibility on. .It Fl k Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. @@ -345,7 +399,9 @@ line are compressed into a single space. .Sh FILE DEPENDENCY SPECIFICATIONS Dependency lines consist of one or more targets, an operator, and zero or more sources. -This creates a relationship where the targets ``depend'' on the sources +This creates a relationship where the targets +.Dq depend +on the sources and are usually created from them. The exact relationship between the target and the source is determined by the operator that separates them. @@ -472,6 +528,14 @@ If the variable name contains only a single letter, the surrounding braces or parentheses are not required. This shorter form is not recommended. .Pp +If the variable name contains a dollar, then the name itself is expanded first. +This allows almost arbitrary variable names, however names containing dollar, +braces, parenthesis, or whitespace are really best avoided! +.Pp +If the result of expanding a variable contains a dollar sign +.Pq Ql \&$ +the string is expanded again. +.Pp Variable substitution occurs at two distinct times, depending on where the variable is being used. Variables in dependency lines are expanded as the line is read. @@ -499,9 +563,12 @@ The list of all sources for this target; also known as .It Va .ARCHIVE The name of the archive file. .It Va .IMPSRC -The name/path of the source from which the target is to be transformed -(the ``implied'' source); also known as +In suffix-transformation rules, the name/path of the source from which the +target is to be transformed (the +.Dq implied +source); also known as .Ql Va \&\*[Lt] . +It is not defined in explicit rules. .It Va .MEMBER The name of the archive member. .It Va .OODATE @@ -547,7 +614,7 @@ These variables are and .Ql Va .MEMBER . .El -.Ss Additional inbuilt variables +.Ss Additional built-in variables In addition, .Nm sets or knows about the following variables: @@ -593,23 +660,34 @@ The list of makefiles read by .Nm , which is useful for tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. +.It Va .MAKE.LEVEL +The recursion depth of +.Nm . +The initial instance of +.Nm +will be 0, and an incremented value is put into the environment +to be seen by the next generation. +This allows tests like: +.Li .if ${.MAKE.LEVEL} == 0 +to protect things which should only be evaluated in the initial instance of +.Nm . .It Va .MAKE.PID -The process-id of +The process-id of .Nm . .It Va .MAKE.PPID -The parent process-id of +The parent process-id of .Nm . .It Va .MAKE.JOB.PREFIX -If +If .Nm is run with .Ar j -then output for each target is prefixed with a token +then output for each target is prefixed with a token .Ql --- target --- the first part of which can be controlled via .Va .MAKE.JOB.PREFIX . .br -For example: +For example: .Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] would produce tokens like .Ql ---make[1234] target --- @@ -694,7 +772,7 @@ may be used. .Pp .Ql Va .OBJDIR may be modified in the makefile as a global variable. -In all cases, +In all cases, .Nm will .Xr chdir 2 @@ -751,10 +829,22 @@ is set to the value of for all programs which .Nm executes. +.It Ev VPATH +Colon-separated +.Pq Dq \&: +lists of directories that +.Nm +will search for files. +The variable is supported for compatibility with old make programs only, +use +.Ql Va .PATH +instead. .El .Ss Variable modifiers Variable expansion may be modified to select or modify each word of the -variable (where a ``word'' is white-space delimited sequence of characters). +variable (where a +.Dq word +is white-space delimited sequence of characters). The general format of a variable expansion is as follows: .Pp .Dl ${variable[:modifier[:...]]} @@ -963,11 +1053,16 @@ Remove adjacent duplicate words (like .Sm off .It Cm \&:\&? Ar true_string Cm \&: Ar false_string .Sm on -If the variable (actually an expression; see below) -evaluates to true, return as its value the +If the variable name (not its value), when parsed as a .if conditional +expression, evaluates to true, return as its value the .Ar true_string , otherwise return the .Ar false_string . +Since the variable name is used as the expression, \&:\&? must be the +first modifier after the variable name itself - which will, of course, +usually contain variable expansions. +If the expression is a single token, it will likely be treated as a check +for the name being defined. .It Ar :old_string=new_string This is the .At V @@ -1052,25 +1147,14 @@ The variable is assigned the value .Ar str after substitution. This modifier and its variations are useful in -obscure situations such as wanting to apply modifiers to -.Cm \&.for -loop iteration variables which won't work due to the way -.Cm \&.for -loops are implemented. +obscure situations such as wanting to set a variable when shell commands +are being parsed. These assignment modifiers always expand to nothing, so if appearing in a rule line by themselves should be preceded with something to keep .Nm happy. -As in: -.Bd -literal -use_foo: \&.USE -\&.for i in ${\&.TARGET} ${\&.TARGET:R}\&.gz - @: ${t::=$i} - @echo t:R:T=${t:R:T} -\&.endfor - -.Ed +.Pp The .Ql Cm \&:: helps avoid false matches with the @@ -1199,8 +1283,7 @@ The possible conditionals are as follows: Export the specified global variable. If no variable is provided, all globals are exported except for internal variables (those that start with -.Ql \&. -). +.Ql \&. ) . This is not affected by the .Fl X flag, so should be used with caution. @@ -1368,19 +1451,25 @@ of a string comparison. .Pp When .Nm -is evaluating one of these conditional expression, and it encounters -a word it doesn't recognize, either the ``make'' or ``defined'' +is evaluating one of these conditional expressions, and it encounters +a (white-space separated) word it doesn't recognize, either the +.Dq make +or +.Dq defined expression is applied to it, depending on the form of the conditional. If the form is -.Ql Ic .ifdef -or +.Ql Ic .ifdef , .Ql Ic .ifndef , -the ``defined'' expression -is applied. +or +.Ql Ic .if +the +.Dq defined +expression is applied. Similarly, if the form is .Ql Ic .ifmake or -.Ql Ic .ifnmake , the ``make'' +.Ql Ic .ifnmake , the +.Dq make expression is applied. .Pp If the conditional evaluates to true the parsing of the makefile continues @@ -1519,9 +1608,9 @@ b1: .Ed the output is always +.Ql a , .Ql b1 , .Ql b , -.Ql a , .Ql x . .br The ordering imposed by @@ -1599,7 +1688,7 @@ could be built, unless is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal -\&.ORDER a b +\&.ORDER: a b b: a .Ed .Pp @@ -1692,6 +1781,14 @@ command in the file. Each source specifies a suffix to .Nm . If no sources are specified, any previously specified suffixes are deleted. +It allows the creation of suffix-transformation rules. +.Pp +Example: +.Bd -literal +\&.SUFFIXES: .o +\&.c.o: + cc -o ${.TARGET} -c ${.IMPSRC} +.Ed .El .Sh ENVIRONMENT .Nm @@ -1703,8 +1800,9 @@ uses the following environment variables, if they exist: .Ev MAKEOBJDIR , .Ev MAKEOBJDIRPREFIX , .Ev MAKESYSPATH , +.Ev PWD , and -.Ev PWD . +.Ev TMPDIR . .Pp .Ev MAKEOBJDIRPREFIX and @@ -1736,6 +1834,12 @@ The way that parallel makes are scheduled changed in .Nx 4.0 so that .ORDER and .WAIT apply recursively to the dependant nodes. The algorithms used may change again in the future. +.Pp +The way that .for loop variables are substituted changed after +.Nx 5.0 +so that they still appear to be variable expansions. +In particular this stops them being treated as syntax, and removes some +obscure problems using them in .if statements. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY diff --git a/devel/bmake/files/bmake.cat1 b/devel/bmake/files/bmake.cat1 index ab7cddc458f..c9f42438d11 100644 --- a/devel/bmake/files/bmake.cat1 +++ b/devel/bmake/files/bmake.cat1 @@ -1,12 +1,13 @@ -MAKE(1) BSD General Commands Manual MAKE(1) +MAKE(1) NetBSD General Commands Manual MAKE(1) NNAAMMEE bbmmaakkee -- maintain program dependencies SSYYNNOOPPSSIISS - bbmmaakkee [--BBeeiikkNNnnqqrrssttWWXX] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] [--ff _m_a_k_e_f_i_l_e] - [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s] [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] - [--VV _v_a_r_i_a_b_l_e] [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] [_t_a_r_g_e_t _._._.] + bbmmaakkee [--BBeeiikkNNnnqqrrssttWWXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s] + [--ff _m_a_k_e_f_i_l_e] [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s] + [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_l_e] [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] + [_t_a_r_g_e_t _._._.] DDEESSCCRRIIPPTTIIOONN bbmmaakkee is a program designed to simplify the maintenance of other pro- @@ -29,6 +30,12 @@ DDEESSCCRRIIPPTTIIOONN command and by executing the commands to make the sources of a dependency line in sequence. + --CC _d_i_r_e_c_t_o_r_y + Change to _d_i_r_e_c_t_o_r_y before reading the makefiles or doing any- + thing else. If multiple --CC options are specified, each is inter- + preted relative to the previous one: --CC _/ --CC _e_t_c is equivalent to + --CC _/_e_t_c. + --DD _v_a_r_i_a_b_l_e Define _v_a_r_i_a_b_l_e to be 1, in the global context. @@ -36,8 +43,12 @@ DDEESSCCRRIIPPTTIIOONN Turn on debugging, and specify which portions of bbmmaakkee are to print debugging information. Unless the flags are preceded by `-' they are added to the _M_A_K_E_F_L_A_G_S environment variable and will - be processed by any child make processes. _F_l_a_g_s is one or more - of the following: + be processed by any child make processes. By default, debugging + information is printed to standard error, but this can be changed + using the _F debugging flag. The debugging output is always + unbuffered; in addition, if debugging is enabled but debugging + output is not directed to standard output, then the standard out- + put is line buffered. _F_l_a_g_s is one or more of the following: _A Print all possible debugging information; equivalent to specifying all of the debugging flags. @@ -45,6 +56,9 @@ DDEESSCCRRIIPPTTIIOONN _a Print debugging information about archive searching and caching. + _C Print debugging information about current working direc- + tory. + _c Print debugging information about conditional evaluation. _d Print debugging information about directory searching and @@ -53,9 +67,18 @@ DDEESSCCRRIIPPTTIIOONN _e Print debugging information about failed commands and targets. - _F Use the rest of `flags' as the name of the file to which - the debug output is written. If the filename ends `.%d' - then the `%d' is replaced by the pid. + _F[++]_f_i_l_e_n_a_m_e + Specify where debugging output is written. This must be + the last flag, because it consumes the remainder of the + argument. If the character immediately after the `F' + flag is `+', then the file will be opened in append mode; + otherwise the file will be overwritten. If the file name + is `stdout' or `stderr' then debugging output will be + written to the standard output or standard error output + file descriptors respectively (and the `+' option has no + effect). Otherwise, the output will be written to the + named file. If the file name ends `.%d' then the `%d' is + replaced by the pid. _f Print debugging information about loop evaluation. @@ -76,10 +99,13 @@ DDEESSCCRRIIPPTTIIOONN _m Print debugging information about making targets, includ- ing modification dates. - _n Don't delete the temporary command scripts created in - _/_t_m_p when running commands. These are created via - mkstemp(3) and have names of the form _/_t_m_p_/_m_a_k_e_X_X_X_X_X. - _N_O_T_E: This can create many file in _/_t_m_p so use with care. + _n Don't delete the temporary command scripts created when + running commands. These temporary scripts are created in + the directory referred to by the TMPDIR environment vari- + able, or in _/_t_m_p if TMPDIR is unset or set to the empty + string. The temporary scripts are created by mkstemp(3), + and have names of the form _m_a_k_e_X_X_X_X_X_X. _N_O_T_E: This can + create many files in TMPDIR or _/_t_m_p, so use with care. _p Print debugging information about makefile parsing. @@ -120,7 +146,13 @@ DDEESSCCRRIIPPTTIIOONN --jj _m_a_x___j_o_b_s Specify the maximum number of jobs that bbmmaakkee may have running at any one time. Turns compatibility mode off, unless the _B flag is - also specified. + also specified. When compatibility mode is off, all commands + associated with a target are executed in a single shell invoca- + tion as opposed to the traditional one shell invocation per line. + This can break traditional scripts which change directories on + each command invocation and then expect to start with a fresh + environment on the next line. It is more efficient to correct + the scripts rather than turn backwards compatibility on. --kk Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation @@ -281,6 +313,14 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS ing braces or parentheses are not required. This shorter form is not recommended. + If the variable name contains a dollar, then the name itself is expanded + first. This allows almost arbitrary variable names, however names con- + taining dollar, braces, parenthesis, or whitespace are really best + avoided! + + If the result of expanding a variable contains a dollar sign (`$') the + string is expanded again. + Variable substitution occurs at two distinct times, depending on where the variable is being used. Variables in dependency lines are expanded as the line is read. Variables in shell commands are expanded when the @@ -308,9 +348,10 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS _._A_R_C_H_I_V_E The name of the archive file. - _._I_M_P_S_R_C The name/path of the source from which the target is to - be transformed (the ``implied'' source); also known as - `_<'. + _._I_M_P_S_R_C In suffix-transformation rules, the name/path of the + source from which the target is to be transformed (the + ``implied'' source); also known as `_<'. It is not + defined in explicit rules. _._M_E_M_B_E_R The name of the archive member. @@ -334,7 +375,7 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS the line. These variables are `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E', and `_._M_E_M_B_E_R'. - AAddddiittiioonnaall iinnbbuuiilltt vvaarriiaabblleess + AAddddiittiioonnaall bbuuiilltt--iinn vvaarriiaabblleess In addition, bbmmaakkee sets or knows about the following variables: _$ A single dollar sign `$', i.e. `$$' expands to a single @@ -361,6 +402,13 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. + _._M_A_K_E_._L_E_V_E_L The recursion depth of bbmmaakkee. The initial instance of + bbmmaakkee will be 0, and an incremented value is put into the + environment to be seen by the next generation. This + allows tests like: .if ${.MAKE.LEVEL} == 0 to protect + things which should only be evaluated in the initial + instance of bbmmaakkee. + _._M_A_K_E_._P_I_D The process-id of bbmmaakkee. _._M_A_K_E_._P_P_I_D The parent process-id of bbmmaakkee. @@ -455,6 +503,11 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS contains a variable transform. `PWD' is set to the value of `_._O_B_J_D_I_R' for all programs which bbmmaakkee executes. + VPATH Colon-separated (``:'') lists of directories that bbmmaakkee + will search for files. The variable is supported for + compatibility with old make programs only, use `_._P_A_T_H' + instead. + VVaarriiaabbllee mmooddiiffiieerrss Variable expansion may be modified to select or modify each word of the variable (where a ``word'' is white-space delimited sequence of charac- @@ -575,9 +628,13 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS ::uu Remove adjacent duplicate words (like uniq(1)). ::??_t_r_u_e___s_t_r_i_n_g::_f_a_l_s_e___s_t_r_i_n_g - If the variable (actually an expression; see below) evaluates to - true, return as its value the _t_r_u_e___s_t_r_i_n_g, otherwise return the - _f_a_l_s_e___s_t_r_i_n_g. + If the variable name (not its value), when parsed as a .if condi- + tional expression, evaluates to true, return as its value the + _t_r_u_e___s_t_r_i_n_g, otherwise return the _f_a_l_s_e___s_t_r_i_n_g. Since the variable + name is used as the expression, :? must be the first modifier after + the variable name itself - which will, of course, usually contain + variable expansions. If the expression is a single token, it will + likely be treated as a check for the name being defined. _:_o_l_d___s_t_r_i_n_g_=_n_e_w___s_t_r_i_n_g This is the AT&T System V UNIX style variable substitution. It must @@ -627,17 +684,10 @@ VVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS ::::==_s_t_r The variable is assigned the value _s_t_r after substitution. This modifier and its variations are useful in obscure situations such as - wanting to apply modifiers to ..ffoorr loop iteration variables which - won't work due to the way ..ffoorr loops are implemented. These assign- - ment modifiers always expand to nothing, so if appearing in a rule - line by themselves should be preceded with something to keep bbmmaakkee - happy. As in: - - use_foo: .USE - .for i in ${.TARGET} ${.TARGET:R}.gz - @: ${t::=$i} - @echo t:R:T=${t:R:T} - .endfor + wanting to set a variable when shell commands are being parsed. + These assignment modifiers always expand to nothing, so if appearing + in a rule line by themselves should be preceded with something to + keep bbmmaakkee happy. The `::::' helps avoid false matches with the AT&T System V UNIX style ::== modifier and since substitution always occurs the ::::== form is @@ -709,7 +759,7 @@ IINNCCLLUUDDEE SSTTAATTEEMMEENNTTSS,, CCOONNDDIITTIIOO ..eexxppoorrtt _v_a_r_i_a_b_l_e Export the specified global variable. If no variable is pro- vided, all globals are exported except for internal variables - (those that start with `.' ). This is not affected by the --XX + (those that start with `.'). This is not affected by the --XX flag, so should be used with caution. Appending a variable name to _._M_A_K_E_._E_X_P_O_R_T_E_D is equivalent to exporting a variable. @@ -798,12 +848,12 @@ IINNCCLLUUDDEE SSTTAATTEEMMEENNTTSS,, CCOONNDDIITTIIOO is assumed that the expanded variable is being compared against 0 or an empty string in the case of a string comparison. - When bbmmaakkee is evaluating one of these conditional expression, and it - encounters a word it doesn't recognize, either the ``make'' or - ``defined'' expression is applied to it, depending on the form of the - conditional. If the form is `..iiffddeeff' or `..iiffnnddeeff', the ``defined'' - expression is applied. Similarly, if the form is `..iiffmmaakkee' or `..iiffnnmmaakkee, - tthhee ````mmaakkee''''' expression is applied. + When bbmmaakkee is evaluating one of these conditional expressions, and it + encounters a (white-space separated) word it doesn't recognize, either + the ``make'' or ``defined'' expression is applied to it, depending on the + form of the conditional. If the form is `..iiffddeeff', `..iiffnnddeeff', or `..iiff' + the ``defined'' expression is applied. Similarly, if the form is + `..iiffmmaakkee' or `..iiffnnmmaakkee, tthhee' ``make'' expression is applied. If the conditional evaluates to true the parsing of the makefile contin- ues as before. If it evaluates to false, the following lines are @@ -894,7 +944,7 @@ SSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS)) b1: echo b1 - the output is always `b1', `b', `a', `x'. + the output is always `a', `b1', `b', `x'. The ordering imposed by ..WWAAIITT is only relevant for parallel makes. @@ -946,7 +996,7 @@ SSPPEECCIIAALL TTAARRGGEETTSS be built, unless `a' is built by another part of the dependency graph, the following is a dependency loop: - .ORDER a b + .ORDER: a b b: a The ordering imposed by ..OORRDDEERR is only relevant for parallel @@ -1008,12 +1058,19 @@ SSPPEECCIIAALL TTAARRGGEETTSS ..SSUUFFFFIIXXEESS Each source specifies a suffix to bbmmaakkee. If no sources are - specified, any previously specified suffixes are deleted. + specified, any previously specified suffixes are deleted. It + allows the creation of suffix-transformation rules. + + Example: + + .SUFFIXES: .o + .c.o: + cc -o ${.TARGET} -c ${.IMPSRC} EENNVVIIRROONNMMEENNTT bbmmaakkee uses the following environment variables, if they exist: MACHINE, MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH, - and PWD. + PWD, and TMPDIR. MAKEOBJDIRPREFIX and MAKEOBJDIR may only be set in the environment or on the command line to bbmmaakkee and not as makefile variables; see the descrip- @@ -1035,6 +1092,11 @@ CCOOMMPPAATTIIBBIILLIITTYY .ORDER and .WAIT apply recursively to the dependant nodes. The algo- rithms used may change again in the future. + The way that .for loop variables are substituted changed after NetBSD 5.0 + so that they still appear to be variable expansions. In particular this + stops them being treated as syntax, and removes some obscure problems + using them in .if statements. + SSEEEE AALLSSOO mkdep(1) @@ -1042,4 +1104,4 @@ HHIISSTTOORRYY bbmmaakkee is derived from NetBSD's make(1). It uses autoconf to facilitate portability to other platforms. -BSD November 19, 2006 BSD +NetBSD 5.0 September 7, 2009 NetBSD 5.0 diff --git a/devel/bmake/files/boot-strap b/devel/bmake/files/boot-strap index 9559e385820..f69ddbae10f 100755 --- a/devel/bmake/files/boot-strap +++ b/devel/bmake/files/boot-strap @@ -21,11 +21,16 @@ # We look for '.bmake-boot-strap.rc' before processing # options. # -# -m "mksrc" +# --share "share_dir" +# Where to put man pages and mk files. +# If $prefix ends in $HOST_TARGET, and $prefix/../share +# exits, the default will be that rather than $prefix/share. +# +# --mksrc "mksrc" # Indicate where the mk files can be found. # Default is ./mk or ../mk, set to 'none' to force # building without "mksrc" but in that case a sys.mk -# needs to exist in the default syspath ($prefix/share/mk) +# needs to exist in the default syspath ($share_dir/mk) # # Possibly useful configure_args: # @@ -51,7 +56,7 @@ # Simon J. Gerraty <sjg@crufty.net> # RCSid: -# $Id: boot-strap,v 1.4 2008/11/11 14:37:05 joerg Exp $ +# $Id: boot-strap,v 1.5 2009/09/18 21:27:25 joerg Exp $ # # @(#) Copyright (c) 2001 Simon J. Gerraty # @@ -118,7 +123,9 @@ do --prefix) prefix=$2; shift 2;; --prefix=*) prefix=`IFS="="; set -- $1; echo $2`; shift;; --src=*) srcdir=`IFS="="; set -- $1; echo $2`; shift;; - --with-mksrc=*) mksrc=`IFS="="; set -- $1; echo $2`; shift;; + --with-mksrc=*|--mksrc=*) mksrc=`IFS="="; set -- $1; echo $2`; shift;; + --share=*) share_dir=`IFS="="; set -- $1; echo $2`; shift;; + --share) share_dir=$2; shift 2;; -s|--src) srcdir=$2; shift 2;; -m|--mksrc) mksrc=$2; shift 2;; -o|--objdir) objdir=$2; shift 2;; @@ -155,7 +162,7 @@ GetDir() { break done } - + srcdir=`GetDir /bmake $srcdir $2 $Mydir ./bmake* $Mydir/../bmake*` [ -d ${srcdir:-/dev/null} ] || Usage case "$mksrc" in @@ -174,10 +181,24 @@ objdir=${objdir:-$OS} [ -d $objdir ] || mkdir $objdir cd $objdir || exit 1 +ShareDir() { + case "/$1" in + */$HOST_TARGET) + if [ -d $1/../share ]; then + echo `dirname $1`/share + return + fi + ;; + esac + echo $1/share +} + +share_dir=${share_dir:-`ShareDir $prefix`} + AddConfigure --prefix= $prefix case "$CONFIGURE_ARGS" in *--with-prefix-sys-path*) ;; # skip -*) AddConfigure --with-default-sys-path= $prefix/share/mk;; +*) AddConfigure --with-default-sys-path= $share_dir/mk;; esac if [ "$mksrc" ]; then AddConfigure --with-mksrc= $mksrc @@ -192,36 +213,54 @@ ${MAKE:-make} -f makefile.boot bootstrap || exit 1 # If -q given, we don't want all the install instructions $quiet exit 0 -make_version=`./bmake -m ./mk -m $prefix/share/mk -m /usr/share/mk -f ./Makefile -V MAKE_VERSION | ( read one two; echo $one )` +make_version=`./bmake -m ./mk -m $share_dir/mk -m /usr/share/mk -f ./Makefile -V MAKE_VERSION | ( read one two; echo $one )` +bmake_version=bmake-$make_version install_prefix() { - bindir=$1/bin - mandir=$1/share/man - mkdir=${2:-$1}/share/mk - echo - echo Commands to install into $1/ - echo - echo mkdir -p $bindir - echo cp $objdir/bmake $bindir/$make_version - echo rm -f $bindir/bmake - echo ln -s $make_version $bindir/bmake - if [ -s bmake.cat1 ]; then - echo mkdir -p $mandir/man1 - echo cp $srcdir/bmake.1 $mandir/man1 - else - echo mkdir -p $mandir/cat1 - echo cp $srcdir/bmake.cat1 $mandir/cat1/bmake.1 - fi - [ "$mksrc" ] && echo $mksrc/install-mk $mkdir + ( + bin_dir= + share_dir= + man_dir= + mk_dir= + while : + do + case "$1" in + *=*) eval "$1"; shift;; + *) break;; + esac + done + bin_dir=${bin_dir:-$1/bin} + share_dir=${share_dir:-`ShareDir $1`} + man_dir=${man_dir:-$share_dir/man} + mk_dir=${mk_dir:-$share_dir/mk} + echo + echo Commands to install into $1/ + echo + echo mkdir -p $bin_dir + echo cp $objdir/bmake $bin_dir/$bmake_version + echo rm -f $bin_dir/bmake + echo ln -s $bmake_version $bin_dir/bmake + if [ -s bmake.cat1 ]; then + echo mkdir -p $man_dir/man1 + echo cp $srcdir/bmake.1 $man_dir/man1 + else + echo mkdir -p $man_dir/cat1 + echo cp $srcdir/bmake.cat1 $man_dir/cat1/bmake.1 + fi + if [ "$mksrc" ]; then + ev=`env | grep '_MK='` + echo $ev sh $mksrc/install-mk $mk_dir + fi + ) } case $prefix/ in $HOME/*) ;; *) CONFIGS=${CONFIGS:-/configs} [ -d $CONFIGS ] && - install_prefix $CONFIGS/$OS/$OSMAJOR.X/$MACHINE_ARCH$prefix + install_prefix mksrc= $CONFIGS/$OS/$OSMAJOR.X/$MACHINE_ARCH$prefix # I like to keep a copy here... - install_prefix $HOME/$HOST_TARGET + install_prefix share_dir=$HOME/share $HOME/$HOST_TARGET ;; esac diff --git a/devel/bmake/files/buf.c b/devel/bmake/files/buf.c index 87507f06559..594bf86b69b 100644 --- a/devel/bmake/files/buf.c +++ b/devel/bmake/files/buf.c @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: buf.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: buf.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: buf.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: buf.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: buf.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -87,7 +87,6 @@ __RCSID("$NetBSD: buf.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); * Functions for automatically-expanded buffers. */ -#include "sprite.h" #include "make.h" #include "buf.h" @@ -95,56 +94,22 @@ __RCSID("$NetBSD: buf.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); #define max(a,b) ((a) > (b) ? (a) : (b)) #endif -/* - * BufExpand -- - * Expand the given buffer to hold the given number of additional - * bytes. - * Makes sure there's room for an extra NULL byte at the end of the - * buffer in case it holds a string. - */ -#define BufExpand(bp,nb) \ - while (bp->left < (nb)+1) {\ - int newSize = (bp)->size * 2; \ - Byte *newBuf = (Byte *)bmake_realloc((bp)->buffer, newSize); \ - \ - (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \ - (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer);\ - (bp)->buffer = newBuf;\ - (bp)->size = newSize;\ - (bp)->left = newSize - ((bp)->inPtr - (bp)->buffer);\ - } - #define BUF_DEF_SIZE 256 /* Default buffer size */ /*- *----------------------------------------------------------------------- - * Buf_OvAddByte -- - * Add a single byte to the buffer. left is zero or negative. - * - * Results: - * None. - * - * Side Effects: - * The buffer may be expanded. + * Buf_Expand_1 -- + * Extend buffer for single byte add. * *----------------------------------------------------------------------- */ void -Buf_OvAddByte(Buffer bp, int byte) +Buf_Expand_1(Buffer *bp) { - int nbytes = 1; - bp->left = 0; - BufExpand(bp, nbytes); - - *bp->inPtr++ = byte; - bp->left--; - - /* - * Null-terminate - */ - *bp->inPtr = 0; + bp->size += max(bp->size, 16); + bp->buffer = bmake_realloc(bp->buffer, bp->size); } - + /*- *----------------------------------------------------------------------- * Buf_AddBytes -- @@ -159,21 +124,22 @@ Buf_OvAddByte(Buffer bp, int byte) *----------------------------------------------------------------------- */ void -Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr) +Buf_AddBytes(Buffer *bp, int numBytes, const Byte *bytesPtr) { + int count = bp->count; + Byte *ptr; - BufExpand(bp, numBytes); - - memcpy(bp->inPtr, bytesPtr, numBytes); - bp->inPtr += numBytes; - bp->left -= numBytes; + if (__predict_false(count + numBytes >= bp->size)) { + bp->size += max(bp->size, numBytes + 16); + bp->buffer = bmake_realloc(bp->buffer, bp->size); + } - /* - * Null-terminate - */ - *bp->inPtr = 0; + ptr = bp->buffer + count; + bp->count = count + numBytes; + ptr[numBytes] = 0; + memcpy(ptr, bytesPtr, numBytes); } - + /*- *----------------------------------------------------------------------- * Buf_GetAll -- @@ -188,19 +154,18 @@ Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr) *----------------------------------------------------------------------- */ Byte * -Buf_GetAll(Buffer bp, int *numBytesPtr) +Buf_GetAll(Buffer *bp, int *numBytesPtr) { - if (numBytesPtr != NULL) { - *numBytesPtr = bp->inPtr - bp->outPtr; - } + if (numBytesPtr != NULL) + *numBytesPtr = bp->count; - return (bp->outPtr); + return (bp->buffer); } - + /*- *----------------------------------------------------------------------- - * Buf_Discard -- + * Buf_Empty -- * Throw away bytes in a buffer. * * Results: @@ -212,38 +177,13 @@ Buf_GetAll(Buffer bp, int *numBytesPtr) *----------------------------------------------------------------------- */ void -Buf_Discard(Buffer bp, int numBytes) +Buf_Empty(Buffer *bp) { - if (bp->inPtr - bp->outPtr <= numBytes) { - bp->inPtr = bp->outPtr = bp->buffer; - bp->left = bp->size; - *bp->inPtr = 0; - } else { - bp->outPtr += numBytes; - } -} - -/*- - *----------------------------------------------------------------------- - * Buf_Size -- - * Returns the number of bytes in the given buffer. Doesn't include - * the null-terminating byte. - * - * Results: - * The number of bytes. - * - * Side Effects: - * None. - * - *----------------------------------------------------------------------- - */ -int -Buf_Size(Buffer buf) -{ - return (buf->inPtr - buf->outPtr); + bp->count = 0; + *bp->buffer = 0; } - + /*- *----------------------------------------------------------------------- * Buf_Init -- @@ -262,24 +202,18 @@ Buf_Size(Buffer buf) * *----------------------------------------------------------------------- */ -Buffer -Buf_Init(int size) +void +Buf_Init(Buffer *bp, int size) { - Buffer bp; /* New Buffer */ - - bp = bmake_malloc(sizeof(*bp)); - if (size <= 0) { size = BUF_DEF_SIZE; } - bp->left = bp->size = size; + bp->size = size; + bp->count = 0; bp->buffer = bmake_malloc(size); - bp->inPtr = bp->outPtr = bp->buffer; - *bp->inPtr = 0; - - return (bp); + *bp->buffer = 0; } - + /*- *----------------------------------------------------------------------- * Buf_Destroy -- @@ -290,46 +224,27 @@ Buf_Init(int size) * freeData TRUE if the data should be destroyed * * Results: - * None. + * Data buffer, NULL if freed * * Side Effects: * The buffer is freed. * *----------------------------------------------------------------------- */ -void -Buf_Destroy(Buffer buf, Boolean freeData) +Byte * +Buf_Destroy(Buffer *buf, Boolean freeData) { + Byte *data; + data = buf->buffer; if (freeData) { - free(buf->buffer); + free(data); + data = NULL; } - free(buf); -} - -/*- - *----------------------------------------------------------------------- - * Buf_ReplaceLastByte -- - * Replace the last byte in a buffer. - * - * Input: - * buf buffer to augment - * byte byte to be written - * - * Results: - * None. - * - * Side Effects: - * If the buffer was empty intially, then a new byte will be added. - * Otherwise, the last byte is overwritten. - * - *----------------------------------------------------------------------- - */ -void -Buf_ReplaceLastByte(Buffer buf, int byte) -{ - if (buf->inPtr == buf->outPtr) - Buf_AddByte(buf, byte); - else - *(buf->inPtr - 1) = byte; + + buf->size = 0; + buf->count = 0; + buf->buffer = NULL; + + return data; } diff --git a/devel/bmake/files/buf.h b/devel/bmake/files/buf.h index a2c04560af3..9bf4033092f 100644 --- a/devel/bmake/files/buf.h +++ b/devel/bmake/files/buf.h @@ -1,4 +1,4 @@ -/* $NetBSD: buf.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: buf.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -80,32 +80,39 @@ #ifndef _BUF_H #define _BUF_H -#include "sprite.h" - typedef char Byte; typedef struct Buffer { int size; /* Current size of the buffer */ - int left; /* Space left (== size - (inPtr - buffer)) */ - Byte *buffer; /* The buffer itself */ - Byte *inPtr; /* Place to write to */ - Byte *outPtr; /* Place to read from */ -} *Buffer; + int count; /* Number of bytes in buffer */ + Byte *buffer; /* The buffer itself (zero terminated) */ +} Buffer; + +/* If we aren't on netbsd, __predict_false() might not be defined. */ +#ifndef __predict_false +#define __predict_false(x) (x) +#endif /* Buf_AddByte adds a single byte to a buffer. */ -#define Buf_AddByte(bp, byte) \ - (void) (--(bp)->left <= 0 ? Buf_OvAddByte(bp, byte), 1 : \ - (*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1) +#define Buf_AddByte(bp, byte) do { \ + int _count = ++(bp)->count; \ + char *_ptr; \ + if (__predict_false(_count >= (bp)->size)) \ + Buf_Expand_1(bp); \ + _ptr = (bp)->buffer + _count; \ + _ptr[-1] = (byte); \ + _ptr[0] = 0; \ + } while (0) #define BUF_ERROR 256 -void Buf_OvAddByte(Buffer, int); -void Buf_AddBytes(Buffer, int, const Byte *); -Byte *Buf_GetAll(Buffer, int *); -void Buf_Discard(Buffer, int); -int Buf_Size(Buffer); -Buffer Buf_Init(int); -void Buf_Destroy(Buffer, Boolean); -void Buf_ReplaceLastByte(Buffer, int); +#define Buf_Size(bp) ((bp)->count) + +void Buf_Expand_1(Buffer *); +void Buf_AddBytes(Buffer *, int, const Byte *); +Byte *Buf_GetAll(Buffer *, int *); +void Buf_Empty(Buffer *); +void Buf_Init(Buffer *, int); +Byte *Buf_Destroy(Buffer *, Boolean); #endif /* _BUF_H */ diff --git a/devel/bmake/files/compat.c b/devel/bmake/files/compat.c index 335ae9c9e24..ce5e9abf67d 100644 --- a/devel/bmake/files/compat.c +++ b/devel/bmake/files/compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.4 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: compat.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: compat.c,v 1.4 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: compat.c,v 1.4 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: compat.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -122,7 +122,7 @@ __RCSID("$NetBSD: compat.c,v 1.4 2008/03/09 19:54:29 joerg Exp $"); static char meta[256]; -static GNode *curTarg = NILGNODE; +static GNode *curTarg = NULL; static GNode *ENDNode; static void CompatInterrupt(int); @@ -162,7 +162,7 @@ CompatInterrupt(int signo) { GNode *gn; - if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) { + if ((curTarg != NULL) && !Targ_Precious (curTarg)) { char *p1; char *file = Var_Value(TARGET, curTarg, &p1); @@ -177,7 +177,7 @@ CompatInterrupt(int signo) */ if (signo == SIGINT) { gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE); - if (gn != NILGNODE) { + if (gn != NULL) { Compat_Make(gn, gn); } } @@ -205,7 +205,7 @@ CompatInterrupt(int signo) *----------------------------------------------------------------------- */ int -CompatRunCommand(ClientData cmdp, ClientData gnp) +CompatRunCommand(void *cmdp, void *gnp) { char *cmdStart; /* Start of expanded command */ char *cp, *bp; @@ -214,8 +214,8 @@ CompatRunCommand(ClientData cmdp, ClientData gnp) volatile Boolean errCheck; /* Check errors */ WAIT_T reason; /* Reason for child's death */ int status; /* Description of child's death */ - int cpid; /* Child actually found */ - ReturnStatus retstat; /* Status of fork */ + pid_t cpid; /* Child actually found */ + pid_t retstat; /* Result of wait */ LstNode cmdNode; /* Node where current command is located */ const char ** volatile av; /* Argument vector for thing to exec */ char ** volatile mav;/* Copy of the argument vector for freeing */ @@ -246,15 +246,15 @@ CompatRunCommand(ClientData cmdp, ClientData gnp) free(cmdStart); Error("%s expands to empty string", cmd); return(0); - } else { - cmd = cmdStart; } + cmd = cmdStart; Lst_Replace(cmdNode, cmdStart); if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { (void)Lst_AtEnd(ENDNode->commands, cmdStart); return(0); - } else if (strcmp(cmdStart, "...") == 0) { + } + if (strcmp(cmdStart, "...") == 0) { gn->type |= OP_SAVE_CMDS; return(0); } @@ -315,7 +315,10 @@ CompatRunCommand(ClientData cmdp, ClientData gnp) if (!doIt && NoExecute(gn)) { return (0); } + if (DEBUG(JOB)) + fprintf(debug_file, "Execute: '%s'\n", cmd); +again: if (useShell) { /* * We need to pass the command off to the shell, typically @@ -342,7 +345,11 @@ CompatRunCommand(ClientData cmdp, ClientData gnp) * No meta-characters, so no need to exec a shell. Break the command * into words to form an argument vector we can execute. */ - mav = brk_string(cmd, &argc, TRUE, &bp); + mav = brk_string(cmd, &argc, TRUE, &bp); + if (mav == NULL) { + useShell = 1; + goto again; + } av = (const char **)mav; } @@ -459,7 +466,7 @@ CompatRunCommand(ClientData cmdp, ClientData gnp) *----------------------------------------------------------------------- */ int -Compat_Make(ClientData gnp, ClientData pgnp) +Compat_Make(void *gnp, void *pgnp) { GNode *gn = (GNode *)gnp; GNode *pgn = (GNode *)pgnp; @@ -486,7 +493,7 @@ Compat_Make(ClientData gnp, ClientData pgnp) goto cohorts; } - if (Lst_Member(gn->iParents, pgn) != NILLNODE) { + if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); if (p1) @@ -546,7 +553,7 @@ Compat_Make(ClientData gnp, ClientData pgnp) if (!touchFlag || (gn->type & OP_MAKE)) { curTarg = gn; Lst_ForEach(gn->commands, CompatRunCommand, gn); - curTarg = NILGNODE; + curTarg = NULL; } else { Job_Touch(gn, gn->type & OP_SILENT); } @@ -580,7 +587,7 @@ Compat_Make(ClientData gnp, ClientData pgnp) */ pgn->flags &= ~REMAKE; } else { - if (Lst_Member(gn->iParents, pgn) != NILLNODE) { + if (Lst_Member(gn->iParents, pgn) != NULL) { char *p1; Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); if (p1) @@ -658,7 +665,7 @@ Compat_Run(Lst targs) */ if (!queryFlag) { gn = Targ_FindNode(".BEGIN", TARG_NOCREATE); - if (gn != NILGNODE) { + if (gn != NULL) { Compat_Make(gn, gn); if (gn->made == ERROR) { PrintOnError("\n\nStop."); diff --git a/devel/bmake/files/cond.c b/devel/bmake/files/cond.c index 16aeb8b1477..9e0f7f39a68 100644 --- a/devel/bmake/files/cond.c +++ b/devel/bmake/files/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.4 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: cond.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: cond.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: cond.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: cond.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: cond.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -92,6 +92,7 @@ __RCSID("$NetBSD: cond.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); */ #include <ctype.h> +#include <errno.h> /* For strtoul() error checking */ #include "make.h" #include "hash.h" @@ -123,15 +124,16 @@ __RCSID("$NetBSD: cond.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); * is applied. * * Tokens are scanned from the 'condExpr' string. The scanner (CondToken) - * will return And for '&' and '&&', Or for '|' and '||', Not for '!', - * LParen for '(', RParen for ')' and will evaluate the other terminal + * will return TOK_AND for '&' and '&&', TOK_OR for '|' and '||', TOK_NOT for '!', + * TOK_LPAREN for '(', TOK_RPAREN for ')' and will evaluate the other terminal * symbols, using either the default function or the function given in the - * terminal, and return the result as either True or False. + * terminal, and return the result as either TOK_TRUE or TOK_FALSE. * - * All Non-Terminal functions (CondE, CondF and CondT) return Err on error. + * All Non-Terminal functions (CondE, CondF and CondT) return TOK_ERROR on error. */ typedef enum { - And, Or, Not, True, False, LParen, RParen, EndOfFile, None, Err + TOK_AND, TOK_OR, TOK_NOT, TOK_TRUE, TOK_FALSE, TOK_LPAREN, TOK_RPAREN, + TOK_EOF, TOK_NONE, TOK_ERROR } Token; /*- @@ -139,24 +141,25 @@ typedef enum { * last two fields are stored in condInvert and condDefProc, respectively. */ static void CondPushBack(Token); -static int CondGetArg(char **, char **, const char *, Boolean); -static Boolean CondDoDefined(int, char *); -static int CondStrMatch(ClientData, ClientData); -static Boolean CondDoMake(int, char *); -static Boolean CondDoExists(int, char *); -static Boolean CondDoTarget(int, char *); -static Boolean CondDoCommands(int, char *); -static char * CondCvtArg(char *, double *); +static int CondGetArg(char **, char **, const char *); +static Boolean CondDoDefined(int, const char *); +static int CondStrMatch(const void *, const void *); +static Boolean CondDoMake(int, const char *); +static Boolean CondDoExists(int, const char *); +static Boolean CondDoTarget(int, const char *); +static Boolean CondDoCommands(int, const char *); +static Boolean CondCvtArg(char *, double *); static Token CondToken(Boolean); static Token CondT(Boolean); static Token CondF(Boolean); static Token CondE(Boolean); +static int do_Cond_EvalExpression(Boolean *); static const struct If { const char *form; /* Form of if */ int formlen; /* Length of form */ Boolean doNot; /* TRUE if default function should be negated */ - Boolean (*defProc)(int, char *); /* Default function to apply */ + Boolean (*defProc)(int, const char *); /* Default function to apply */ } ifs[] = { { "def", 3, FALSE, CondDoDefined }, { "ndef", 4, TRUE, CondDoDefined }, @@ -166,10 +169,9 @@ static const struct If { { NULL, 0, FALSE, NULL } }; -static Boolean condInvert; /* Invert the default function */ -static Boolean (*condDefProc)(int, char *); /* Default function to apply */ +static const struct If *if_info; /* Info for current statement */ static char *condExpr; /* The expression to parse */ -static Token condPushBack=None; /* Single push-back token used in +static Token condPushBack=TOK_NONE; /* Single push-back token used in * parsing */ static unsigned int cond_depth = 0; /* current .if nesting level */ @@ -222,21 +224,18 @@ CondPushBack(Token t) *----------------------------------------------------------------------- */ static int -CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens) +CondGetArg(char **linePtr, char **argPtr, const char *func) { char *cp; int argLen; Buffer buf; + int paren_depth; + char ch; cp = *linePtr; - if (parens) { - while (*cp != '(' && *cp != '\0') { - cp++; - } - if (*cp == '(') { - cp++; - } - } + if (func != NULL) + /* Skip opening '(' - verfied by caller */ + cp++; if (*cp == '\0') { /* @@ -257,9 +256,15 @@ CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens) * Create a buffer for the argument and start it out at 16 characters * long. Why 16? Why not? */ - buf = Buf_Init(16); + Buf_Init(&buf, 16); - while ((strchr(" \t)&|", *cp) == NULL) && (*cp != '\0')) { + paren_depth = 0; + for (;;) { + ch = *cp; + if (ch == 0 || ch == ' ' || ch == '\t') + break; + if ((ch == '&' || ch == '|') && paren_depth == 0) + break; if (*cp == '$') { /* * Parse the variable spec and install it as part of the argument @@ -272,32 +277,32 @@ CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens) void *freeIt; cp2 = Var_Parse(cp, VAR_CMD, TRUE, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_AddBytes(&buf, strlen(cp2), cp2); if (freeIt) free(freeIt); cp += len; - } else { - Buf_AddByte(buf, (Byte)*cp); - cp++; + continue; } + if (ch == '(') + paren_depth++; + else + if (ch == ')' && --paren_depth < 0) + break; + Buf_AddByte(&buf, *cp); + cp++; } - Buf_AddByte(buf, (Byte)'\0'); - *argPtr = (char *)Buf_GetAll(buf, &argLen); - Buf_Destroy(buf, FALSE); + *argPtr = Buf_GetAll(&buf, &argLen); + Buf_Destroy(&buf, FALSE); while (*cp == ' ' || *cp == '\t') { cp++; } - if (parens && *cp != ')') { + + if (func != NULL && *cp++ != ')') { Parse_Error(PARSE_WARNING, "Missing closing parenthesis for %s()", func); return (0); - } else if (parens) { - /* - * Advance pointer past close parenthesis. - */ - cp++; } *linePtr = cp; @@ -318,13 +323,11 @@ CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens) *----------------------------------------------------------------------- */ static Boolean -CondDoDefined(int argLen, char *arg) +CondDoDefined(int argLen, const char *arg) { - char savec = arg[argLen]; char *p1; Boolean result; - arg[argLen] = '\0'; if (Var_Value(arg, VAR_CMD, &p1) != NULL) { result = TRUE; } else { @@ -332,7 +335,6 @@ CondDoDefined(int argLen, char *arg) } if (p1) free(p1); - arg[argLen] = savec; return (result); } @@ -351,9 +353,9 @@ CondDoDefined(int argLen, char *arg) *----------------------------------------------------------------------- */ static int -CondStrMatch(ClientData string, ClientData pattern) +CondStrMatch(const void *string, const void *pattern) { - return(!Str_Match((char *)string,(char *)pattern)); + return(!Str_Match(string, pattern)); } /*- @@ -370,19 +372,9 @@ CondStrMatch(ClientData string, ClientData pattern) *----------------------------------------------------------------------- */ static Boolean -CondDoMake(int argLen, char *arg) +CondDoMake(int argLen, const char *arg) { - char savec = arg[argLen]; - Boolean result; - - arg[argLen] = '\0'; - if (Lst_Find(create, arg, CondStrMatch) == NILLNODE) { - result = FALSE; - } else { - result = TRUE; - } - arg[argLen] = savec; - return (result); + return Lst_Find(create, arg, CondStrMatch) != NULL; } /*- @@ -399,13 +391,11 @@ CondDoMake(int argLen, char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoExists(int argLen, char *arg) +CondDoExists(int argLen, const char *arg) { - char savec = arg[argLen]; Boolean result; char *path; - arg[argLen] = '\0'; path = Dir_FindFile(arg, dirSearchPath); if (path != NULL) { result = TRUE; @@ -413,7 +403,6 @@ CondDoExists(int argLen, char *arg) } else { result = FALSE; } - arg[argLen] = savec; if (DEBUG(COND)) { fprintf(debug_file, "exists(%s) result is \"%s\"\n", arg, path ? path : ""); @@ -435,21 +424,12 @@ CondDoExists(int argLen, char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoTarget(int argLen, char *arg) +CondDoTarget(int argLen, const char *arg) { - char savec = arg[argLen]; - Boolean result; GNode *gn; - arg[argLen] = '\0'; gn = Targ_FindNode(arg, TARG_NOCREATE); - if ((gn != NILGNODE) && !OP_NOP(gn->type)) { - result = TRUE; - } else { - result = FALSE; - } - arg[argLen] = savec; - return (result); + return (gn != NULL) && !OP_NOP(gn->type); } /*- @@ -468,67 +448,51 @@ CondDoTarget(int argLen, char *arg) *----------------------------------------------------------------------- */ static Boolean -CondDoCommands(int argLen, char *arg) +CondDoCommands(int argLen, const char *arg) { - char savec = arg[argLen]; - Boolean result; GNode *gn; - arg[argLen] = '\0'; gn = Targ_FindNode(arg, TARG_NOCREATE); - if ((gn != NILGNODE) && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands)) { - result = TRUE; - } else { - result = FALSE; - } - arg[argLen] = savec; - return (result); + return (gn != NULL) && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands); } /*- *----------------------------------------------------------------------- * CondCvtArg -- - * Convert the given number into a double. If the number begins - * with 0x, it is interpreted as a hexadecimal integer - * and converted to a double from there. All other strings just have - * strtod called on them. + * Convert the given number into a double. + * We try a base 10 or 16 integer conversion first, if that fails + * then we try a floating point conversion instead. * * Results: * Sets 'value' to double value of string. - * Returns NULL if string was fully consumed, - * else returns remaining input. - * - * Side Effects: - * Can change 'value' even if string is not a valid number. - * + * Returns 'true' if the convertion suceeded * *----------------------------------------------------------------------- */ -static char * +static Boolean CondCvtArg(char *str, double *value) { - if ((*str == '0') && (str[1] == 'x')) { - long i; - - for (str += 2, i = 0; *str; str++) { - int x; - if (isdigit((unsigned char) *str)) - x = *str - '0'; - else if (isxdigit((unsigned char) *str)) - x = 10 + *str - isupper((unsigned char) *str) ? 'A' : 'a'; - else - break; - i = (i << 4) + x; - } - *value = (double) i; - return *str ? str : NULL; + char *eptr, ech; + unsigned long l_val; + double d_val; + + errno = 0; + l_val = strtoul(str, &eptr, str[1] == 'x' ? 16 : 10); + ech = *eptr; + if (ech == 0 && errno != ERANGE) { + d_val = str[0] == '-' ? -(double)-l_val : (double)l_val; } else { - char *eptr; - *value = strtod(str, &eptr); - return *eptr ? eptr : NULL; + if (ech != 0 && ech != '.' && ech != 'e' && ech != 'E') + return FALSE; + d_val = strtod(str, &eptr); + if (*eptr) + return FALSE; } + + *value = d_val; + return TRUE; } - + /*- *----------------------------------------------------------------------- * CondGetString -- @@ -558,7 +522,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) int qt; char *start; - buf = Buf_Init(0); + Buf_Init(&buf, 0); str = NULL; *freeIt = NULL; *quoted = qt = *condExpr == '"' ? 1 : 0; @@ -569,7 +533,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) case '\\': if (condExpr[1] != '\0') { condExpr++; - Buf_AddByte(buf, (Byte)*condExpr); + Buf_AddByte(&buf, *condExpr); } break; case '"': @@ -577,7 +541,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) condExpr++; /* we don't want the quotes */ goto got_str; } else - Buf_AddByte(buf, (Byte)*condExpr); /* likely? */ + Buf_AddByte(&buf, *condExpr); /* likely? */ break; case ')': case '!': @@ -589,7 +553,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) if (!qt) goto got_str; else - Buf_AddByte(buf, (Byte)*condExpr); + Buf_AddByte(&buf, *condExpr); break; case '$': /* if we are in quotes, then an undefined variable is ok */ @@ -623,7 +587,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) * Nope, we better copy str to buf */ for (cp = str; *cp; cp++) { - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(&buf, *cp); } if (*freeIt) { free(*freeIt); @@ -633,16 +597,15 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) condExpr--; /* don't skip over next char */ break; default: - Buf_AddByte(buf, (Byte)*condExpr); + Buf_AddByte(&buf, *condExpr); break; } } got_str: - Buf_AddByte(buf, (Byte)'\0'); - str = (char *)Buf_GetAll(buf, NULL); + str = Buf_GetAll(&buf, NULL); *freeIt = str; cleanup: - Buf_Destroy(buf, FALSE); + Buf_Destroy(&buf, FALSE); return str; } @@ -655,381 +618,367 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt) * A Token for the next lexical token in the stream. * * Side Effects: - * condPushback will be set back to None if it is used. + * condPushback will be set back to TOK_NONE if it is used. * *----------------------------------------------------------------------- */ static Token -CondToken(Boolean doEval) +compare_expression(Boolean doEval) { - Token t; + Token t; + char *lhs; + char *rhs; + char *op; + void *lhsFree; + void *rhsFree; + Boolean lhsQuoted; + Boolean rhsQuoted; + double left, right; + + t = TOK_ERROR; + rhs = NULL; + lhsFree = rhsFree = FALSE; + lhsQuoted = rhsQuoted = FALSE; + + /* + * Parse the variable spec and skip over it, saving its + * value in lhs. + */ + lhs = CondGetString(doEval, &lhsQuoted, &lhsFree); + if (!lhs) + goto done; - if (condPushBack == None) { - while (*condExpr == ' ' || *condExpr == '\t') { - condExpr++; - } - switch (*condExpr) { - case '(': - t = LParen; - condExpr++; - break; - case ')': - t = RParen; - condExpr++; - break; - case '|': - if (condExpr[1] == '|') { - condExpr++; - } - condExpr++; - t = Or; - break; - case '&': - if (condExpr[1] == '&') { - condExpr++; - } - condExpr++; - t = And; - break; - case '!': - t = Not; - condExpr++; - break; - case '#': - case '\n': - case '\0': - t = EndOfFile; - break; - case '"': - case '$': { - char *lhs; - char *rhs; - char *op; - void *lhsFree; - void *rhsFree; - Boolean lhsQuoted; - Boolean rhsQuoted; - -do_compare_setup: - - rhs = NULL; - lhsFree = rhsFree = FALSE; - lhsQuoted = rhsQuoted = FALSE; - - /* - * Parse the variable spec and skip over it, saving its - * value in lhs. - */ - t = Err; - lhs = CondGetString(doEval, &lhsQuoted, &lhsFree); - if (!lhs) { - if (lhsFree) - free(lhsFree); - return Err; - } - /* - * Skip whitespace to get to the operator - */ - while (isspace((unsigned char) *condExpr)) - condExpr++; + /* + * Skip whitespace to get to the operator + */ + while (isspace((unsigned char) *condExpr)) + condExpr++; - /* - * Make sure the operator is a valid one. If it isn't a - * known relational operator, pretend we got a - * != 0 comparison. - */ - op = condExpr; - switch (*condExpr) { - case '!': - case '=': - case '<': - case '>': - if (condExpr[1] == '=') { - condExpr += 2; - } else { - condExpr += 1; - } - break; - default: - op = UNCONST("!="); - if (lhsQuoted) - rhs = UNCONST(""); - else - rhs = UNCONST("0"); - - goto do_compare; - } - while (isspace((unsigned char) *condExpr)) { - condExpr++; - } - if (*condExpr == '\0') { - Parse_Error(PARSE_WARNING, - "Missing right-hand-side of operator"); - goto error; - } - rhs = CondGetString(doEval, &rhsQuoted, &rhsFree); - if (!rhs) { - if (lhsFree) - free(lhsFree); - if (rhsFree) - free(rhsFree); - return Err; - } -do_compare: - if (rhsQuoted || lhsQuoted) { -do_string_compare: - if (((*op != '!') && (*op != '=')) || (op[1] != '=')) { - Parse_Error(PARSE_WARNING, - "String comparison operator should be either == or !="); - goto error; - } - - if (DEBUG(COND)) { - fprintf(debug_file, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n", - lhs, rhs, op); - } - /* - * Null-terminate rhs and perform the comparison. - * t is set to the result. - */ - if (*op == '=') { - t = strcmp(lhs, rhs) ? False : True; - } else { - t = strcmp(lhs, rhs) ? True : False; - } - } else { - /* - * rhs is either a float or an integer. Convert both the - * lhs and the rhs to a double and compare the two. - */ - double left, right; - char *cp; - - if (CondCvtArg(lhs, &left)) - goto do_string_compare; - if ((cp = CondCvtArg(rhs, &right)) && - cp == rhs) - goto do_string_compare; - - if (DEBUG(COND)) { - fprintf(debug_file, "left = %f, right = %f, op = %.2s\n", left, - right, op); - } - switch(op[0]) { - case '!': - if (op[1] != '=') { - Parse_Error(PARSE_WARNING, - "Unknown operator"); - goto error; - } - t = (left != right ? True : False); - break; - case '=': - if (op[1] != '=') { - Parse_Error(PARSE_WARNING, - "Unknown operator"); - goto error; - } - t = (left == right ? True : False); - break; - case '<': - if (op[1] == '=') { - t = (left <= right ? True : False); - } else { - t = (left < right ? True : False); - } - break; - case '>': - if (op[1] == '=') { - t = (left >= right ? True : False); - } else { - t = (left > right ? True : False); - } - break; - } - } -error: - if (lhsFree) - free(lhsFree); - if (rhsFree) - free(rhsFree); - break; + /* + * Make sure the operator is a valid one. If it isn't a + * known relational operator, pretend we got a + * != 0 comparison. + */ + op = condExpr; + switch (*condExpr) { + case '!': + case '=': + case '<': + case '>': + if (condExpr[1] == '=') { + condExpr += 2; + } else { + condExpr += 1; } - default: { - Boolean (*evalProc)(int, char *); - Boolean invert = FALSE; - char *arg = NULL; - int arglen = 0; - - if (istoken(condExpr, "defined", 7)) { - /* - * Use CondDoDefined to evaluate the argument and - * CondGetArg to extract the argument from the 'function - * call'. - */ - evalProc = CondDoDefined; - condExpr += 7; - arglen = CondGetArg(&condExpr, &arg, "defined", TRUE); - if (arglen == 0) { - condExpr -= 7; - goto use_default; - } - } else if (istoken(condExpr, "make", 4)) { - /* - * Use CondDoMake to evaluate the argument and - * CondGetArg to extract the argument from the 'function - * call'. - */ - evalProc = CondDoMake; - condExpr += 4; - arglen = CondGetArg(&condExpr, &arg, "make", TRUE); - if (arglen == 0) { - condExpr -= 4; - goto use_default; - } - } else if (istoken(condExpr, "exists", 6)) { - /* - * Use CondDoExists to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoExists; - condExpr += 6; - arglen = CondGetArg(&condExpr, &arg, "exists", TRUE); - if (arglen == 0) { - condExpr -= 6; - goto use_default; - } - } else if (istoken(condExpr, "empty", 5)) { - /* - * Use Var_Parse to parse the spec in parens and return - * True if the resulting string is empty. - */ - int did_warn, length; - void *freeIt; - char *val; - - condExpr += 5; - - did_warn = 0; - for (arglen = 0; condExpr[arglen] != '\0'; arglen += 1) { - if (condExpr[arglen] == '(') - break; - if (!isspace((unsigned char)condExpr[arglen]) && - !did_warn) { - - Parse_Error(PARSE_WARNING, - "Extra characters after \"empty\""); - did_warn = 1; - } - } - - if (condExpr[arglen] != '\0') { - val = Var_Parse(&condExpr[arglen - 1], VAR_CMD, - FALSE, &length, &freeIt); - if (val == var_Error) { - t = Err; - } else { - /* - * A variable is empty when it just contains - * spaces... 4/15/92, christos - */ - char *p; - for (p = val; *p && isspace((unsigned char)*p); p++) - continue; - t = (*p == '\0') ? True : False; - } - if (freeIt) { - free(freeIt); - } - /* - * Advance condExpr to beyond the closing ). Note that - * we subtract one from arglen + length b/c length - * is calculated from condExpr[arglen - 1]. - */ - condExpr += arglen + length - 1; - } else { - condExpr -= 5; - goto use_default; - } - break; - } else if (istoken(condExpr, "target", 6)) { - /* - * Use CondDoTarget to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoTarget; - condExpr += 6; - arglen = CondGetArg(&condExpr, &arg, "target", TRUE); - if (arglen == 0) { - condExpr -= 6; - goto use_default; - } - } else if (istoken(condExpr, "commands", 8)) { - /* - * Use CondDoCommands to evaluate the argument and - * CondGetArg to extract the argument from the - * 'function call'. - */ - evalProc = CondDoCommands; - condExpr += 8; - arglen = CondGetArg(&condExpr, &arg, "commands", TRUE); - if (arglen == 0) { - condExpr -= 8; - goto use_default; - } - } else { - /* - * The symbol is itself the argument to the default - * function. We advance condExpr to the end of the symbol - * by hand (the next whitespace, closing paren or - * binary operator) and set to invert the evaluation - * function if condInvert is TRUE. - */ - if (isdigit((unsigned char)condExpr[0])) { - /* - * Variables may already be substituted - * by the time we get here. - */ - goto do_compare_setup; - } - use_default: - invert = condInvert; - evalProc = condDefProc; - arglen = CondGetArg(&condExpr, &arg, "", FALSE); - } - - /* - * Evaluate the argument using the set function. If invert - * is TRUE, we invert the sense of the function. - */ - t = (!doEval || (* evalProc) (arglen, arg) ? - (invert ? False : True) : - (invert ? True : False)); - if (arg) - free(arg); - break; + break; + default: + if (!doEval) { + t = TOK_FALSE; + goto done; } + /* For .ifxxx "..." check for non-empty string. */ + if (lhsQuoted) { + t = lhs[0] != 0 ? TOK_TRUE : TOK_FALSE; + goto done; + } + /* For .ifxxx <number> compare against zero */ + if (CondCvtArg(lhs, &left)) { + t = left != 0.0 ? TOK_TRUE : TOK_FALSE; + goto done; + } + /* For .if ${...} check for non-empty string (defProc is ifdef). */ + if (if_info->form[0] == 0) { + t = lhs[0] != 0 ? TOK_TRUE : TOK_FALSE; + goto done; + } + /* Otherwise action default test ... */ + t = if_info->defProc(strlen(lhs), lhs) != if_info->doNot ? TOK_TRUE : TOK_FALSE; + goto done; + } + + while (isspace((unsigned char)*condExpr)) + condExpr++; + + if (*condExpr == '\0') { + Parse_Error(PARSE_WARNING, + "Missing right-hand-side of operator"); + goto done; + } + + rhs = CondGetString(doEval, &rhsQuoted, &rhsFree); + if (!rhs) + goto done; + + if (rhsQuoted || lhsQuoted) { +do_string_compare: + if (((*op != '!') && (*op != '=')) || (op[1] != '=')) { + Parse_Error(PARSE_WARNING, + "String comparison operator should be either == or !="); + goto done; + } + + if (DEBUG(COND)) { + fprintf(debug_file, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n", + lhs, rhs, op); + } + /* + * Null-terminate rhs and perform the comparison. + * t is set to the result. + */ + if (*op == '=') { + t = strcmp(lhs, rhs) ? TOK_FALSE : TOK_TRUE; + } else { + t = strcmp(lhs, rhs) ? TOK_TRUE : TOK_FALSE; } } else { - t = condPushBack; - condPushBack = None; + /* + * rhs is either a float or an integer. Convert both the + * lhs and the rhs to a double and compare the two. + */ + + if (!CondCvtArg(lhs, &left) || !CondCvtArg(rhs, &right)) + goto do_string_compare; + + if (DEBUG(COND)) { + fprintf(debug_file, "left = %f, right = %f, op = %.2s\n", left, + right, op); + } + switch(op[0]) { + case '!': + if (op[1] != '=') { + Parse_Error(PARSE_WARNING, + "Unknown operator"); + goto done; + } + t = (left != right ? TOK_TRUE : TOK_FALSE); + break; + case '=': + if (op[1] != '=') { + Parse_Error(PARSE_WARNING, + "Unknown operator"); + goto done; + } + t = (left == right ? TOK_TRUE : TOK_FALSE); + break; + case '<': + if (op[1] == '=') { + t = (left <= right ? TOK_TRUE : TOK_FALSE); + } else { + t = (left < right ? TOK_TRUE : TOK_FALSE); + } + break; + case '>': + if (op[1] == '=') { + t = (left >= right ? TOK_TRUE : TOK_FALSE); + } else { + t = (left > right ? TOK_TRUE : TOK_FALSE); + } + break; + } } - return (t); + +done: + if (lhsFree) + free(lhsFree); + if (rhsFree) + free(rhsFree); + return t; } - + +static int +get_mpt_arg(char **linePtr, char **argPtr, const char *func) +{ + /* + * Use Var_Parse to parse the spec in parens and return + * TOK_TRUE if the resulting string is empty. + */ + int length; + void *freeIt; + char *val; + char *cp = *linePtr; + + /* We do all the work here and return the result as the length */ + *argPtr = NULL; + + val = Var_Parse(cp - 1, VAR_CMD, FALSE, &length, &freeIt); + /* + * Advance *linePtr to beyond the closing ). Note that + * we subtract one because 'length' is calculated from 'cp - 1'. + */ + *linePtr = cp - 1 + length; + + if (val == var_Error) { + free(freeIt); + return -1; + } + + /* A variable is empty when it just contains spaces... 4/15/92, christos */ + while (isspace(*(unsigned char *)val)) + val++; + + /* + * For consistency with the other functions we can't generate the + * true/false here. + */ + length = *val ? 2 : 1; + if (freeIt) + free(freeIt); + return length; +} + +static Boolean +CondDoEmpty(int arglen, const char *arg) +{ + return arglen == 1; +} + +static Token +compare_function(Boolean doEval) +{ + static const struct fn_def { + const char *fn_name; + int fn_name_len; + int (*fn_getarg)(char **, char **, const char *); + Boolean (*fn_proc)(int, const char *); + } fn_defs[] = { + { "defined", 7, CondGetArg, CondDoDefined }, + { "make", 4, CondGetArg, CondDoMake }, + { "exists", 6, CondGetArg, CondDoExists }, + { "empty", 5, get_mpt_arg, CondDoEmpty }, + { "target", 6, CondGetArg, CondDoTarget }, + { "commands", 8, CondGetArg, CondDoCommands }, + { NULL, 0, NULL, NULL }, + }; + const struct fn_def *fn_def; + Token t; + char *arg = NULL; + int arglen; + char *cp = condExpr; + char *cp1; + + for (fn_def = fn_defs; fn_def->fn_name != NULL; fn_def++) { + if (!istoken(cp, fn_def->fn_name, fn_def->fn_name_len)) + continue; + cp += fn_def->fn_name_len; + /* There can only be whitespace before the '(' */ + while (isspace(*(unsigned char *)cp)) + cp++; + if (*cp != '(') + break; + + arglen = fn_def->fn_getarg(&cp, &arg, fn_def->fn_name); + if (arglen <= 0) { + condExpr = cp; + return arglen < 0 ? TOK_ERROR : TOK_FALSE; + } + /* Evaluate the argument using the required function. */ + t = !doEval || fn_def->fn_proc(arglen, arg) ? TOK_TRUE : TOK_FALSE; + if (arg) + free(arg); + condExpr = cp; + return t; + } + + /* Push anything numeric through the compare expression */ + cp = condExpr; + if (isdigit((unsigned char)cp[0]) || strchr("+-", cp[0])) + return compare_expression(doEval); + + /* + * Most likely we have a naked token to apply the default function to. + * However ".if a == b" gets here when the "a" is unquoted and doesn't + * start with a '$'. This surprises people. + * If what follows the function argument is a '=' or '!' then the syntax + * would be invalid if we did "defined(a)" - so instead treat as an + * expression. + */ + arglen = CondGetArg(&cp, &arg, NULL); + for (cp1 = cp; isspace(*(unsigned char *)cp1); cp1++) + continue; + if (*cp1 == '=' || *cp1 == '!') + return compare_expression(doEval); + condExpr = cp; + + /* + * Evaluate the argument using the default function. + * This path always treats .if as .ifdef. To get here the character + * after .if must have been taken literally, so the argument cannot + * be empty - even if it contained a variable expansion. + */ + t = !doEval || if_info->defProc(arglen, arg) != if_info->doNot ? TOK_TRUE : TOK_FALSE; + if (arg) + free(arg); + return t; +} + +static Token +CondToken(Boolean doEval) +{ + Token t; + + t = condPushBack; + if (t != TOK_NONE) { + condPushBack = TOK_NONE; + return t; + } + + while (*condExpr == ' ' || *condExpr == '\t') { + condExpr++; + } + + switch (*condExpr) { + + case '(': + condExpr++; + return TOK_LPAREN; + + case ')': + condExpr++; + return TOK_RPAREN; + + case '|': + if (condExpr[1] == '|') { + condExpr++; + } + condExpr++; + return TOK_OR; + + case '&': + if (condExpr[1] == '&') { + condExpr++; + } + condExpr++; + return TOK_AND; + + case '!': + condExpr++; + return TOK_NOT; + + case '#': + case '\n': + case '\0': + return TOK_EOF; + + case '"': + case '$': + return compare_expression(doEval); + + default: + return compare_function(doEval); + } +} + /*- *----------------------------------------------------------------------- * CondT -- * Parse a single term in the expression. This consists of a terminal - * symbol or Not and a terminal symbol (not including the binary + * symbol or TOK_NOT and a terminal symbol (not including the binary * operators): * T -> defined(variable) | make(target) | exists(file) | symbol * T -> ! T | ( E ) * * Results: - * True, False or Err. + * TOK_TRUE, TOK_FALSE or TOK_ERROR. * * Side Effects: * Tokens are consumed. @@ -1043,28 +992,28 @@ CondT(Boolean doEval) t = CondToken(doEval); - if (t == EndOfFile) { + if (t == TOK_EOF) { /* * If we reached the end of the expression, the expression * is malformed... */ - t = Err; - } else if (t == LParen) { + t = TOK_ERROR; + } else if (t == TOK_LPAREN) { /* * T -> ( E ) */ t = CondE(doEval); - if (t != Err) { - if (CondToken(doEval) != RParen) { - t = Err; + if (t != TOK_ERROR) { + if (CondToken(doEval) != TOK_RPAREN) { + t = TOK_ERROR; } } - } else if (t == Not) { + } else if (t == TOK_NOT) { t = CondT(doEval); - if (t == True) { - t = False; - } else if (t == False) { - t = True; + if (t == TOK_TRUE) { + t = TOK_FALSE; + } else if (t == TOK_FALSE) { + t = TOK_TRUE; } } return (t); @@ -1077,7 +1026,7 @@ CondT(Boolean doEval) * F -> T && F | T * * Results: - * True, False or Err + * TOK_TRUE, TOK_FALSE or TOK_ERROR * * Side Effects: * Tokens are consumed. @@ -1090,18 +1039,18 @@ CondF(Boolean doEval) Token l, o; l = CondT(doEval); - if (l != Err) { + if (l != TOK_ERROR) { o = CondToken(doEval); - if (o == And) { + if (o == TOK_AND) { /* * F -> T && F * - * If T is False, the whole thing will be False, but we have to + * If T is TOK_FALSE, the whole thing will be TOK_FALSE, but we have to * parse the r.h.s. anyway (to throw it away). - * If T is True, the result is the r.h.s., be it an Err or no. + * If T is TOK_TRUE, the result is the r.h.s., be it an TOK_ERROR or no. */ - if (l == True) { + if (l == TOK_TRUE) { l = CondF(doEval); } else { (void)CondF(FALSE); @@ -1123,7 +1072,7 @@ CondF(Boolean doEval) * E -> F || E | F * * Results: - * True, False or Err. + * TOK_TRUE, TOK_FALSE or TOK_ERROR. * * Side Effects: * Tokens are, of course, consumed. @@ -1136,19 +1085,19 @@ CondE(Boolean doEval) Token l, o; l = CondF(doEval); - if (l != Err) { + if (l != TOK_ERROR) { o = CondToken(doEval); - if (o == Or) { + if (o == TOK_OR) { /* * E -> F || E * * A similar thing occurs for ||, except that here we make sure - * the l.h.s. is False before we bother to evaluate the r.h.s. - * Once again, if l is False, the result is the r.h.s. and once - * again if l is True, we parse the r.h.s. to throw it away. + * the l.h.s. is TOK_FALSE before we bother to evaluate the r.h.s. + * Once again, if l is TOK_FALSE, the result is the r.h.s. and once + * again if l is TOK_TRUE, we parse the r.h.s. to throw it away. */ - if (l == False) { + if (l == TOK_FALSE) { l = CondE(doEval); } else { (void)CondE(FALSE); @@ -1182,44 +1131,64 @@ CondE(Boolean doEval) *----------------------------------------------------------------------- */ int -Cond_EvalExpression(int dosetup, char *line, Boolean *value, int eprint) +Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprint) { - if (dosetup) { - condDefProc = CondDoDefined; - condInvert = 0; - } + static const struct If *dflt_info; + const struct If *sv_if_info = if_info; + char *sv_condExpr = condExpr; + Token sv_condPushBack = condPushBack; + int rval; while (*line == ' ' || *line == '\t') line++; + if (info == NULL && (info = dflt_info) == NULL) { + /* Scan for the entry for .if - it can't be first */ + for (info = ifs; ; info++) + if (info->form[0] == 0) + break; + dflt_info = info; + } + + if_info = info != NULL ? info : ifs + 4; condExpr = line; - condPushBack = None; + condPushBack = TOK_NONE; + + rval = do_Cond_EvalExpression(value); + + if (rval == COND_INVALID && eprint) + Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", line); + + if_info = sv_if_info; + condExpr = sv_condExpr; + condPushBack = sv_condPushBack; + + return rval; +} + +static int +do_Cond_EvalExpression(Boolean *value) +{ switch (CondE(TRUE)) { - case True: - if (CondToken(TRUE) == EndOfFile) { + case TOK_TRUE: + if (CondToken(TRUE) == TOK_EOF) { *value = TRUE; - break; + return COND_PARSE; } - goto err; - /*FALLTHRU*/ - case False: - if (CondToken(TRUE) == EndOfFile) { + break; + case TOK_FALSE: + if (CondToken(TRUE) == TOK_EOF) { *value = FALSE; - break; + return COND_PARSE; } - /*FALLTHRU*/ - case Err: -err: - if (eprint) - Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", - line); - return (COND_INVALID); + break; default: + case TOK_ERROR: break; } - return COND_PARSE; + return COND_INVALID; } @@ -1288,6 +1257,8 @@ Cond_Eval(char *line) } /* Return state for previous conditional */ cond_depth--; + if (cond_depth > MAXIF) + return COND_SKIP; return cond_state[cond_depth] <= ELSE_ACTIVE ? COND_PARSE : COND_SKIP; } @@ -1297,9 +1268,11 @@ Cond_Eval(char *line) /* It is else... */ if (cond_depth == cond_min_depth) { Parse_Error(level, "if-less else"); - return COND_INVALID; + return COND_PARSE; } + if (cond_depth > MAXIF) + return COND_SKIP; state = cond_state[cond_depth]; switch (state) { case SEARCH_FOR_ELIF: @@ -1342,25 +1315,34 @@ Cond_Eval(char *line) } /* Now we know what sort of 'if' it is... */ - state = cond_state[cond_depth]; if (isElif) { if (cond_depth == cond_min_depth) { Parse_Error(level, "if-less elif"); - return COND_INVALID; + return COND_PARSE; } - if (state == SKIP_TO_ENDIF || state == ELSE_ACTIVE) + if (cond_depth > MAXIF) + /* Error reported when we saw the .if ... */ + return COND_SKIP; + state = cond_state[cond_depth]; + if (state == SKIP_TO_ENDIF || state == ELSE_ACTIVE) { Parse_Error(PARSE_WARNING, "extra elif"); + cond_state[cond_depth] = SKIP_TO_ENDIF; + return COND_SKIP; + } if (state != SEARCH_FOR_ELIF) { /* Either just finished the 'true' block, or already SKIP_TO_ELSE */ cond_state[cond_depth] = SKIP_TO_ELSE; return COND_SKIP; } } else { + /* Normal .if */ if (cond_depth >= MAXIF) { + cond_depth++; Parse_Error(PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); - return COND_INVALID; + return COND_SKIP; } + state = cond_state[cond_depth]; cond_depth++; if (state > ELSE_ACTIVE) { /* If we aren't parsing the data, treat as always false */ @@ -1369,15 +1351,12 @@ Cond_Eval(char *line) } } - /* Initialize file-global variables for parsing the expression */ - condDefProc = ifp->defProc; - condInvert = ifp->doNot; - /* And evaluate the conditional expresssion */ - if (Cond_EvalExpression(0, line, &value, 1) == COND_INVALID) { - /* Although we get make to reprocess the line, set a state */ - cond_state[cond_depth] = SEARCH_FOR_ELIF; - return COND_INVALID; + if (Cond_EvalExpression(ifp, line, &value, 1) == COND_INVALID) { + /* Syntax error in conditional, error message already output. */ + /* Skip everything to matching .endif */ + cond_state[cond_depth] = SKIP_TO_ELSE; + return COND_SKIP; } if (!value) { diff --git a/devel/bmake/files/configure b/devel/bmake/files/configure index 50892693033..f3c64c0c1d6 100755 --- a/devel/bmake/files/configure +++ b/devel/bmake/files/configure @@ -7941,11 +7941,6 @@ else diff_u= echo no >&6 fi - -if egrep "__EXTENSIONS__" /usr/include/signal.h >/dev/null 2>&1; then - CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__" -fi - echo "checking for MACHINE & MACHINE_ARCH..." >&6 cat > conftest.$ac_ext <<EOF #include "confdefs.h" diff --git a/devel/bmake/files/configure.in b/devel/bmake/files/configure.in index cc9fec0719d..0306566edec 100644 --- a/devel/bmake/files/configure.in +++ b/devel/bmake/files/configure.in @@ -1,6 +1,6 @@ dnl dnl RCSid: -dnl $Id: configure.in,v 1.8 2008/11/11 19:47:38 joerg Exp $ +dnl $Id: configure.in,v 1.9 2009/09/18 21:27:25 joerg Exp $ dnl dnl Process this file with autoconf to produce a configure script dnl @@ -24,6 +24,10 @@ no) ;; dnl dnl dnl Check for OS problems +dnl Solaris's signal.h only privides sigset_t etc if one of +dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined. +dnl The later two seem to cause more problems than they solve so if we +dnl see _EXTENSIONS_ we use it. AC_USE_SYSTEM_EXTENSIONS dnl Checks for programs. AC_PROG_CC @@ -137,16 +141,6 @@ else echo no >&6 fi dnl -dnl -dnl Solaris's signal.h only privides sigset_t etc if one of -dnl _EXTENSIONS_ _POSIX_C_SOURCE or _XOPEN_SOURCE are defined. -dnl The later two seem to cause more problems than they solve so if we -dnl see _EXTENSIONS_ we use it. -dnl Note we _don't_ want AC_EGREP_HEADER as we don't want CPP involved. -dnl -AC_EGREP(__EXTENSIONS__, /usr/include/signal.h, -CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__",) -dnl dnl AC_* don't quite cut it. dnl echo "checking for MACHINE & MACHINE_ARCH..." >&6 diff --git a/devel/bmake/files/dir.c b/devel/bmake/files/dir.c index 0bba6b1ec21..086c24ca1f9 100644 --- a/devel/bmake/files/dir.c +++ b/devel/bmake/files/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: dir.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: dir.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: dir.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: dir.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -244,12 +244,12 @@ static Hash_Table mtimes; /* Results of doing a last-resort stat in * should be ok, but... */ -static int DirFindName(ClientData, ClientData); +static int DirFindName(const void *, const void *); static int DirMatchFiles(const char *, Path *, Lst); static void DirExpandCurly(const char *, const char *, Lst, Lst); static void DirExpandInt(const char *, Lst, Lst); -static int DirPrintWord(ClientData, ClientData); -static int DirPrintDir(ClientData, ClientData); +static int DirPrintWord(void *, void *); +static int DirPrintDir(void *, void *); static char *DirLookup(Path *, const char *, const char *, Boolean); static char *DirLookupSubdir(Path *, const char *); static char *DirFindDot(Boolean, const char *, const char *); @@ -373,9 +373,9 @@ Dir_End(void) Dir_Destroy(dotLast); Dir_Destroy(dot); Dir_ClearPath(dirSearchPath); - Lst_Destroy(dirSearchPath, NOFREE); + Lst_Destroy(dirSearchPath, NULL); Dir_ClearPath(openDirectories); - Lst_Destroy(openDirectories, NOFREE); + Lst_Destroy(openDirectories, NULL); Hash_DeleteTable(&mtimes); #endif } @@ -395,7 +395,7 @@ Dir_SetPATH(void) Var_Delete(".PATH", VAR_GLOBAL); if (Lst_Open(dirSearchPath) == SUCCESS) { - if ((ln = Lst_First(dirSearchPath)) != NILLNODE) { + if ((ln = Lst_First(dirSearchPath)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) { hasLastDot = TRUE; @@ -410,7 +410,7 @@ Dir_SetPATH(void) Var_Append(".PATH", cur->name, VAR_GLOBAL); } - while ((ln = Lst_Next(dirSearchPath)) != NILLNODE) { + while ((ln = Lst_Next(dirSearchPath)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) continue; @@ -448,9 +448,9 @@ Dir_SetPATH(void) *----------------------------------------------------------------------- */ static int -DirFindName(ClientData p, ClientData dname) +DirFindName(const void *p, const void *dname) { - return (strcmp(((Path *)p)->name, (char *)dname)); + return (strcmp(((const Path *)p)->name, dname)); } /*- @@ -701,7 +701,7 @@ DirExpandInt(const char *word, Lst path, Lst expansions) Path *p; /* Directory in the node */ if (Lst_Open(path) == SUCCESS) { - while ((ln = Lst_Next(path)) != NILLNODE) { + while ((ln = Lst_Next(path)) != NULL) { p = (Path *)Lst_Datum(ln); DirMatchFiles(word, p, expansions); } @@ -724,7 +724,7 @@ DirExpandInt(const char *word, Lst path, Lst expansions) *----------------------------------------------------------------------- */ static int -DirPrintWord(ClientData word, ClientData dummy) +DirPrintWord(void *word, void *dummy) { fprintf(debug_file, "%s ", (char *)word); @@ -814,7 +814,7 @@ Dir_Expand(const char *word, Lst path, Lst expansions) path = Lst_Init(FALSE); (void)Dir_AddDir(path, dirpath); DirExpandInt(cp+1, path, expansions); - Lst_Destroy(path, NOFREE); + Lst_Destroy(path, NULL); } } else { /* @@ -917,6 +917,8 @@ DirLookupSubdir(Path *p, const char *name) } if (stat(file, &stb) == 0) { + if (stb.st_mtime == 0) + stb.st_mtime = 1; /* * Save the modification time so if it's needed, we don't have * to fetch it again. @@ -925,8 +927,8 @@ DirLookupSubdir(Path *p, const char *name) fprintf(debug_file, " Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), file); } - entry = Hash_CreateEntry(&mtimes, (char *)file, NULL); - Hash_SetValue(entry, (long)stb.st_mtime); + entry = Hash_CreateEntry(&mtimes, file, NULL); + Hash_SetTimeValue(entry, stb.st_mtime); nearmisses += 1; return (file); } @@ -1082,10 +1084,10 @@ Dir_FindFile(const char *name, Lst path) fprintf(debug_file, "couldn't open path, file not found\n"); } misses += 1; - return (NULL); + return NULL; } - if ((ln = Lst_First(path)) != NILLNODE) { + if ((ln = Lst_First(path)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) { hasLastDot = TRUE; @@ -1123,7 +1125,7 @@ Dir_FindFile(const char *name, Lst path) return file; } - while ((ln = Lst_Next(path)) != NILLNODE) { + while ((ln = Lst_Next(path)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) continue; @@ -1160,7 +1162,7 @@ Dir_FindFile(const char *name, Lst path) fprintf(debug_file, " failed.\n"); } misses += 1; - return (NULL); + return NULL; } if (name[0] != '/') { @@ -1181,7 +1183,7 @@ Dir_FindFile(const char *name, Lst path) } (void)Lst_Open(path); - while ((ln = Lst_Next(path)) != NILLNODE) { + while ((ln = Lst_Next(path)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) continue; @@ -1215,7 +1217,7 @@ Dir_FindFile(const char *name, Lst path) if (DEBUG(DIR)) { fprintf(debug_file, " Checked . already, returning NULL\n"); } - return(NULL); + return NULL; } } else { /* name[0] == '/' */ @@ -1237,7 +1239,7 @@ Dir_FindFile(const char *name, Lst path) return *file?file:NULL; (void)Lst_Open(path); - while ((ln = Lst_Next(path)) != NILLNODE) { + while ((ln = Lst_Next(path)) != NULL) { p = (Path *)Lst_Datum(ln); if (p == dotLast) continue; @@ -1276,8 +1278,8 @@ Dir_FindFile(const char *name, Lst path) bigmisses += 1; ln = Lst_Last(path); - if (ln == NILLNODE) { - return (NULL); + if (ln == NULL) { + return NULL; } else { p = (Path *)Lst_Datum(ln); } @@ -1285,7 +1287,7 @@ Dir_FindFile(const char *name, Lst path) if (Hash_FindEntry(&p->files, cp) != NULL) { return (bmake_strdup(name)); } else { - return (NULL); + return NULL; } #else /* !notdef */ if (DEBUG(DIR)) { @@ -1300,18 +1302,20 @@ Dir_FindFile(const char *name, Lst path) } return(bmake_strdup(name)); } else if (stat(name, &stb) == 0) { + if (stb.st_mtime == 0) + stb.st_mtime = 1; entry = Hash_CreateEntry(&mtimes, name, NULL); if (DEBUG(DIR)) { fprintf(debug_file, " Caching %s for %s\n", Targ_FmtTime(stb.st_mtime), name); } - Hash_SetValue(entry, (long)stb.st_mtime); + Hash_SetTimeValue(entry, stb.st_mtime); return (bmake_strdup(name)); } else { if (DEBUG(DIR)) { fprintf(debug_file, " failed. Returning NULL\n"); } - return (NULL); + return NULL; } #endif /* notdef */ } @@ -1451,9 +1455,9 @@ Dir_MTime(GNode *gn) */ if (DEBUG(DIR)) { fprintf(debug_file, "Using cached time %s for %s\n", - Targ_FmtTime((time_t)(long)Hash_GetValue(entry)), fullName); + Targ_FmtTime(Hash_GetTimeValue(entry)), fullName); } - stb.st_mtime = (time_t)(long)Hash_GetValue(entry); + stb.st_mtime = Hash_GetTimeValue(entry); Hash_DeleteEntry(&mtimes, entry); } else if (stat(fullName, &stb) < 0) { if (gn->type & OP_MEMBER) { @@ -1463,7 +1467,14 @@ Dir_MTime(GNode *gn) } else { stb.st_mtime = 0; } + } else if (stb.st_mtime == 0) { + /* + * 0 handled specially by the code, if the time is really 0, return + * something else instead + */ + stb.st_mtime = 1; } + if (fullName && gn->path == NULL) { gn->path = fullName; } @@ -1495,14 +1506,14 @@ Dir_MTime(GNode *gn) Path * Dir_AddDir(Lst path, const char *name) { - LstNode ln = NILLNODE; /* node in case Path structure is found */ + LstNode ln = NULL; /* node in case Path structure is found */ Path *p = NULL; /* pointer to new Path structure */ DIR *d; /* for reading directory */ struct dirent *dp; /* entry in directory */ if (strcmp(name, ".DOTLAST") == 0) { - ln = Lst_Find(path, UNCONST(name), DirFindName); - if (ln != NILLNODE) + ln = Lst_Find(path, name, DirFindName); + if (ln != NULL) return (Path *)Lst_Datum(ln); else { dotLast->refCount += 1; @@ -1511,10 +1522,10 @@ Dir_AddDir(Lst path, const char *name) } if (path) - ln = Lst_Find(openDirectories, UNCONST(name), DirFindName); - if (ln != NILLNODE) { + ln = Lst_Find(openDirectories, name, DirFindName); + if (ln != NULL) { p = (Path *)Lst_Datum(ln); - if (path && Lst_Member(path, p) == NILLNODE) { + if (path && Lst_Member(path, p) == NULL) { p->refCount += 1; (void)Lst_AtEnd(path, p); } @@ -1569,8 +1580,8 @@ Dir_AddDir(Lst path, const char *name) * *----------------------------------------------------------------------- */ -ClientData -Dir_CopyDir(ClientData p) +void * +Dir_CopyDir(void *p) { ((Path *)p)->refCount += 1; @@ -1609,7 +1620,7 @@ Dir_MakeFlags(const char *flag, Lst path) str = bmake_strdup(""); if (Lst_Open(path) == SUCCESS) { - while ((ln = Lst_Next(path)) != NILLNODE) { + while ((ln = Lst_Next(path)) != NULL) { p = (Path *)Lst_Datum(ln); s2 = str_concat(flag, p->name, 0); str = str_concat(s1 = str, s2, STR_ADDSPACE); @@ -1641,7 +1652,7 @@ Dir_MakeFlags(const char *flag, Lst path) *----------------------------------------------------------------------- */ void -Dir_Destroy(ClientData pp) +Dir_Destroy(void *pp) { Path *p = (Path *)pp; p->refCount -= 1; @@ -1710,9 +1721,9 @@ Dir_Concat(Lst path1, Lst path2) LstNode ln; Path *p; - for (ln = Lst_First(path2); ln != NILLNODE; ln = Lst_Succ(ln)) { + for (ln = Lst_First(path2); ln != NULL; ln = Lst_Succ(ln)) { p = (Path *)Lst_Datum(ln); - if (Lst_Member(path1, p) == NILLNODE) { + if (Lst_Member(path1, p) == NULL) { p->refCount += 1; (void)Lst_AtEnd(path1, p); } @@ -1733,7 +1744,7 @@ Dir_PrintDirectories(void) hits * 100 / (hits + bigmisses + nearmisses) : 0)); fprintf(debug_file, "# %-20s referenced\thits\n", "directory"); if (Lst_Open(openDirectories) == SUCCESS) { - while ((ln = Lst_Next(openDirectories)) != NILLNODE) { + while ((ln = Lst_Next(openDirectories)) != NULL) { p = (Path *)Lst_Datum(ln); fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); } @@ -1742,7 +1753,7 @@ Dir_PrintDirectories(void) } static int -DirPrintDir(ClientData p, ClientData dummy) +DirPrintDir(void *p, void *dummy) { fprintf(debug_file, "%s ", ((Path *)p)->name); return (dummy ? 0 : 0); diff --git a/devel/bmake/files/dir.h b/devel/bmake/files/dir.h index 6426e5d20a6..71d54f2df69 100644 --- a/devel/bmake/files/dir.h +++ b/devel/bmake/files/dir.h @@ -1,4 +1,4 @@ -/* $NetBSD: dir.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: dir.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -102,7 +102,7 @@ void Dir_ClearPath(Lst); void Dir_Concat(Lst, Lst); void Dir_PrintDirectories(void); void Dir_PrintPath(Lst); -void Dir_Destroy(ClientData); -ClientData Dir_CopyDir(ClientData); +void Dir_Destroy(void *); +void * Dir_CopyDir(void *); #endif /* _DIR */ diff --git a/devel/bmake/files/for.c b/devel/bmake/files/for.c index 2b0a57985d6..644e73bbe8d 100644 --- a/devel/bmake/files/for.c +++ b/devel/bmake/files/for.c @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: for.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -30,14 +30,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: for.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: for.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: for.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: for.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -59,6 +59,11 @@ __RCSID("$NetBSD: for.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); #include "hash.h" #include "dir.h" #include "buf.h" +#include "strlist.h" + +#define FOR_SUB_ESCAPE_CHAR 1 +#define FOR_SUB_ESCAPE_BRACE 2 +#define FOR_SUB_ESCAPE_PAREN 4 /* * For statements are of the form: @@ -85,42 +90,37 @@ static int forLevel = 0; /* Nesting level */ */ typedef struct _For { Buffer buf; /* Body of loop */ - char **vars; /* Iteration variables */ - int nvars; /* # of iteration vars */ - Lst lst; /* List of items */ + strlist_t vars; /* Iteration variables */ + strlist_t items; /* Substitution items */ + char *parse_buf; + int short_var; + int sub_next; } For; -static For accumFor; /* Loop being accumulated */ - -static void ForAddVar(const char *, size_t); - +static For *accumFor; /* Loop being accumulated */ -/*- - *----------------------------------------------------------------------- - * ForAddVar -- - * Add an iteration variable to the currently accumulating for. - * - * Results: none - * Side effects: no additional side effects. - *----------------------------------------------------------------------- - */ -static void -ForAddVar(const char *data, size_t len) +static char * +make_str(const char *ptr, int len) { - Buffer buf; - int varlen; + char *new_ptr; - buf = Buf_Init(0); - Buf_AddBytes(buf, len, (Byte *)UNCONST(data)); - - accumFor.nvars++; - accumFor.vars = bmake_realloc(accumFor.vars, accumFor.nvars*sizeof(char *)); + new_ptr = bmake_malloc(len + 1); + memcpy(new_ptr, ptr, len); + new_ptr[len] = 0; + return new_ptr; +} - accumFor.vars[accumFor.nvars-1] = (char *)Buf_GetAll(buf, &varlen); +static void +For_Free(For *arg) +{ + Buf_Destroy(&arg->buf, TRUE); + strlist_clean(&arg->vars); + strlist_clean(&arg->items); + free(arg->parse_buf); - Buf_Destroy(buf, FALSE); + free(arg); } /*- @@ -134,9 +134,9 @@ ForAddVar(const char *data, size_t len) * line Line to parse * * Results: - * TRUE: We found a for loop, or we are inside a for loop - * FALSE: We did not find a for loop, or we found the end of the for - * for loop. + * 0: Not a .for statement, parse the line + * 1: We found a for loop + * -1: A .for statement with a bad syntax error, discard. * * Side Effects: * None. @@ -146,119 +146,121 @@ ForAddVar(const char *data, size_t len) int For_Eval(char *line) { - char *ptr = line, *sub, *in, *wrd; - int level; /* Level at which to report errors. */ - - level = PARSE_FATAL; - + For *new_for; + char *ptr = line, *sub; + int len; + int escapes; + unsigned char ch; + + /* Skip the '.' and any following whitespace */ + for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++) + continue; + + /* + * If we are not in a for loop quickly determine if the statement is + * a for. + */ + if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' || + !isspace((unsigned char) ptr[3])) { + if (ptr[0] == 'e' && strncmp(ptr+1, "ndfor", 5) == 0) { + Parse_Error(PARSE_FATAL, "for-less endfor"); + return -1; + } + return 0; + } + ptr += 3; - if (forLevel == 0) { - Buffer buf; - int varlen; - static const char instr[] = "in"; + /* + * we found a for loop, and now we are going to parse it. + */ - for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++) - continue; - /* - * If we are not in a for loop quickly determine if the statement is - * a for. - */ - if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' || - !isspace((unsigned char) ptr[3])) - return FALSE; - ptr += 3; + new_for = bmake_malloc(sizeof *new_for); + memset(new_for, 0, sizeof *new_for); - /* - * we found a for loop, and now we are going to parse it. - */ + /* Grab the variables. Terminate on "in". */ + for (;; ptr += len) { while (*ptr && isspace((unsigned char) *ptr)) ptr++; - - /* - * Find the "in". - */ - for (in = ptr; *in; in++) { - if (isspace((unsigned char) in[0]) && in[1]== 'i' && - in[2] == 'n' && - (in[3] == '\0' || isspace((unsigned char) in[3]))) - break; + if (*ptr == '\0') { + Parse_Error(PARSE_FATAL, "missing `in' in for"); + For_Free(new_for); + return -1; } - if (*in == '\0') { - Parse_Error(level, "missing `in' in for"); - return 0; + for (len = 1; ptr[len] && !isspace((unsigned char)ptr[len]); len++) + continue; + if (len == 2 && ptr[0] == 'i' && ptr[1] == 'n') { + ptr += 2; + break; } + if (len == 1) + new_for->short_var = 1; + strlist_add_str(&new_for->vars, make_str(ptr, len), len); + } - /* - * Grab the variables. - */ - accumFor.vars = NULL; - - while (ptr < in) { - wrd = ptr; - while (*ptr && !isspace((unsigned char) *ptr)) - ptr++; - ForAddVar(wrd, ptr - wrd); - while (*ptr && isspace((unsigned char) *ptr)) - ptr++; - } + if (strlist_num(&new_for->vars) == 0) { + Parse_Error(PARSE_FATAL, "no iteration variables in for"); + For_Free(new_for); + return -1; + } - if (accumFor.nvars == 0) { - Parse_Error(level, "no iteration variables in for"); - return 0; + while (*ptr && isspace((unsigned char) *ptr)) + ptr++; + + /* + * Make a list with the remaining words + * The values are substituted as ${:U<value>...} so we must \ escape + * characters that break that syntax. + * Variables are fully expanded - so it is safe for escape $. + * We can't do the escapes here - because we don't know whether + * we are substuting into ${...} or $(...). + */ + sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE); + + for (ptr = sub;; ptr += len) { + while (*ptr && isspace((unsigned char)*ptr)) + ptr++; + if (*ptr == 0) + break; + escapes = 0; + for (len = 0; (ch = ptr[len]) != 0 && !isspace(ch); len++) { + if (ch == ':' || ch == '$' || ch == '\\') + escapes |= FOR_SUB_ESCAPE_CHAR; + else if (ch == ')') + escapes |= FOR_SUB_ESCAPE_PAREN; + else if (ch == /*{*/ '}') + escapes |= FOR_SUB_ESCAPE_BRACE; } + strlist_add_str(&new_for->items, make_str(ptr, len), escapes); + } - /* At this point we should be pointing right at the "in" */ - /* - * compensate for hp/ux's brain damaged assert macro that - * does not handle double quotes nicely. - */ - assert(!memcmp(ptr, instr, 2)); - ptr += 2; - - while (*ptr && isspace((unsigned char) *ptr)) - ptr++; + free(sub); + if (strlist_num(&new_for->items) % strlist_num(&new_for->vars)) { + Parse_Error(PARSE_FATAL, + "Wrong number of words in .for substitution list %d %d", + strlist_num(&new_for->items), strlist_num(&new_for->vars)); /* - * Make a list with the remaining words + * Return 'success' so that the body of the .for loop is accumulated. + * Remove all items so that the loop doesn't iterate. */ - accumFor.lst = Lst_Init(FALSE); - buf = Buf_Init(0); - sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE); + strlist_clean(&new_for->items); + } -#define ADDWORD() \ - Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd), \ - Buf_AddByte(buf, (Byte)'\0'), \ - Lst_AtFront(accumFor.lst, Buf_GetAll(buf, &varlen)), \ - Buf_Destroy(buf, FALSE) + Buf_Init(&new_for->buf, 0); + accumFor = new_for; + forLevel = 1; + return 1; +} - for (ptr = sub; *ptr && isspace((unsigned char) *ptr); ptr++) - continue; +/* + * Add another line to a .for loop. + * Returns 0 when the matching .endfor is reached. + */ - for (wrd = ptr; *ptr; ptr++) - if (isspace((unsigned char) *ptr)) { - ADDWORD(); - buf = Buf_Init(0); - while (*ptr && isspace((unsigned char) *ptr)) - ptr++; - wrd = ptr--; - } - if (DEBUG(FOR)) { - int i; - for (i = 0; i < accumFor.nvars; i++) { - (void)fprintf(debug_file, "For: variable %s\n", accumFor.vars[i]); - } - (void)fprintf(debug_file, "For: list %s\n", sub); - } - if (ptr - wrd > 0) - ADDWORD(); - else - Buf_Destroy(buf, TRUE); - free(sub); - - accumFor.buf = Buf_Init(0); - forLevel++; - return 1; - } +int +For_Accum(char *line) +{ + char *ptr = line; if (*ptr == '.') { @@ -269,10 +271,8 @@ For_Eval(char *line) (isspace((unsigned char) ptr[6]) || !ptr[6])) { if (DEBUG(FOR)) (void)fprintf(debug_file, "For: end for %d\n", forLevel); - if (--forLevel < 0) { - Parse_Error(level, "for-less endfor"); + if (--forLevel <= 0) return 0; - } } else if (strncmp(ptr, "for", 3) == 0 && isspace((unsigned char) ptr[3])) { forLevel++; @@ -281,13 +281,9 @@ For_Eval(char *line) } } - if (forLevel != 0 && accumFor.buf) { - Buf_AddBytes(accumFor.buf, strlen(line), (Byte *)line); - Buf_AddByte(accumFor.buf, (Byte)'\n'); - return 1; - } - - return 0; + Buf_AddBytes(&accumFor->buf, strlen(line), line); + Buf_AddByte(&accumFor->buf, '\n'); + return 1; } @@ -304,88 +300,172 @@ For_Eval(char *line) * *----------------------------------------------------------------------- */ -void -For_Run(int lineno) + +static int +for_var_len(const char *var) { - For arg; - LstNode ln; - char **values; - int i, done = 0, len; - char *guy, *orig_guy, *old_guy; + char ch, var_start, var_end; + int depth; + int len; + + var_start = *var; + if (var_start == 0) + /* just escape the $ */ + return 0; + + if (var_start == '(') + var_end = ')'; + else if (var_start == '{') + var_end = '}'; + else + /* Single char variable */ + return 1; - if (accumFor.buf == NULL || accumFor.vars == NULL || accumFor.lst == NULL) - return; - arg = accumFor; - accumFor.buf = NULL; - accumFor.vars = NULL; - accumFor.nvars = 0; - accumFor.lst = NULL; + depth = 1; + for (len = 1; (ch = var[len++]) != 0;) { + if (ch == var_start) + depth++; + else if (ch == var_end && --depth == 0) + return len; + } - if (Lst_Open(arg.lst) != SUCCESS) + /* Variable end not found, escape the $ */ + return 0; +} + +static void +for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech) +{ + const char *item = strlist_str(items, item_no); + int len; + char ch; + + /* If there were no escapes, or the only escape is the other variable + * terminator, then just substitute the full string */ + if (!(strlist_info(items, item_no) & + (ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) { + Buf_AddBytes(cmds, strlen(item), item); return; + } - values = bmake_malloc(arg.nvars * sizeof(char *)); - - while (!done) { - /* - * due to the dumb way this is set up, this loop must run - * backwards. - */ - for (i = arg.nvars - 1; i >= 0; i--) { - ln = Lst_Next(arg.lst); - if (ln == NILLNODE) { - if (i != arg.nvars-1) { - Parse_Error(PARSE_FATAL, - "Not enough words in for substitution list"); - } - done = 1; + /* Escape ':', '$', '\\' and 'ech' - removed by :U processing */ + while ((ch = *item++) != 0) { + if (ch == '$') { + len = for_var_len(item); + if (len != 0) { + Buf_AddBytes(cmds, len + 1, item - 1); + item += len; + continue; + } + Buf_AddByte(cmds, '\\'); + } else if (ch == ':' || ch == '\\' || ch == ech) + Buf_AddByte(cmds, '\\'); + Buf_AddByte(cmds, ch); + } +} + +static char * +For_Iterate(void *v_arg) +{ + For *arg = v_arg; + int i, len; + char *var; + char *cp; + char *cmd_cp; + char *body_end; + char ch; + Buffer cmds; + + if (arg->sub_next + strlist_num(&arg->vars) > strlist_num(&arg->items)) { + /* No more iterations */ + For_Free(arg); + return NULL; + } + + free(arg->parse_buf); + arg->parse_buf = NULL; + + /* + * Scan the for loop body and replace references to the loop variables + * with variable references that expand to the required text. + * Using variable expansions ensures that the .for loop can't generate + * syntax, and that the later parsing will still see a variable. + * We assume that the null variable will never be defined. + * + * The detection of substitions of the loop control variable is naive. + * Many of the modifiers use \ to escape $ (not $) so it is possible + * to contrive a makefile where an unwanted substitution happens. + */ + + cmd_cp = Buf_GetAll(&arg->buf, &len); + body_end = cmd_cp + len; + Buf_Init(&cmds, len + 256); + for (cp = cmd_cp; (cp = strchr(cp, '$')) != NULL;) { + char ech; + ch = *++cp; + if ((ch == '(' && (ech = ')')) || (ch == '{' && (ech = '}'))) { + cp++; + /* Check variable name against the .for loop variables */ + STRLIST_FOREACH(var, &arg->vars, i) { + len = strlist_info(&arg->vars, i); + if (memcmp(cp, var, len) != 0) + continue; + if (cp[len] != ':' && cp[len] != ech && cp[len] != '\\') + continue; + /* Found a variable match. Replace with :U<value> */ + Buf_AddBytes(&cmds, cp - cmd_cp, cmd_cp); + Buf_AddBytes(&cmds, 2, ":U"); + cp += len; + cmd_cp = cp; + for_substitute(&cmds, &arg->items, arg->sub_next + i, ech); break; - } else { - values[i] = (char *)Lst_Datum(ln); } + continue; } - if (done) + if (ch == 0) break; - - for (i = 0; i < arg.nvars; i++) { - Var_Set(arg.vars[i], values[i], VAR_GLOBAL, 0); - if (DEBUG(FOR)) - (void)fprintf(debug_file, "--- %s = %s\n", arg.vars[i], - values[i]); + /* Probably a single character name, ignore $$ and stupid ones. {*/ + if (!arg->short_var || strchr("}):$", ch) != NULL) { + cp++; + continue; } - - /* - * Hack, hack, kludge. - * This is really ugly, but to do it any better way would require - * making major changes to var.c, which I don't want to get into - * yet. There is no mechanism for expanding some variables, only - * for expanding a single variable. That should be corrected, but - * not right away. (XXX) - */ - - guy = (char *)Buf_GetAll(arg.buf, &len); - orig_guy = guy; - for (i = 0; i < arg.nvars; i++) { - old_guy = guy; - guy = Var_Subst(arg.vars[i], guy, VAR_GLOBAL, FALSE); - if (old_guy != orig_guy) - free(old_guy); + STRLIST_FOREACH(var, &arg->vars, i) { + if (var[0] != ch || var[1] != 0) + continue; + /* Found a variable match. Replace with ${:U<value>} */ + Buf_AddBytes(&cmds, cp - cmd_cp, cmd_cp); + Buf_AddBytes(&cmds, 3, "{:U"); + cmd_cp = ++cp; + for_substitute(&cmds, &arg->items, arg->sub_next + i, /*{*/ '}'); + Buf_AddBytes(&cmds, 1, "}"); + break; } - Parse_SetInput(NULL, lineno, -1, guy); - - for (i = 0; i < arg.nvars; i++) - Var_Delete(arg.vars[i], VAR_GLOBAL); } + Buf_AddBytes(&cmds, body_end - cmd_cp, cmd_cp); - free(values); + cp = Buf_Destroy(&cmds, FALSE); + if (DEBUG(FOR)) + (void)fprintf(debug_file, "For: loop body:\n%s", cp); - Lst_Close(arg.lst); + arg->sub_next += strlist_num(&arg->vars); - for (i=0; i<arg.nvars; i++) { - free(arg.vars[i]); - } - free(arg.vars); + arg->parse_buf = cp; + return cp; +} + +void +For_Run(int lineno) +{ + For *arg; + + arg = accumFor; + accumFor = NULL; - Lst_Destroy(arg.lst, (FreeProc *)free); - Buf_Destroy(arg.buf, TRUE); + if (strlist_num(&arg->items) == 0) { + /* Nothing to expand - possibly due to an earlier syntax error. */ + For_Free(arg); + return; + } + + Parse_SetInput(NULL, lineno, -1, For_Iterate, arg); } diff --git a/devel/bmake/files/hash.c b/devel/bmake/files/hash.c index 6323f1a48d8..d4876386bae 100644 --- a/devel/bmake/files/hash.c +++ b/devel/bmake/files/hash.c @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: hash.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: hash.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: hash.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: hash.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: hash.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -227,7 +227,7 @@ Hash_FindEntry(Hash_Table *t, const char *key) for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next) if (e->namehash == h && strcmp(e->name, p) == 0) return (e); - return (NULL); + return NULL; } /* @@ -291,7 +291,7 @@ Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr) hp = &t->bucketPtr[h & t->mask]; e->next = *hp; *hp = e; - e->clientData = NULL; + Hash_SetValue(e, NULL); e->namehash = h; (void)strcpy(e->name, p); t->numEntries++; @@ -411,7 +411,7 @@ Hash_EnumNext(Hash_Search *searchPtr) */ while (e == NULL) { if (searchPtr->nextIndex >= t->size) - return (NULL); + return NULL; e = t->bucketPtr[searchPtr->nextIndex++]; } searchPtr->hashEntryPtr = e; diff --git a/devel/bmake/files/hash.h b/devel/bmake/files/hash.h index 0374942fb99..35bfedac64e 100644 --- a/devel/bmake/files/hash.h +++ b/devel/bmake/files/hash.h @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: hash.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -89,8 +89,10 @@ typedef struct Hash_Entry { struct Hash_Entry *next; /* Used to link together all the * entries associated with the same * bucket. */ - ClientData clientData; /* Arbitrary piece of data associated - * with key. */ + union { + void *clientPtr; /* Arbitrary pointer */ + time_t clientTime; /* Arbitrary Time */ + } clientInfo; unsigned namehash; /* hash value of key */ char name[1]; /* key string */ } Hash_Entry; @@ -119,11 +121,12 @@ typedef struct Hash_Search { */ /* - * ClientData Hash_GetValue(h) + * void * Hash_GetValue(h) * Hash_Entry *h; */ -#define Hash_GetValue(h) ((h)->clientData) +#define Hash_GetValue(h) ((h)->clientInfo.clientPtr) +#define Hash_GetTimeValue(h) ((h)->clientInfo.clientTime) /* * Hash_SetValue(h, val); @@ -131,7 +134,8 @@ typedef struct Hash_Search { * char *val; */ -#define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val)) +#define Hash_SetValue(h, val) ((h)->clientInfo.clientPtr = (val)) +#define Hash_SetTimeValue(h, val) ((h)->clientInfo.clientTime = (val)) /* * Hash_Size(n) returns the number of words in an object of n bytes diff --git a/devel/bmake/files/job.c b/devel/bmake/files/job.c index 7932b893f4d..455c87b91ea 100644 --- a/devel/bmake/files/job.c +++ b/devel/bmake/files/job.c @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.7 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.7 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.7 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: job.c,v 1.8 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -197,7 +197,7 @@ int not_parallel = 0; /* set if .NOT_PARALLEL */ * .END target but we keep it around to avoid having to search for it * all the time. */ -static GNode *postCommands = NILGNODE; +static GNode *postCommands = NULL; /* node containing commands to execute when * everything else is done */ static int numCommands; /* The number of commands actually printed @@ -355,11 +355,13 @@ static sigset_t caught_signals; /* Set of signals we handle */ #define KILLPG(pid, sig) killpg((pid), (sig)) #endif +static char *tmpdir; /* directory name, always ending with "/" */ + static void JobChildSig(int); static void JobContinueSig(int); static Job *JobFindPid(int, int); -static int JobPrintCommand(ClientData, ClientData); -static int JobSaveCommand(ClientData, ClientData); +static int JobPrintCommand(void *, void *); +static int JobSaveCommand(void *, void *); static void JobClose(Job *); static void JobExec(Job *, char **); static void JobMakeArgv(Job *, char **); @@ -674,7 +676,7 @@ JobFindPid(int pid, int status) *----------------------------------------------------------------------- */ static int -JobPrintCommand(ClientData cmdp, ClientData jobp) +JobPrintCommand(void *cmdp, void *jobp) { Boolean noSpecials; /* true if we shouldn't worry about * inserting special commands into @@ -907,7 +909,7 @@ JobPrintCommand(ClientData cmdp, ClientData jobp) *----------------------------------------------------------------------- */ static int -JobSaveCommand(ClientData cmd, ClientData gn) +JobSaveCommand(void *cmd, void *gn) { cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, FALSE); (void)Lst_AtEnd(postCommands->commands, cmd); @@ -1072,7 +1074,7 @@ JobFinish (Job *job, WAIT_T status) * the parents. In addition, any saved commands for the node are placed * on the .END target. */ - if (job->tailCmds != NILLNODE) { + if (job->tailCmds != NULL) { Lst_ForEachFrom(job->node->commands, job->tailCmds, JobSaveCommand, job->node); @@ -1210,7 +1212,7 @@ Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) * No commands. Look for .DEFAULT rule from which we might infer * commands */ - if ((DEFAULT != NILGNODE) && !Lst_IsEmpty(DEFAULT->commands) && + if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) && (gn->type & OP_SPECIAL) == 0) { char *p1; /* @@ -1319,6 +1321,7 @@ JobExec(Job *job, char **argv) if (cpid == 0) { /* Child */ + sigset_t tmask; /* * Reset all signal handlers; this is necessary because we also @@ -1327,8 +1330,8 @@ JobExec(Job *job, char **argv) JobSigReset(); /* Now unblock signals */ - sigemptyset(&mask); - JobSigUnlock(&mask); + sigemptyset(&tmask); + JobSigUnlock(&tmask); /* * Must duplicate the input stream down to the child's input and @@ -1519,7 +1522,7 @@ JobStart(GNode *gn, int flags) flags |= JOB_SPECIAL; job->node = gn; - job->tailCmds = NILLNODE; + job->tailCmds = NULL; /* * Set the initial value of the flags for this job based on the global @@ -1552,11 +1555,10 @@ JobStart(GNode *gn, int flags) (!noExecute && !touchFlag)) { /* * tfile is the name of a file into which all shell commands are - * put. It is used over by removing it before the child shell is - * executed. The XXXXXX in the string are replaced by the pid of - * the make process in a 6-character field with leading zeroes. + * put. It is removed before the child shell is executed, unless + * DEBUG(SCRIPT) is set. */ - char tfile[sizeof(TMPPAT)]; + char *tfile; sigset_t mask; /* * We're serious here, but if the commands were bogus, we're @@ -1567,7 +1569,9 @@ JobStart(GNode *gn, int flags) } JobSigLock(&mask); - (void)strcpy(tfile, TMPPAT); + tfile = bmake_malloc(strlen(tmpdir) + sizeof(TMPPAT)); + strcpy(tfile, tmpdir); + strcat(tfile, TMPPAT); if ((tfd = mkstemp(tfile)) == -1) Punt("Could not create temporary file %s", strerror(errno)); if (!DEBUG(SCRIPT)) @@ -1598,6 +1602,8 @@ JobStart(GNode *gn, int flags) if (numCommands == 0) { noExec = TRUE; } + + free(tfile); } else if (NoExecute(gn)) { /* * Not executing anything -- just print all the commands to stdout @@ -1655,7 +1661,7 @@ JobStart(GNode *gn, int flags) * the commands for the job were no good. */ if (cmdsOK && aborting == 0) { - if (job->tailCmds != NILLNODE) { + if (job->tailCmds != NULL) { Lst_ForEachFrom(job->node->commands, job->tailCmds, JobSaveCommand, job->node); @@ -1897,7 +1903,7 @@ JobRun(GNode *targ) Lst lst = Lst_Init(FALSE); Lst_AtEnd(lst, targ); (void)Make_Run(lst); - Lst_Destroy(lst, NOFREE); + Lst_Destroy(lst, NULL); JobStart(targ, JOB_SPECIAL); while (jobTokensRunning) { Job_CatchOutput(); @@ -2130,6 +2136,8 @@ void Job_Init(void) { GNode *begin; /* node for commands to do at the very start */ + const char *p; + size_t len; /* Allocate space for all the job info */ job_table = bmake_malloc(maxJobs * sizeof *job_table); @@ -2140,7 +2148,19 @@ Job_Init(void) aborting = 0; errors = 0; - lastNode = NILGNODE; + lastNode = NULL; + + /* set tmpdir, and ensure that it ends with "/" */ + p = getenv("TMPDIR"); + if (p == NULL || *p == '\0') { + p = _PATH_TMP; + } + len = strlen(p); + tmpdir = bmake_malloc(len + 2); + strcpy(tmpdir, p); + if (tmpdir[len - 1] != '/') { + strcat(tmpdir, "/"); + } if (maxJobs == 1) { /* @@ -2218,7 +2238,7 @@ Job_Init(void) begin = Targ_FindNode(".BEGIN", TARG_NOCREATE); - if (begin != NILGNODE) { + if (begin != NULL) { JobRun(begin); if (begin->made == ERROR) { PrintOnError("\n\nStop."); @@ -2270,7 +2290,7 @@ JobMatchShell(const char *name) if (strcmp(name, sh->name) == 0) return (sh); } - return (NULL); + return NULL; } /*- @@ -2344,6 +2364,10 @@ Job_ParseShell(char *line) * Parse the specification by keyword */ words = brk_string(line, &argc, TRUE, &path); + if (words == NULL) { + Error("Unterminated quoted string [%s]", line); + return FAILURE; + } shellArgv = path; for (path = NULL, argv = words; argc != 0; argc--, argv++) { @@ -2519,7 +2543,7 @@ JobInterrupt(int runINTERRUPT, int signo) if (runINTERRUPT && !touchFlag) { interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE); - if (interrupt != NILGNODE) { + if (interrupt != NULL) { ignoreErrors = FALSE; JobRun(interrupt); } @@ -2544,7 +2568,7 @@ JobInterrupt(int runINTERRUPT, int signo) int Job_Finish(void) { - if (postCommands != NILGNODE && + if (postCommands != NULL && (!Lst_IsEmpty(postCommands->commands) || !Lst_IsEmpty(postCommands->children))) { if (errors) { diff --git a/devel/bmake/files/job.h b/devel/bmake/files/job.h index 3083c57c999..4ff63c0bbd9 100644 --- a/devel/bmake/files/job.h +++ b/devel/bmake/files/job.h @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.5 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: job.h,v 1.6 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -80,7 +80,7 @@ #ifndef _JOB_H_ #define _JOB_H_ -#define TMPPAT "/tmp/makeXXXXXX" +#define TMPPAT "makeXXXXXX" /* relative to tmpdir */ #ifdef USE_SELECT /* @@ -118,7 +118,7 @@ emul_poll(struct pollfd *fd, int nfd, int timeout); * 1) The process id of the child shell * 2) The graph node describing the target being made by this job * 3) A LstNode for the first command to be saved after the job - * completes. This is NILLNODE if there was no "..." in the job's + * completes. This is NULL if there was no "..." in the job's * commands. * 4) An FILE* for writing out the commands. This is only * used before the job is actually started. diff --git a/devel/bmake/files/lst.h b/devel/bmake/files/lst.h index b3efa00e602..d5817473f86 100644 --- a/devel/bmake/files/lst.h +++ b/devel/bmake/files/lst.h @@ -1,4 +1,4 @@ -/* $NetBSD: lst.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lst.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -92,19 +92,8 @@ typedef struct List *Lst; typedef struct ListNode *LstNode; -typedef ClientData DuplicateProc(ClientData); -typedef void FreeProc(ClientData); - -#define NILLST ((Lst)NIL) -#define NILLNODE ((LstNode)NIL) - -/* - * NOFREE can be used as the freeProc to Lst_Destroy when the elements are - * not to be freed. - * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate. - */ -#define NOFREE ((FreeProc *)NULL) -#define NOCOPY ((DuplicateProc *)NULL) +typedef void *DuplicateProc(void *); +typedef void FreeProc(void *); #define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */ #define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */ @@ -125,17 +114,17 @@ Boolean Lst_IsEmpty(Lst); * Functions to modify a list */ /* Insert an element before another */ -ReturnStatus Lst_InsertBefore(Lst, LstNode, ClientData); +ReturnStatus Lst_InsertBefore(Lst, LstNode, void *); /* Insert an element after another */ -ReturnStatus Lst_InsertAfter(Lst, LstNode, ClientData); +ReturnStatus Lst_InsertAfter(Lst, LstNode, void *); /* Place an element at the front of a lst. */ -ReturnStatus Lst_AtFront(Lst, ClientData); +ReturnStatus Lst_AtFront(Lst, void *); /* Place an element at the end of a lst. */ -ReturnStatus Lst_AtEnd(Lst, ClientData); +ReturnStatus Lst_AtEnd(Lst, void *); /* Remove an element */ ReturnStatus Lst_Remove(Lst, LstNode); /* Replace a node with a new value */ -ReturnStatus Lst_Replace(LstNode, ClientData); +ReturnStatus Lst_Replace(LstNode, void *); /* Concatenate two lists */ ReturnStatus Lst_Concat(Lst, Lst, int); @@ -151,30 +140,30 @@ LstNode Lst_Succ(LstNode); /* Return predecessor to given element */ LstNode Lst_Prev(LstNode); /* Get datum from LstNode */ -ClientData Lst_Datum(LstNode); +void *Lst_Datum(LstNode); /* * Functions for entire lists */ /* Find an element in a list */ -LstNode Lst_Find(Lst, ClientData, int (*)(ClientData, ClientData)); +LstNode Lst_Find(Lst, const void *, int (*)(const void *, const void *)); /* Find an element starting from somewhere */ -LstNode Lst_FindFrom(Lst, LstNode, ClientData, - int (*cProc)(ClientData, ClientData)); +LstNode Lst_FindFrom(Lst, LstNode, const void *, + int (*cProc)(const void *, const void *)); /* * See if the given datum is on the list. Returns the LstNode containing * the datum */ -LstNode Lst_Member(Lst, ClientData); +LstNode Lst_Member(Lst, void *); /* Apply a function to all elements of a lst */ -int Lst_ForEach(Lst, int (*)(ClientData, ClientData), ClientData); +int Lst_ForEach(Lst, int (*)(void *, void *), void *); /* * Apply a function to all elements of a lst starting from a certain point. * If the list is circular, the application will wrap around to the * beginning of the list again. */ -int Lst_ForEachFrom(Lst, LstNode, int (*)(ClientData, ClientData), - ClientData); +int Lst_ForEachFrom(Lst, LstNode, int (*)(void *, void *), + void *); /* * these functions are for dealing with a list as a table, of sorts. * An idea of the "current element" is kept and used by all the functions @@ -193,8 +182,8 @@ void Lst_Close(Lst); * for using the list as a queue */ /* Place an element at tail of queue */ -ReturnStatus Lst_EnQueue(Lst, ClientData); +ReturnStatus Lst_EnQueue(Lst, void *); /* Remove an element from head of queue */ -ClientData Lst_DeQueue(Lst); +void *Lst_DeQueue(Lst); #endif /* _LST_H_ */ diff --git a/devel/bmake/files/lst.lib/lstAppend.c b/devel/bmake/files/lst.lib/lstAppend.c index 6249ce751ae..910c328d4f8 100644 --- a/devel/bmake/files/lst.lib/lstAppend.c +++ b/devel/bmake/files/lst.lib/lstAppend.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAppend.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstAppend.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAppend.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstAppend.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstAppend.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAppend.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstAppend.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -69,18 +69,18 @@ __RCSID("$NetBSD: lstAppend.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * A new ListNode is created and linked in to the List. The lastPtr * field of the List will be altered if ln is the last node in the * list. lastPtr and firstPtr will alter if the list was empty and - * ln was NILLNODE. + * ln was NULL. * *----------------------------------------------------------------------- */ ReturnStatus -Lst_InsertAfter(Lst l, LstNode ln, ClientData d) +Lst_InsertAfter(Lst l, LstNode ln, void *d) { List list; ListNode lNode; ListNode nLNode; - if (LstValid (l) && (ln == NILLNODE && LstIsEmpty (l))) { + if (LstValid (l) && (ln == NULL && LstIsEmpty (l))) { goto ok; } @@ -96,11 +96,11 @@ Lst_InsertAfter(Lst l, LstNode ln, ClientData d) nLNode->datum = d; nLNode->useCount = nLNode->flags = 0; - if (lNode == NilListNode) { + if (lNode == NULL) { if (list->isCirc) { nLNode->nextPtr = nLNode->prevPtr = nLNode; } else { - nLNode->nextPtr = nLNode->prevPtr = NilListNode; + nLNode->nextPtr = nLNode->prevPtr = NULL; } list->firstPtr = list->lastPtr = nLNode; } else { @@ -108,7 +108,7 @@ Lst_InsertAfter(Lst l, LstNode ln, ClientData d) nLNode->nextPtr = lNode->nextPtr; lNode->nextPtr = nLNode; - if (nLNode->nextPtr != NilListNode) { + if (nLNode->nextPtr != NULL) { nLNode->nextPtr->prevPtr = nLNode; } diff --git a/devel/bmake/files/lst.lib/lstAtEnd.c b/devel/bmake/files/lst.lib/lstAtEnd.c index a0b0eed50bb..675274f91af 100644 --- a/devel/bmake/files/lst.lib/lstAtEnd.c +++ b/devel/bmake/files/lst.lib/lstAtEnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAtEnd.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstAtEnd.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstAtEnd.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAtEnd.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstAtEnd.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -70,7 +70,7 @@ __RCSID("$NetBSD: lstAtEnd.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ ReturnStatus -Lst_AtEnd(Lst l, ClientData d) +Lst_AtEnd(Lst l, void *d) { LstNode end; diff --git a/devel/bmake/files/lst.lib/lstAtFront.c b/devel/bmake/files/lst.lib/lstAtFront.c index 4b3b2198d8c..5dec59f5df4 100644 --- a/devel/bmake/files/lst.lib/lstAtFront.c +++ b/devel/bmake/files/lst.lib/lstAtFront.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstAtFront.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstAtFront.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstAtFront.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstAtFront.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstAtFront.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -67,7 +67,7 @@ __RCSID("$NetBSD: lstAtFront.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ ReturnStatus -Lst_AtFront(Lst l, ClientData d) +Lst_AtFront(Lst l, void *d) { LstNode front; diff --git a/devel/bmake/files/lst.lib/lstConcat.c b/devel/bmake/files/lst.lib/lstConcat.c index a72f1463e78..f27ff4aa57b 100644 --- a/devel/bmake/files/lst.lib/lstConcat.c +++ b/devel/bmake/files/lst.lib/lstConcat.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstConcat.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstConcat.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstConcat.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstConcat.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstConcat.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstConcat.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstConcat.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -90,7 +90,7 @@ Lst_Concat(Lst l1, Lst l2, int flags) } if (flags == LST_CONCLINK) { - if (list2->firstPtr != NilListNode) { + if (list2->firstPtr != NULL) { /* * We set the nextPtr of the * last element of list two to be NIL to make the loop easier and @@ -99,7 +99,7 @@ Lst_Concat(Lst l1, Lst l2, int flags) * to NIL space and the first element will be untouched if it * existed before and will also point to NIL space if it didn't. */ - list2->lastPtr->nextPtr = NilListNode; + list2->lastPtr->nextPtr = NULL; /* * So long as the second list isn't empty, we just link the * first element of the second list to the last element of the @@ -109,14 +109,14 @@ Lst_Concat(Lst l1, Lst l2, int flags) * the last element of the first list. */ list2->firstPtr->prevPtr = list1->lastPtr; - if (list1->lastPtr != NilListNode) { + if (list1->lastPtr != NULL) { list1->lastPtr->nextPtr = list2->firstPtr; } else { list1->firstPtr = list2->firstPtr; } list1->lastPtr = list2->lastPtr; } - if (list1->isCirc && list1->firstPtr != NilListNode) { + if (list1->isCirc && list1->firstPtr != NULL) { /* * If the first list is supposed to be circular and it is (now) * non-empty, we must make sure it's circular by linking the @@ -126,7 +126,7 @@ Lst_Concat(Lst l1, Lst l2, int flags) list1->lastPtr->nextPtr = list1->firstPtr; } free(l2); - } else if (list2->firstPtr != NilListNode) { + } else if (list2->firstPtr != NULL) { /* * We set the nextPtr of the last element of list 2 to be nil to make * the loop less difficult. The loop simply goes through the entire @@ -139,14 +139,14 @@ Lst_Concat(Lst l1, Lst l2, int flags) * the first list must have been empty so the newly-created node is * made the first node of the list. */ - list2->lastPtr->nextPtr = NilListNode; + list2->lastPtr->nextPtr = NULL; for (last = list1->lastPtr, ln = list2->firstPtr; - ln != NilListNode; + ln != NULL; ln = ln->nextPtr) { PAlloc (nln, ListNode); nln->datum = ln->datum; - if (last != NilListNode) { + if (last != NULL) { last->nextPtr = nln; } else { list1->firstPtr = nln; @@ -172,7 +172,7 @@ Lst_Concat(Lst l1, Lst l2, int flags) list1->lastPtr->nextPtr = list1->firstPtr; list1->firstPtr->prevPtr = list1->lastPtr; } else { - last->nextPtr = NilListNode; + last->nextPtr = NULL; } if (list2->isCirc) { diff --git a/devel/bmake/files/lst.lib/lstDatum.c b/devel/bmake/files/lst.lib/lstDatum.c index 25b3b54384a..4d327319bd5 100644 --- a/devel/bmake/files/lst.lib/lstDatum.c +++ b/devel/bmake/files/lst.lib/lstDatum.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDatum.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstDatum.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDatum.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstDatum.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstDatum.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDatum.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstDatum.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -58,20 +58,20 @@ __RCSID("$NetBSD: lstDatum.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Return the datum stored in the given node. * * Results: - * The datum or (ick!) NIL if the node is invalid. + * The datum or NULL if the node is invalid. * * Side Effects: * None. * *----------------------------------------------------------------------- */ -ClientData +void * Lst_Datum(LstNode ln) { - if (ln != NILLNODE) { + if (ln != NULL) { return ((ln)->datum); } else { - return ((ClientData) NIL); + return NULL; } } diff --git a/devel/bmake/files/lst.lib/lstDeQueue.c b/devel/bmake/files/lst.lib/lstDeQueue.c index a64e22ed2f5..a5db30094fd 100644 --- a/devel/bmake/files/lst.lib/lstDeQueue.c +++ b/devel/bmake/files/lst.lib/lstDeQueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDeQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstDeQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstDeQueue.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDeQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstDeQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -58,7 +58,7 @@ __RCSID("$NetBSD: lstDeQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Remove and return the datum at the head of the given list. * * Results: - * The datum in the node at the head or (ick) NIL if the list + * The datum in the node at the head or NULL if the list * is empty. * * Side Effects: @@ -66,20 +66,20 @@ __RCSID("$NetBSD: lstDeQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * *----------------------------------------------------------------------- */ -ClientData +void * Lst_DeQueue(Lst l) { - ClientData rd; + void *rd; ListNode tln; tln = Lst_First(l); - if (tln == NilListNode) { - return ((ClientData) NIL); + if (tln == NULL) { + return NULL; } rd = tln->datum; if (Lst_Remove(l, tln) == FAILURE) { - return ((ClientData) NIL); + return NULL; } else { return (rd); } diff --git a/devel/bmake/files/lst.lib/lstDestroy.c b/devel/bmake/files/lst.lib/lstDestroy.c index 424bbda5b7f..09d25d32da6 100644 --- a/devel/bmake/files/lst.lib/lstDestroy.c +++ b/devel/bmake/files/lst.lib/lstDestroy.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDestroy.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstDestroy.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDestroy.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstDestroy.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstDestroy.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDestroy.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstDestroy.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -68,40 +68,34 @@ __RCSID("$NetBSD: lstDestroy.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ void -Lst_Destroy(Lst l, FreeProc *freeProc) +Lst_Destroy(Lst list, FreeProc *freeProc) { ListNode ln; - ListNode tln = NilListNode; - List list = l; + ListNode tln = NULL; - if (l == NILLST || ! l) { - /* - * Note the check for l == (Lst)0 to catch uninitialized static Lst's. - * Gross, but useful. - */ + if (list == NULL) return; - } /* To ease scanning */ - if (list->lastPtr != NilListNode) - list->lastPtr->nextPtr = NilListNode; + if (list->lastPtr != NULL) + list->lastPtr->nextPtr = NULL; else { - free(l); + free(list); return; } if (freeProc) { - for (ln = list->firstPtr; ln != NilListNode; ln = tln) { + for (ln = list->firstPtr; ln != NULL; ln = tln) { tln = ln->nextPtr; freeProc(ln->datum); free(ln); } } else { - for (ln = list->firstPtr; ln != NilListNode; ln = tln) { + for (ln = list->firstPtr; ln != NULL; ln = tln) { tln = ln->nextPtr; free(ln); } } - free(l); + free(list); } diff --git a/devel/bmake/files/lst.lib/lstDupl.c b/devel/bmake/files/lst.lib/lstDupl.c index d47e408e7ed..e81320828c8 100644 --- a/devel/bmake/files/lst.lib/lstDupl.c +++ b/devel/bmake/files/lst.lib/lstDupl.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstDupl.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstDupl.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstDupl.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstDupl.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstDupl.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstDupl.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstDupl.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -56,15 +56,15 @@ __RCSID("$NetBSD: lstDupl.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); /*- *----------------------------------------------------------------------- * Lst_Duplicate -- - * Duplicate an entire list. If a function to copy a ClientData is + * Duplicate an entire list. If a function to copy a void *is * given, the individual client elements will be duplicated as well. * * Input: * l the list to duplicate - * copyProc A function to duplicate each ClientData + * copyProc A function to duplicate each void * * * Results: - * The new Lst structure or NILLST if failure. + * The new Lst structure or NULL if failure. * * Side Effects: * A new list is created. @@ -78,26 +78,26 @@ Lst_Duplicate(Lst l, DuplicateProc *copyProc) List list = l; if (!LstValid (l)) { - return (NILLST); + return NULL; } nl = Lst_Init(list->isCirc); - if (nl == NILLST) { - return (NILLST); + if (nl == NULL) { + return NULL; } ln = list->firstPtr; - while (ln != NilListNode) { - if (copyProc != NOCOPY) { + while (ln != NULL) { + if (copyProc != NULL) { if (Lst_AtEnd(nl, copyProc(ln->datum)) == FAILURE) { - return (NILLST); + return NULL; } } else if (Lst_AtEnd(nl, ln->datum) == FAILURE) { - return (NILLST); + return NULL; } if (list->isCirc && ln == list->lastPtr) { - ln = NilListNode; + ln = NULL; } else { ln = ln->nextPtr; } diff --git a/devel/bmake/files/lst.lib/lstEnQueue.c b/devel/bmake/files/lst.lib/lstEnQueue.c index 4b644fac0c7..fda551c2548 100644 --- a/devel/bmake/files/lst.lib/lstEnQueue.c +++ b/devel/bmake/files/lst.lib/lstEnQueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstEnQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstEnQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstEnQueue.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstEnQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstEnQueue.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -67,7 +67,7 @@ __RCSID("$NetBSD: lstEnQueue.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ ReturnStatus -Lst_EnQueue(Lst l, ClientData d) +Lst_EnQueue(Lst l, void *d) { if (LstValid (l) == FALSE) { return (FAILURE); diff --git a/devel/bmake/files/lst.lib/lstFind.c b/devel/bmake/files/lst.lib/lstFind.c index b92f98d258c..5243f30c1b9 100644 --- a/devel/bmake/files/lst.lib/lstFind.c +++ b/devel/bmake/files/lst.lib/lstFind.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFind.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstFind.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFind.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstFind.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstFind.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFind.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstFind.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -59,7 +59,7 @@ __RCSID("$NetBSD: lstFind.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * and the given datum. * * Results: - * The found node or NILLNODE if none matches. + * The found node or NULL if none matches. * * Side Effects: * None. @@ -67,7 +67,7 @@ __RCSID("$NetBSD: lstFind.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ LstNode -Lst_Find(Lst l, ClientData d, int (*cProc)(ClientData, ClientData)) +Lst_Find(Lst l, const void *d, int (*cProc)(const void *, const void *)) { return (Lst_FindFrom(l, Lst_First(l), d, cProc)); } diff --git a/devel/bmake/files/lst.lib/lstFindFrom.c b/devel/bmake/files/lst.lib/lstFindFrom.c index 70b8ff0df51..3e076874dbd 100644 --- a/devel/bmake/files/lst.lib/lstFindFrom.c +++ b/devel/bmake/files/lst.lib/lstFindFrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFindFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstFindFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstFindFrom.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFindFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstFindFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -60,7 +60,7 @@ __RCSID("$NetBSD: lstFindFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * determine when it has been found. * * Results: - * The found node or NILLNODE + * The found node or NULL * * Side Effects: * None. @@ -68,31 +68,23 @@ __RCSID("$NetBSD: lstFindFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ LstNode -Lst_FindFrom(Lst l, LstNode ln, ClientData d, - int (*cProc)(ClientData, ClientData)) +Lst_FindFrom(Lst l, LstNode ln, const void *d, + int (*cProc)(const void *, const void *)) { ListNode tln; - Boolean found = FALSE; if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) { - return (NILLNODE); + return NULL; } tln = ln; do { - if ((*cProc) (tln->datum, d) == 0) { - found = TRUE; - break; - } else { - tln = tln->nextPtr; - } - } while (tln != ln && tln != NilListNode); + if ((*cProc)(tln->datum, d) == 0) + return (tln); + tln = tln->nextPtr; + } while (tln != ln && tln != NULL); - if (found) { - return (tln); - } else { - return (NILLNODE); - } + return NULL; } diff --git a/devel/bmake/files/lst.lib/lstFirst.c b/devel/bmake/files/lst.lib/lstFirst.c index f40c80eeeaa..7adb1db9e62 100644 --- a/devel/bmake/files/lst.lib/lstFirst.c +++ b/devel/bmake/files/lst.lib/lstFirst.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstFirst.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstFirst.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstFirst.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstFirst.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstFirst.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstFirst.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstFirst.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -58,7 +58,7 @@ __RCSID("$NetBSD: lstFirst.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Return the first node on the given list. * * Results: - * The first node or NILLNODE if the list is empty. + * The first node or NULL if the list is empty. * * Side Effects: * None. @@ -69,7 +69,7 @@ LstNode Lst_First(Lst l) { if (!LstValid (l) || LstIsEmpty (l)) { - return (NILLNODE); + return NULL; } else { return (l->firstPtr); } diff --git a/devel/bmake/files/lst.lib/lstForEach.c b/devel/bmake/files/lst.lib/lstForEach.c index 571191cedec..bdaf22fd7c5 100644 --- a/devel/bmake/files/lst.lib/lstForEach.c +++ b/devel/bmake/files/lst.lib/lstForEach.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstForEach.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstForEach.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstForEach.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstForEach.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstForEach.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstForEach.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstForEach.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -69,7 +69,7 @@ __RCSID("$NetBSD: lstForEach.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); */ /*VARARGS2*/ int -Lst_ForEach(Lst l, int (*proc)(ClientData, ClientData), ClientData d) +Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d) { return Lst_ForEachFrom(l, Lst_First(l), proc, d); } diff --git a/devel/bmake/files/lst.lib/lstForEachFrom.c b/devel/bmake/files/lst.lib/lstForEachFrom.c index b0f3b39d423..a16c1f7f0f1 100644 --- a/devel/bmake/files/lst.lib/lstForEachFrom.c +++ b/devel/bmake/files/lst.lib/lstForEachFrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstForEachFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstForEachFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstForEachFrom.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstForEachFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstForEachFrom.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -70,8 +70,8 @@ __RCSID("$NetBSD: lstForEachFrom.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); */ /*VARARGS2*/ int -Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(ClientData, ClientData), - ClientData d) +Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *), + void *d) { ListNode tln = ln; List list = l; @@ -98,7 +98,7 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(ClientData, ClientData), * - nothing's been added after the current node (check this * after proc() has been called). */ - done = (next == NilListNode || next == list->firstPtr); + done = (next == NULL || next == list->firstPtr); (void) tln->useCount++; result = (*proc) (tln->datum, d); diff --git a/devel/bmake/files/lst.lib/lstInit.c b/devel/bmake/files/lst.lib/lstInit.c index 929ffec2da3..4435d9a68cd 100644 --- a/devel/bmake/files/lst.lib/lstInit.c +++ b/devel/bmake/files/lst.lib/lstInit.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstInit.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstInit.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstInit.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstInit.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstInit.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstInit.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstInit.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -75,8 +75,8 @@ Lst_Init(Boolean circ) PAlloc (nList, List); - nList->firstPtr = NilListNode; - nList->lastPtr = NilListNode; + nList->firstPtr = NULL; + nList->lastPtr = NULL; nList->isOpen = FALSE; nList->isCirc = circ; nList->atEnd = Unknown; diff --git a/devel/bmake/files/lst.lib/lstInsert.c b/devel/bmake/files/lst.lib/lstInsert.c index f038baf4236..fde8a5ec0f7 100644 --- a/devel/bmake/files/lst.lib/lstInsert.c +++ b/devel/bmake/files/lst.lib/lstInsert.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstInsert.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstInsert.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstInsert.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstInsert.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstInsert.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstInsert.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstInsert.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -73,7 +73,7 @@ __RCSID("$NetBSD: lstInsert.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ ReturnStatus -Lst_InsertBefore(Lst l, LstNode ln, ClientData d) +Lst_InsertBefore(Lst l, LstNode ln, void *d) { ListNode nLNode; /* new lnode for d */ ListNode lNode = ln; @@ -83,7 +83,7 @@ Lst_InsertBefore(Lst l, LstNode ln, ClientData d) /* * check validity of arguments */ - if (LstValid (l) && (LstIsEmpty (l) && ln == NILLNODE)) + if (LstValid (l) && (LstIsEmpty (l) && ln == NULL)) goto ok; if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) { @@ -96,18 +96,18 @@ Lst_InsertBefore(Lst l, LstNode ln, ClientData d) nLNode->datum = d; nLNode->useCount = nLNode->flags = 0; - if (ln == NILLNODE) { + if (ln == NULL) { if (list->isCirc) { nLNode->prevPtr = nLNode->nextPtr = nLNode; } else { - nLNode->prevPtr = nLNode->nextPtr = NilListNode; + nLNode->prevPtr = nLNode->nextPtr = NULL; } list->firstPtr = list->lastPtr = nLNode; } else { nLNode->prevPtr = lNode->prevPtr; nLNode->nextPtr = lNode; - if (nLNode->prevPtr != NilListNode) { + if (nLNode->prevPtr != NULL) { nLNode->prevPtr->nextPtr = nLNode; } lNode->prevPtr = nLNode; diff --git a/devel/bmake/files/lst.lib/lstInt.h b/devel/bmake/files/lst.lib/lstInt.h index a9c9e587af3..c79dc42c6b0 100644 --- a/devel/bmake/files/lst.lib/lstInt.h +++ b/devel/bmake/files/lst.lib/lstInt.h @@ -1,4 +1,4 @@ -/* $NetBSD: lstInt.h,v 1.5 2008/11/11 14:37:06 joerg Exp $ */ +/* $NetBSD: lstInt.h,v 1.6 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -41,8 +41,8 @@ #ifndef _LSTINT_H_ #define _LSTINT_H_ -#include "../make.h" #include "../lst.h" +#include "../make_malloc.h" typedef struct ListNode { struct ListNode *prevPtr; /* previous element in list */ @@ -51,15 +51,13 @@ typedef struct ListNode { * node may not be deleted until count * goes to 0 */ flags:8; /* Node status flags */ - ClientData datum; /* datum associated with this element */ + void *datum; /* datum associated with this element */ } *ListNode; /* * Flags required for synchronization */ #define LN_DELETED 0x0001 /* List node should be removed when done */ -#define NilListNode ((ListNode)-1) - typedef enum { Head, Middle, Tail, Unknown } Where; @@ -74,14 +72,12 @@ typedef struct List { */ Where atEnd; /* Where in the list the last access was */ Boolean isOpen; /* true if list has been Lst_Open'ed */ - ListNode curPtr; /* current node, if open. NilListNode if + ListNode curPtr; /* current node, if open. NULL if * *just* opened */ ListNode prevPtr; /* Previous node, if open. Used by * Lst_Remove */ } *List; -#define NilList ((List)-1) - /* * PAlloc (var, ptype) -- * Allocate a pointer-typedef structure 'ptype' into the variable 'var' @@ -92,18 +88,18 @@ typedef struct List { * LstValid (l) -- * Return TRUE if the list l is valid */ -#define LstValid(l) ((Lst)(l) != NILLST) +#define LstValid(l) ((Lst)(l) != NULL) /* * LstNodeValid (ln, l) -- * Return TRUE if the LstNode ln is valid with respect to l */ -#define LstNodeValid(ln, l) ((ln) != NILLNODE) +#define LstNodeValid(ln, l) ((ln) != NULL) /* * LstIsEmpty (l) -- * TRUE if the list l is empty. */ -#define LstIsEmpty(l) (((List)(l))->firstPtr == NilListNode) +#define LstIsEmpty(l) (((List)(l))->firstPtr == NULL) #endif /* _LSTINT_H_ */ diff --git a/devel/bmake/files/lst.lib/lstIsEmpty.c b/devel/bmake/files/lst.lib/lstIsEmpty.c index a79c34fb80e..6e4a43cf027 100644 --- a/devel/bmake/files/lst.lib/lstIsEmpty.c +++ b/devel/bmake/files/lst.lib/lstIsEmpty.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstIsEmpty.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstIsEmpty.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstIsEmpty.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstIsEmpty.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstIsEmpty.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -63,8 +63,8 @@ __RCSID("$NetBSD: lstIsEmpty.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Side Effects: * None. * - * A list is considered empty if its firstPtr == NilListNode (or if - * the list itself is NILLIST). + * A list is considered empty if its firstPtr == NULL (or if + * the list itself is NULL). *----------------------------------------------------------------------- */ Boolean diff --git a/devel/bmake/files/lst.lib/lstLast.c b/devel/bmake/files/lst.lib/lstLast.c index f920ac9f301..df3155c80ca 100644 --- a/devel/bmake/files/lst.lib/lstLast.c +++ b/devel/bmake/files/lst.lib/lstLast.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstLast.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstLast.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstLast.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstLast.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstLast.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstLast.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstLast.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -58,7 +58,7 @@ __RCSID("$NetBSD: lstLast.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Return the last node on the list l. * * Results: - * The requested node or NILLNODE if the list is empty. + * The requested node or NULL if the list is empty. * * Side Effects: * None. @@ -69,7 +69,7 @@ LstNode Lst_Last(Lst l) { if (!LstValid(l) || LstIsEmpty (l)) { - return (NILLNODE); + return NULL; } else { return (l->lastPtr); } diff --git a/devel/bmake/files/lst.lib/lstMember.c b/devel/bmake/files/lst.lib/lstMember.c index f79d03ab3a8..87ab2f63a51 100644 --- a/devel/bmake/files/lst.lib/lstMember.c +++ b/devel/bmake/files/lst.lib/lstMember.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstMember.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstMember.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstMember.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstMember.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstMember.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstMember.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstMember.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -53,14 +53,14 @@ __RCSID("$NetBSD: lstMember.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); #include "lstInt.h" LstNode -Lst_Member(Lst l, ClientData d) +Lst_Member(Lst l, void *d) { List list = l; ListNode lNode; lNode = list->firstPtr; - if (lNode == NilListNode) { - return NILLNODE; + if (lNode == NULL) { + return NULL; } do { @@ -68,7 +68,7 @@ Lst_Member(Lst l, ClientData d) return lNode; } lNode = lNode->nextPtr; - } while (lNode != NilListNode && lNode != list->firstPtr); + } while (lNode != NULL && lNode != list->firstPtr); - return NILLNODE; + return NULL; } diff --git a/devel/bmake/files/lst.lib/lstNext.c b/devel/bmake/files/lst.lib/lstNext.c index 2733d78bc56..8a9904745f3 100644 --- a/devel/bmake/files/lst.lib/lstNext.c +++ b/devel/bmake/files/lst.lib/lstNext.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstNext.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstNext.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstNext.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstNext.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstNext.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstNext.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstNext.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -63,8 +63,8 @@ __RCSID("$NetBSD: lstNext.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * Return the next node for the given list. * * Results: - * The next node or NILLNODE if the list has yet to be opened. Also - * if the list is non-circular and the end has been reached, NILLNODE + * The next node or NULL if the list has yet to be opened. Also + * if the list is non-circular and the end has been reached, NULL * is returned. * * Side Effects: @@ -80,12 +80,12 @@ Lst_Next(Lst l) if ((LstValid (l) == FALSE) || (list->isOpen == FALSE)) { - return (NILLNODE); + return NULL; } list->prevPtr = list->curPtr; - if (list->curPtr == NilListNode) { + if (list->curPtr == NULL) { if (list->atEnd == Unknown) { /* * If we're just starting out, atEnd will be Unknown. @@ -95,14 +95,14 @@ Lst_Next(Lst l) list->curPtr = tln = list->firstPtr; list->atEnd = Middle; } else { - tln = NilListNode; + tln = NULL; list->atEnd = Tail; } } else { tln = list->curPtr->nextPtr; list->curPtr = tln; - if (tln == list->firstPtr || tln == NilListNode) { + if (tln == list->firstPtr || tln == NULL) { /* * If back at the front, then we've hit the end... */ diff --git a/devel/bmake/files/lst.lib/lstOpen.c b/devel/bmake/files/lst.lib/lstOpen.c index 901bbc69120..dcbc672e025 100644 --- a/devel/bmake/files/lst.lib/lstOpen.c +++ b/devel/bmake/files/lst.lib/lstOpen.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstOpen.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstOpen.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstOpen.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstOpen.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstOpen.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstOpen.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstOpen.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -66,7 +66,7 @@ __RCSID("$NetBSD: lstOpen.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * SUCCESS or FAILURE. * * Side Effects: - * isOpen is set TRUE and curPtr is set to NilListNode so the + * isOpen is set TRUE and curPtr is set to NULL so the * other sequential functions no it was just opened and can choose * the first element accessed based on this. * @@ -80,7 +80,7 @@ Lst_Open(Lst l) } (l)->isOpen = TRUE; (l)->atEnd = LstIsEmpty (l) ? Head : Unknown; - (l)->curPtr = NilListNode; + (l)->curPtr = NULL; return (SUCCESS); } diff --git a/devel/bmake/files/lst.lib/lstRemove.c b/devel/bmake/files/lst.lib/lstRemove.c index fd1f712191b..2b4034ea28d 100644 --- a/devel/bmake/files/lst.lib/lstRemove.c +++ b/devel/bmake/files/lst.lib/lstRemove.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstRemove.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstRemove.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstRemove.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstRemove.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstRemove.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstRemove.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstRemove.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -61,7 +61,7 @@ __RCSID("$NetBSD: lstRemove.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); * SUCCESS or FAILURE. * * Side Effects: - * The list's firstPtr will be set to NilListNode if ln is the last + * The list's firstPtr will be set to NULL if ln is the last * node on the list. firsPtr and lastPtr will be altered if ln is * either the first or last node, respectively, on the list. * @@ -81,10 +81,10 @@ Lst_Remove(Lst l, LstNode ln) /* * unlink it from the list */ - if (lNode->nextPtr != NilListNode) { + if (lNode->nextPtr != NULL) { lNode->nextPtr->prevPtr = lNode->prevPtr; } - if (lNode->prevPtr != NilListNode) { + if (lNode->prevPtr != NULL) { lNode->prevPtr->nextPtr = lNode->nextPtr; } @@ -102,12 +102,12 @@ Lst_Remove(Lst l, LstNode ln) /* * Sequential access stuff. If the node we're removing is the current * node in the list, reset the current node to the previous one. If the - * previous one was non-existent (prevPtr == NilListNode), we set the + * previous one was non-existent (prevPtr == NULL), we set the * end to be Unknown, since it is. */ if (list->isOpen && (list->curPtr == lNode)) { list->curPtr = list->prevPtr; - if (list->curPtr == NilListNode) { + if (list->curPtr == NULL) { list->atEnd = Unknown; } } @@ -118,7 +118,7 @@ Lst_Remove(Lst l, LstNode ln) * this case). The list is, therefore, empty and is marked as such */ if (list->firstPtr == lNode) { - list->firstPtr = NilListNode; + list->firstPtr = NULL; } /* diff --git a/devel/bmake/files/lst.lib/lstReplace.c b/devel/bmake/files/lst.lib/lstReplace.c index 9dd1f97de77..55fde547e33 100644 --- a/devel/bmake/files/lst.lib/lstReplace.c +++ b/devel/bmake/files/lst.lib/lstReplace.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstReplace.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstReplace.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstReplace.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstReplace.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstReplace.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstReplace.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstReplace.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -66,9 +66,9 @@ __RCSID("$NetBSD: lstReplace.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); *----------------------------------------------------------------------- */ ReturnStatus -Lst_Replace(LstNode ln, ClientData d) +Lst_Replace(LstNode ln, void *d) { - if (ln == NILLNODE) { + if (ln == NULL) { return (FAILURE); } else { (ln)->datum = d; diff --git a/devel/bmake/files/lst.lib/lstSucc.c b/devel/bmake/files/lst.lib/lstSucc.c index c39df6a6830..ea66417bc4c 100644 --- a/devel/bmake/files/lst.lib/lstSucc.c +++ b/devel/bmake/files/lst.lib/lstSucc.c @@ -1,4 +1,4 @@ -/* $NetBSD: lstSucc.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: lstSucc.c,v 1.3 2009/09/18 21:27:26 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -33,14 +33,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: lstSucc.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: lstSucc.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: lstSucc.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: lstSucc.c,v 1.3 2009/09/18 21:27:26 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -70,8 +70,8 @@ __RCSID("$NetBSD: lstSucc.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); LstNode Lst_Succ(LstNode ln) { - if (ln == NILLNODE) { - return (NILLNODE); + if (ln == NULL) { + return NULL; } else { return (ln->nextPtr); } diff --git a/devel/bmake/files/main.c b/devel/bmake/files/main.c index 39141b41cc9..647d28dc3d6 100644 --- a/devel/bmake/files/main.c +++ b/devel/bmake/files/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.5 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: main.c,v 1.6 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.5 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.6 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.5 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.6 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -179,9 +179,10 @@ static const char * tracefile; static char * Check_Cwd_av(int, char **, int); #endif static void MainParseArgs(int, char **); -static int ReadMakefile(ClientData, ClientData); +static int ReadMakefile(const void *, const void *); static void usage(void); +static Boolean ignorePWD; /* if we use -C, PWD is meaningless */ static char curdir[MAXPATHLEN + 1]; /* startup directory */ static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */ char *progname; /* the program name */ @@ -215,6 +216,9 @@ parse_debug_options(const char *argvalue) case 'a': debug |= DEBUG_ARCH; break; + case 'C': + debug |= DEBUG_CWD; + break; case 'c': debug |= DEBUG_COND; break; @@ -341,7 +345,7 @@ MainParseArgs(int argc, char **argv) Boolean inOption, dashDash = FALSE; char found_path[MAXPATHLEN + 1]; /* for searching for sys.mk */ -#define OPTFLAGS "BD:I:J:NST:V:WXd:ef:ij:km:nqrst" +#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrst" /* Can't actually use getopt(3) because rescanning is not portable */ getopt_def = OPTFLAGS; @@ -392,8 +396,18 @@ rearg: compatMake = TRUE; Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL); break; + case 'C': + if (chdir(argvalue) == -1) { + (void)fprintf(stderr, + "%s: chdir %s: %s\n", + progname, argvalue, + strerror(errno)); + exit(1); + } + ignorePWD = TRUE; + break; case 'D': - if (argvalue == NULL) goto noarg; + if (argvalue == NULL || argvalue[0] == 0) goto noarg; Var_Set(argvalue, "1", VAR_GLOBAL, 0); Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL); Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL); @@ -593,7 +607,7 @@ noarg: * Only those that come from the various arguments. */ void -Main_ParseArgLine(char *line) +Main_ParseArgLine(const char *line) { char **argv; /* Manufactured argument vector */ int argc; /* Number of arguments in argv */ @@ -629,6 +643,11 @@ Main_ParseArgLine(char *line) free(p1); argv = brk_string(buf, &argc, TRUE, &args); + if (argv == NULL) { + Error("Unterminated quoted string [%s]", buf); + free(buf); + return; + } free(buf); MainParseArgs(argc, argv); @@ -682,11 +701,27 @@ Main_SetObjdir(const char *path) * TRUE if ok, FALSE on error */ static int -ReadAllMakefiles(ClientData p, ClientData q) +ReadAllMakefiles(const void *p, const void *q) { return (ReadMakefile(p, q) == 0); } +#ifdef SIGINFO +/*ARGSUSED*/ +static void +siginfo(int signo) +{ + char dir[MAXPATHLEN]; + char str[2 * MAXPATHLEN]; + int len; + if (getcwd(dir, sizeof(dir)) == NULL) + return; + len = snprintf(str, sizeof(str), "%s: Working in: %s\n", progname, dir); + if (len > 0) + (void)write(STDERR_FILENO, str, (size_t)len); +} +#endif + /*- * main -- * The main function, for obvious reasons. Initializes variables @@ -732,8 +767,11 @@ main(int argc, char **argv) /* default to writing debug to stderr */ debug_file = stderr; +#ifdef SIGINFO + (void)signal(SIGINFO, siginfo); +#endif /* - * Set the seed to produce a different random sequences + * Set the seed to produce a different random sequence * on each program execution. */ gettimeofday(&rightnow, NULL); @@ -756,42 +794,7 @@ main(int argc, char **argv) } } #endif - /* - * Find where we are and take care of PWD for the automounter... - * All this code is so that we know where we are when we start up - * on a different machine with pmake. - */ - if (getcwd(curdir, MAXPATHLEN) == NULL) { - (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno)); - exit(2); - } - if (stat(curdir, &sa) == -1) { - (void)fprintf(stderr, "%s: %s: %s.\n", - progname, curdir, strerror(errno)); - exit(2); - } - - /* - * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX - * since the value of curdir can very depending on how we got - * here. Ie sitting at a shell prompt (shell that provides $PWD) - * or via subdir.mk in which case its likely a shell which does - * not provide it. - * So, to stop it breaking this case only, we ignore PWD if - * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform. - */ -#ifndef NO_PWD_OVERRIDE - if ((pwd = getenv("PWD")) != NULL && getenv("MAKEOBJDIRPREFIX") == NULL) { - const char *makeobjdir = getenv("MAKEOBJDIR"); - - if (makeobjdir == NULL || !strchr(makeobjdir, '$')) { - if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && - sa.st_dev == sb.st_dev) - (void)strncpy(curdir, pwd, MAXPATHLEN); - } - } -#endif /* * Get the name of this type of MACHINE from utsname * so we can share an executable for similar machines. @@ -834,7 +837,6 @@ main(int argc, char **argv) */ Var_Init(); /* Initialize the lists of variables for * parsing arguments */ - Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0); Var_Set("MACHINE", machine, VAR_GLOBAL, 0); Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0); #ifdef MAKE_VERSION @@ -842,32 +844,6 @@ main(int argc, char **argv) #endif Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */ - /* - * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that, - * MAKEOBJDIR is set in the environment, try only that value - * and fall back to .CURDIR if it does not exist. - * - * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and - * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none - * of these paths exist, just use .CURDIR. - */ - Dir_Init(curdir); - (void)Main_SetObjdir(curdir); - - if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) { - (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir); - (void)Main_SetObjdir(mdpath); - } else if ((path = getenv("MAKEOBJDIR")) != NULL) { - (void)Main_SetObjdir(path); - } else { - (void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine); - if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) { - (void)snprintf(mdpath, MAXPATHLEN, "%s%s", - _PATH_OBJDIRPREFIX, curdir); - (void)Main_SetObjdir(mdpath); - } - } - create = Lst_Init(FALSE); makefiles = Lst_Init(FALSE); printVars = FALSE; @@ -887,7 +863,7 @@ main(int argc, char **argv) maxJobs = DEFMAXLOCAL; /* Set default local max concurrency */ maxJobTokens = maxJobs; compatMake = FALSE; /* No compat mode */ - + ignorePWD = FALSE; /* * Initialize the parsing, directory and variable modules to prepare @@ -914,7 +890,12 @@ main(int argc, char **argv) */ { char tmp[64]; + const char *ep; + if (!(ep = getenv(MAKE_LEVEL))) { + ep = "0"; + } + Var_Set(MAKE_LEVEL, ep, VAR_GLOBAL, 0); snprintf(tmp, sizeof(tmp), "%u", getpid()); Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0); snprintf(tmp, sizeof(tmp), "%u", getppid()); @@ -936,6 +917,72 @@ main(int argc, char **argv) MainParseArgs(argc, argv); /* + * Find where we are (now) and take care of PWD for the automounter... + * All this code is so that we know where we are when we start up + * on a different machine with pmake. + */ + if (getcwd(curdir, MAXPATHLEN) == NULL) { + (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno)); + exit(2); + } + + if (stat(curdir, &sa) == -1) { + (void)fprintf(stderr, "%s: %s: %s.\n", + progname, curdir, strerror(errno)); + exit(2); + } + + /* + * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX + * since the value of curdir can vary depending on how we got + * here. Ie sitting at a shell prompt (shell that provides $PWD) + * or via subdir.mk in which case its likely a shell which does + * not provide it. + * So, to stop it breaking this case only, we ignore PWD if + * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform. + */ +#ifndef NO_PWD_OVERRIDE + if (!ignorePWD && + (pwd = getenv("PWD")) != NULL && + getenv("MAKEOBJDIRPREFIX") == NULL) { + const char *makeobjdir = getenv("MAKEOBJDIR"); + + if (makeobjdir == NULL || !strchr(makeobjdir, '$')) { + if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino && + sa.st_dev == sb.st_dev) + (void)strncpy(curdir, pwd, MAXPATHLEN); + } + } +#endif + Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0); + + /* + * Find the .OBJDIR. If MAKEOBJDIRPREFIX, or failing that, + * MAKEOBJDIR is set in the environment, try only that value + * and fall back to .CURDIR if it does not exist. + * + * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and + * finally _PATH_OBJDIRPREFIX`pwd`, in that order. If none + * of these paths exist, just use .CURDIR. + */ + Dir_Init(curdir); + (void)Main_SetObjdir(curdir); + + if ((path = getenv("MAKEOBJDIRPREFIX")) != NULL) { + (void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir); + (void)Main_SetObjdir(mdpath); + } else if ((path = getenv("MAKEOBJDIR")) != NULL) { + (void)Main_SetObjdir(path); + } else { + (void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine); + if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) { + (void)snprintf(mdpath, MAXPATHLEN, "%s%s", + _PATH_OBJDIRPREFIX, curdir); + (void)Main_SetObjdir(mdpath); + } + } + + /* * Be compatible if user did not specify -j and did not explicitly * turned compatibility on */ @@ -952,7 +999,7 @@ main(int argc, char **argv) Suff_Init(); Trace_Init(tracefile); - DEFAULT = NILGNODE; + DEFAULT = NULL; (void)time(&now); Trace_Log(MAKESTART, NULL); @@ -965,7 +1012,7 @@ main(int argc, char **argv) if (!Lst_IsEmpty(create)) { LstNode ln; - for (ln = Lst_First(create); ln != NILLNODE; + for (ln = Lst_First(create); ln != NULL; ln = Lst_Succ(ln)) { char *name = (char *)Lst_Datum(ln); @@ -1020,7 +1067,7 @@ main(int argc, char **argv) Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK); ln = Lst_Find(sysMkPath, NULL, ReadMakefile); - if (ln == NILLNODE) + if (ln == NULL) Fatal("%s: cannot open %s.", progname, (char *)Lst_Datum(ln)); } @@ -1029,16 +1076,16 @@ main(int argc, char **argv) LstNode ln; ln = Lst_Find(makefiles, NULL, ReadAllMakefiles); - if (ln != NILLNODE) + if (ln != NULL) Fatal("%s: cannot open %s.", progname, (char *)Lst_Datum(ln)); - } else if (ReadMakefile(UNCONST("makefile"), NULL) != 0) - (void)ReadMakefile(UNCONST("Makefile"), NULL); + } else if (ReadMakefile("makefile", NULL) != 0) + (void)ReadMakefile("Makefile", NULL); /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */ if (!noBuiltins || !printVars) { doing_depend = TRUE; - (void)ReadMakefile(UNCONST(".depend"), NULL); + (void)ReadMakefile(".depend", NULL); doing_depend = FALSE; } @@ -1109,7 +1156,7 @@ main(int argc, char **argv) if (printVars) { LstNode ln; - for (ln = Lst_First(variables); ln != NILLNODE; + for (ln = Lst_First(variables); ln != NULL; ln = Lst_Succ(ln)) { char *var = (char *)Lst_Datum(ln); char *value; @@ -1160,9 +1207,9 @@ main(int argc, char **argv) } #ifdef CLEANUP - Lst_Destroy(targs, NOFREE); - Lst_Destroy(variables, NOFREE); - Lst_Destroy(makefiles, NOFREE); + Lst_Destroy(targs, NULL); + Lst_Destroy(variables, NULL); + Lst_Destroy(makefiles, NULL); Lst_Destroy(create, (FreeProc *)free); #endif @@ -1195,9 +1242,9 @@ main(int argc, char **argv) * lots */ static int -ReadMakefile(ClientData p, ClientData q __unused) +ReadMakefile(const void *p, const void *q __unused) { - char *fname = p; /* makefile to read */ + const char *fname = p; /* makefile to read */ int fd; size_t len = MAXPATHLEN; char *name, *path = bmake_malloc(len); @@ -1314,12 +1361,17 @@ Check_Cwd_av(int ac, char **av, int copy) int i; int n; - if (Check_Cwd_Off) + if (Check_Cwd_Off) { + if (DEBUG(CWD)) + fprintf(debug_file, "check_cwd: check is off.\n"); return NULL; + } if (make[0] == NULL) { if (Var_Exists("NOCHECKMAKECHDIR", VAR_GLOBAL)) { Check_Cwd_Off = 1; + if (DEBUG(CWD)) + fprintf(debug_file, "check_cwd: turning check off.\n"); return NULL; } @@ -1332,12 +1384,18 @@ Check_Cwd_av(int ac, char **av, int copy) make[2] = NULL; cur_dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp); } - if (ac == 0 || av == NULL) + if (ac == 0 || av == NULL) { + if (DEBUG(CWD)) + fprintf(debug_file, "check_cwd: empty command.\n"); return NULL; /* initialization only */ + } if (getenv("MAKEOBJDIR") == NULL && - getenv("MAKEOBJDIRPREFIX") == NULL) + getenv("MAKEOBJDIRPREFIX") == NULL) { + if (DEBUG(CWD)) + fprintf(debug_file, "check_cwd: no obj dirs.\n"); return NULL; + } next_cmd = 1; @@ -1360,8 +1418,8 @@ Check_Cwd_av(int ac, char **av, int copy) /* * XXX this should not happen. */ - fprintf(stderr, "WARNING: raw arg ends in shell meta '%s'\n", - av[i]); + fprintf(stderr, "%s: WARNING: raw arg ends in shell meta '%s'\n", + progname, av[i]); } } else next_cmd = 0; @@ -1370,10 +1428,9 @@ Check_Cwd_av(int ac, char **av, int copy) if (*cp == ';' || *cp == '&' || *cp == '|') is_cmd = 1; -#ifdef check_cwd_debug - fprintf(stderr, "av[%d] == %s '%s'", + if (DEBUG(CWD)) + fprintf(debug_file, "av[%d] == %s '%s'", i, (is_cmd) ? "cmd" : "arg", av[i]); -#endif if (is_cmd != 0) { if (*cp == '(' || *cp == '{' || *cp == ';' || *cp == '&' || *cp == '|') { @@ -1387,25 +1444,22 @@ Check_Cwd_av(int ac, char **av, int copy) } } if (strcmp(cp, "cd") == 0 || strcmp(cp, "chdir") == 0) { -#ifdef check_cwd_debug - fprintf(stderr, " == cd, done.\n"); -#endif + if (DEBUG(CWD)) + fprintf(debug_file, " == cd, done.\n"); return NULL; } for (mp = make; *mp != NULL; ++mp) { n = strlen(*mp); if (strcmp(cp, *mp) == 0) { -#ifdef check_cwd_debug - fprintf(stderr, " %s == '%s', chdir(%s)\n", + if (DEBUG(CWD)) + fprintf(debug_file, " %s == '%s', chdir(%s)\n", cp, *mp, cur_dir); -#endif return cur_dir; } } } -#ifdef check_cwd_debug - fprintf(stderr, "\n"); -#endif + if (DEBUG(CWD)) + fprintf(debug_file, "\n"); } return NULL; } @@ -1422,10 +1476,9 @@ Check_Cwd_Cmd(const char *cmd) if (cmd) { av = brk_string(cmd, &ac, TRUE, &bp); -#ifdef check_cwd_debug - fprintf(stderr, "splitting: '%s' -> %d words\n", + if (DEBUG(CWD)) + fprintf(debug_file, "splitting: '%s' -> %d words\n", cmd, ac); -#endif } else { ac = 0; av = NULL; @@ -1541,13 +1594,13 @@ Cmd_Exec(const char *cmd, const char **errnum) */ (void)close(fds[1]); - buf = Buf_Init(0); + Buf_Init(&buf, 0); do { char result[BUFSIZ]; cc = read(fds[0], result, sizeof(result)); if (cc > 0) - Buf_AddBytes(buf, cc, (Byte *)result); + Buf_AddBytes(&buf, cc, result); } while (cc > 0 || (cc == -1 && errno == EINTR)); @@ -1562,13 +1615,15 @@ Cmd_Exec(const char *cmd, const char **errnum) while(((pid = waitpid(cpid, &status, 0)) != cpid) && (pid >= 0)) continue; - res = (char *)Buf_GetAll(buf, &cc); - Buf_Destroy(buf, FALSE); + cc = Buf_Size(&buf); + res = Buf_Destroy(&buf, FALSE); if (cc == 0) *errnum = "Couldn't read shell's output for \"%s\""; - if (WAIT_STATUS(status)) + if (WIFSIGNALED(status)) + *errnum = "\"%s\" exited on a signal"; + else if (WEXITSTATUS(status) != 0) *errnum = "\"%s\" returned non-zero status"; /* @@ -1614,13 +1669,22 @@ void Error(const char *fmt, ...) { va_list ap; - - va_start(ap, fmt); - fprintf(stderr, "%s: ", progname); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - (void)fflush(stderr); + FILE *err_file; + + err_file = debug_file; + if (err_file == stdout) + err_file = stderr; + for (;;) { + va_start(ap, fmt); + fprintf(err_file, "%s: ", progname); + (void)vfprintf(err_file, fmt, ap); + va_end(ap); + (void)fprintf(err_file, "\n"); + (void)fflush(err_file); + if (err_file == stderr) + break; + err_file = stderr; + } } /*- @@ -1725,84 +1789,6 @@ Finish(int errors) Fatal("%d error%s", errors, errors == 1 ? "" : "s"); } -#ifndef USE_EMALLOC -/* - * enomem -- - * die when out of memory. - */ -static void -enomem(void) -{ - (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno)); - exit(2); -} - -/* - * bmake_malloc -- - * malloc, but die on error. - */ -void * -bmake_malloc(size_t len) -{ - void *p; - - if ((p = malloc(len)) == NULL) - enomem(); - return(p); -} - -/* - * bmake_strdup -- - * strdup, but die on error. - */ -char * -bmake_strdup(const char *str) -{ - size_t len; - char *p; - - len = strlen(str) + 1; - if ((p = malloc(len)) == NULL) - enomem(); - return memcpy(p, str, len); -} - -/* - * bmake_strndup -- - * strndup, but die on error. - */ -char * -bmake_strndup(const char *str, size_t max_len) -{ - size_t len; - char *p; - - if (str == NULL) - return NULL; - - len = strlen(str); - if (len > max_len) - len = max_len; - p = bmake_malloc(len + 1); - memcpy(p, str, len); - p[len] = '\0'; - - return(p); -} - -/* - * bmake_realloc -- - * realloc, but die on error. - */ -void * -bmake_realloc(void *ptr, size_t size) -{ - if ((ptr = realloc(ptr, size)) == NULL) - enomem(); - return(ptr); -} -#endif - /* * enunlink -- * Remove a file carefully, avoiding directories. @@ -1837,7 +1823,7 @@ execError(const char *af, const char *av) iov[i].iov_len = strlen(iov[i].iov_base), \ i++) #else -#define IOADD(void)write(2, s, strlen(s)) +#define IOADD(s) (void)write(2, s, strlen(s)) #endif IOADD(progname); @@ -1862,7 +1848,8 @@ static void usage(void) { (void)fprintf(stderr, -"usage: %s [-BeikNnqrstWX] [-D variable] [-d flags] [-f makefile]\n\ +"usage: %s [-BeikNnqrstWX] \n\ + [-C directory] [-D variable] [-d flags] [-f makefile]\n\ [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\ [-V variable] [variable=value] [target ...]\n", progname); exit(2); @@ -1870,7 +1857,7 @@ usage(void) int -PrintAddr(ClientData a, ClientData b) +PrintAddr(void *a, void *b) { printf("%lx ", (unsigned long) a); return b ? 0 : 0; diff --git a/devel/bmake/files/make.1 b/devel/bmake/files/make.1 index d38521ad531..cb5d0daac5f 100644 --- a/devel/bmake/files/make.1 +++ b/devel/bmake/files/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.3 2008/11/11 14:37:05 joerg Exp $ +.\" $NetBSD: make.1,v 1.4 2009/09/18 21:27:25 joerg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd October 29, 2008 +.Dd September 7, 2009 .Dt MAKE 1 .Os .Sh NAME @@ -39,6 +39,9 @@ .Nm .Op Fl BeikNnqrstWX .Bk -words +.Op Fl C Ar directory +.Ek +.Bk -words .Op Fl D Ar variable .Ek .Bk -words @@ -104,6 +107,16 @@ The options are as follows: .It Fl B Try to be backwards compatible by executing a single shell per command and by executing the commands to make the sources of a dependency line in sequence. +.It Fl C Ar directory +Change to +.Ar directory +before reading the makefiles or doing anything else. +If multiple +.Fl C +options are specified, each is interpreted relative to the previous one: +.Fl C Pa / Fl C Pa etc +is equivalent to +.Fl C Pa /etc . .It Fl D Ar variable Define .Ar variable @@ -132,6 +145,8 @@ Print all possible debugging information; equivalent to specifying all of the debugging flags. .It Ar a Print debugging information about archive searching and caching. +.It Ar C +Print debugging information about current working directory. .It Ar c Print debugging information about conditional evaluation. .It Ar d @@ -183,16 +198,24 @@ Also known as "loud" behavior. Print debugging information about making targets, including modification dates. .It Ar n -Don't delete the temporary command scripts created in +Don't delete the temporary command scripts created when running commands. +These temporary scripts are created in the directory +referred to by the +.Ev TMPDIR +environment variable, or in .Pa /tmp -when running commands. -These are created via -.Xr mkstemp 3 +if +.Ev TMPDIR +is unset or set to the empty string. +The temporary scripts are created by +.Xr mkstemp 3 , and have names of the form -.Pa /tmp/makeXXXXX . +.Pa makeXXXXXX . .Em NOTE : -This can create many file in -.Pa /tmp +This can create many files in +.Ev TMPDIR +or +.Pa /tmp , so use with care. .It Ar p Print debugging information about makefile parsing. @@ -246,6 +269,14 @@ may have running at any one time. Turns compatibility mode off, unless the .Ar B flag is also specified. +When compatibility mode is off, all commands associated with a +target are executed in a single shell invocation as opposed to the +traditional one shell invocation per line. +This can break traditional scripts which change directories on each +command invocation and then expect to start with a fresh environment +on the next line. +It is more efficient to correct the scripts rather than turn backwards +compatibility on. .It Fl k Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. @@ -497,6 +528,14 @@ If the variable name contains only a single letter, the surrounding braces or parentheses are not required. This shorter form is not recommended. .Pp +If the variable name contains a dollar, then the name itself is expanded first. +This allows almost arbitrary variable names, however names containing dollar, +braces, parenthesis, or whitespace are really best avoided! +.Pp +If the result of expanding a variable contains a dollar sign +.Pq Ql \&$ +the string is expanded again. +.Pp Variable substitution occurs at two distinct times, depending on where the variable is being used. Variables in dependency lines are expanded as the line is read. @@ -575,7 +614,7 @@ These variables are and .Ql Va .MEMBER . .El -.Ss Additional inbuilt variables +.Ss Additional built-in variables In addition, .Nm sets or knows about the following variables: @@ -621,6 +660,17 @@ The list of makefiles read by .Nm , which is useful for tracking dependencies. Each makefile is recorded only once, regardless of the number of times read. +.It Va .MAKE.LEVEL +The recursion depth of +.Nm . +The initial instance of +.Nm +will be 0, and an incremented value is put into the environment +to be seen by the next generation. +This allows tests like: +.Li .if ${.MAKE.LEVEL} == 0 +to protect things which should only be evaluated in the initial instance of +.Nm . .It Va .MAKE.PID The process-id of .Nm . @@ -779,6 +829,16 @@ is set to the value of for all programs which .Nm executes. +.It Ev VPATH +Colon-separated +.Pq Dq \&: +lists of directories that +.Nm +will search for files. +The variable is supported for compatibility with old make programs only, +use +.Ql Va .PATH +instead. .El .Ss Variable modifiers Variable expansion may be modified to select or modify each word of the @@ -993,45 +1053,16 @@ Remove adjacent duplicate words (like .Sm off .It Cm \&:\&? Ar true_string Cm \&: Ar false_string .Sm on -If the variable (actually an expression; see below) -evaluates to true, return as its value the +If the variable name (not its value), when parsed as a .if conditional +expression, evaluates to true, return as its value the .Ar true_string , otherwise return the .Ar false_string . -The expression parser needs careful feeding to avoid surprises. -For example the following all do what one might expect, -.Dl ${"${NUMBERS:M42}":?match:no} -.Dl ${${NUMBER:U0} > 0:?set:zero} -.Dl ${empty(NUMBER):?empty:set} -The first case expands to -.Ql match -if -.Dv NUMBERS -contains the value 42 (the quotes are important). -The second expands to -.Ql zero -unless -.Dv NUMBER -is set to a value greater than 0. -The last case expands to -.Ql empty -or -.Ql set -depending on whether -.Dv NUMBER -is empty. -In this example, use of -.Ql {} -rather than -.Ql () -is important to avoid the parser getting confused. -By contrast, the following examples will -.Em not -behave as expected. -.Dl ${"1 < 0":?always:no} -.Dl ${NUMBERS:M42:?always:no} -in both cases the expansion will always be -.Ql always . +Since the variable name is used as the expression, \&:\&? must be the +first modifier after the variable name itself - which will, of course, +usually contain variable expansions. +If the expression is a single token, it will likely be treated as a check +for the name being defined. .It Ar :old_string=new_string This is the .At V @@ -1116,25 +1147,14 @@ The variable is assigned the value .Ar str after substitution. This modifier and its variations are useful in -obscure situations such as wanting to apply modifiers to -.Cm \&.for -loop iteration variables which won't work due to the way -.Cm \&.for -loops are implemented. +obscure situations such as wanting to set a variable when shell commands +are being parsed. These assignment modifiers always expand to nothing, so if appearing in a rule line by themselves should be preceded with something to keep .Nm happy. -As in: -.Bd -literal -use_foo: \&.USE -\&.for i in ${\&.TARGET} ${\&.TARGET:R}\&.gz - @: ${t::=$i} - @echo t:R:T=${t:R:T} -\&.endfor - -.Ed +.Pp The .Ql Cm \&:: helps avoid false matches with the @@ -1263,8 +1283,7 @@ The possible conditionals are as follows: Export the specified global variable. If no variable is provided, all globals are exported except for internal variables (those that start with -.Ql \&. -). +.Ql \&. ) . This is not affected by the .Fl X flag, so should be used with caution. @@ -1432,16 +1451,17 @@ of a string comparison. .Pp When .Nm -is evaluating one of these conditional expression, and it encounters -a word it doesn't recognize, either the +is evaluating one of these conditional expressions, and it encounters +a (white-space separated) word it doesn't recognize, either the .Dq make or .Dq defined expression is applied to it, depending on the form of the conditional. If the form is -.Ql Ic .ifdef -or +.Ql Ic .ifdef , .Ql Ic .ifndef , +or +.Ql Ic .if the .Dq defined expression is applied. @@ -1588,9 +1608,9 @@ b1: .Ed the output is always +.Ql a , .Ql b1 , .Ql b , -.Ql a , .Ql x . .br The ordering imposed by @@ -1668,7 +1688,7 @@ could be built, unless is built by another part of the dependency graph, the following is a dependency loop: .Bd -literal -\&.ORDER a b +\&.ORDER: a b b: a .Ed .Pp @@ -1780,8 +1800,9 @@ uses the following environment variables, if they exist: .Ev MAKEOBJDIR , .Ev MAKEOBJDIRPREFIX , .Ev MAKESYSPATH , +.Ev PWD , and -.Ev PWD . +.Ev TMPDIR . .Pp .Ev MAKEOBJDIRPREFIX and @@ -1813,6 +1834,12 @@ The way that parallel makes are scheduled changed in .Nx 4.0 so that .ORDER and .WAIT apply recursively to the dependant nodes. The algorithms used may change again in the future. +.Pp +The way that .for loop variables are substituted changed after +.Nx 5.0 +so that they still appear to be variable expansions. +In particular this stops them being treated as syntax, and removes some +obscure problems using them in .if statements. .Sh SEE ALSO .Xr mkdep 1 .Sh HISTORY @@ -1820,3 +1847,14 @@ A .Nm command appeared in .At v7 . +.Sh BUGS +The +.Nm +syntax is difficult to parse without actually acting of the data. +For instance finding the end of a variable use should involve scanning each +the modifiers using the correct terminator for each field. +In many places +.Nm +just counts {} and () in order to find the end of a variable expansion. +.Pp +There is no way of escaping a space character in a filename. diff --git a/devel/bmake/files/make.c b/devel/bmake/files/make.c index 56105156f85..307f0a9a1c1 100644 --- a/devel/bmake/files/make.c +++ b/devel/bmake/files/make.c @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: make.c,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: make.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"; +static char rcsid[] = "$NetBSD: make.c,v 1.3 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: make.c,v 1.2 2008/03/09 19:54:29 joerg Exp $"); +__RCSID("$NetBSD: make.c,v 1.3 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -127,17 +127,17 @@ static Lst toBeMade; /* The current fringe of the graph. These * Make_Update and subtracted from by * MakeStartJobs */ -static int MakeAddChild(ClientData, ClientData); -static int MakeFindChild(ClientData, ClientData); -static int MakeUnmark(ClientData, ClientData); -static int MakeAddAllSrc(ClientData, ClientData); -static int MakeTimeStamp(ClientData, ClientData); -static int MakeHandleUse(ClientData, ClientData); +static int MakeAddChild(void *, void *); +static int MakeFindChild(void *, void *); +static int MakeUnmark(void *, void *); +static int MakeAddAllSrc(void *, void *); +static int MakeTimeStamp(void *, void *); +static int MakeHandleUse(void *, void *); static Boolean MakeStartJobs(void); -static int MakePrintStatus(ClientData, ClientData); -static int MakeCheckOrder(ClientData, ClientData); -static int MakeBuildChild(ClientData, ClientData); -static int MakeBuildParent(ClientData, ClientData); +static int MakePrintStatus(void *, void *); +static int MakeCheckOrder(void *, void *); +static int MakeBuildChild(void *, void *); +static int MakeBuildParent(void *, void *); static void make_abort(GNode *gn, int line) @@ -185,7 +185,7 @@ Make_TimeStamp(GNode *pgn, GNode *cgn) * */ static int -MakeTimeStamp(ClientData pgn, ClientData cgn) +MakeTimeStamp(void *pgn, void *cgn) { return Make_TimeStamp((GNode *)pgn, (GNode *)cgn); } @@ -362,7 +362,7 @@ Make_OODate(GNode *gn) *----------------------------------------------------------------------- */ static int -MakeAddChild(ClientData gnp, ClientData lp) +MakeAddChild(void *gnp, void *lp) { GNode *gn = (GNode *)gnp; Lst l = (Lst) lp; @@ -394,7 +394,7 @@ MakeAddChild(ClientData gnp, ClientData lp) *----------------------------------------------------------------------- */ static int -MakeFindChild(ClientData gnp, ClientData pgnp) +MakeFindChild(void *gnp, void *pgnp) { GNode *gn = (GNode *)gnp; GNode *pgn = (GNode *)pgnp; @@ -450,9 +450,9 @@ Make_HandleUse(GNode *cgn, GNode *pgn) * prepend the child's commands to the parent. */ Lst cmds = pgn->commands; - pgn->commands = Lst_Duplicate(cgn->commands, NOCOPY); + pgn->commands = Lst_Duplicate(cgn->commands, NULL); (void)Lst_Concat(pgn->commands, cmds, LST_CONCNEW); - Lst_Destroy(cmds, NOFREE); + Lst_Destroy(cmds, NULL); } else { /* * .USE or target has no commands -- @@ -463,7 +463,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn) } if (Lst_Open(cgn->children) == SUCCESS) { - while ((ln = Lst_Next(cgn->children)) != NILLNODE) { + while ((ln = Lst_Next(cgn->children)) != NULL) { GNode *tgn, *gn = (GNode *)Lst_Datum(ln); /* @@ -482,7 +482,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn) if (gn->name && gn->uname && strcmp(gn->name, gn->uname) != 0) { /* See if we have a target for this node. */ tgn = Targ_FindNode(gn->name, TARG_NOCREATE); - if (tgn != NILGNODE) + if (tgn != NULL) gn = tgn; } @@ -518,7 +518,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn) *----------------------------------------------------------------------- */ static int -MakeHandleUse(ClientData cgnp, ClientData pgnp) +MakeHandleUse(void *cgnp, void *pgnp) { GNode *cgn = (GNode *)cgnp; GNode *pgn = (GNode *)pgnp; @@ -541,7 +541,7 @@ MakeHandleUse(ClientData cgnp, ClientData pgnp) * children the parent has. This is used by Make_Run to decide * whether to queue the parent or examine its children... */ - if ((ln = Lst_Member(pgn->children, cgn)) != NILLNODE) { + if ((ln = Lst_Member(pgn->children, cgn)) != NULL) { Lst_Remove(pgn->children, ln); pgn->unmade--; } @@ -720,7 +720,7 @@ Make_Update(GNode *cgn) /* Now mark all the parents as having one less unmade child */ if (Lst_Open(parents) == SUCCESS) { - while ((ln = Lst_Next(parents)) != NILLNODE) { + while ((ln = Lst_Next(parents)) != NULL) { pgn = (GNode *)Lst_Datum(ln); if (DEBUG(MAKE)) fprintf(debug_file, "inspect parent %s%s: flags %x, " @@ -823,7 +823,7 @@ Make_Update(GNode *cgn) if (Lst_Open(cgn->iParents) == SUCCESS) { char *cpref = Var_Value(PREFIX, cgn, &p1); - while ((ln = Lst_Next(cgn->iParents)) != NILLNODE) { + while ((ln = Lst_Next(cgn->iParents)) != NULL) { pgn = (GNode *)Lst_Datum(ln); if (pgn->flags & REMAKE) { Var_Set(IMPSRC, cname, pgn, 0); @@ -860,7 +860,7 @@ Make_Update(GNode *cgn) *----------------------------------------------------------------------- */ static int -MakeUnmark(ClientData cgnp, ClientData pgnp __unused) +MakeUnmark(void *cgnp, void *pgnp __unused) { GNode *cgn = (GNode *)cgnp; @@ -876,7 +876,7 @@ MakeUnmark(ClientData cgnp, ClientData pgnp __unused) * */ static int -MakeAddAllSrc(ClientData cgnp, ClientData pgnp) +MakeAddAllSrc(void *cgnp, void *pgnp) { GNode *cgn = (GNode *)cgnp; GNode *pgn = (GNode *)pgnp; @@ -994,7 +994,7 @@ Make_DoAllVar(GNode *gn) */ static int -MakeCheckOrder(ClientData v_bn, ClientData ignore __unused) +MakeCheckOrder(void *v_bn, void *ignore __unused) { GNode *bn = v_bn; @@ -1007,7 +1007,7 @@ MakeCheckOrder(ClientData v_bn, ClientData ignore __unused) } static int -MakeBuildChild(ClientData v_cn, ClientData toBeMade_next) +MakeBuildChild(void *v_cn, void *toBeMade_next) { GNode *cn = v_cn; @@ -1029,7 +1029,7 @@ MakeBuildChild(ClientData v_cn, ClientData toBeMade_next) cn->name, cn->cohort_num); cn->made = REQUESTED; - if (toBeMade_next == NILLNODE) + if (toBeMade_next == NULL) Lst_AtEnd(toBeMade, cn); else Lst_InsertBefore(toBeMade, toBeMade_next, cn); @@ -1046,7 +1046,7 @@ MakeBuildChild(ClientData v_cn, ClientData toBeMade_next) /* When a .ORDER RHS node completes we do this on each LHS */ static int -MakeBuildParent(ClientData v_pn, ClientData toBeMade_next) +MakeBuildParent(void *v_pn, void *toBeMade_next) { GNode *pn = v_pn; @@ -1165,7 +1165,7 @@ MakeStartJobs(void) *----------------------------------------------------------------------- */ static int -MakePrintStatusOrder(ClientData ognp, ClientData gnp) +MakePrintStatusOrder(void *ognp, void *gnp) { GNode *ogn = ognp; GNode *gn = gnp; @@ -1187,7 +1187,7 @@ MakePrintStatusOrder(ClientData ognp, ClientData gnp) } static int -MakePrintStatus(ClientData gnp, ClientData v_errors) +MakePrintStatus(void *gnp, void *v_errors) { GNode *gn = (GNode *)gnp; int *errors = v_errors; @@ -1276,7 +1276,7 @@ Make_ExpandUse(Lst targs) GNode *gn; /* a temporary pointer */ Lst examine; /* List of targets to examine */ - examine = Lst_Duplicate(targs, NOCOPY); + examine = Lst_Duplicate(targs, NULL); /* * Make an initial downward pass over the graph, marking nodes to be made @@ -1300,7 +1300,7 @@ Make_ExpandUse(Lst targs) if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts)) { /* Append all the 'cohorts' to the list of things to examine */ Lst new; - new = Lst_Duplicate(gn->cohorts, NOCOPY); + new = Lst_Duplicate(gn->cohorts, NULL); Lst_Concat(new, examine, LST_CONCLINK); examine = new; } @@ -1344,7 +1344,7 @@ Make_ExpandUse(Lst targs) Lst_ForEach(gn->children, MakeAddChild, examine); } - Lst_Destroy(examine, NOFREE); + Lst_Destroy(examine, NULL); } /*- @@ -1359,7 +1359,7 @@ Make_ExpandUse(Lst targs) */ static int -link_parent(ClientData cnp, ClientData pnp) +link_parent(void *cnp, void *pnp) { GNode *cn = cnp; GNode *pn = pnp; @@ -1417,7 +1417,7 @@ Make_ProcessWait(Lst targs) Lst_ForEach(targs, link_parent, pgn); /* Start building with the 'dummy' .MAIN' node */ - MakeBuildChild(pgn, NILLNODE); + MakeBuildChild(pgn, NULL); examine = Lst_Init(FALSE); Lst_AtEnd(examine, pgn); @@ -1435,14 +1435,14 @@ Make_ProcessWait(Lst targs) if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (pgn->cohorts)) { /* Append all the 'cohorts' to the list of things to examine */ Lst new; - new = Lst_Duplicate(pgn->cohorts, NOCOPY); + new = Lst_Duplicate(pgn->cohorts, NULL); Lst_Concat(new, examine, LST_CONCLINK); examine = new; } owln = Lst_First(pgn->children); Lst_Open(pgn->children); - for (; (ln = Lst_Next(pgn->children)) != NILLNODE; ) { + for (; (ln = Lst_Next(pgn->children)) != NULL; ) { cgn = Lst_Datum(ln); if (cgn->type & OP_WAIT) { /* Make the .WAIT node depend on the previous children */ @@ -1455,7 +1455,7 @@ Make_ProcessWait(Lst targs) Lst_Close(pgn->children); } - Lst_Destroy(examine, NOFREE); + Lst_Destroy(examine, NULL); } /*- diff --git a/devel/bmake/files/make.h b/devel/bmake/files/make.h index 03d8ad6d2e9..f57f5f162b7 100644 --- a/devel/bmake/files/make.h +++ b/devel/bmake/files/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: make.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -121,6 +121,7 @@ #include "hash.h" #include "make-conf.h" #include "buf.h" +#include "make_malloc.h" /* * some vendors don't have this --sjg @@ -230,11 +231,6 @@ typedef struct GNode { } GNode; /* - * Manifest constants - */ -#define NILGNODE ((GNode *) NIL) - -/* * The OP_ constants are used when parsing a dependency line as a way of * communicating to other parts of the program the way in which a target * should be made. These constants are bitwise-OR'ed together and @@ -306,7 +302,7 @@ typedef struct GNode { * do if the desired node(s) is (are) not found. If the TARG_CREATE constant * is given, a new, empty node will be created for the target, placed in the * table of all targets and its address returned. If TARG_NOCREATE is given, - * a NIL pointer will be returned. + * a NULL pointer will be returned. */ #define TARG_NOCREATE 0x00 /* don't create it */ #define TARG_CREATE 0x01 /* create node if not found */ @@ -418,6 +414,7 @@ extern char *progname; /* The program name */ #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */ #define MAKE_EXPORTED ".MAKE.EXPORTED" /* variables we export */ #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all the makefiles we read */ +#define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */ /* * debug control: @@ -426,32 +423,29 @@ extern char *progname; /* The program name */ */ FILE *debug_file; /* Output written here - default stdout */ extern int debug; -#define DEBUG_ARCH 0x0001 -#define DEBUG_COND 0x0002 -#define DEBUG_DIR 0x0004 -#define DEBUG_GRAPH1 0x0008 -#define DEBUG_GRAPH2 0x0010 -#define DEBUG_JOB 0x0020 -#define DEBUG_MAKE 0x0040 -#define DEBUG_SUFF 0x0080 -#define DEBUG_TARG 0x0100 -#define DEBUG_VAR 0x0200 -#define DEBUG_FOR 0x0400 -#define DEBUG_SHELL 0x0800 -#define DEBUG_ERROR 0x1000 -#define DEBUG_LOUD 0x2000 +#define DEBUG_ARCH 0x00001 +#define DEBUG_COND 0x00002 +#define DEBUG_DIR 0x00004 +#define DEBUG_GRAPH1 0x00008 +#define DEBUG_GRAPH2 0x00010 +#define DEBUG_JOB 0x00020 +#define DEBUG_MAKE 0x00040 +#define DEBUG_SUFF 0x00080 +#define DEBUG_TARG 0x00100 +#define DEBUG_VAR 0x00200 +#define DEBUG_FOR 0x00400 +#define DEBUG_SHELL 0x00800 +#define DEBUG_ERROR 0x01000 +#define DEBUG_LOUD 0x02000 #define DEBUG_GRAPH3 0x10000 #define DEBUG_SCRIPT 0x20000 #define DEBUG_PARSE 0x40000 +#define DEBUG_CWD 0x80000 #define CONCAT(a,b) a##b #define DEBUG(module) (debug & CONCAT(DEBUG_,module)) -/* - * Since there are so many, all functions that return non-integer values are - * extracted by means of a sed script or two and stuck in the file "nonints.h" - */ #include "nonints.h" int Make_TimeStamp(GNode *, GNode *); diff --git a/devel/bmake/files/makefile.boot.in b/devel/bmake/files/makefile.boot.in index d2d57f6b715..bb4eada2dff 100644 --- a/devel/bmake/files/makefile.boot.in +++ b/devel/bmake/files/makefile.boot.in @@ -1,5 +1,5 @@ # RCSid: -# $Id: makefile.boot.in,v 1.7 2008/03/09 19:54:29 joerg Exp $ +# $Id: makefile.boot.in,v 1.8 2009/09/18 21:27:25 joerg Exp $ # # modify MACHINE and MACHINE_ARCH as appropriate for your target architecture @@ -23,7 +23,9 @@ CFLAGS= @CFLAGS@ -I. -I$(srcdir) @DEFS@ @CPPFLAGS@ ${XDEFS} \ MDEFS="-D@force_machine@MACHINE=\"@machine@\"" "-DMACHINE_ARCH=\"@machine_arch@\"" OBJ=arch.o buf.o compat.o cond.o dir.o for.o hash.o job.o main.o make.o \ - parse.o str.o suff.o targ.o trace.o var.o util.o getopt.o sigcompat.o @LIBOBJS@ + parse.o str.o suff.o targ.o trace.o var.o util.o getopt.o sigcompat.o \ + strlist.o make_malloc.o \ + @LIBOBJS@ BMAKE_ENV= CC="$(CC)" LIBC= MAKEFLAGS= MAKESYSPATH=${BOOTSTRAP_SYS_PATH} diff --git a/devel/bmake/files/nonints.h b/devel/bmake/files/nonints.h index d37682390c7..d15eb74a397 100644 --- a/devel/bmake/files/nonints.h +++ b/devel/bmake/files/nonints.h @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: nonints.h,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -90,22 +90,24 @@ void Arch_End(void); int Arch_IsLib(GNode *); /* compat.c */ -int CompatRunCommand(ClientData, ClientData); +int CompatRunCommand(void *, void *); void Compat_Run(Lst); -int Compat_Make(ClientData, ClientData); +int Compat_Make(void *, void *); /* cond.c */ -int Cond_EvalExpression(int, char *, Boolean *, int); +struct If; +int Cond_EvalExpression(const struct If *, char *, Boolean *, int); int Cond_Eval(char *); void Cond_restore_depth(unsigned int); unsigned int Cond_save_depth(void); /* for.c */ int For_Eval(char *); +int For_Accum(char *); void For_Run(int); /* main.c */ -void Main_ParseArgLine(char *); +void Main_ParseArgLine(const char *); int main(int, char **); char *Cmd_Exec(const char *, const char **); void Error(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); @@ -114,20 +116,8 @@ void Fatal(const char *, ...) void Punt(const char *, ...) __attribute__((__format__(__printf__, 1, 2),__noreturn__)); void DieHorribly(void) __attribute__((__noreturn__)); -int PrintAddr(ClientData, ClientData); +int PrintAddr(void *, void *); void Finish(int); -#ifndef USE_EMALLOC -void *bmake_malloc(size_t); -void *bmake_realloc(void *, size_t); -char *bmake_strdup(const char *); -char *bmake_strndup(const char *, size_t); -#else -#include <util.h> -#define bmake_malloc(x) emalloc(x) -#define bmake_realloc(x,y) erealloc(x,y) -#define bmake_strdup(x) estrdup(x) -#define bmake_strndup(x,y) estrndup(x,y) -#endif int eunlink(const char *); void execError(const char *, const char *); @@ -141,7 +131,7 @@ void Parse_AddIncludeDir(char *); void Parse_File(const char *, int); void Parse_Init(void); void Parse_End(void); -void Parse_SetInput(const char *, int, int, char *); +void Parse_SetInput(const char *, int, int, char *(*)(void *), void *); Lst Parse_MainName(void); /* str.c */ @@ -150,13 +140,13 @@ char **brk_string(const char *, int *, Boolean, char **); char *Str_FindSubstring(const char *, const char *); int Str_Match(const char *, const char *); char *Str_SYSVMatch(const char *, const char *, int *len); -void Str_SYSVSubst(Buffer, char *, char *, int); +void Str_SYSVSubst(Buffer *, char *, char *, int); /* suff.c */ void Suff_ClearSuffixes(void); Boolean Suff_IsTransform(char *); GNode *Suff_AddTransform(char *); -int Suff_EndTransform(ClientData, ClientData); +int Suff_EndTransform(void *, void *); void Suff_AddSuffix(char *, GNode **); Lst Suff_GetPath(char *); void Suff_DoPaths(void); @@ -180,8 +170,8 @@ Boolean Targ_Ignore(GNode *); Boolean Targ_Silent(GNode *); Boolean Targ_Precious(GNode *); void Targ_SetMain(GNode *); -int Targ_PrintCmd(ClientData, ClientData); -int Targ_PrintNode(ClientData, ClientData); +int Targ_PrintCmd(void *, void *); +int Targ_PrintNode(void *, void *); char *Targ_FmtTime(time_t); void Targ_PrintType(int); void Targ_PrintGraph(int); diff --git a/devel/bmake/files/parse.c b/devel/bmake/files/parse.c index 5da1a49d416..7660549ff29 100644 --- a/devel/bmake/files/parse.c +++ b/devel/bmake/files/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.4 2009/03/20 16:38:59 joerg Exp $ */ +/* $NetBSD: parse.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.4 2009/03/20 16:38:59 joerg Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.4 2009/03/20 16:38:59 joerg Exp $"); +__RCSID("$NetBSD: parse.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -155,14 +155,17 @@ static GNode *mainNode; /* The main target to create. This is the * first target on the first dependency * line in the first makefile */ typedef struct IFile { - const char *fname; /* name of file */ - int lineno; /* line number in file */ - int fd; /* the open file */ - int cond_depth; /* 'if' nesting when file opened */ + const char *fname; /* name of file */ + int lineno; /* current line number in file */ + int first_lineno; /* line number of start of text */ + int fd; /* the open file */ + int cond_depth; /* 'if' nesting when file opened */ char *P_str; /* point to base of string buffer */ char *P_ptr; /* point to next char of string buffer */ char *P_end; /* point to the end of string buffer */ int P_buflen; /* current size of file buffer */ + char *(*nextbuf)(void *); /* Function to get more data */ + void *nextbuf_arg; /* Opaque arg for nextbuf() */ } IFile; #define IFILE_BUFLEN 0x8000 @@ -222,7 +225,7 @@ static ParseSpecial specType; #define LPAREN '(' #define RPAREN ')' /* - * Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER + * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER * seen, then set to each successive source on the line. */ static GNode *predecessor; @@ -285,15 +288,15 @@ static void ParseErrorInternal(const char *, size_t, int, const char *, ...) static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list) __attribute__((__format__(__printf__, 5, 0))); static int ParseFindKeyword(const char *); -static int ParseLinkSrc(ClientData, ClientData); -static int ParseDoOp(ClientData, ClientData); +static int ParseLinkSrc(void *, void *); +static int ParseDoOp(void *, void *); static void ParseDoSrc(int, const char *); -static int ParseFindMain(ClientData, ClientData); -static int ParseAddDir(ClientData, ClientData); -static int ParseClearPath(ClientData, ClientData); +static int ParseFindMain(void *, void *); +static int ParseAddDir(void *, void *); +static int ParseClearPath(void *, void *); static void ParseDoDependency(char *); -static int ParseAddCmd(ClientData, ClientData); -static void ParseHasCommands(ClientData); +static int ParseAddCmd(void *, void *); +static void ParseHasCommands(void *); static void ParseDoInclude(char *); static void ParseSetParseFile(const char *); #ifdef SYSVINCLUDE @@ -472,32 +475,26 @@ void Parse_Error(int type, const char *fmt, ...) { va_list ap; + const char *fname; + size_t lineno; - va_start(ap, fmt); - if (curFile == (IFile *)NIL) { - /* avoid segfault */ - static IFile intFile = { - NULL, 0, /* fd */ -1, 0, NULL, NULL, NULL, 0 - }; - curFile = &intFile; + if (curFile == NULL) { + fname = NULL; + lineno = 0; + } else { + fname = curFile->fname; + lineno = curFile->lineno; } - ParseVErrorInternal(stderr, curFile->fname, curFile->lineno, - type, fmt, ap); + + va_start(ap, fmt); + ParseVErrorInternal(stderr, fname, lineno, type, fmt, ap); va_end(ap); if (debug_file != stderr && debug_file != stdout) { va_start(ap, fmt); - ParseVErrorInternal(debug_file, curFile->fname, curFile->lineno, - type, fmt, ap); + ParseVErrorInternal(debug_file, fname, lineno, type, fmt, ap); va_end(ap); } - /* - * if we get this far, make sure we don't leave curFile - * pointing to our dummy one. - */ - if (curFile->fname == NULL) { - curFile = (IFile *)NIL; - } } /*- @@ -521,7 +518,7 @@ Parse_Error(int type, const char *fmt, ...) *--------------------------------------------------------------------- */ static int -ParseLinkSrc(ClientData pgnp, ClientData cgnp) +ParseLinkSrc(void *pgnp, void *cgnp) { GNode *pgn = (GNode *)pgnp; GNode *cgn = (GNode *)cgnp; @@ -561,7 +558,7 @@ ParseLinkSrc(ClientData pgnp, ClientData cgnp) *--------------------------------------------------------------------- */ static int -ParseDoOp(ClientData gnp, ClientData opp) +ParseDoOp(void *gnp, void *opp) { GNode *gn = (GNode *)gnp; int op = *(int *)opp; @@ -698,7 +695,7 @@ ParseDoSrc(int tOp, const char *src) * source and the current one. */ gn = Targ_FindNode(src, TARG_CREATE); - if (predecessor != NILGNODE) { + if (predecessor != NULL) { (void)Lst_AtEnd(predecessor->order_succ, gn); (void)Lst_AtEnd(gn->order_pred, predecessor); if (DEBUG(PARSE)) { @@ -757,7 +754,7 @@ ParseDoSrc(int tOp, const char *src) *----------------------------------------------------------------------- */ static int -ParseFindMain(ClientData gnp, ClientData dummy) +ParseFindMain(void *gnp, void *dummy) { GNode *gn = (GNode *)gnp; if ((gn->type & OP_NOTARGET) == 0) { @@ -783,7 +780,7 @@ ParseFindMain(ClientData gnp, ClientData dummy) *----------------------------------------------------------------------- */ static int -ParseAddDir(ClientData path, ClientData name) +ParseAddDir(void *path, void *name) { (void)Dir_AddDir((Lst) path, (char *)name); return(0); @@ -803,7 +800,7 @@ ParseAddDir(ClientData path, ClientData name) *----------------------------------------------------------------------- */ static int -ParseClearPath(ClientData path, ClientData dummy) +ParseClearPath(void *path, void *dummy) { Dir_ClearPath((Lst) path); return(dummy ? 0 : 0); @@ -979,7 +976,7 @@ ParseDoDependency(char *line) * main target. * .NOTPARALLEL Make only one target at a time. * .SINGLESHELL Create a shell for each command. - * .ORDER Must set initial predecessor to NIL + * .ORDER Must set initial predecessor to NULL */ switch (specType) { case ExPath: @@ -1013,7 +1010,7 @@ ParseDoDependency(char *line) compatMake = TRUE; break; case Order: - predecessor = NILGNODE; + predecessor = NULL; break; default: break; @@ -1028,7 +1025,7 @@ ParseDoDependency(char *line) specType = ExPath; path = Suff_GetPath(&line[5]); - if (path == NILLST) { + if (path == NULL) { Parse_Error(PARSE_FATAL, "Suffix '%s' not defined (yet)", &line[5]); @@ -1113,7 +1110,7 @@ ParseDoDependency(char *line) /* * Don't need the list of target names anymore... */ - Lst_Destroy(curTargs, NOFREE); + Lst_Destroy(curTargs, NULL); curTargs = NULL; if (!Lst_IsEmpty(targets)) { @@ -1292,7 +1289,7 @@ ParseDoDependency(char *line) line = cp; } if (paths) { - Lst_Destroy(paths, NOFREE); + Lst_Destroy(paths, NULL); } if (specType == ExPath) Dir_SetPATH(); @@ -1327,7 +1324,7 @@ ParseDoDependency(char *line) gn = (GNode *)Lst_DeQueue(sources); ParseDoSrc(tOp, gn->name); } - Lst_Destroy(sources, NOFREE); + Lst_Destroy(sources, NULL); cp = line; } else { if (*cp) { @@ -1344,7 +1341,7 @@ ParseDoDependency(char *line) } } - if (mainNode == NILGNODE) { + if (mainNode == NULL) { /* * If we have yet to decide on a main target to make, in the * absence of any user input, we want the first target on @@ -1356,7 +1353,7 @@ ParseDoDependency(char *line) out: if (curTargs) - Lst_Destroy(curTargs, NOFREE); + Lst_Destroy(curTargs, NULL); } /*- @@ -1382,7 +1379,7 @@ Boolean Parse_IsVar(char *line) { Boolean wasSpace = FALSE; /* set TRUE if found a space */ - Boolean haveName = FALSE; /* Set TRUE if have a variable name */ + char ch; int level = 0; #define ISEQOPERATOR(c) \ (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!')) @@ -1393,70 +1390,31 @@ Parse_IsVar(char *line) for (;(*line == ' ') || (*line == '\t'); line++) continue; - for (; *line != '=' || level != 0; line++) - switch (*line) { - case '\0': - /* - * end-of-line -- can't be a variable assignment. - */ - return FALSE; - - case ' ': - case '\t': - /* - * there can be as much white space as desired so long as there is - * only one word before the operator - */ - wasSpace = TRUE; - break; - - case LPAREN: - case '{': + /* Scan for one of the assignment operators outside a variable expansion */ + while ((ch = *line++) != 0) { + if (ch == '(' || ch == '{') { level++; - break; - - case '}': - case RPAREN: + continue; + } + if (ch == ')' || ch == '}') { level--; - break; - - default: - if (wasSpace && haveName) { - if (ISEQOPERATOR(*line)) { - /* - * We must have a finished word - */ - if (level != 0) - return FALSE; - - /* - * When an = operator [+?!:] is found, the next - * character must be an = or it ain't a valid - * assignment. - */ - if (line[1] == '=') - return haveName; -#ifdef SUNSHCMD - /* - * This is a shell command - */ - if (strncmp(line, ":sh", 3) == 0) - return haveName; -#endif - } - /* - * This is the start of another word, so not assignment. - */ - return FALSE; - } - else { - haveName = TRUE; - wasSpace = FALSE; - } - break; + continue; + } + if (level != 0) + continue; + while (ch == ' ' || ch == '\t') { + ch = *line++; + wasSpace = TRUE; } + if (ch == '=') + return TRUE; + if (*line == '=' && ISEQOPERATOR(ch)) + return TRUE; + if (wasSpace) + return FALSE; + } - return haveName; + return FALSE; } /*- @@ -1496,6 +1454,7 @@ Parse_DoVar(char *line, GNode *ctxt) Boolean freeCp = FALSE; /* TRUE if cp needs to be freed, * i.e. if any variable expansion was * performed */ + int depth; /* * Skip to variable name @@ -1506,9 +1465,19 @@ Parse_DoVar(char *line, GNode *ctxt) /* * Skip to operator character, nulling out whitespace as we go + * XXX Rather than counting () and {} we should look for $ and + * then expand the variable. */ - for (cp = line + 1; *cp != '='; cp++) { - if (isspace ((unsigned char)*cp)) { + for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) { + if (*cp == '(' || *cp == '{') { + depth++; + continue; + } + if (*cp == ')' || *cp == '}') { + depth--; + continue; + } + if (depth == 0 && isspace ((unsigned char)*cp)) { *cp = '\0'; } } @@ -1656,7 +1625,7 @@ Parse_DoVar(char *line, GNode *ctxt) * A new element is added to the commands list of the node. */ static int -ParseAddCmd(ClientData gnp, ClientData cmd) +ParseAddCmd(void *gnp, void *cmd) { GNode *gn = (GNode *)gnp; @@ -1708,7 +1677,7 @@ ParseAddCmd(ClientData gnp, ClientData cmd) *----------------------------------------------------------------------- */ static void -ParseHasCommands(ClientData gnp) +ParseHasCommands(void *gnp) { GNode *gn = (GNode *)gnp; if (!Lst_IsEmpty(gn->commands)) { @@ -1810,11 +1779,11 @@ Parse_include_file(char *file, Boolean isSystem, int silent) * If we have a suffix specific path we should use that. */ char *suff; - Lst suffPath = NILLST; + Lst suffPath = NULL; if ((suff = strrchr(file, '.'))) { suffPath = Suff_GetPath(suff); - if (suffPath != NILLST) { + if (suffPath != NULL) { fullname = Dir_FindFile(file, suffPath); } } @@ -1852,7 +1821,7 @@ Parse_include_file(char *file, Boolean isSystem, int silent) } /* Start reading from this file next */ - Parse_SetInput(fullname, 0, fd, NULL); + Parse_SetInput(fullname, 0, fd, NULL, NULL); } static void @@ -1989,18 +1958,20 @@ ParseTrackInput(const char *name) *--------------------------------------------------------------------- */ void -Parse_SetInput(const char *name, int line, int fd, char *buf) +Parse_SetInput(const char *name, int line, int fd, char *(*nextbuf)(void *), void *arg) { + char *buf; + if (name == NULL) name = curFile->fname; else ParseTrackInput(name); if (DEBUG(PARSE)) - fprintf(debug_file, "Parse_SetInput: file %s, line %d, fd %d, buf %p\n", - name, line, fd, buf); + fprintf(debug_file, "Parse_SetInput: file %s, line %d, fd %d, nextbuf %p, arg %p\n", + name, line, fd, nextbuf, arg); - if (fd == -1 && buf == NULL) + if (fd == -1 && nextbuf == NULL) /* sanity */ return; @@ -2019,12 +1990,12 @@ Parse_SetInput(const char *name, int line, int fd, char *buf) */ curFile->fname = name; curFile->lineno = line; + curFile->first_lineno = line; curFile->fd = fd; - curFile->cond_depth = Cond_save_depth(); + curFile->nextbuf = nextbuf; + curFile->nextbuf_arg = arg; - ParseSetParseFile(name); - - if (buf == NULL) { + if (nextbuf == NULL) { /* * Allocate a 32k data buffer (as stdio seems to). * Set pointers so that first ParseReadc has to do a file read. @@ -2036,12 +2007,20 @@ Parse_SetInput(const char *name, int line, int fd, char *buf) curFile->P_end = buf; curFile->P_buflen = IFILE_BUFLEN; } else { - /* Start reading from the start of the buffer */ + /* Get first block of input data */ + buf = curFile->nextbuf(curFile->nextbuf_arg); + if (buf == NULL) { + /* Was all a waste of time ... */ + free(curFile); + return; + } curFile->P_str = buf; curFile->P_ptr = buf; curFile->P_end = NULL; } + curFile->cond_depth = Cond_save_depth(); + ParseSetParseFile(name); } #ifdef SYSVINCLUDE @@ -2126,6 +2105,20 @@ ParseTraditionalInclude(char *line) static int ParseEOF(void) { + char *ptr; + + if (curFile->nextbuf != NULL) { + /* eg .for loop data, get next iteration */ + ptr = curFile->nextbuf(curFile->nextbuf_arg); + curFile->P_ptr = ptr; + curFile->P_str = ptr; + curFile->lineno = curFile->first_lineno; + if (ptr != NULL) { + /* Iterate again */ + return CONTINUE; + } + } + /* Ensure the makefile (or loop) didn't have mismatched conditionals */ Cond_restore_depth(curFile->cond_depth); @@ -2138,7 +2131,7 @@ ParseEOF(void) curFile = Lst_DeQueue(includes); - if (curFile == (IFile *)NIL) { + if (curFile == NULL) { /* We've run out of input */ Var_Delete(".PARSEDIR", VAR_GLOBAL); Var_Delete(".PARSEFILE", VAR_GLOBAL); @@ -2369,6 +2362,7 @@ ParseReadLine(void) char *line; /* Result */ int lineLength; /* Length of result */ int lineno; /* Saved line # */ + int rval; for (;;) { line = ParseGetLine(0, &lineLength); @@ -2394,10 +2388,17 @@ ParseReadLine(void) case COND_PARSE: continue; case COND_INVALID: /* Not a conditional line */ - if (!For_Eval(line)) + /* Check for .for loops */ + rval = For_Eval(line); + if (rval == 0) + /* Not a .for line */ break; + if (rval < 0) + /* Syntax error - error printed, ignore line */ + continue; + /* Start of a .for loop */ lineno = curFile->lineno; - /* Skip after the matching end */ + /* Accumulate loop lines until matching .endfor */ do { line = ParseGetLine(PARSE_RAW, &lineLength); if (line == NULL) { @@ -2405,7 +2406,7 @@ ParseReadLine(void) "Unexpected end of file in for loop.\n"); break; } - } while (For_Eval(line)); + } while (For_Accum(line)); /* Stash each iteration as a new 'input file' */ For_Run(lineno); /* Read next line from for-loop buffer */ @@ -2469,7 +2470,7 @@ Parse_File(const char *name, int fd) inLine = FALSE; fatals = 0; - Parse_SetInput(name, 0, fd, NULL); + Parse_SetInput(name, 0, fd, NULL, NULL); do { for (; (line = ParseReadLine()) != NULL; ) { @@ -2616,7 +2617,7 @@ Parse_File(const char *name, int fd) * Need a non-circular list for the target nodes */ if (targets) - Lst_Destroy(targets, NOFREE); + Lst_Destroy(targets, NULL); targets = Lst_Init(FALSE); inLine = TRUE; @@ -2658,7 +2659,7 @@ Parse_File(const char *name, int fd) void Parse_Init(void) { - mainNode = NILGNODE; + mainNode = NULL; parseIncPath = Lst_Init(FALSE); sysIncPath = Lst_Init(FALSE); defIncPath = Lst_Init(FALSE); @@ -2674,11 +2675,11 @@ Parse_End(void) #ifdef CLEANUP Lst_Destroy(targCmds, (FreeProc *)free); if (targets) - Lst_Destroy(targets, NOFREE); + Lst_Destroy(targets, NULL); Lst_Destroy(defIncPath, Dir_Destroy); Lst_Destroy(sysIncPath, Dir_Destroy); Lst_Destroy(parseIncPath, Dir_Destroy); - Lst_Destroy(includes, NOFREE); /* Should be empty now */ + Lst_Destroy(includes, NULL); /* Should be empty now */ #endif } @@ -2704,7 +2705,7 @@ Parse_MainName(void) mainList = Lst_Init(FALSE); - if (mainNode == NILGNODE) { + if (mainNode == NULL) { Punt("no target to make."); /*NOTREACHED*/ } else if (mainNode->type & OP_DOUBLEDEP) { diff --git a/devel/bmake/files/pathnames.h b/devel/bmake/files/pathnames.h index a54f889b295..819d3cd1ea6 100644 --- a/devel/bmake/files/pathnames.h +++ b/devel/bmake/files/pathnames.h @@ -1,4 +1,4 @@ -/* $NetBSD: pathnames.h,v 1.3 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: pathnames.h,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1990, 1993 @@ -29,7 +29,7 @@ * SUCH DAMAGE. * * from: @(#)pathnames.h 5.2 (Berkeley) 6/1/90 - * $Id: pathnames.h,v 1.3 2008/03/09 19:54:29 joerg Exp $ + * $Id: pathnames.h,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ #if HAVE_CONFIG_H @@ -57,3 +57,6 @@ # define _PATH_DEFSYSPATH _path_defsyspath # endif #endif +#ifndef _PATH_TMP +#define _PATH_TMP "/tmp/" /* with trailing slash */ +#endif diff --git a/devel/bmake/files/sigcompat.c b/devel/bmake/files/sigcompat.c index 91639ba4a7f..13be76ddc47 100644 --- a/devel/bmake/files/sigcompat.c +++ b/devel/bmake/files/sigcompat.c @@ -96,12 +96,15 @@ #if defined(sun) && !(defined(__svr4__) || defined(__SVR4)) # define NO_SIGCOMPAT #endif +#if defined(__MINT__) +# define NO_SIGCOMPAT +#endif #if !defined(NO_SIGCOMPAT) && (defined(HAVE_SIGACTION) || defined(SA_NOCLDSTOP)) #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)sigcompat.c 5.3 (Berkeley) 2/24/91";*/ -static char *rcsid = "$Id: sigcompat.c,v 1.3 2008/03/09 19:54:29 joerg Exp $"; +static char *rcsid = "$Id: sigcompat.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #endif /* LIBC_SCCS and not lint */ #undef signal diff --git a/devel/bmake/files/sprite.h b/devel/bmake/files/sprite.h index 66599175975..b66ee595e4b 100644 --- a/devel/bmake/files/sprite.h +++ b/devel/bmake/files/sprite.h @@ -1,4 +1,4 @@ -/* $NetBSD: sprite.h,v 1.2 2008/03/09 19:54:29 joerg Exp $ */ +/* $NetBSD: sprite.h,v 1.3 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -113,25 +113,4 @@ typedef int ReturnStatus; #define SUCCESS 0x00000000 #define FAILURE 0x00000001 - -/* - * A nil pointer must be something that will cause an exception if - * referenced. There are two nils: the kernels nil and the nil used - * by user processes. - */ - -#define NIL ~0 -#ifndef NULL -#define NULL 0 -#endif /* NULL */ - -/* - * ClientData is an uninterpreted word. It is defined as an int so that - * kdbx will not interpret client data as a string. The - * client data will generally not be used in arithmetic. - * But we don't have kdbx anymore so we define it as void (christos) - */ - -typedef void *ClientData; - #endif /* _SPRITE */ diff --git a/devel/bmake/files/str.c b/devel/bmake/files/str.c index 3631731d4e2..db16743f445 100644 --- a/devel/bmake/files/str.c +++ b/devel/bmake/files/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: str.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: str.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: str.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; #else -__RCSID("$NetBSD: str.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: str.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -175,7 +175,11 @@ brk_string(const char *str, int *store_argc, Boolean expand, char **buffer) inquote = (char) ch; /* Don't miss "" or '' */ if (start == NULL && p[1] == inquote) { - start = t + 1; + if (!expand) { + start = t; + *t++ = ch; + } else + start = t + 1; p++; inquote = '\0'; break; @@ -211,15 +215,22 @@ brk_string(const char *str, int *store_argc, Boolean expand, char **buffer) } argv[argc++] = start; start = NULL; - if (ch == '\n' || ch == '\0') + if (ch == '\n' || ch == '\0') { + if (expand && inquote) { + free(argv); + free(*buffer); + *buffer = NULL; + return NULL; + } goto done; + } continue; case '\\': if (!expand) { if (!start) start = t; *t++ = '\\'; - if (*(p+1) == '\0') // catch '\' at end of line + if (*(p+1) == '\0') /* catch '\' at end of line */ continue; ch = *++p; break; @@ -476,20 +487,20 @@ Str_SYSVMatch(const char *word, const char *pattern, int *len) *----------------------------------------------------------------------- */ void -Str_SYSVSubst(Buffer buf, char *pat, char *src, int len) +Str_SYSVSubst(Buffer *buf, char *pat, char *src, int len) { char *m; if ((m = strchr(pat, '%')) != NULL) { /* Copy the prefix */ - Buf_AddBytes(buf, m - pat, (Byte *)pat); + Buf_AddBytes(buf, m - pat, pat); /* skip the % */ pat = m + 1; } /* Copy the pattern */ - Buf_AddBytes(buf, len, (Byte *)src); + Buf_AddBytes(buf, len, src); /* append the rest */ - Buf_AddBytes(buf, strlen(pat), (Byte *)pat); + Buf_AddBytes(buf, strlen(pat), pat); } diff --git a/devel/bmake/files/suff.c b/devel/bmake/files/suff.c index 74790c0297f..149d64e62ec 100644 --- a/devel/bmake/files/suff.c +++ b/devel/bmake/files/suff.c @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: suff.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: suff.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: suff.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; #else -__RCSID("$NetBSD: suff.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: suff.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -128,7 +128,7 @@ __RCSID("$NetBSD: suff.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); * * Suff_FindDeps Find implicit sources for and the location of * a target based on its suffix. Returns the - * bottom-most node added to the graph or NILGNODE + * bottom-most node added to the graph or NULL * if the target had no implicit sources. * * Suff_FindPath Return the appropriate path to search in @@ -212,20 +212,20 @@ static Suff *emptySuff; /* The empty suffix required for POSIX * single-suffix transformation rules */ -static char *SuffStrIsPrefix(char *, char *); -static char *SuffSuffIsSuffix(Suff *, SuffixCmpData *); -static int SuffSuffIsSuffixP(ClientData, ClientData); -static int SuffSuffHasNameP(ClientData, ClientData); -static int SuffSuffIsPrefix(ClientData, ClientData); -static int SuffGNHasNameP(ClientData, ClientData); -static void SuffUnRef(ClientData, ClientData); -static void SuffFree(ClientData); +static const char *SuffStrIsPrefix(const char *, const char *); +static char *SuffSuffIsSuffix(const Suff *, const SuffixCmpData *); +static int SuffSuffIsSuffixP(const void *, const void *); +static int SuffSuffHasNameP(const void *, const void *); +static int SuffSuffIsPrefix(const void *, const void *); +static int SuffGNHasNameP(const void *, const void *); +static void SuffUnRef(void *, void *); +static void SuffFree(void *); static void SuffInsert(Lst, Suff *); static void SuffRemove(Lst, Suff *); static Boolean SuffParseTransform(char *, Suff **, Suff **); -static int SuffRebuildGraph(ClientData, ClientData); -static int SuffScanTargets(ClientData, ClientData); -static int SuffAddSrc(ClientData, ClientData); +static int SuffRebuildGraph(void *, void *); +static int SuffScanTargets(void *, void *); +static int SuffAddSrc(void *, void *); static int SuffRemoveSrc(Lst); static void SuffAddLevel(Lst, Src *); static Src *SuffFindThem(Lst, Lst); @@ -236,9 +236,9 @@ static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *); static void SuffFindDeps(GNode *, Lst); static void SuffFindArchiveDeps(GNode *, Lst); static void SuffFindNormalDeps(GNode *, Lst); -static int SuffPrintName(ClientData, ClientData); -static int SuffPrintSuff(ClientData, ClientData); -static int SuffPrintTrans(ClientData, ClientData); +static int SuffPrintName(void *, void *); +static int SuffPrintSuff(void *, void *); +static int SuffPrintTrans(void *, void *); /*************** Lst Predicates ****************/ /*- @@ -257,8 +257,8 @@ static int SuffPrintTrans(ClientData, ClientData); * None *----------------------------------------------------------------------- */ -static char * -SuffStrIsPrefix(char *pref, char *str) +static const char * +SuffStrIsPrefix(const char *pref, const char *str) { while (*str && *pref == *str) { pref++; @@ -287,7 +287,7 @@ SuffStrIsPrefix(char *pref, char *str) *----------------------------------------------------------------------- */ static char * -SuffSuffIsSuffix(Suff *s, SuffixCmpData *sd) +SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd) { char *p1; /* Pointer into suffix name */ char *p2; /* Pointer into string being examined */ @@ -321,9 +321,9 @@ SuffSuffIsSuffix(Suff *s, SuffixCmpData *sd) *----------------------------------------------------------------------- */ static int -SuffSuffIsSuffixP(ClientData s, ClientData sd) +SuffSuffIsSuffixP(const void *s, const void *sd) { - return(!SuffSuffIsSuffix((Suff *)s, (SuffixCmpData *)sd)); + return(!SuffSuffIsSuffix(s, sd)); } /*- @@ -344,9 +344,9 @@ SuffSuffIsSuffixP(ClientData s, ClientData sd) *----------------------------------------------------------------------- */ static int -SuffSuffHasNameP(ClientData s, ClientData sname) +SuffSuffHasNameP(const void *s, const void *sname) { - return (strcmp((char *)sname, ((Suff *)s)->name)); + return (strcmp(sname, ((const Suff *)s)->name)); } /*- @@ -369,9 +369,9 @@ SuffSuffHasNameP(ClientData s, ClientData sname) *----------------------------------------------------------------------- */ static int -SuffSuffIsPrefix(ClientData s, ClientData str) +SuffSuffIsPrefix(const void *s, const void *str) { - return (SuffStrIsPrefix(((Suff *)s)->name, (char *)str) == NULL ? 1 : 0); + return SuffStrIsPrefix(((const Suff *)s)->name, str) == NULL; } /*- @@ -391,20 +391,20 @@ SuffSuffIsPrefix(ClientData s, ClientData str) *----------------------------------------------------------------------- */ static int -SuffGNHasNameP(ClientData gn, ClientData name) +SuffGNHasNameP(const void *gn, const void *name) { - return (strcmp((char *)name, ((GNode *)gn)->name)); + return (strcmp(name, ((const GNode *)gn)->name)); } /*********** Maintenance Functions ************/ static void -SuffUnRef(ClientData lp, ClientData sp) +SuffUnRef(void *lp, void *sp) { Lst l = (Lst) lp; LstNode ln = Lst_Member(l, sp); - if (ln != NILLNODE) { + if (ln != NULL) { Lst_Remove(l, ln); ((Suff *)sp)->refCount--; } @@ -423,7 +423,7 @@ SuffUnRef(ClientData lp, ClientData sp) *----------------------------------------------------------------------- */ static void -SuffFree(ClientData sp) +SuffFree(void *sp) { Suff *s = (Suff *)sp; @@ -440,9 +440,9 @@ SuffFree(ClientData sp) s->refCount); #endif - Lst_Destroy(s->ref, NOFREE); - Lst_Destroy(s->children, NOFREE); - Lst_Destroy(s->parents, NOFREE); + Lst_Destroy(s->ref, NULL); + Lst_Destroy(s->children, NULL); + Lst_Destroy(s->parents, NULL); Lst_Destroy(s->searchPath, Dir_Destroy); free(s->name); @@ -498,7 +498,7 @@ SuffInsert(Lst l, Suff *s) if (Lst_Open(l) == FAILURE) { return; } - while ((ln = Lst_Next(l)) != NILLNODE) { + while ((ln = Lst_Next(l)) != NULL) { s2 = (Suff *)Lst_Datum(ln); if (s2->sNum >= s->sNum) { break; @@ -509,7 +509,7 @@ SuffInsert(Lst l, Suff *s) if (DEBUG(SUFF)) { fprintf(debug_file, "inserting %s(%d)...", s->name, s->sNum); } - if (ln == NILLNODE) { + if (ln == NULL) { if (DEBUG(SUFF)) { fprintf(debug_file, "at end of list\n"); } @@ -586,8 +586,8 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) Suff *single = NULL;/* Source of possible transformation to * null suffix */ - srcLn = NILLNODE; - singleLn = NILLNODE; + srcLn = NULL; + singleLn = NULL; /* * Loop looking first for a suffix that matches the start of the @@ -596,17 +596,17 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) * parsed the string. */ for (;;) { - if (srcLn == NILLNODE) { + if (srcLn == NULL) { srcLn = Lst_Find(sufflist, str, SuffSuffIsPrefix); } else { srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), str, SuffSuffIsPrefix); } - if (srcLn == NILLNODE) { + if (srcLn == NULL) { /* * Ran out of source suffixes -- no such rule */ - if (singleLn != NILLNODE) { + if (singleLn != NULL) { /* * Not so fast Mr. Smith! There was a suffix that encompassed * the entire string, so we assume it was a transformation @@ -629,7 +629,7 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr) singleLn = srcLn; } else { targLn = Lst_Find(sufflist, str2, SuffSuffHasNameP); - if (targLn != NILLNODE) { + if (targLn != NULL) { *srcPtr = src; *targPtr = (Suff *)Lst_Datum(targLn); return (TRUE); @@ -689,7 +689,7 @@ Suff_AddTransform(char *line) LstNode ln; /* Node for existing transformation */ ln = Lst_Find(transforms, line, SuffGNHasNameP); - if (ln == NILLNODE) { + if (ln == NULL) { /* * Make a new graph node for the transformation. It will be filled in * by the Parse module. @@ -704,8 +704,8 @@ Suff_AddTransform(char *line) * attached to several different transformations. */ gn = (GNode *)Lst_Datum(ln); - Lst_Destroy(gn->commands, NOFREE); - Lst_Destroy(gn->children, NOFREE); + Lst_Destroy(gn->commands, NULL); + Lst_Destroy(gn->children, NULL); gn->commands = Lst_Init(FALSE); gn->children = Lst_Init(FALSE); } @@ -749,7 +749,7 @@ Suff_AddTransform(char *line) *----------------------------------------------------------------------- */ int -Suff_EndTransform(ClientData gnp, ClientData dummy) +Suff_EndTransform(void *gnp, void *dummy) { GNode *gn = (GNode *)gnp; @@ -823,7 +823,7 @@ Suff_EndTransform(ClientData gnp, ClientData dummy) *----------------------------------------------------------------------- */ static int -SuffRebuildGraph(ClientData transformp, ClientData sp) +SuffRebuildGraph(void *transformp, void *sp) { GNode *transform = (GNode *)transformp; Suff *s = (Suff *)sp; @@ -835,10 +835,10 @@ SuffRebuildGraph(ClientData transformp, ClientData sp) /* * First see if it is a transformation from this suffix. */ - cp = SuffStrIsPrefix(s->name, transform->name); + cp = UNCONST(SuffStrIsPrefix(s->name, transform->name)); if (cp != NULL) { ln = Lst_Find(sufflist, cp, SuffSuffHasNameP); - if (ln != NILLNODE) { + if (ln != NULL) { /* * Found target. Link in and return, since it can't be anything * else. @@ -866,7 +866,7 @@ SuffRebuildGraph(ClientData transformp, ClientData sp) * Replace the start of the target suffix */ cp[1] = s->name[0]; - if (ln != NILLNODE) { + if (ln != NULL) { /* * Found it -- establish the proper relationship */ @@ -896,14 +896,14 @@ SuffRebuildGraph(ClientData transformp, ClientData sp) *----------------------------------------------------------------------- */ static int -SuffScanTargets(ClientData targetp, ClientData gsp) +SuffScanTargets(void *targetp, void *gsp) { GNode *target = (GNode *)targetp; GNodeSuff *gs = (GNodeSuff *)gsp; Suff *s, *t; char *ptr; - if (*gs->gn == NILGNODE && gs->r && (target->type & OP_NOTARGET) == 0) { + if (*gs->gn == NULL && gs->r && (target->type & OP_NOTARGET) == 0) { *gs->gn = target; Targ_SetMain(target); return 1; @@ -919,10 +919,10 @@ SuffScanTargets(ClientData targetp, ClientData gsp) if (SuffParseTransform(target->name, &s, &t)) { if (*gs->gn == target) { gs->r = TRUE; - *gs->gn = NILGNODE; - Targ_SetMain(NILGNODE); + *gs->gn = NULL; + Targ_SetMain(NULL); } - Lst_Destroy(target->children, NOFREE); + Lst_Destroy(target->children, NULL); target->children = Lst_Init(FALSE); target->type = OP_TRANSFORM; /* @@ -965,7 +965,7 @@ Suff_AddSuffix(char *str, GNode **gn) GNodeSuff gs; ln = Lst_Find(sufflist, str, SuffSuffHasNameP); - if (ln == NILLNODE) { + if (ln == NULL) { s = bmake_malloc(sizeof(Suff)); s->name = bmake_strdup(str); @@ -1003,7 +1003,7 @@ Suff_AddSuffix(char *str, GNode **gn) * Return the search path for the given suffix, if it's defined. * * Results: - * The searchPath for the desired suffix or NILLST if the suffix isn't + * The searchPath for the desired suffix or NULL if the suffix isn't * defined. * * Side Effects: @@ -1017,8 +1017,8 @@ Suff_GetPath(char *sname) Suff *s; ln = Lst_Find(sufflist, sname, SuffSuffHasNameP); - if (ln == NILLNODE) { - return (NILLST); + if (ln == NULL) { + return NULL; } else { s = (Suff *)Lst_Datum(ln); return (s->searchPath); @@ -1059,7 +1059,7 @@ Suff_DoPaths(void) inIncludes = Lst_Init(FALSE); inLibs = Lst_Init(FALSE); - while ((ln = Lst_Next(sufflist)) != NILLNODE) { + while ((ln = Lst_Next(sufflist)) != NULL) { s = (Suff *)Lst_Datum(ln); if (!Lst_IsEmpty (s->searchPath)) { #ifdef INCLUDES @@ -1115,7 +1115,7 @@ Suff_AddInclude(char *sname) Suff *s; ln = Lst_Find(sufflist, sname, SuffSuffHasNameP); - if (ln != NILLNODE) { + if (ln != NULL) { s = (Suff *)Lst_Datum(ln); s->flags |= SUFF_INCLUDE; } @@ -1147,7 +1147,7 @@ Suff_AddLib(char *sname) Suff *s; ln = Lst_Find(sufflist, sname, SuffSuffHasNameP); - if (ln != NILLNODE) { + if (ln != NULL) { s = (Suff *)Lst_Datum(ln); s->flags |= SUFF_LIBRARY; } @@ -1174,7 +1174,7 @@ Suff_AddLib(char *sname) *----------------------------------------------------------------------- */ static int -SuffAddSrc(ClientData sp, ClientData lsp) +SuffAddSrc(void *sp, void *lsp) { Suff *s = (Suff *)sp; LstSrc *ls = (LstSrc *)lsp; @@ -1193,7 +1193,7 @@ SuffAddSrc(ClientData sp, ClientData lsp) s2->file = bmake_strdup(targ->pref); s2->pref = targ->pref; s2->parent = targ; - s2->node = NILGNODE; + s2->node = NULL; s2->suff = s; s->refCount++; s2->children = 0; @@ -1211,7 +1211,7 @@ SuffAddSrc(ClientData sp, ClientData lsp) s2->file = str_concat(targ->pref, s->name, 0); s2->pref = targ->pref; s2->parent = targ; - s2->node = NILGNODE; + s2->node = NULL; s2->suff = s; s->refCount++; s2->children = 0; @@ -1284,7 +1284,7 @@ SuffRemoveSrc(Lst l) #endif - while ((ln = Lst_Next(l)) != NILLNODE) { + while ((ln = Lst_Next(l)) != NULL) { s = (Src *)Lst_Datum(ln); if (s->children == 0) { free(s->file); @@ -1293,14 +1293,14 @@ SuffRemoveSrc(Lst l) else { #ifdef DEBUG_SRC LstNode ln = Lst_Member(s->parent->cp, s); - if (ln != NILLNODE) + if (ln != NULL) Lst_Remove(s->parent->cp, ln); #endif --s->parent->children; } #ifdef DEBUG_SRC fprintf(debug_file, "free: [l=%x] p=%x %d\n", l, s, s->children); - Lst_Destroy(s->cp, NOFREE); + Lst_Destroy(s->cp, NULL); #endif Lst_Remove(l, ln); free(s); @@ -1357,7 +1357,7 @@ SuffFindThem(Lst srcs, Lst slst) * A file is considered to exist if either a node exists in the * graph for it or the file actually exists. */ - if (Targ_FindNode(s->file, TARG_NOCREATE) != NILGNODE) { + if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) { #ifdef DEBUG_SRC fprintf(debug_file, "remove %x from %x\n", s, srcs); #endif @@ -1399,7 +1399,7 @@ SuffFindThem(Lst srcs, Lst slst) * targ Src structure to play with * * Results: - * The Src structure of the "winning" child, or NIL if no such beast. + * The Src structure of the "winning" child, or NULL if no such beast. * * Side Effects: * A Src structure may be allocated. @@ -1423,7 +1423,7 @@ SuffFindCmds(Src *targ, Lst slst) for (;;) { ln = Lst_Next(t->children); - if (ln == NILLNODE) { + if (ln == NULL) { Lst_Close(t->children); return NULL; } @@ -1452,9 +1452,8 @@ SuffFindCmds(Src *targ, Lst slst) * The node matches the prefix ok, see if it has a known * suffix. */ - ln = Lst_Find(sufflist, &cp[prefLen], - SuffSuffHasNameP); - if (ln == NILLNODE) + ln = Lst_Find(sufflist, &cp[prefLen], SuffSuffHasNameP); + if (ln == NULL) continue; /* * It even has a known suffix, see if there's a transformation @@ -1464,7 +1463,7 @@ SuffFindCmds(Src *targ, Lst slst) */ suff = (Suff *)Lst_Datum(ln); - if (Lst_Member(suff->parents, targ->suff) != NILLNODE) + if (Lst_Member(suff->parents, targ->suff) != NULL) break; } @@ -1642,7 +1641,7 @@ SuffExpandChildren(LstNode cln, GNode *pgn) /* Expand wildcards on new node */ SuffExpandWildcards(Lst_Prev(cln), pgn); } - Lst_Destroy(members, NOFREE); + Lst_Destroy(members, NULL); /* * Free the result @@ -1699,7 +1698,7 @@ SuffExpandWildcards(LstNode cln, GNode *pgn) /* * Nuke what's left of the list */ - Lst_Destroy(explist, NOFREE); + Lst_Destroy(explist, NULL); if (DEBUG(SUFF)) { fprintf(debug_file, "\n"); @@ -1749,7 +1748,7 @@ Suff_FindPath(GNode* gn) if (DEBUG(SUFF)) { fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name); } - if (ln != NILLNODE) + if (ln != NULL) suff = (Suff *)Lst_Datum(ln); /* XXX: Here we can save the suffix so we don't have to do this again */ } @@ -1812,7 +1811,7 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) ln = Lst_Find(transforms, tname, SuffGNHasNameP); free(tname); - if (ln == NILLNODE) { + if (ln == NULL) { /* * Not really such a transformation rule (can happen when we're * called to link an OP_MEMBER and OP_ARCHV node), so return @@ -1840,7 +1839,7 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s) /* * Deal with wildcards and variables in any acquired sources */ - for (ln = Lst_Succ(ln); ln != NILLNODE; ln = nln) { + for (ln = Lst_Succ(ln); ln != NULL; ln = nln) { nln = Lst_Succ(ln); SuffExpandChildren(ln, tGn); } @@ -1961,7 +1960,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) sd.ename = eoarch; ln = Lst_Find(ms->parents, &sd, SuffSuffIsSuffixP); - if (ln != NILLNODE) { + if (ln != NULL) { /* * Got one -- apply it */ @@ -2060,13 +2059,13 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * Should we find one, we discard the one we found before. */ - while (ln != NILLNODE) { + while (ln != NULL) { /* * Look for next possible suffix... */ ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP); - if (ln != NILLNODE) { + if (ln != NULL) { int prefLen; /* Length of the prefix */ /* @@ -2182,7 +2181,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * Now we've got the important local variables set, expand any sources * that still contain variables or wildcards in their names. */ - for (ln = Lst_First(gn->children); ln != NILLNODE; ln = nln) { + for (ln = Lst_First(gn->children); ln != NULL; ln = nln) { nln = Lst_Succ(ln); SuffExpandChildren(ln, gn); } @@ -2274,7 +2273,7 @@ sfnd_abort: * up to, but not including, the parent node. */ while (bottom && bottom->parent != NULL) { - if (Lst_Member(slst, bottom) == NILLNODE) { + if (Lst_Member(slst, bottom) == NULL) { Lst_AtEnd(slst, bottom); } bottom = bottom->parent; @@ -2302,7 +2301,7 @@ sfnd_abort: * transformation rule. Also, the unmade field of gn is incremented. * Etc. */ - if (bottom->node == NILGNODE) { + if (bottom->node == NULL) { bottom->node = Targ_FindNode(bottom->file, TARG_CREATE); } @@ -2314,7 +2313,7 @@ sfnd_abort: src->node->suffix = src->suff; src->node->suffix->refCount++; - if (targ->node == NILGNODE) { + if (targ->node == NULL) { targ->node = Targ_FindNode(targ->file, TARG_CREATE); } @@ -2350,7 +2349,7 @@ sfnd_abort: */ sfnd_return: if (bottom) - if (Lst_Member(slst, bottom) == NILLNODE) + if (Lst_Member(slst, bottom) == NULL) Lst_AtEnd(slst, bottom); while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs)) @@ -2435,11 +2434,10 @@ SuffFindDeps(GNode *gn, Lst slst) LstNode ln; Suff *s; - ln = Lst_Find(sufflist, UNCONST(LIBSUFF), - SuffSuffHasNameP); + ln = Lst_Find(sufflist, LIBSUFF, SuffSuffHasNameP); if (gn->suffix) gn->suffix->refCount--; - if (ln != NILLNODE) { + if (ln != NULL) { gn->suffix = s = (Suff *)Lst_Datum(ln); gn->suffix->refCount++; Arch_FindLib(gn, s->searchPath); @@ -2485,7 +2483,7 @@ Suff_SetNull(char *name) LstNode ln; ln = Lst_Find(sufflist, name, SuffSuffHasNameP); - if (ln != NILLNODE) { + if (ln != NULL) { s = (Suff *)Lst_Datum(ln); if (suffNull != NULL) { suffNull->flags &= ~SUFF_NULL; @@ -2566,22 +2564,22 @@ Suff_End(void) Lst_Destroy(suffClean, SuffFree); if (suffNull) SuffFree(suffNull); - Lst_Destroy(srclist, NOFREE); - Lst_Destroy(transforms, NOFREE); + Lst_Destroy(srclist, NULL); + Lst_Destroy(transforms, NULL); #endif } /********************* DEBUGGING FUNCTIONS **********************/ -static int SuffPrintName(ClientData s, ClientData dummy) +static int SuffPrintName(void *s, void *dummy) { fprintf(debug_file, "%s ", ((Suff *)s)->name); return (dummy ? 0 : 0); } static int -SuffPrintSuff(ClientData sp, ClientData dummy) +SuffPrintSuff(void *sp, void *dummy) { Suff *s = (Suff *)sp; int flags; @@ -2623,7 +2621,7 @@ SuffPrintSuff(ClientData sp, ClientData dummy) } static int -SuffPrintTrans(ClientData tp, ClientData dummy) +SuffPrintTrans(void *tp, void *dummy) { GNode *t = (GNode *)tp; diff --git a/devel/bmake/files/targ.c b/devel/bmake/files/targ.c index 09888e72e29..1a264b069ec 100644 --- a/devel/bmake/files/targ.c +++ b/devel/bmake/files/targ.c @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.3 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: targ.c,v 1.4 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: targ.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: targ.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: targ.c,v 1.3 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: targ.c,v 1.4 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -144,13 +144,13 @@ static Hash_Table targets; /* a hash table of same */ #define HTSIZE 191 /* initial size of hash table */ -static int TargPrintOnlySrc(ClientData, ClientData); -static int TargPrintName(ClientData, ClientData); +static int TargPrintOnlySrc(void *, void *); +static int TargPrintName(void *, void *); #ifdef CLEANUP -static void TargFreeGN(ClientData); +static void TargFreeGN(void *); #endif -static int TargPropagateCohort(ClientData, ClientData); -static int TargPropagateNode(ClientData, ClientData); +static int TargPropagateCohort(void *, void *); +static int TargPropagateNode(void *, void *); /*- *----------------------------------------------------------------------- @@ -187,7 +187,7 @@ void Targ_End(void) { #ifdef CLEANUP - Lst_Destroy(allTargets, NOFREE); + Lst_Destroy(allTargets, NULL); if (allGNs) Lst_Destroy(allGNs, TargFreeGN); Hash_DeleteTable(&targets); @@ -285,7 +285,7 @@ Targ_NewGN(const char *name) *----------------------------------------------------------------------- */ static void -TargFreeGN(ClientData gnp) +TargFreeGN(void *gnp) { GNode *gn = (GNode *)gnp; @@ -297,14 +297,14 @@ TargFreeGN(ClientData gnp) free(gn->path); /* gn->fname points to name allocated when file was opened, don't free */ - Lst_Destroy(gn->iParents, NOFREE); - Lst_Destroy(gn->cohorts, NOFREE); - Lst_Destroy(gn->parents, NOFREE); - Lst_Destroy(gn->children, NOFREE); - Lst_Destroy(gn->order_succ, NOFREE); - Lst_Destroy(gn->order_pred, NOFREE); + Lst_Destroy(gn->iParents, NULL); + Lst_Destroy(gn->cohorts, NULL); + Lst_Destroy(gn->parents, NULL); + Lst_Destroy(gn->children, NULL); + Lst_Destroy(gn->order_succ, NULL); + Lst_Destroy(gn->order_pred, NULL); Hash_DeleteTable(&gn->context); - Lst_Destroy(gn->commands, NOFREE); + Lst_Destroy(gn->commands, NULL); free(gn); } #endif @@ -321,7 +321,7 @@ TargFreeGN(ClientData gnp) * found * * Results: - * The node in the list if it was. If it wasn't, return NILGNODE of + * The node in the list if it was. If it wasn't, return NULL of * flags was TARG_NOCREATE or the newly created and initialized node * if it was TARG_CREATE * @@ -340,7 +340,7 @@ Targ_FindNode(const char *name, int flags) if (!(flags & (TARG_CREATE | TARG_NOHASH))) { he = Hash_FindEntry(&targets, name); if (he == NULL) - return (NILGNODE); + return NULL; return (GNode *)Hash_GetValue(he); } @@ -392,10 +392,10 @@ Targ_FindList(Lst names, int flags) if (Lst_Open(names) == FAILURE) { return (nodes); } - while ((ln = Lst_Next(names)) != NILLNODE) { + while ((ln = Lst_Next(names)) != NULL) { name = (char *)Lst_Datum(ln); gn = Targ_FindNode(name, flags); - if (gn != NILGNODE) { + if (gn != NULL) { /* * Note: Lst_AtEnd must come before the Lst_Concat so the nodes * are added to the list in the order in which they were @@ -511,7 +511,7 @@ Targ_SetMain(GNode *gn) } static int -TargPrintName(ClientData gnp, ClientData pflags __unused) +TargPrintName(void *gnp, void *pflags __unused) { GNode *gn = (GNode *)gnp; @@ -522,7 +522,7 @@ TargPrintName(ClientData gnp, ClientData pflags __unused) int -Targ_PrintCmd(ClientData cmd, ClientData dummy) +Targ_PrintCmd(void *cmd, void *dummy) { fprintf(debug_file, "\t%s\n", (char *)cmd); return (dummy ? 0 : 0); @@ -623,7 +623,7 @@ made_name(enum enum_made made) *----------------------------------------------------------------------- */ int -Targ_PrintNode(ClientData gnp, ClientData passp) +Targ_PrintNode(void *gnp, void *passp) { GNode *gn = (GNode *)gnp; int pass = passp ? *(int *)passp : 0; @@ -716,7 +716,7 @@ Targ_PrintNode(ClientData gnp, ClientData passp) *----------------------------------------------------------------------- */ static int -TargPrintOnlySrc(ClientData gnp, ClientData dummy __unused) +TargPrintOnlySrc(void *gnp, void *dummy __unused) { GNode *gn = (GNode *)gnp; if (!OP_NOP(gn->type)) @@ -789,7 +789,7 @@ Targ_PrintGraph(int pass) *----------------------------------------------------------------------- */ static int -TargPropagateNode(ClientData gnp, ClientData junk __unused) +TargPropagateNode(void *gnp, void *junk __unused) { GNode *gn = (GNode *)gnp; @@ -817,7 +817,7 @@ TargPropagateNode(ClientData gnp, ClientData junk __unused) *----------------------------------------------------------------------- */ static int -TargPropagateCohort(ClientData cgnp, ClientData pgnp) +TargPropagateCohort(void *cgnp, void *pgnp) { GNode *cgn = (GNode *)cgnp; GNode *pgn = (GNode *)pgnp; diff --git a/devel/bmake/files/trace.c b/devel/bmake/files/trace.c index a11a395aee6..917885b88d3 100644 --- a/devel/bmake/files/trace.c +++ b/devel/bmake/files/trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: trace.c,v 1.4 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: trace.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -31,11 +31,11 @@ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: trace.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: trace.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: trace.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: trace.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif /* not lint */ #endif @@ -96,8 +96,8 @@ Trace_Log(TrEvent event, Job *job) gettimeofday(&rightnow, NULL); - fprintf(trfile, "%ld.%06d %d %s %d %s", - rightnow.tv_sec, (int)rightnow.tv_usec, + fprintf(trfile, "%lld.%06ld %d %s %d %s", + (long long)rightnow.tv_sec, (long)rightnow.tv_usec, jobTokensRunning, evname[event], trpid, trwd); if (job != NULL) { diff --git a/devel/bmake/files/unit-tests/Makefile.in b/devel/bmake/files/unit-tests/Makefile.in index 6718ee3d55c..5f51dcfe04c 100644 --- a/devel/bmake/files/unit-tests/Makefile.in +++ b/devel/bmake/files/unit-tests/Makefile.in @@ -1,6 +1,6 @@ -# $Id: Makefile.in,v 1.3 2008/11/11 14:37:06 joerg Exp $ +# $Id: Makefile.in,v 1.4 2009/09/18 21:27:26 joerg Exp $ # -# $NetBSD: Makefile.in,v 1.3 2008/11/11 14:37:06 joerg Exp $ +# $NetBSD: Makefile.in,v 1.4 2009/09/18 21:27:26 joerg Exp $ # # Unit tests for make(1) # The main targets are: @@ -54,6 +54,7 @@ clean: TEST_MAKE?= ${.MAKE} TOOL_SED ?= sed +TOOL_TR ?= tr # The driver. # We always pretend .MAKE was called 'make' @@ -63,6 +64,7 @@ TOOL_SED ?= sed test: @echo "${TEST_MAKE} -f ${MAKEFILE} > ${.TARGET}.out 2>&1" @cd ${.OBJDIR} && ${TEST_MAKE} -f ${MAKEFILE} 2>&1 | \ + ${TOOL_TR} -d '\015' | \ ${TOOL_SED} -e 's,^${TEST_MAKE:T:C/\./\\\./g}:,make:,' \ -e '/stopped/s, /.*, unit-tests,' \ -e 's,${.CURDIR:C/\./\\\./g}/,,g' \ diff --git a/devel/bmake/files/unit-tests/test.exp b/devel/bmake/files/unit-tests/test.exp index d34ae999607..bcbe90590e9 100644 --- a/devel/bmake/files/unit-tests/test.exp +++ b/devel/bmake/files/unit-tests/test.exp @@ -74,10 +74,10 @@ Expect: Unknown modifier 'Z' make: Unknown modifier 'Z' VAR:Z= Expect: Unclosed variable specification for VAR -make: Unclosed variable specification for VAR +make: Unclosed variable specification (expecting '}') for "VAR" (value "Thevariable") modifier S VAR:S,V,v,=Thevariable Expect: Unclosed variable specification for VAR -make: Unclosed variable specification for VAR +make: Unclosed variable specification after complex modifier (expecting '}') for VAR VAR:S,V,v,=Thevariable Expect: Unclosed substitution for VAR (, missing) make: Unclosed substitution for VAR (, missing) @@ -97,6 +97,7 @@ LIB=d X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBD.A" LIB=e X_LIBS:M${LIB${LIB:tu}} is "/tmp/libe.a" LIB=e X_LIBS:M*/lib${LIB}.a is "/tmp/libe.a" LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A" +Mscanner=OK path=':/bin:/usr/bin::/sbin:/usr/sbin:.:/home/user/bin:.' path='/bin:/usr/bin:/sbin:/usr/sbin:/home/user/bin' path='/bin:/usr/bin:/sbin:/usr/sbin:/homes/user/bin' diff --git a/devel/bmake/files/util.c b/devel/bmake/files/util.c index a92153c5742..6fa507a4a2a 100644 --- a/devel/bmake/files/util.c +++ b/devel/bmake/files/util.c @@ -1,18 +1,18 @@ -/* $NetBSD: util.c,v 1.4 2008/11/11 19:47:38 joerg Exp $ */ +/* $NetBSD: util.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /* * Missing stuff from OS's * - * $Id: util.c,v 1.4 2008/11/11 19:47:38 joerg Exp $ + * $Id: util.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ #include "make.h" #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: util.c,v 1.4 2008/11/11 19:47:38 joerg Exp $"; +static char rcsid[] = "$NetBSD: util.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #ifndef lint -__RCSID("$NetBSD: util.c,v 1.4 2008/11/11 19:47:38 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif #endif @@ -290,7 +290,7 @@ getwd(char *pathname) if (stat("/", &st_root) == -1) { (void)sprintf(pathname, "getwd: Cannot stat \"/\" (%s)", strerror(errno)); - return (NULL); + return NULL; } pathbuf[MAXPATHLEN - 1] = '\0'; pathptr = &pathbuf[MAXPATHLEN - 1]; @@ -301,7 +301,7 @@ getwd(char *pathname) if (lstat(".", &st_cur) == -1) { (void)sprintf(pathname, "getwd: Cannot stat \".\" (%s)", strerror(errno)); - return (NULL); + return NULL; } nextpathptr = strrcpy(nextpathptr, "../"); @@ -320,13 +320,13 @@ getwd(char *pathname) (void)sprintf(pathname, "getwd: Cannot stat directory \"%s\" (%s)", nextpathptr, strerror(errno)); - return (NULL); + return NULL; } if ((dp = opendir(nextpathptr)) == NULL) { (void)sprintf(pathname, "getwd: Cannot open directory \"%s\" (%s)", nextpathptr, strerror(errno)); - return (NULL); + return NULL; } /* look in the parent for the entry with the same inode */ @@ -350,7 +350,7 @@ getwd(char *pathname) "getwd: Cannot stat \"%s\" (%s)", d->d_name, strerror(errno)); (void)closedir(dp); - return (NULL); + return NULL; } /* check if we found it yet */ if (st_next.st_ino == st_cur.st_ino && @@ -362,7 +362,7 @@ getwd(char *pathname) (void)sprintf(pathname, "getwd: Cannot find \".\" in \"..\""); (void)closedir(dp); - return (NULL); + return NULL; } st_cur = st_dotdot; pathptr = strrcpy(pathptr, d->d_name); @@ -522,10 +522,10 @@ strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) s = snprintf(buf, len, "%s", months[tm->tm_mon]); break; case 'd': - s = snprintf(buf, len, "%s", tm->tm_mday); + s = snprintf(buf, len, "%02d", tm->tm_mday); break; case 'Y': - s = snprintf(buf, len, "%s", 1900 + tm->tm_year); + s = snprintf(buf, len, "%d", 1900 + tm->tm_year); break; default: s = snprintf(buf, len, "Unsupported format %c", diff --git a/devel/bmake/files/var.c b/devel/bmake/files/var.c index 5b592314755..f063d5ccac5 100644 --- a/devel/bmake/files/var.c +++ b/devel/bmake/files/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.4 2008/11/11 14:37:05 joerg Exp $ */ +/* $NetBSD: var.c,v 1.5 2009/09/18 21:27:25 joerg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); +__RCSID("$NetBSD: var.c,v 1.5 2009/09/18 21:27:25 joerg Exp $"); #endif #endif /* not lint */ #endif @@ -86,31 +86,31 @@ __RCSID("$NetBSD: var.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); * Variable-handling functions * * Interface: - * Var_Set Set the value of a variable in the given - * context. The variable is created if it doesn't - * yet exist. The value and variable name need not - * be preserved. + * Var_Set Set the value of a variable in the given + * context. The variable is created if it doesn't + * yet exist. The value and variable name need not + * be preserved. * * Var_Append Append more characters to an existing variable - * in the given context. The variable needn't - * exist already -- it will be created if it doesn't. - * A space is placed between the old value and the - * new one. + * in the given context. The variable needn't + * exist already -- it will be created if it doesn't. + * A space is placed between the old value and the + * new one. * * Var_Exists See if a variable exists. * * Var_Value Return the value of a variable in a context or - * NULL if the variable is undefined. + * NULL if the variable is undefined. * * Var_Subst Substitute named variable, or all variables if * NULL in a string using - * the given context as the top-most one. If the - * third argument is non-zero, Parse_Error is - * called if any variables are undefined. + * the given context as the top-most one. If the + * third argument is non-zero, Parse_Error is + * called if any variables are undefined. * * Var_Parse Parse a variable expansion from a string and - * return the result and the number of characters - * consumed. + * return the result and the number of characters + * consumed. * * Var_Delete Delete a variable in a context. * @@ -118,7 +118,7 @@ __RCSID("$NetBSD: var.c,v 1.4 2008/11/11 14:37:05 joerg Exp $"); * * Debugging: * Var_Dump Print out all variables defined in the given - * context. + * context. * * XXX: There's a lot of duplication in these functions. */ @@ -175,8 +175,8 @@ GNode *VAR_CMD; /* variables defined on the command-line */ typedef struct Var { char *name; /* the variable's name */ - Buffer val; /* its value */ - int flags; /* miscellaneous status flags */ + Buffer val; /* its value */ + int flags; /* miscellaneous status flags */ #define VAR_IN_USE 1 /* Variable's value currently being used. * Used to avoid recursion */ #define VAR_FROM_ENV 2 /* Variable comes from the environment */ @@ -205,7 +205,7 @@ static int var_exportedVars = VAR_EXPORTED_NONE; * We pass this to Var_Export when doing the initial export * or after updating an exported var. */ -#define VAR_EXPORT_FORCE 1 +#define VAR_EXPORT_PARENT 1 /* Var*Pattern flags */ #define VAR_SUB_GLOBAL 0x01 /* Apply substitution globally */ @@ -232,28 +232,28 @@ typedef struct { * several space-separated words). */ } Var_Parse_State; -/* struct passed as ClientData to VarSubstitute() for ":S/lhs/rhs/", +/* struct passed as 'void *' to VarSubstitute() for ":S/lhs/rhs/", * to VarSYSVMatch() for ":lhs=rhs". */ typedef struct { const char *lhs; /* String to match */ - int leftLen; /* Length of string */ + int leftLen; /* Length of string */ const char *rhs; /* Replacement string (w/ &'s removed) */ - int rightLen; /* Length of replacement */ - int flags; + int rightLen; /* Length of replacement */ + int flags; } VarPattern; -/* struct passed as ClientData to VarLoopExpand() for ":@tvar@str@" */ +/* struct passed as 'void *' to VarLoopExpand() for ":@tvar@str@" */ typedef struct { GNode *ctxt; /* variable context */ char *tvar; /* name of temp var */ - int tvarLen; + int tvarLen; char *str; /* string to expand */ - int strLen; + int strLen; int errnum; /* errnum for not defined */ } VarLoop_t; #ifndef NO_REGEX -/* struct passed as ClientData to VarRESubstitute() for ":C///" */ +/* struct passed as 'void *' to VarRESubstitute() for ":C///" */ typedef struct { regex_t re; int nsub; @@ -272,30 +272,30 @@ typedef struct { static Var *VarFind(const char *, GNode *, int); static void VarAdd(const char *, const char *, GNode *); static Boolean VarHead(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static Boolean VarTail(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static Boolean VarSuffix(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static Boolean VarRoot(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static Boolean VarMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); #ifdef SYSVVARSUB static Boolean VarSYSVMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); #endif static Boolean VarNoMatch(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); #ifndef NO_REGEX static void VarREError(int, regex_t *, const char *); static Boolean VarRESubstitute(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); #endif static Boolean VarSubstitute(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static Boolean VarLoopExpand(GNode *, Var_Parse_State *, - char *, Boolean, Buffer, ClientData); + char *, Boolean, Buffer *, void *); static char *VarGetPattern(GNode *, Var_Parse_State *, int, const char **, int, int *, int *, VarPattern *); @@ -303,12 +303,12 @@ static char *VarQuote(char *); static char *VarChangeCase(char *, int); static char *VarModify(GNode *, Var_Parse_State *, const char *, - Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer, ClientData), - ClientData); + Boolean (*)(GNode *, Var_Parse_State *, char *, Boolean, Buffer *, void *), + void *); static char *VarOrder(const char *, const char); static char *VarUniq(const char *); static int VarWordCompare(const void *, const void *); -static void VarPrintVar(ClientData); +static void VarPrintVar(void *); #define BROPEN '{' #define BRCLOSE '}' @@ -331,7 +331,7 @@ static void VarPrintVar(ClientData); * * Results: * A pointer to the structure describing the desired variable or - * NIL if the variable does not exist. + * NULL if the variable does not exist. * * Side Effects: * None @@ -341,7 +341,7 @@ static Var * VarFind(const char *name, GNode *ctxt, int flags) { Hash_Entry *var; - Var *v; + Var *v; /* * If the variable name begins with a '.', it could very well be one of @@ -397,15 +397,15 @@ VarFind(const char *name, GNode *ctxt, int flags) char *env; if ((env = getenv(name)) != NULL) { - int len; + int len; v = bmake_malloc(sizeof(Var)); v->name = bmake_strdup(name); len = strlen(env); - v->val = Buf_Init(len + 1); - Buf_AddBytes(v->val, len, (Byte *)env); + Buf_Init(&v->val, len + 1); + Buf_AddBytes(&v->val, len, env); v->flags = VAR_FROM_ENV; return (v); @@ -414,15 +414,15 @@ VarFind(const char *name, GNode *ctxt, int flags) { var = Hash_FindEntry(&VAR_GLOBAL->context, name); if (var == NULL) { - return ((Var *)NIL); + return NULL; } else { return ((Var *)Hash_GetValue(var)); } } else { - return((Var *)NIL); + return NULL; } } else if (var == NULL) { - return ((Var *)NIL); + return NULL; } else { return ((Var *)Hash_GetValue(var)); } @@ -450,7 +450,7 @@ VarFreeEnv(Var *v, Boolean destroy) if ((v->flags & VAR_FROM_ENV) == 0) return FALSE; free(v->name); - Buf_Destroy(v->val, destroy); + Buf_Destroy(&v->val, destroy); free(v); return TRUE; } @@ -478,14 +478,14 @@ static void VarAdd(const char *name, const char *val, GNode *ctxt) { Var *v; - int len; + int len; Hash_Entry *h; v = bmake_malloc(sizeof(Var)); len = val ? strlen(val) : 0; - v->val = Buf_Init(len+1); - Buf_AddBytes(v->val, len, (const Byte *)val); + Buf_Init(&v->val, len+1); + Buf_AddBytes(&v->val, len, val); v->flags = 0; @@ -530,7 +530,7 @@ Var_Delete(const char *name, GNode *ctxt) if (v->name != ln->name) free(v->name); Hash_DeleteEntry(&ctxt->context, ln); - Buf_Destroy(v->val, TRUE); + Buf_Destroy(&v->val, TRUE); free(v); } } @@ -541,9 +541,10 @@ Var_Delete(const char *name, GNode *ctxt) * We ignore make internal variables (those which start with '.') * Also we jump through some hoops to avoid calling setenv * more than necessary since it can leak. + * We only manipulate flags of vars if 'parent' is set. */ static int -Var_Export1(const char *name, int force) +Var_Export1(const char *name, int parent) { char tmp[BUFSIZ]; Var *v; @@ -568,40 +569,44 @@ Var_Export1(const char *name, int force) } } v = VarFind(name, VAR_GLOBAL, 0); - if (v == (Var *)NIL) { + if (v == NULL) { return 0; } - if (!force && + if (!parent && (v->flags & (VAR_EXPORTED|VAR_REEXPORT)) == VAR_EXPORTED) { return 0; /* nothing to do */ } - val = (char *)Buf_GetAll(v->val, NULL); + val = Buf_GetAll(&v->val, NULL); if (strchr(val, '$')) { - /* Flag this as something we need to re-export */ - v->flags |= (VAR_EXPORTED|VAR_REEXPORT); - if (force) { + if (parent) { /* + * Flag this as something we need to re-export. * No point actually exporting it now though, * the child can do it at the last minute. */ + v->flags |= (VAR_EXPORTED|VAR_REEXPORT); return 1; } n = snprintf(tmp, sizeof(tmp), "${%s}", name); - if (n < sizeof(tmp)) { + if (n < (int)sizeof(tmp)) { val = Var_Subst(NULL, tmp, VAR_GLOBAL, 0); setenv(name, val, 1); free(val); } } else { - v->flags &= ~VAR_REEXPORT; /* once will do */ - if (force || !(v->flags & VAR_EXPORTED)) { + if (parent) { + v->flags &= ~VAR_REEXPORT; /* once will do */ + } + if (parent || !(v->flags & VAR_EXPORTED)) { setenv(name, val, 1); } } /* * This is so Var_Set knows to call Var_Export again... */ - v->flags |= VAR_EXPORTED; + if (parent) { + v->flags |= VAR_EXPORTED; + } return 1; } @@ -637,12 +642,12 @@ Var_ExportVars(void) * We have a number of exported vars, */ n = snprintf(tmp, sizeof(tmp), "${" MAKE_EXPORTED ":O:u}"); - if (n < sizeof(tmp)) { + if (n < (int)sizeof(tmp)) { char **av; char *as; int ac; int i; - + val = Var_Subst(NULL, tmp, VAR_GLOBAL, 0); av = brk_string(val, &ac, FALSE, &as); for (i = 0; i < ac; i++) { @@ -693,7 +698,7 @@ Var_Export(char *str, int isExport) continue; } } - if (Var_Export1(name, VAR_EXPORT_FORCE)) { + if (Var_Export1(name, VAR_EXPORT_PARENT)) { if (VAR_EXPORTED_ALL != var_exportedVars) var_exportedVars = VAR_EXPORTED_YES; if (isExport) { @@ -738,20 +743,29 @@ void Var_Set(const char *name, const char *val, GNode *ctxt, int flags) { Var *v; - const char *cp = name; - + char *expanded_name = NULL; + /* * We only look for a variable in the given context since anything set * here will override anything in a lower context, so there's not much * point in searching them all just to save a bit of memory... */ - if ((name = strchr(cp, '$'))) { - name = Var_Subst(NULL, cp, ctxt, 0); - } else - name = cp; + if (strchr(name, '$') != NULL) { + expanded_name = Var_Subst(NULL, name, ctxt, 0); + if (expanded_name[0] == 0) { + if (DEBUG(VAR)) { + fprintf(debug_file, "Var_Set(\"%s\", \"%s\", ...) " + "name expands to empty string - ignored\n", + name, val); + } + free(expanded_name); + return; + } + name = expanded_name; + } if (ctxt == VAR_GLOBAL) { v = VarFind(name, VAR_CMD, 0); - if (v != (Var *)NIL) { + if (v != NULL) { if ((v->flags & VAR_FROM_CMD)) { if (DEBUG(VAR)) { fprintf(debug_file, "%s:%s = %s ignored!\n", ctxt->name, name, val); @@ -762,17 +776,17 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) } } v = VarFind(name, ctxt, 0); - if (v == (Var *)NIL) { + if (v == NULL) { VarAdd(name, val, ctxt); } else { - Buf_Discard(v->val, Buf_Size(v->val)); - Buf_AddBytes(v->val, strlen(val), (const Byte *)val); + Buf_Empty(&v->val); + Buf_AddBytes(&v->val, strlen(val), val); if (DEBUG(VAR)) { fprintf(debug_file, "%s:%s = %s\n", ctxt->name, name, val); } if ((v->flags & VAR_EXPORTED)) { - Var_Export1(name, VAR_EXPORT_FORCE); + Var_Export1(name, VAR_EXPORT_PARENT); } } /* @@ -780,11 +794,12 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) * to the environment (as per POSIX standard) */ if (ctxt == VAR_CMD && (flags & VAR_NO_EXPORT) == 0) { - if (v == (Var *)NIL) { + if (v == NULL) { /* we just added it */ v = VarFind(name, ctxt, 0); } - v->flags |= VAR_FROM_CMD; + if (v != NULL) + v->flags |= VAR_FROM_CMD; /* * If requested, don't export these in the environment * individually. We still put them in MAKEOVERRIDES so @@ -796,10 +811,27 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags) Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL); } + /* + * Another special case. + * Several make's support this sort of mechanism for tracking + * recursion - but each uses a different name. + * We allow the makefiles to update .MAKE.LEVEL and ensure + * children see a correctly incremented value. + */ + if (ctxt == VAR_GLOBAL && strcmp(MAKE_LEVEL, name) == 0) { + char tmp[64]; + int level; + + level = atoi(val); + snprintf(tmp, sizeof(tmp), "%u", level + 1); + setenv(MAKE_LEVEL, tmp, 1); + } + + out: - if (name != cp) - free(UNCONST(name)); - if (v != (Var *)NIL) + if (expanded_name != NULL) + free(expanded_name); + if (v != NULL) VarFreeEnv(v, TRUE); } @@ -835,24 +867,33 @@ Var_Append(const char *name, const char *val, GNode *ctxt) { Var *v; Hash_Entry *h; - const char *cp = name; + char *expanded_name = NULL; + + if (strchr(name, '$') != NULL) { + expanded_name = Var_Subst(NULL, name, ctxt, 0); + if (expanded_name[0] == 0) { + if (DEBUG(VAR)) { + fprintf(debug_file, "Var_Append(\"%s\", \"%s\", ...) " + "name expands to empty string - ignored\n", + name, val); + } + free(expanded_name); + return; + } + name = expanded_name; + } - if ((name = strchr(cp, '$'))) { - name = Var_Subst(NULL, cp, ctxt, 0); - } else - name = cp; - v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); - if (v == (Var *)NIL) { + if (v == NULL) { VarAdd(name, val, ctxt); } else { - Buf_AddByte(v->val, (Byte)' '); - Buf_AddBytes(v->val, strlen(val), (const Byte *)val); + Buf_AddByte(&v->val, ' '); + Buf_AddBytes(&v->val, strlen(val), val); if (DEBUG(VAR)) { fprintf(debug_file, "%s:%s = %s\n", ctxt->name, name, - (char *)Buf_GetAll(v->val, NULL)); + Buf_GetAll(&v->val, NULL)); } if (v->flags & VAR_FROM_ENV) { @@ -867,8 +908,8 @@ Var_Append(const char *name, const char *val, GNode *ctxt) Hash_SetValue(h, v); } } - if (name != cp) - free(UNCONST(name)); + if (expanded_name != NULL) + free(expanded_name); } /*- @@ -891,7 +932,7 @@ Var_Append(const char *name, const char *val, GNode *ctxt) Boolean Var_Exists(const char *name, GNode *ctxt) { - Var *v; + Var *v; char *cp; if ((cp = strchr(name, '$')) != NULL) { @@ -901,7 +942,7 @@ Var_Exists(const char *name, GNode *ctxt) if (cp != NULL) { free(cp); } - if (v == (Var *)NIL) { + if (v == NULL) { return(FALSE); } else { (void)VarFreeEnv(v, TRUE); @@ -932,13 +973,13 @@ Var_Value(const char *name, GNode *ctxt, char **frp) v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); *frp = NULL; - if (v != (Var *)NIL) { - char *p = ((char *)Buf_GetAll(v->val, NULL)); + if (v != NULL) { + char *p = (Buf_GetAll(&v->val, NULL)); if (VarFreeEnv(v, FALSE)) *frp = p; return p; } else { - return (NULL); + return NULL; } } @@ -965,8 +1006,8 @@ Var_Value(const char *name, GNode *ctxt, char **frp) */ static Boolean VarHead(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData dummy) + char *word, Boolean addSpace, Buffer *buf, + void *dummy) { char *slash; @@ -976,7 +1017,7 @@ VarHead(GNode *ctx __unused, Var_Parse_State *vpstate, Buf_AddByte(buf, vpstate->varSpace); } *slash = '\0'; - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); *slash = '/'; return (TRUE); } else { @@ -985,7 +1026,7 @@ VarHead(GNode *ctx __unused, Var_Parse_State *vpstate, */ if (addSpace && vpstate->varSpace) Buf_AddByte(buf, vpstate->varSpace); - Buf_AddByte(buf, (Byte)'.'); + Buf_AddByte(buf, '.'); } return(dummy ? TRUE : TRUE); } @@ -1013,8 +1054,8 @@ VarHead(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarTail(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData dummy) + char *word, Boolean addSpace, Buffer *buf, + void *dummy) { char *slash; @@ -1025,10 +1066,10 @@ VarTail(GNode *ctx __unused, Var_Parse_State *vpstate, slash = strrchr(word, '/'); if (slash != NULL) { *slash++ = '\0'; - Buf_AddBytes(buf, strlen(slash), (Byte *)slash); + Buf_AddBytes(buf, strlen(slash), slash); slash[-1] = '/'; } else { - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return (dummy ? TRUE : TRUE); } @@ -1055,8 +1096,8 @@ VarTail(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarSuffix(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData dummy) + char *word, Boolean addSpace, Buffer *buf, + void *dummy) { char *dot; @@ -1066,7 +1107,7 @@ VarSuffix(GNode *ctx __unused, Var_Parse_State *vpstate, Buf_AddByte(buf, vpstate->varSpace); } *dot++ = '\0'; - Buf_AddBytes(buf, strlen(dot), (Byte *)dot); + Buf_AddBytes(buf, strlen(dot), dot); dot[-1] = '.'; addSpace = TRUE; } @@ -1096,8 +1137,8 @@ VarSuffix(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarRoot(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData dummy) + char *word, Boolean addSpace, Buffer *buf, + void *dummy) { char *dot; @@ -1108,10 +1149,10 @@ VarRoot(GNode *ctx __unused, Var_Parse_State *vpstate, dot = strrchr(word, '.'); if (dot != NULL) { *dot = '\0'; - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); *dot = '.'; } else { - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return (dummy ? TRUE : TRUE); } @@ -1140,15 +1181,17 @@ VarRoot(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarMatch(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData pattern) + char *word, Boolean addSpace, Buffer *buf, + void *pattern) { + if (DEBUG(VAR)) + fprintf(debug_file, "VarMatch [%s] [%s]\n", word, (char *)pattern); if (Str_Match(word, (char *)pattern)) { if (addSpace && vpstate->varSpace) { Buf_AddByte(buf, vpstate->varSpace); } addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return(addSpace); } @@ -1179,8 +1222,8 @@ VarMatch(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarSYSVMatch(GNode *ctx, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData patp) + char *word, Boolean addSpace, Buffer *buf, + void *patp) { int len; char *ptr; @@ -1197,7 +1240,7 @@ VarSYSVMatch(GNode *ctx, Var_Parse_State *vpstate, Str_SYSVSubst(buf, varexp, ptr, len); free(varexp); } else { - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return(addSpace); @@ -1229,15 +1272,15 @@ VarSYSVMatch(GNode *ctx, Var_Parse_State *vpstate, */ static Boolean VarNoMatch(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData pattern) + char *word, Boolean addSpace, Buffer *buf, + void *pattern) { if (!Str_Match(word, (char *)pattern)) { if (addSpace && vpstate->varSpace) { Buf_AddByte(buf, vpstate->varSpace); } addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return(addSpace); } @@ -1266,8 +1309,8 @@ VarNoMatch(GNode *ctx __unused, Var_Parse_State *vpstate, */ static Boolean VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, - char *word, Boolean addSpace, Buffer buf, - ClientData patternp) + char *word, Boolean addSpace, Buffer *buf, + void *patternp) { int wordLen; /* Length of word */ char *cp; /* General pointer */ @@ -1297,8 +1340,7 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, Buf_AddByte(buf, vpstate->varSpace); } addSpace = TRUE; - Buf_AddBytes(buf, pattern->rightLen, - (const Byte *)pattern->rhs); + Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); } pattern->flags |= VAR_SUB_MATCHED; } else if (pattern->flags & VAR_MATCH_END) { @@ -1316,10 +1358,9 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, } addSpace = TRUE; } - Buf_AddBytes(buf, pattern->rightLen, - (const Byte *)pattern->rhs); + Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); Buf_AddBytes(buf, wordLen - pattern->leftLen, - (Byte *)(word + pattern->leftLen)); + (word + pattern->leftLen)); pattern->flags |= VAR_SUB_MATCHED; } } else if (pattern->flags & VAR_MATCH_START) { @@ -1349,9 +1390,8 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, } addSpace = TRUE; } - Buf_AddBytes(buf, cp - word, (const Byte *)word); - Buf_AddBytes(buf, pattern->rightLen, - (const Byte *)pattern->rhs); + Buf_AddBytes(buf, cp - word, word); + Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); pattern->flags |= VAR_SUB_MATCHED; } else { /* @@ -1383,9 +1423,8 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, Buf_AddByte(buf, vpstate->varSpace); addSpace = FALSE; } - Buf_AddBytes(buf, cp-word, (const Byte *)word); - Buf_AddBytes(buf, pattern->rightLen, - (const Byte *)pattern->rhs); + Buf_AddBytes(buf, cp-word, word); + Buf_AddBytes(buf, pattern->rightLen, pattern->rhs); wordLen -= (cp - word) + pattern->leftLen; word = cp + pattern->leftLen; if (wordLen == 0) { @@ -1403,7 +1442,7 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, if (addSpace && vpstate->varSpace) { Buf_AddByte(buf, vpstate->varSpace); } - Buf_AddBytes(buf, wordLen, (Byte *)word); + Buf_AddBytes(buf, wordLen, word); } /* * If added characters to the buffer, need to add a space @@ -1418,7 +1457,7 @@ VarSubstitute(GNode *ctx __unused, Var_Parse_State *vpstate, if (addSpace && vpstate->varSpace) { Buf_AddByte(buf, vpstate->varSpace); } - Buf_AddBytes(buf, wordLen, (Byte *)word); + Buf_AddBytes(buf, wordLen, word); return(TRUE); } @@ -1466,8 +1505,8 @@ VarREError(int errnum, regex_t *pat, const char *str) */ static Boolean VarRESubstitute(GNode *ctx __unused, Var_Parse_State *vpstate __unused, - char *word, Boolean addSpace, Buffer buf, - ClientData patternp) + char *word, Boolean addSpace, Buffer *buf, + void *patternp) { VarREPattern *pat; int xrv; @@ -1606,8 +1645,8 @@ VarRESubstitute(GNode *ctx __unused, Var_Parse_State *vpstate __unused, */ static Boolean VarLoopExpand(GNode *ctx __unused, Var_Parse_State *vpstate __unused, - char *word, Boolean addSpace, Buffer buf, - ClientData loopp) + char *word, Boolean addSpace, Buffer *buf, + void *loopp) { VarLoop_t *loop = (VarLoop_t *)loopp; char *s; @@ -1619,7 +1658,7 @@ VarLoopExpand(GNode *ctx __unused, Var_Parse_State *vpstate __unused, if (s != NULL && *s != '\0') { if (addSpace && *s != '\n') Buf_AddByte(buf, ' '); - Buf_AddBytes(buf, (slen = strlen(s)), (Byte *)s); + Buf_AddBytes(buf, (slen = strlen(s)), s); addSpace = (slen > 0 && s[slen - 1] != '\n'); free(s); } @@ -1651,7 +1690,7 @@ static char * VarSelectWords(GNode *ctx __unused, Var_Parse_State *vpstate, const char *str, VarSelectWords_t *seldata) { - Buffer buf; /* Buffer for the new string */ + Buffer buf; /* Buffer for the new string */ Boolean addSpace; /* TRUE if need to add a space to the * buffer before adding the trimmed * word */ @@ -1659,8 +1698,8 @@ VarSelectWords(GNode *ctx __unused, Var_Parse_State *vpstate, char *as; /* word list memory */ int ac, i; int start, end, step; - - buf = Buf_Init(0); + + Buf_Init(&buf, 0); addSpace = FALSE; if (vpstate->oneBigWord) { @@ -1703,9 +1742,9 @@ VarSelectWords(GNode *ctx __unused, Var_Parse_State *vpstate, i += step) { if (av[i] && *av[i]) { if (addSpace && vpstate->varSpace) { - Buf_AddByte(buf, vpstate->varSpace); + Buf_AddByte(&buf, vpstate->varSpace); } - Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_AddBytes(&buf, strlen(av[i]), av[i]); addSpace = TRUE; } } @@ -1713,10 +1752,7 @@ VarSelectWords(GNode *ctx __unused, Var_Parse_State *vpstate, free(as); free(av); - Buf_AddByte(buf, '\0'); - as = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return (as); + return Buf_Destroy(&buf, FALSE); } /*- @@ -1742,10 +1778,10 @@ static char * VarModify(GNode *ctx, Var_Parse_State *vpstate, const char *str, Boolean (*modProc)(GNode *, Var_Parse_State *, char *, - Boolean, Buffer, ClientData), - ClientData datum) + Boolean, Buffer *, void *), + void *datum) { - Buffer buf; /* Buffer for the new string */ + Buffer buf; /* Buffer for the new string */ Boolean addSpace; /* TRUE if need to add a space to the * buffer before adding the trimmed * word */ @@ -1753,7 +1789,7 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate, char *as; /* word list memory */ int ac, i; - buf = Buf_Init(0); + Buf_Init(&buf, 0); addSpace = FALSE; if (vpstate->oneBigWord) { @@ -1768,16 +1804,13 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate, } for (i = 0; i < ac; i++) { - addSpace = (*modProc)(ctx, vpstate, av[i], addSpace, buf, datum); + addSpace = (*modProc)(ctx, vpstate, av[i], addSpace, &buf, datum); } free(as); free(av); - Buf_AddByte(buf, '\0'); - as = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return (as); + return Buf_Destroy(&buf, FALSE); } @@ -1808,12 +1841,12 @@ VarWordCompare(const void *a, const void *b) static char * VarOrder(const char *str, const char otype) { - Buffer buf; /* Buffer for the new string */ + Buffer buf; /* Buffer for the new string */ char **av; /* word list [first word does not count] */ char *as; /* word list memory */ int ac, i; - buf = Buf_Init(0); + Buf_Init(&buf, 0); av = brk_string(str, &ac, FALSE, &as); @@ -1845,18 +1878,15 @@ VarOrder(const char *str, const char otype) } /* end of switch */ for (i = 0; i < ac; i++) { - Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_AddBytes(&buf, strlen(av[i]), av[i]); if (i != ac - 1) - Buf_AddByte(buf, ' '); + Buf_AddByte(&buf, ' '); } free(as); free(av); - Buf_AddByte(buf, '\0'); - as = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return (as); + return Buf_Destroy(&buf, FALSE); } @@ -1879,12 +1909,12 @@ VarOrder(const char *str, const char otype) static char * VarUniq(const char *str) { - Buffer buf; /* Buffer for new string */ + Buffer buf; /* Buffer for new string */ char **av; /* List of words to affect */ char *as; /* Word list memory */ int ac, i, j; - buf = Buf_Init(0); + Buf_Init(&buf, 0); av = brk_string(str, &ac, FALSE, &as); if (ac > 1) { @@ -1895,18 +1925,15 @@ VarUniq(const char *str) } for (i = 0; i < ac; i++) { - Buf_AddBytes(buf, strlen(av[i]), (Byte *)av[i]); + Buf_AddBytes(&buf, strlen(av[i]), av[i]); if (i != ac - 1) - Buf_AddByte(buf, ' '); + Buf_AddByte(&buf, ' '); } free(as); free(av); - Buf_AddByte(buf, '\0'); - as = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return as; + return Buf_Destroy(&buf, FALSE); } @@ -1938,8 +1965,11 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate __unused, int *length, VarPattern *pattern) { const char *cp; - Buffer buf = Buf_Init(0); + char *rstr; + Buffer buf; int junk; + + Buf_Init(&buf, 0); if (length == NULL) length = &junk; @@ -1955,12 +1985,12 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate __unused, */ for (cp = *tstr; *cp && (*cp != delim); cp++) { if (IS_A_MATCH(cp, delim)) { - Buf_AddByte(buf, (Byte)cp[1]); + Buf_AddByte(&buf, cp[1]); cp++; } else if (*cp == '$') { if (cp[1] == delim) { if (flags == NULL) - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(&buf, *cp); else /* * Unescaped $ at end of pattern => anchor @@ -1979,7 +2009,7 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate __unused, * substitution and recurse. */ cp2 = Var_Parse(cp, ctxt, errnum, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_AddBytes(&buf, strlen(cp2), cp2); if (freeIt) free(freeIt); cp += len - 1; @@ -2004,34 +2034,31 @@ VarGetPattern(GNode *ctxt, Var_Parse_State *vpstate __unused, --depth; } } - Buf_AddBytes(buf, cp2 - cp, (const Byte *)cp); + Buf_AddBytes(&buf, cp2 - cp, cp); cp = --cp2; } else - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(&buf, *cp); } } } else if (pattern && *cp == '&') - Buf_AddBytes(buf, pattern->leftLen, (const Byte *)pattern->lhs); + Buf_AddBytes(&buf, pattern->leftLen, pattern->lhs); else - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(&buf, *cp); } - Buf_AddByte(buf, (Byte)'\0'); - if (*cp != delim) { *tstr = cp; *length = 0; return NULL; } - else { - char *rstr; - *tstr = ++cp; - rstr = (char *)Buf_GetAll(buf, length); - *length -= 1; /* Don't count the NULL */ - Buf_Destroy(buf, FALSE); - return rstr; - } + + *tstr = ++cp; + *length = Buf_Size(&buf); + rstr = Buf_Destroy(&buf, FALSE); + if (DEBUG(VAR)) + fprintf(debug_file, "Modifier pattern: \"%s\"\n", rstr); + return rstr; } /*- @@ -2061,23 +2088,23 @@ VarQuote(char *str) newline = "\\\n"; nlen = strlen(newline); - buf = Buf_Init(0); + Buf_Init(&buf, 0); while (*str != '\0') { if ((len = strcspn(str, meta)) != 0) { - Buf_AddBytes(buf, len, str); + Buf_AddBytes(&buf, len, str); str += len; } else if (*str == '\n') { - Buf_AddBytes(buf, nlen, newline); + Buf_AddBytes(&buf, nlen, newline); ++str; } else { - Buf_AddByte(buf, (Byte)'\\'); - Buf_AddByte(buf, (Byte)*str); + Buf_AddByte(&buf, '\\'); + Buf_AddByte(&buf, *str); ++str; } } - Buf_AddByte(buf, (Byte)'\0'); - str = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + str = Buf_Destroy(&buf, FALSE); + if (DEBUG(VAR)) + fprintf(debug_file, "QuoteMeta: [%s]\n", str); return str; } @@ -2105,99 +2132,96 @@ VarChangeCase(char *str, int upper) int (*modProc)(int); modProc = (upper ? toupper : tolower); - buf = Buf_Init(0); + Buf_Init(&buf, 0); for (; *str ; str++) { - Buf_AddByte(buf, (Byte)modProc(*str)); + Buf_AddByte(&buf, modProc(*str)); } - Buf_AddByte(buf, (Byte)'\0'); - str = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return str; + return Buf_Destroy(&buf, FALSE); } /* * Now we need to apply any modifiers the user wants applied. * These are: * :M<pattern> words which match the given <pattern>. - * <pattern> is of the standard file - * wildcarding form. + * <pattern> is of the standard file + * wildcarding form. * :N<pattern> words which do not match the given <pattern>. * :S<d><pat1><d><pat2><d>[1gW] - * Substitute <pat2> for <pat1> in the value + * Substitute <pat2> for <pat1> in the value * :C<d><pat1><d><pat2><d>[1gW] - * Substitute <pat2> for regex <pat1> in the value - * :H Substitute the head of each word - * :T Substitute the tail of each word - * :E Substitute the extension (minus '.') of - * each word - * :R Substitute the root of each word - * (pathname minus the suffix). - * :O ("Order") Alphabeticaly sort words in variable. - * :Ox ("intermiX") Randomize words in variable. - * :u ("uniq") Remove adjacent duplicate words. - * :tu Converts the variable contents to uppercase. - * :tl Converts the variable contents to lowercase. - * :ts[c] Sets varSpace - the char used to - * separate words to 'c'. If 'c' is - * omitted then no separation is used. - * :tW Treat the variable contents as a single - * word, even if it contains spaces. - * (Mnemonic: one big 'W'ord.) - * :tw Treat the variable contents as multiple - * space-separated words. - * (Mnemonic: many small 'w'ords.) - * :[index] Select a single word from the value. - * :[start..end] Select multiple words from the value. - * :[*] or :[0] Select the entire value, as a single - * word. Equivalent to :tW. - * :[@] Select the entire value, as multiple - * words. Undoes the effect of :[*]. - * Equivalent to :tw. - * :[#] Returns the number of words in the value. - * - * :?<true-value>:<false-value> - * If the variable evaluates to true, return - * true value, else return the second value. - * :lhs=rhs Like :S, but the rhs goes to the end of - * the invocation. - * :sh Treat the current value as a command - * to be run, new value is its output. + * Substitute <pat2> for regex <pat1> in the value + * :H Substitute the head of each word + * :T Substitute the tail of each word + * :E Substitute the extension (minus '.') of + * each word + * :R Substitute the root of each word + * (pathname minus the suffix). + * :O ("Order") Alphabeticaly sort words in variable. + * :Ox ("intermiX") Randomize words in variable. + * :u ("uniq") Remove adjacent duplicate words. + * :tu Converts the variable contents to uppercase. + * :tl Converts the variable contents to lowercase. + * :ts[c] Sets varSpace - the char used to + * separate words to 'c'. If 'c' is + * omitted then no separation is used. + * :tW Treat the variable contents as a single + * word, even if it contains spaces. + * (Mnemonic: one big 'W'ord.) + * :tw Treat the variable contents as multiple + * space-separated words. + * (Mnemonic: many small 'w'ords.) + * :[index] Select a single word from the value. + * :[start..end] Select multiple words from the value. + * :[*] or :[0] Select the entire value, as a single + * word. Equivalent to :tW. + * :[@] Select the entire value, as multiple + * words. Undoes the effect of :[*]. + * Equivalent to :tw. + * :[#] Returns the number of words in the value. + * + * :?<true-value>:<false-value> + * If the variable evaluates to true, return + * true value, else return the second value. + * :lhs=rhs Like :S, but the rhs goes to the end of + * the invocation. + * :sh Treat the current value as a command + * to be run, new value is its output. * The following added so we can handle ODE makefiles. - * :@<tmpvar>@<newval>@ - * Assign a temporary local variable <tmpvar> - * to the current value of each word in turn - * and replace each word with the result of - * evaluating <newval> - * :D<newval> Use <newval> as value if variable defined - * :U<newval> Use <newval> as value if variable undefined - * :L Use the name of the variable as the value. - * :P Use the path of the node that has the same - * name as the variable as the value. This - * basically includes an implied :L so that - * the common method of refering to the path - * of your dependent 'x' in a rule is to use - * the form '${x:P}'. - * :!<cmd>! Run cmd much the same as :sh run's the - * current value of the variable. + * :@<tmpvar>@<newval>@ + * Assign a temporary local variable <tmpvar> + * to the current value of each word in turn + * and replace each word with the result of + * evaluating <newval> + * :D<newval> Use <newval> as value if variable defined + * :U<newval> Use <newval> as value if variable undefined + * :L Use the name of the variable as the value. + * :P Use the path of the node that has the same + * name as the variable as the value. This + * basically includes an implied :L so that + * the common method of refering to the path + * of your dependent 'x' in a rule is to use + * the form '${x:P}'. + * :!<cmd>! Run cmd much the same as :sh run's the + * current value of the variable. * The ::= modifiers, actually assign a value to the variable. * Their main purpose is in supporting modifiers of .for loop * iterators and other obscure uses. They always expand to * nothing. In a target rule that would otherwise expand to an * empty line they can be preceded with @: to keep make happy. * Eg. - * + * * foo: .USE * .for i in ${.TARGET} ${.TARGET:R}.gz - * @: ${t::=$i} - * @echo blah ${t:T} + * @: ${t::=$i} + * @echo blah ${t:T} * .endfor - * - * ::=<str> Assigns <str> as the new value of variable. - * ::?=<str> Assigns <str> as value of variable if - * it was not already set. - * ::+=<str> Appends <str> to variable. - * ::!=<cmd> Assigns output of <cmd> as the new value of - * variable. + * + * ::=<str> Assigns <str> as the new value of variable. + * ::?=<str> Assigns <str> as value of variable if + * it was not already set. + * ::+=<str> Appends <str> to variable. + * ::!=<cmd> Assigns output of <cmd> as the new value of + * variable. */ static char * @@ -2222,11 +2246,11 @@ ApplyModifiers(char *nstr, const char *tstr, parsestate.varSpace = ' '; /* word separator */ start = cp = tstr; - + while (*tstr && *tstr != endc) { if (*tstr == '$') { - /* + /* * We have some complex modifiers in a variable. */ void *freeIt; @@ -2261,7 +2285,7 @@ ApplyModifiers(char *nstr, const char *tstr, if (*tstr == ':') tstr++; else if (!*tstr && endc) { - Error("Unclosed variable specification for %s", v->name); + Error("Unclosed variable specification after complex modifier (expecting '%c') for %s", endc, v->name); goto out; } continue; @@ -2285,6 +2309,9 @@ ApplyModifiers(char *nstr, const char *tstr, VarPattern pattern; int how; + if (v->name[0] == 0) + goto bad_modifier; + v_ctxt = ctxt; sv_name = NULL; ++tstr; @@ -2297,12 +2324,12 @@ ApplyModifiers(char *nstr, const char *tstr, v->name = bmake_strdup(v->name); } else if (ctxt != VAR_GLOBAL) { Var *gv = VarFind(v->name, ctxt, 0); - if (gv == (Var *)NIL) + if (gv == NULL) v_ctxt = VAR_GLOBAL; else VarFreeEnv(gv, TRUE); } - + switch ((how = *tstr)) { case '+': case '?': @@ -2401,7 +2428,7 @@ ApplyModifiers(char *nstr, const char *tstr, * the delimiter (expand the variable substitution). * The result is left in the Buffer buf. */ - buf = Buf_Init(0); + Buf_Init(&buf, 0); for (cp = tstr + 1; *cp != endc && *cp != ':' && *cp != '\0'; cp++) { @@ -2411,7 +2438,7 @@ ApplyModifiers(char *nstr, const char *tstr, (cp[1] == endc) || (cp[1] == '\\'))) { - Buf_AddByte(buf, (Byte)cp[1]); + Buf_AddByte(&buf, cp[1]); cp++; } else if (*cp == '$') { /* @@ -2423,15 +2450,14 @@ ApplyModifiers(char *nstr, const char *tstr, void *freeIt; cp2 = Var_Parse(cp, ctxt, errnum, &len, &freeIt); - Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); + Buf_AddBytes(&buf, strlen(cp2), cp2); if (freeIt) free(freeIt); cp += len - 1; } else { - Buf_AddByte(buf, (Byte)*cp); + Buf_AddByte(&buf, *cp); } } - Buf_AddByte(buf, (Byte)'\0'); termc = *cp; @@ -2442,11 +2468,10 @@ ApplyModifiers(char *nstr, const char *tstr, if ((v->flags & VAR_JUNK) != 0) v->flags |= VAR_KEEP; if (wantit) { - newStr = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + newStr = Buf_Destroy(&buf, FALSE); } else { newStr = nstr; - Buf_Destroy(buf, TRUE); + Buf_Destroy(&buf, TRUE); } break; } @@ -2462,11 +2487,11 @@ ApplyModifiers(char *nstr, const char *tstr, case 'P': { GNode *gn; - + if ((v->flags & VAR_JUNK) != 0) v->flags |= VAR_KEEP; gn = Targ_FindNode(v->name, TARG_NOCREATE); - if (gn == NILGNODE || gn->type & OP_NOPATH) { + if (gn == NULL || gn->type & OP_NOPATH) { newStr = NULL; } else if (gn->path) { newStr = bmake_strdup(gn->path); @@ -2515,7 +2540,7 @@ ApplyModifiers(char *nstr, const char *tstr, * which we must free(). */ char *estr; - + cp = tstr+1; /* point to char after '[' */ delim = ']'; /* look for closing ']' */ estr = VarGetPattern(ctxt, &parsestate, @@ -2678,7 +2703,7 @@ ApplyModifiers(char *nstr, const char *tstr, default: if (isdigit((unsigned char)tstr[3])) { char *ep; - + parsestate.varSpace = strtoul(&tstr[3], &ep, 0); if (*ep != ':' && *ep != endc) @@ -2755,9 +2780,11 @@ ApplyModifiers(char *nstr, const char *tstr, const char *endpat; /* points just after end of pattern */ char *cp2; Boolean copy; /* pattern should be, or has been, copied */ + Boolean needSubst; int nest; copy = FALSE; + needSubst = FALSE; nest = 1; /* * In the loop below, ignore ':' unless we are at @@ -2772,13 +2799,18 @@ ApplyModifiers(char *nstr, const char *tstr, if (*cp == '\\' && (cp[1] == ':' || cp[1] == endc || cp[1] == startc)) { - copy = TRUE; + if (!needSubst) { + copy = TRUE; + } cp++; continue; } - if (*cp == startc) + if (*cp == '$') { + needSubst = TRUE; + } + if (*cp == '(' || *cp == '{') ++nest; - if (*cp == endc) { + if (*cp == ')' || *cp == '}') { --nest; if (nest == 0) break; @@ -2813,29 +2845,27 @@ ApplyModifiers(char *nstr, const char *tstr, * nul-terminated string soon, so construct one now. */ pattern = bmake_strndup(tstr+1, endpat - (tstr + 1)); - copy = TRUE; } - if (strchr(pattern, '$') != NULL) { + if (needSubst) { /* * pattern contains embedded '$', so use Var_Subst to * expand it. */ cp2 = pattern; pattern = Var_Subst(NULL, cp2, ctxt, errnum); - if (copy) - free(cp2); - copy = TRUE; + free(cp2); } - if (*tstr == 'M' || *tstr == 'm') { + if (DEBUG(VAR)) + fprintf(debug_file, "Pattern for [%s] is [%s]\n", nstr, + pattern); + if (*tstr == 'M') { newStr = VarModify(ctxt, &parsestate, nstr, VarMatch, pattern); } else { newStr = VarModify(ctxt, &parsestate, nstr, VarNoMatch, pattern); } - if (copy) { - free(pattern); - } + free(pattern); break; } case 'S': @@ -2903,7 +2933,7 @@ ApplyModifiers(char *nstr, const char *tstr, free(UNCONST(pattern.rhs)); delim = '\0'; break; - } + } case '?': { VarPattern pattern; @@ -2931,7 +2961,7 @@ ApplyModifiers(char *nstr, const char *tstr, termc = *--cp; delim = '\0'; - if (Cond_EvalExpression(1, v->name, &value, 0) + if (Cond_EvalExpression(NULL, v->name, &value, 0) == COND_INVALID) { Error("Bad conditional expression `%s' in %s?%s:%s", v->name, v->name, pattern.lhs, pattern.rhs); @@ -3104,7 +3134,7 @@ ApplyModifiers(char *nstr, const char *tstr, goto default_case; #endif default: - default_case: + default_case: { #ifdef SYSVVARSUB /* @@ -3143,7 +3173,7 @@ ApplyModifiers(char *nstr, const char *tstr, */ delim='='; cp = tstr; - if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, + if ((pattern.lhs = VarGetPattern(ctxt, &parsestate, errnum, &cp, delim, &pattern.flags, &pattern.leftLen, NULL)) == NULL) goto cleanup; @@ -3192,7 +3222,7 @@ ApplyModifiers(char *nstr, const char *tstr, } } if (termc == '\0' && endc != '\0') { - Error("Unclosed variable specification for %s", v->name); + Error("Unclosed variable specification (expecting '%c') for \"%s\" (value \"%s\") modifier %c", endc, v->name, nstr, modifier); } else if (termc == ':') { cp++; } @@ -3252,11 +3282,11 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, void **freePtr) { const char *tstr; /* Pointer into str */ - Var *v; /* Variable in invocation */ + Var *v; /* Variable in invocation */ Boolean haveModifier;/* TRUE if have modifiers for the variable */ char endc; /* Ending character when variable in parens * or braces */ - char startc=0; /* Starting character when variable in parens + char startc; /* Starting character when variable in parens * or braces */ int vlen; /* Length of variable name */ const char *start; /* Points to original start of str */ @@ -3266,6 +3296,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, * is done to support dynamic sources. The * result is just the invocation, unaltered */ Var_Parse_State parsestate; /* Flags passed to helper functions */ + char name[2]; *freePtr = NULL; dynamic = FALSE; @@ -3273,19 +3304,24 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, parsestate.oneBigWord = FALSE; parsestate.varSpace = ' '; /* word separator */ - if (str[1] != PROPEN && str[1] != BROPEN) { + startc = str[1]; + if (startc != PROPEN && startc != BROPEN) { /* * If it's not bounded by braces of some sort, life is much simpler. * We just need to check for the first character and return the * value if it exists. */ - char name[2]; - name[0] = str[1]; + /* Error out some really stupid names */ + if (startc == '\0' || strchr(")}:$", startc)) { + *lengthPtr = 1; + return var_Error; + } + name[0] = startc; name[1] = '\0'; v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); - if (v == (Var *)NIL) { + if (v == NULL) { *lengthPtr = 2; if ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)) { @@ -3318,15 +3354,11 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, tstr = &str[1]; endc = str[1]; } - } else if (str[1] == '\0') { - *lengthPtr = 1; - return (errnum ? var_Error : varNoError); } else { Buffer buf; /* Holds the variable name */ - startc = str[1]; endc = startc == PROPEN ? PRCLOSE : BRCLOSE; - buf = Buf_Init(0); + Buf_Init(&buf, 0); /* * Skip to the end character or a colon, whichever comes first. @@ -3343,14 +3375,14 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, void *freeIt; char *rval = Var_Parse(tstr, ctxt, errnum, &rlen, &freeIt); if (rval != NULL) { - Buf_AddBytes(buf, strlen(rval), (Byte *)rval); + Buf_AddBytes(&buf, strlen(rval), rval); } if (freeIt) free(freeIt); tstr += rlen - 1; } else - Buf_AddByte(buf, (Byte)*tstr); + Buf_AddByte(&buf, *tstr); } if (*tstr == ':') { haveModifier = TRUE; @@ -3363,12 +3395,10 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, * the end of the string, since that's what make does. */ *lengthPtr = tstr - str; - Buf_Destroy(buf, TRUE); + Buf_Destroy(&buf, TRUE); return (var_Error); } - Buf_AddByte(buf, (Byte)'\0'); - str = Buf_GetAll(buf, NULL); - vlen = strlen(str); + str = Buf_GetAll(&buf, &vlen); /* * At this point, str points into newly allocated memory from @@ -3382,65 +3412,50 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, */ v = VarFind(str, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); - if ((v == (Var *)NIL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) && - (vlen == 2) && (str[1] == 'F' || str[1] == 'D')) - { + /* + * Check also for bogus D and F forms of local variables since we're + * in a local context and the name is the right length. + */ + if ((v == NULL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) && + (vlen == 2) && (str[1] == 'F' || str[1] == 'D') && + strchr("@%*!<>", str[0]) != NULL) { /* - * Check for bogus D and F forms of local variables since we're - * in a local context and the name is the right length. + * Well, it's local -- go look for it. */ - switch(*str) { - case '@': - case '%': - case '*': - case '!': - case '>': - case '<': - { - char vname[2]; - char *val; - - /* - * Well, it's local -- go look for it. - */ - vname[0] = *str; - vname[1] = '\0'; - v = VarFind(vname, ctxt, 0); + name[0] = *str; + name[1] = '\0'; + v = VarFind(name, ctxt, 0); - if (v != (Var *)NIL) { - /* - * No need for nested expansion or anything, as we're - * the only one who sets these things and we sure don't - * but nested invocations in them... - */ - val = (char *)Buf_GetAll(v->val, NULL); + if (v != NULL) { + /* + * No need for nested expansion or anything, as we're + * the only one who sets these things and we sure don't + * but nested invocations in them... + */ + nstr = Buf_GetAll(&v->val, NULL); - if (str[1] == 'D') { - val = VarModify(ctxt, &parsestate, val, VarHead, - NULL); - } else { - val = VarModify(ctxt, &parsestate, val, VarTail, - NULL); - } - /* - * Resulting string is dynamically allocated, so - * tell caller to free it. - */ - *freePtr = val; - *lengthPtr = tstr-start+1; - Buf_Destroy(buf, TRUE); - VarFreeEnv(v, TRUE); - return(val); - } - break; + if (str[1] == 'D') { + nstr = VarModify(ctxt, &parsestate, nstr, VarHead, + NULL); + } else { + nstr = VarModify(ctxt, &parsestate, nstr, VarTail, + NULL); } + /* + * Resulting string is dynamically allocated, so + * tell caller to free it. + */ + *freePtr = nstr; + *lengthPtr = tstr-start+1; + Buf_Destroy(&buf, TRUE); + VarFreeEnv(v, TRUE); + return nstr; } } - if (v == (Var *)NIL) { + if (v == NULL) { if (((vlen == 1) || - (((vlen == 2) && (str[1] == 'F' || - str[1] == 'D')))) && + (((vlen == 2) && (str[1] == 'F' || str[1] == 'D')))) && ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL))) { /* @@ -3485,10 +3500,10 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, if (dynamic) { char *pstr = bmake_strndup(start, *lengthPtr); *freePtr = pstr; - Buf_Destroy(buf, TRUE); + Buf_Destroy(&buf, TRUE); return(pstr); } else { - Buf_Destroy(buf, TRUE); + Buf_Destroy(&buf, TRUE); return (errnum ? var_Error : varNoError); } } else { @@ -3498,12 +3513,12 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, */ v = bmake_malloc(sizeof(Var)); v->name = UNCONST(str); - v->val = Buf_Init(1); + Buf_Init(&v->val, 1); v->flags = VAR_JUNK; - Buf_Destroy(buf, FALSE); + Buf_Destroy(&buf, FALSE); } } else - Buf_Destroy(buf, TRUE); + Buf_Destroy(&buf, TRUE); } if (v->flags & VAR_IN_USE) { @@ -3521,7 +3536,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, * been dynamically-allocated, so it will need freeing when we * return. */ - nstr = (char *)Buf_GetAll(v->val, NULL); + nstr = Buf_GetAll(&v->val, NULL); if (strchr(nstr, '$') != NULL) { nstr = Var_Subst(NULL, nstr, ctxt, errnum); *freePtr = nstr; @@ -3549,7 +3564,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, if (v->flags & VAR_FROM_ENV) { Boolean destroy = FALSE; - if (nstr != (char *)Buf_GetAll(v->val, NULL)) { + if (nstr != Buf_GetAll(&v->val, NULL)) { destroy = TRUE; } else { /* @@ -3577,8 +3592,8 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, nstr = var_Error; } } - if (nstr != (char *)Buf_GetAll(v->val, NULL)) - Buf_Destroy(v->val, TRUE); + if (nstr != Buf_GetAll(&v->val, NULL)) + Buf_Destroy(&v->val, TRUE); free(v->name); free(v); } @@ -3608,22 +3623,22 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr, char * Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) { - Buffer buf; /* Buffer for forming things */ + Buffer buf; /* Buffer for forming things */ char *val; /* Value to substitute for a variable */ - int length; /* Length of the variable invocation */ + int length; /* Length of the variable invocation */ Boolean trailingBslash; /* variable ends in \ */ void *freeIt = NULL; /* Set if it should be freed */ static Boolean errorReported; /* Set true if an error has already * been reported to prevent a plethora * of messages when recursing */ - buf = Buf_Init(0); + Buf_Init(&buf, 0); errorReported = FALSE; trailingBslash = FALSE; while (*str) { if (*str == '\n' && trailingBslash) - Buf_AddByte(buf, ' '); + Buf_AddByte(&buf, ' '); if (var == NULL && (*str == '$') && (str[1] == '$')) { /* * A dollar sign may be escaped either with another dollar sign. @@ -3631,7 +3646,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) * dollar sign into the buffer directly. */ str++; - Buf_AddByte(buf, (Byte)*str); + Buf_AddByte(&buf, *str); str++; } else if (*str != '$') { /* @@ -3642,19 +3657,19 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) for (cp = str++; *str != '$' && *str != '\0'; str++) continue; - Buf_AddBytes(buf, str - cp, (const Byte *)cp); + Buf_AddBytes(&buf, str - cp, cp); } else { if (var != NULL) { int expand; for (;;) { if (str[1] == '\0') { /* A trailing $ is kind of a special case */ - Buf_AddByte(buf, str[0]); + Buf_AddByte(&buf, str[0]); str++; expand = FALSE; } else if (str[1] != PROPEN && str[1] != BROPEN) { if (str[1] != *var || strlen(var) > 1) { - Buf_AddBytes(buf, 2, (const Byte *)str); + Buf_AddBytes(&buf, 2, str); str += 2; expand = FALSE; } @@ -3678,7 +3693,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) * the nested one */ if (*p == '$') { - Buf_AddBytes(buf, p - str, (const Byte *)str); + Buf_AddBytes(&buf, p - str, str); str = p; continue; } @@ -3691,7 +3706,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) */ for (;*p != '$' && *p != '\0'; p++) continue; - Buf_AddBytes(buf, p - str, (const Byte *)str); + Buf_AddBytes(&buf, p - str, str); str = p; expand = FALSE; } @@ -3734,7 +3749,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) str += length; errorReported = TRUE; } else { - Buf_AddByte(buf, (Byte)*str); + Buf_AddByte(&buf, *str); str += 1; } } else { @@ -3749,7 +3764,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) * into the new string. */ length = strlen(val); - Buf_AddBytes(buf, length, (Byte *)val); + Buf_AddBytes(&buf, length, val); trailingBslash = length > 0 && val[length - 1] == '\\'; } if (freeIt) { @@ -3759,10 +3774,7 @@ Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr) } } - Buf_AddByte(buf, '\0'); - val = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return (val); + return Buf_Destroy(&buf, FALSE); } /*- @@ -3843,10 +3855,10 @@ Var_End(void) /****************** PRINT DEBUGGING INFO *****************/ static void -VarPrintVar(ClientData vp) +VarPrintVar(void *vp) { Var *v = (Var *)vp; - fprintf(debug_file, "%-16s = %s\n", v->name, (char *)Buf_GetAll(v->val, NULL)); + fprintf(debug_file, "%-16s = %s\n", v->name, Buf_GetAll(&v->val, NULL)); } /*- |