Import the 6-May-2012 release of the "Portable" BSD make tool (from NetBSD).

Submitted by:	sjg@juniper.net
This commit is contained in:
David E. O'Brien 2012-06-08 21:57:36 +00:00
parent 3e4da6f5b3
commit b379932fc0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/NetBSD/bmake/dist/; revision=236769
svn path=/vendor/NetBSD/bmake/20120606/; revision=236770; tag=vendor/NetBSD/bmake/20120606
138 changed files with 43381 additions and 16627 deletions

1346
ChangeLog Normal file

File diff suppressed because it is too large Load Diff

120
FILES Normal file
View File

@ -0,0 +1,120 @@
FILES
ChangeLog
bmake.cat1
boot-strap
bsd.after-import.mk
os.sh
Makefile.in
PSD.doc/Makefile
PSD.doc/tutorial.ms
README
arch.c
buf.c
buf.h
compat.c
cond.c
make-conf.h
make_malloc.c
make_malloc.h
config.h.in
configure
aclocal.m4
configure.in
dir.c
dir.h
find_lib.sh
for.c
getopt.c
hash.c
hash.h
install-sh
job.c
job.h
meta.c
meta.h
dirname.c
realpath.c
strlcpy.c
strlist.c
strlist.h
stresep.c
trace.c
trace.h
lst.h
lst.lib/Makefile
lst.lib/lstAppend.c
lst.lib/lstAtEnd.c
lst.lib/lstAtFront.c
lst.lib/lstClose.c
lst.lib/lstConcat.c
lst.lib/lstDatum.c
lst.lib/lstDeQueue.c
lst.lib/lstDestroy.c
lst.lib/lstDupl.c
lst.lib/lstEnQueue.c
lst.lib/lstFind.c
lst.lib/lstFindFrom.c
lst.lib/lstFirst.c
lst.lib/lstForEach.c
lst.lib/lstForEachFrom.c
lst.lib/lstInit.c
lst.lib/lstInsert.c
lst.lib/lstInt.h
lst.lib/lstIsAtEnd.c
lst.lib/lstIsEmpty.c
lst.lib/lstLast.c
lst.lib/lstMember.c
lst.lib/lstNext.c
lst.lib/lstOpen.c
lst.lib/lstPrev.c
lst.lib/lstRemove.c
lst.lib/lstReplace.c
lst.lib/lstSucc.c
machine.sh
main.c
make.1
bmake.1
make.c
make.h
make-bootstrap.sh.in
missing/sys/cdefs.h
mkdeps.sh
nonints.h
parse.c
pathnames.h
ranlib.h
setenv.c
sigcompat.c
sprite.h
str.c
suff.c
targ.c
util.c
var.c
wait.h
unit-tests/Makefile.in
unit-tests/comment
unit-tests/cond1
unit-tests/doterror
unit-tests/dotwait
unit-tests/error
unit-tests/export
unit-tests/export-all
unit-tests/forsubst
unit-tests/hash
unit-tests/misc
unit-tests/moderrs
unit-tests/modmatch
unit-tests/modmisc
unit-tests/modorder
unit-tests/modts
unit-tests/modword
unit-tests/phony-end
unit-tests/posix
unit-tests/qequals
unit-tests/sysv
unit-tests/ternary
unit-tests/test.exp
unit-tests/unexport
unit-tests/unexport-env
unit-tests/varcmd

181
Makefile.in Normal file
View File

@ -0,0 +1,181 @@
# $NetBSD: Makefile,v 1.56 2012/05/30 21:54:23 sjg Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
# $Id: Makefile.in,v 1.161 2012/06/06 20:02:32 sjg 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 \
lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \
lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
SRCS += lstPrev.c
# you can use this Makefile if you have an earlier version of bmake.
prefix= @prefix@
srcdir= @srcdir@
CC?= @CC@
# Base version on src date
MAKE_VERSION= 20120606
MACHINE=@machine@
MACHINE_ARCH=@machine_arch@
DEFAULT_SYS_PATH = @default_sys_path@
CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
CFLAGS+= -I. -I${srcdir} @DEFS@ @CPPFLAGS@ ${XDEFS} -DMAKE_NATIVE
CFLAGS+= ${CFLAGS_${.TARGET:T}}
CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}}
COPTS.main.c+= "-DMAKE_VERSION=\"${MAKE_VERSION}\""
LDFLAGS= @LDFLAGS@
LIBOBJS= @LIBOBJS@
LDADD= @LIBS@
.if !empty(LIBOBJS)
SRCS+= ${LIBOBJS:T:.o=.c}
.endif
USE_META ?= @use_meta@
.if ${USE_META:tl} != "no"
SRCS+= meta.c
CPPFLAGS+= -DUSE_META
FILEMON_H ?= @filemon_h@
.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
COPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H}
.endif
.endif
.PATH: ${srcdir}
.PATH: ${srcdir}/lst.lib
OS!= uname -s
ARCH!= uname -p 2>/dev/null || uname -m
# list of OS's which are derrived from BSD4.4
isBSD44= NetBSD FreeBSD OpenBSD DragonFly
.if ${OS} == "NetBSD"
# Don't set these for anyone else since we don't know what the effect may be.
# On FreeBSD WARNS=2 sets a bunch of -W flags that make does not handle.
WFORMAT= 1
WARNS=4
.NOPATH: bmake.cat1
.if make(install) && exists(${DESTDIR}/usr/share/doc)
SUBDIR= PSD.doc
.endif
.endif
.if empty(isBSD44:M${OS})
# XXX not sure if we still want this given that configure
# lets us force or not the definition of MACHINE.
CFLAGS_main.o+= "-DFORCE_MACHINE=\"${MACHINE}\""
MANTARGET=cat
INSTALL?=${srcdir}/install-sh
.if (${MACHINE} == "sun386")
# even I don't have one of these anymore :-)
CFLAGS+= -DPORTAR
.elif (${MACHINE} != "sunos")
SRCS+= sigcompat.c
CFLAGS+= -DSIGNAL_FLAGS=SA_RESTART
.endif
.endif
.if make(obj) || make(clean)
SUBDIR+= unit-tests
.endif
# many systems use gcc these days
CC_IS_GCC=@GCC@
.if ${CC_IS_GCC} == "yes"
# problem with gcc3
CFLAGS_var.o+= -Wno-cast-qual
.endif
CFLAGS_main.o+= "-D@force_machine@MACHINE=\"${MACHINE}\"" "-DMACHINE_ARCH=\"${MACHINE_ARCH}\""
EXTRACT_MAN=no
MAN=${PROG}.1
.if (${PROG} != "make")
${MAN}: make.1
@echo making ${PROG}.1
@sed -e 's/^.Nx/NetBSD/' -e '/^.Nm/s/make/${PROG}/' -e '/^.Sh HISTORY/,$$d' ${srcdir}/make.1 > $@
@(echo ".Sh HISTORY"; \
echo ".Nm"; \
echo "is derived from NetBSD"; \
echo ".Xr make 1 ."; \
echo It uses autoconf to facilitate portability to other platforms.) >> $@
.endif
.if !empty(isBSD44:M${OS})
.if "${OS}" != "NetBSD"
MAN1=${MAN}
.endif
MANTARGET?=man
.endif
MANTARGET?= cat
MANDEST?= ${MANDIR}/${MANTARGET}1
.if ${MANTARGET} == "cat"
_mfromdir=${srcdir}
.endif
.if exists(${srcdir}/../Makefile.inc)
.include "${srcdir}/../Makefile.inc"
.endif
.-include <bsd.prog.mk>
# sigh, FreeBSD at least includes bsd.subdir.mk via bsd.obj.mk
# so the inclusion below, results in complaints about re-defined
# targets. For NetBSD though we need to explicitly include it.
.if defined(SUBDIR) && !target(${SUBDIR:[1]})
.-include <bsd.subdir.mk>
.endif
CPPFLAGS+= -DMAKE_NATIVE
COPTS.var.c += -Wno-cast-qual
COPTS.job.c += -Wno-format-nonliteral
COPTS.parse.c += -Wno-format-nonliteral
COPTS.var.c += -Wno-format-nonliteral
# Force these
BINDIR= ${prefix}/bin
MANDIR= ${prefix}/man
arch.o: config.h
# make sure that MAKE_VERSION gets updated.
main.o: ${SRCS} ${MAKEFILE}
MK?=${prefix}/share/mk
MKSRC?=@mksrc@
INSTALL?=${srcdir}/install-sh
beforeinstall:
test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m 775 -d ${DESTDIR}${BINDIR}
test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m 775 -d ${DESTDIR}${MANDEST}
# latest version of *.mk includes an installer.
# you should not need to set USE_OS
install-mk:
.if exists(${MKSRC}/install-mk)
test -d ${DESTDIR}${MK} || ${INSTALL} -m 775 -d ${DESTDIR}${MK}
${MKSRC}/install-mk -v -m 644 ${DESTDIR}${MK} ${USE_OS}
.else
@echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false
.endif
.ifdef TOOLDIR
# this is a native netbsd build,
# use libutil rather than the local emalloc etc.
CPPFLAGS+= -DUSE_EMALLOC
LDADD+=-lutil
DPADD+=${LIBUTIL}
.endif
# A simple unit-test driver to help catch regressions
accept test:
cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}

View File

@ -1,3 +1,4 @@
# $NetBSD: Makefile,v 1.2 1995/06/14 15:20:23 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 8/14/93
DIR= psd/12.make

View File

@ -1,5 +1,4 @@
.\" Copyright (c) 1988, 1989 by Adam de Boor
.\" Copyright (c) 1989 by Berkeley Softworks
.\" $NetBSD: tutorial.ms,v 1.11 2011/08/18 15:19:30 sjg Exp $
.\" Copyright (c) 1988, 1989, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@ -14,6 +13,36 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" Copyright (c) 1988, 1989 by Adam de Boor
.\" Copyright (c) 1989 by Berkeley Softworks
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Adam de Boor.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
@ -34,7 +63,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)tutorial.ms 8.4 (Berkeley) 4/28/95
.\" @(#)tutorial.ms 8.1 (Berkeley) 8/18/93
.\"
.EH 'PSD:12-%''PMake \*- A Tutorial'
.OH 'PMake \*- A Tutorial''PSD:12-%'
@ -43,8 +72,6 @@
.\" is numeric, it is taken as the depth for numbering (as for .NH), else
.\" the default (1) is assumed.
.\"
.\" $Id: tutorial.ms,v 1.4 89/01/08 20:20:22 adam Exp Locker: adam $
.\"
.\" @P The initial paragraph distance.
.\" @Q The piece of section number to increment (or 0 if none given)
.\" @R Section header.
@ -87,14 +114,15 @@
.nr g4 \\n(.s
.sp -1
.\" .st cf
\D's -1u'\D't 5u'
\D't 5u'
.sp -1
\h'50u'\D'l 71u 0u'\D'l 50u 50u'\D'l 0u 71u'\D'l -50u 50u'\D'l -71u 0u'\D'l -50u -50u'\D'l 0u -71u'\D'l 50u -50u'
\h'50u'
.sp -1
\D't 3u'
.sp -1
.sp 7u
\h'53u'\D'p 14 68u 0u 46u 46u 0u 68u -46u 46u -68u 0u -47u -46u 0u -68u 47u -46u'
\h'53u'
\d\D'p -0.19i 0.0i 0.0i -0.13i 0.30i 0.0i 0.0i 0.13i'
.sp -1
.ft R
.ps 6
@ -104,7 +132,7 @@
\h'85u'\v'0.85n'\h-\w\\*(g9u/2u\&\\*(g9
.sp |\\n(g8u
.sp 166u
\D't 3u'\D's -1u'
\D't 3u'
.br
.po
.rt
@ -150,7 +178,7 @@ be familiar. PMake's most important feature is its ability to run
several different jobs at once, making the creation of systems
considerably faster. It also has a great deal more functionality than
Make. Throughout the text, whenever something is mentioned that is an
important difference between PMake and Make (i.e. something that will
important difference between PMake and Make (i.e. something that will
cause a makefile to fail if you don't do something about it), or is
simply important, it will be flagged with a little sign in the left
margin, like this:
@ -599,7 +627,7 @@ likely freeze if you execute something that produces thousands of
bytes of output (8 Kb is the limit on many UNIX systems).
.LP
The value of a variable may be retrieved by enclosing the variable
name in parentheses or curly braces and preceeding the whole thing
name in parentheses or curly braces and preceding the whole thing
with a dollar sign.
.LP
For example, to set the variable CFLAGS to the string
@ -1272,6 +1300,15 @@ administrator. If locking is on,
will turn it off, and vice versa. Note that this locking will not
prevent \fIyou\fP from invoking PMake twice in the same place \*- if
you own the lock file, PMake will warn you about it but continue to execute.
.IP "\fB\-m\fP \fIdirectory\fP"
.Ix 0 def flags -m
Tells PMake another place to search for included makefiles via the <...>
style. Several
.B \-m
options can be given to form a search path. If this construct is used the
default system makefile search path is completely overridden.
To be explained in chapter 3, section 3.2.
.Rm 2 3.2
.IP \fB\-n\fP
.Ix 0 def flags -n
This flag tells PMake not to execute the commands needed to update the
@ -1417,7 +1454,7 @@ the screen from being filled with garbage even more indecipherable
than you usually see. PMake has two ways of doing this, one of which
provides for much cleaner output and a clear separation between the
output of different jobs, the other of which provides a more immediate
response so one can tell what is really happpening. The former is done
response so one can tell what is really happening. The former is done
by notifying you when the creation of a target starts, capturing the
output and transferring it to the screen all at once when the job
finishes. The latter is done by catching the output of the shell (and
@ -1521,7 +1558,7 @@ using the
.Ix 0 ref !=
.Ix 0 ref variable assignment shell-output
operator. Variables may be expanded (their value inserted) by enclosing
their name in parentheses or curly braces, prceeded by a dollar sign.
their name in parentheses or curly braces, preceded by a dollar sign.
A dollar sign may be escaped with another dollar sign. Variables are
not expanded if PMake doesn't know about them. There are seven local
variables:
@ -1587,7 +1624,7 @@ suffix is usually a text file to be processed by Troff with the \-ms
macro package, and so on.
One of the best aspects of both Make and PMake comes from their
understanding of how the suffix of a file pertains to its contents and
their ability to do things with a file based soley on its suffix. This
their ability to do things with a file based solely on its suffix. This
ability comes from something known as a transformation rule. A
transformation rule specifies how to change a file with one suffix
into a file with another suffix.
@ -1912,11 +1949,15 @@ or this
.DE
The difference between the two is where PMake searches for the file:
the first way, PMake will look for
the file only in the system makefile directory (to find out what that
directory is, give PMake the
the file only in the system makefile directory (or directories)
(to find out what that directory is, give PMake the
.B \-h
flag).
.Ix 0 ref flags -h
The system makefile directory search path can be overridden via the
.B \-m
option.
.Ix 0 ref flags -m
For files in double-quotes, the search is more complex:
.RS
.IP 1)
@ -2588,7 +2629,7 @@ in the variable to be replaced by
.I replacement-string ,
unless the
.CW g
flag is given at the end, in which case all occurences of the string
flag is given at the end, in which case all occurrences of the string
are replaced. The substitution is performed on each word in the
variable in turn. If
.I search-string
@ -2599,7 +2640,7 @@ the string must match starting at the beginning of the word. If
ends with a
.CW $ ,
the string must match to the end of the word (these two may be
combined to force an exact match). If a backslash preceeds these two
combined to force an exact match). If a backslash precedes these two
characters, however, they lose their special meaning. Variable
expansion also occurs in the normal fashion inside both the
.I search-string
@ -2624,7 +2665,7 @@ character is replaced by the
unless it is preceded by a backslash.
You are allowed to use any character except
colon or exclamation point to separate the two strings. This so-called
delimiter character may be placed in either string by preceeding it
delimiter character may be placed in either string by preceding it
with a backslash.
.IP T
.Ix 0 def :T
@ -2927,10 +2968,10 @@ looks like this:
.DS
.SM
#
# Rules for making libraries. The object files that make up the library are
# removed once they are archived.
# Rules for making libraries. The object files that make up the library
# are removed once they are archived.
#
# To make several libararies in parallel, you should define the variable
# To make several libraries in parallel, you should define the variable
# "many_libraries". This will serialize the invocations of ranlib.
#
# To use, do something like this:
@ -2954,19 +2995,19 @@ ARFLAGS ?= crl
#
# Re-archive the out-of-date members and recreate the library's table of
# contents using ranlib. If many_libraries is defined, put the ranlib off
# til the end so many libraries can be made at once.
# contents using ranlib. If many_libraries is defined, put the ranlib
# off til the end so many libraries can be made at once.
#
MAKELIB : .USE .PRECIOUS
ar $(ARFLAGS) $(.TARGET) $(.OODATE)
#ifndef no_ranlib
# ifdef many_libraries
...
# endif many_libraries
# endif /* many_libraries */
ranlib $(.TARGET)
#endif no_ranlib
#endif /* no_ranlib */
#endif _MAKELIB_MK
#endif /* _MAKELIB_MK */
.DE
.xH 2 On the Condition...
.Rd 1
@ -3054,8 +3095,8 @@ identify the system on which PMake is being run.
The syntax is
.CW exists( \fIfile\fP\c
.CW )
and is true if the file can be found on the global search path (i.e.
that defined by
and is true if the file can be found on the global search path
(i.e. that defined by
.CW .PATH
targets, not by
.CW .PATH \fIsuffix\fP
@ -3168,7 +3209,7 @@ FORMATTER = ditroff -Plaser_printer
FORMATTER = nroff -Pdot_matrix_printer
#endif
.DE
would wreak havok if you tried
would wreak havoc if you tried
.CW "pmake draft print" '' ``
since you would use the same formatter for each target. As I said,
this all gets somewhat complicated.
@ -3289,7 +3330,7 @@ within that loop will be printed, etc. The specification runs like
this:
.DS
#
# This is a shell specification to have the bourne shell echo
# This is a shell specification to have the Bourne shell echo
# the commands just before executing them, rather than when it reads
# them. Useful if you want to see how variables are being expanded, etc.
#
@ -3325,7 +3366,7 @@ When the echo off command is executed, the shell will print
.CW \-x
flag (rather than the
.CW \-v
flag PMake usually uses)). PMake will remove all occurences of this
flag PMake usually uses)). PMake will remove all occurrences of this
string from the output, so you don't notice extra commands you didn't
put there.
.Bp

47
README Normal file
View File

@ -0,0 +1,47 @@
bmake
This directory contains a port of the BSD make tool (from NetBSD)
I have run it on SunOS,Solaris,HP-UX,AIX,IRIX,FreeBSD and Linux.
Version 3 was re-worked from scratch to better facilitate
importing newer make(1) versions from NetBSD. The original code base
was NetBSD-1.0, so version 3 was built by doing a fresh import of the
NetBSD-1.0 usr.bin/make, adding the autoconf and other portability
patches to sync it with bmake v2, and then NetBSD's make
of Feb 20, 2000 was imported and conflicts dealt with.
NetBSD's make was again imported on June 6 and December 15, 2000.
In 2003 bmake switched to a date based version (first was 20030714)
which generally represents the date it was last merged with NetBSD's
make. Since then, NetBSD's make is imported within a week of any
interesting changes, so that bmake tracks it very closely.
Building:
The prefered way to bootstrap bmake is:
./bmake/boot-strap
there are a number of args - most of which get passed to configure,
eg.
./bmake/boot-strap --prefix=/opt
see the boot-strap script for details.
To make much use of bmake you will need the bsd.*.mk macros or my
portable *.mk macros. See
http://www.crufty.net/ftp/pub/sjg/mk.tar.gz
which will be links to the latest versions.
On a non-BSD system, you would want to unpack mk[-YYYYmmdd].tar.gz in
the same directory as bmake (so ./mk and ./bmake exist), and
./bmake/boot-strap will do the rest.
If you want to do it all by hand then read boot-strap first to get the
idea.
Even if you have an earlier version of bmake installed, use boot-strap
to ensure that all goes well.
--sjg

77
aclocal.m4 vendored Normal file
View File

@ -0,0 +1,77 @@
dnl RCSid:
dnl $Id: aclocal.m4,v 1.5 2003/03/06 21:21:30 sjg Exp $
dnl
dnl
dnl AC_CHECK_HEADER_HAS(HEADER, PATTERN, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]))
AC_DEFUN(AC_CHECK_HEADER_HAS,
[dnl first check if header exists and if so, see if it contains PATTERN
ac_has_hdr=`echo "ac_cv_header_$1" | sed 'y%./+-%__p_%'`
ac_has_it=`echo "ac_cv_header_$1"_$2 | sed 'y%./+-%__p_%'`
if eval "test \"`echo x'$'$ac_has_hdr`\" = x"; then
AC_CHECK_HEADER($1)
fi
if eval "test \"`echo '$'$ac_has_hdr`\" = yes"; then
ac_x=HAVE_`echo "$1" | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
AC_DEFINE_UNQUOTED($ac_x)
AC_MSG_CHECKING([if $1 has $2])
AC_CACHE_VAL($ac_has_it,
[eval $ac_has_it=no
AC_EGREP_HEADER($2, $1, eval "$ac_has_it=yes")])
if eval "test \"`echo '$'$ac_has_it`\" = yes"; then
AC_MSG_RESULT(yes)
ac_x=HAVE_`echo "$1"_$2 | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
AC_DEFINE_UNQUOTED($ac_x)
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT(no)
ifelse([$4], , , [$4
])dnl
fi
fi
])
dnl AC_EGREP(PATTERN, FILE, ACTION-IF-FOUND [,
dnl ACTION-IF-NOT-FOUND])
AC_DEFUN(AC_EGREP,
[
dnl Prevent m4 from eating character classes:
changequote(, )dnl
if egrep "$1" $2 >/dev/null 2>&1; then
changequote([, ])dnl
ifelse([$3], , :, [$3])
ifelse([$4], , , [else
$4
])dnl
fi
])
dnl
dnl Test for __attribute__
dnl
AC_DEFUN(AC_C___ATTRIBUTE__, [
AC_MSG_CHECKING(for __attribute__)
AC_CACHE_VAL(ac_cv___attribute__, [
AC_TRY_COMPILE([
#include <stdlib.h>
],
[
static void foo(void) __attribute__ ((noreturn));
static void
foo(void)
{
exit(1);
}
],
ac_cv___attribute__=yes,
ac_cv___attribute__=no)])
if test "$ac_cv___attribute__" = "yes"; then
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
fi
AC_MSG_RESULT($ac_cv___attribute__)
])

File diff suppressed because it is too large Load Diff

2043
bmake.1 Normal file

File diff suppressed because it is too large Load Diff

1305
bmake.cat1 Normal file

File diff suppressed because it is too large Load Diff

388
boot-strap Executable file
View File

@ -0,0 +1,388 @@
:
# NAME:
# boot-strap
#
# SYNOPSIS:
# boot-strap [--"configure_arg" ... ][-s "srcdir"][-m "mksrc"]\\
# ["prefix" ["bmakesrc" ["mksrc"]]]
#
# DESCRIPTION:
# This script is used to configure/build bmake it builds for
# each OS in a subdir to keep the src clean.
# On successful completion it echos commands to put the new
# bmake binary into the /configs tree (if it exists)
# (http://www.crufty.net/FreeWare/configs.html), $prefix/bin
# and a suitable ~/*bin directory.
#
# Options:
#
# -c "rc"
# Pick up settings from "rc".
# We look for '.bmake-boot-strap.rc' before processing
# options.
#
# --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 ($share_dir/mk)
#
# Possibly useful configure_args:
#
# --without-meta
# disable use of meta mode.
#
# --without-filemon
# disable use of filemon(9) which is currently only
# available for NetBSD and FreeBSD.
#
# --with-filemon="path/to/filemon.h"
# enables use of filemon(9) by meta mode.
#
# --with-machine="machine"
# set "machine" to override that determined by
# machine.sh
#
# --with-force-machine="machine"
# force "machine" even if uname(3) provides a value.
#
# --with-machine_arch="machine_arch"
# set "machine_arch" to override that determined by
# machine.sh
#
# --with-default-sys-path="syspath"
# set an explicit default "syspath" which is where bmake
# will look for sys.mk and friends.
#
# AUTHOR:
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: boot-strap,v 1.39 2012/03/26 17:08:22 sjg Exp $
#
# @(#) Copyright (c) 2001 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@crufty.net
#
Mydir=`dirname $0`
. "$Mydir/os.sh"
case "$Mydir" in
/*) ;;
*) Mydir=`cd "$Mydir" && 'pwd'`;;
esac
Usage() {
[ "$1" ] && echo "ERROR: $@" >&2
echo "Usage:" >&2
echo "$0 [--<configure_arg> ...][-s <srcdir>][-m <mksrc>][<prefix> [[<srcdir>] [<mksrc>]]]" >&2
exit 1
}
Error() {
echo "ERROR: $@" >&2
exit 1
}
source_rc() {
rc="$1"; shift
for d in ${*:-""}
do
r="${d:+$d/}$rc"
[ -f "$r" -a -s "$r" ] || continue
echo "NOTE: reading $r"
. "$r"
break
done
}
CONFIGURE_ARGS=
MAKESYSPATH=
# pick a useful default prefix (for me at least ;-)
for prefix in /opt/$HOST_TARGET "$HOME/$HOST_TARGET" /usr/pkg /usr/local ""
do
[ -d "${prefix:-.}" ] && break
done
srcdir=
mksrc=
objdir=
quiet=:
source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME"
get_optarg() {
expr "x$1" : "x[^=]*=\\(.*\\)"
}
while :
do
case "$1" in
--) shift; break;;
--prefix) prefix="$2"; shift;;
--prefix=*) prefix=`get_optarg "$1"`;;
--src=*) srcdir=`get_optarg "$1"`;;
--with-mksrc=*|--mksrc=*) mksrc=`get_optarg "$1"`;;
--share=*) share_dir=`get_optarg "$1"`;;
--share) share_dir="$2"; shift;;
--with-default-sys-path=*)
CONFIGURE_ARGS="$1"
MAKESYSPATH=`get_optarg "$1"`;;
--with-default-sys-path)
CONFIGURE_ARGS="$1 $2"
MAKESYSPATH="$2"; shift;;
-s|--src) srcdir="$2"; shift;;
-m|--mksrc) mksrc="$2"; shift;;
-o|--objdir) objdir="$2"; shift;;
-q) quiet=;;
-c) source_rc "$2"; shift;;
--*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1";;
*=*) eval "$1"; export `expr "x$1" : "x\\(.[^=]*\\)=.*"`;;
*) break;;
esac
shift
done
AddConfigure() {
case " $CONFIGURE_ARGS " in
*" $1"*) ;;
*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1$2";;
esac
}
GetDir() {
match="$1"
shift
fmatch="$1"
shift
for dir in $*
do
[ -d "$dir" ] || continue
case "/$dir/" in
*$match*) ;;
*) continue;;
esac
case "$fmatch" in
.) ;;
*) [ -s $dir/$fmatch ] || continue;;
esac
case "$dir/" in
*./*) cd "$dir" && 'pwd';;
/*) echo $dir;;
*) cd "$dir" && 'pwd';;
esac
break
done
}
FindHereOrAbove() {
(
_t=-s
while :
do
case "$1" in
-C) cd "$2"; shift; shift;;
-?) _t=$1; shift;;
*) break;;
esac
done
case "$1" in
/*) # we shouldn't be here
[ $_t "$1" ] && echo "$1"
return
;;
.../*) want=`echo "$1" | sed 's,^.../*,,'`;;
*) want="$1";;
esac
here=`'pwd'`
while :
do
if [ $_t "./$want" ]; then
echo "$here/$want"
return
fi
cd ..
here=`'pwd'`
case "$here" in
/) return;;
esac
done
)
}
# is $1 missing from $2 (or PATH) ?
no_path() {
eval "__p=\$${2:-PATH}"
case ":$__p:" in *:"$1":*) return 1;; *) return 0;; esac
}
# if $1 exists and is not in path, append it
add_path () {
case "$1" in
-?) t=$1; shift;;
*) t=-d;;
esac
case "$2,$1" in
MAKESYSPATH,.../*) ;;
*) [ $t ${1:-.} ] || return;;
esac
no_path $* && eval ${2:-PATH}="$__p${__p:+:}$1"
}
srcdir=`GetDir /bmake make-bootstrap.sh.in "$srcdir" "$2" "$Mydir" ./bmake* "$Mydir"/../bmake*`
[ -d "${srcdir:-/dev/null}" ] || Usage
case "$mksrc" in
none|-) # we don't want it
mksrc=
;;
.../*) # find here or above
mksrc=`FindHereOrAbove -C "$Mydir" -s "$mksrc/sys.mk"`
# that found a file
mksrc=`dirname $mksrc`
;;
*) # guess we want mksrc...
mksrc=`GetDir /mk sys.mk "$mksrc" "$3" ./mk* "$srcdir"/mk* "$srcdir"/../mk*`
[ -d "${mksrc:-/dev/null}" ] || Usage "Use '-m none' to build without mksrc"
;;
esac
# Ok, get to work...
objdir="${objdir:-$OS}"
[ -d "$objdir" ] || mkdir -p "$objdir"
[ -d "$objdir" ] || mkdir "$objdir"
cd "$objdir" || exit 1
# make it absolute
objdir=`'pwd'`
ShareDir() {
case "/$1" in
/) [ -d /share ] || return;;
*/$HOST_TARGET)
if [ -d "$1/../share" ]; then
echo `dirname "$1"`/share
return
fi
;;
esac
echo $1/share
}
# make it easy to force prefix to use $HOST_TARGET
: looking at "$prefix"
case "$prefix" in
*/host?target) prefix=`echo "$prefix" | sed "s,host.target,${HOST_TARGET},"`;;
esac
share_dir="${share_dir:-`ShareDir $prefix`}"
AddConfigure --prefix= "$prefix"
case "$CONFIGURE_ARGS" in
*--with-*-sys-path*) ;; # skip
*) [ "$share_dir" ] && AddConfigure --with-default-sys-path= "$share_dir/mk";;
esac
if [ "$mksrc" ]; then
AddConfigure --with-mksrc= "$mksrc"
# not all cc's support this
CFLAGS_MF= CFLAGS_MD=
export CFLAGS_MF CFLAGS_MD
fi
$srcdir/configure $CONFIGURE_ARGS || exit 1
chmod 755 make-bootstrap.sh || exit 1
./make-bootstrap.sh || exit 1
if [ -z "$MAKESYSPATH" ]; then
add_path "${share_dir:-...}/mk" MAKESYSPATH
case "$HOST_TARGET" in
netbsd*) add_path /usr/share/mk MAKESYSPATH;;
esac
fi
if [ -s "${mksrc:-/dev/null}/install-mk" ]; then
sh "${mksrc}/install-mk" "$objdir/mk"
case "$MAKESYSPATH" in
.../mk*) ;;
*) MAKESYSPATH=".../mk:${MAKESYSPATH}";;
esac
fi
# make sure test below uses the same diff that configure did
TOOL_DIFF=`type diff | sed 's,[()],,g;s,^[^/][^/]*,,;q'`
export MAKESYSPATH TOOL_DIFF
if [ "$mksrc" ]; then
$objdir/bmake test || exit 1
else
# assume nothing
$objdir/bmake -r -m / test || exit 1
fi
# If -q given, we don't want all the install instructions
$quiet exit 0
make_version=`./bmake -r -m / -f ./Makefile -V MAKE_VERSION | ( read one two; echo $one )`
bmake_version=bmake-$make_version
if [ -s /usr/share/tmac/andoc.tmac ]; then
# this should be ok
man_subdir=man1
man_src=$srcdir/bmake.1
else
# guess not
man_subdir=cat1
man_src=$srcdir/bmake.cat1
fi
install_prefix() {
(
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
echo mkdir -p $man_dir/$man_subdir
echo cp $man_src $man_dir/$man_subdir/bmake.1
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 mksrc= "$CONFIGS/$OS/$OSMAJOR.X/$MACHINE_ARCH$prefix"
# I like to keep a copy here...
install_prefix share_dir="$HOME/share" "$HOME/$HOST_TARGET"
;;
esac
install_prefix "$prefix"

87
bsd.after-import.mk Normal file
View File

@ -0,0 +1,87 @@
# $Id: bsd.after-import.mk,v 1.3 2012/06/06 17:48:14 sjg Exp $
# This makefile is for use when integrating bmake into a BSD build
# system. Use this makefile after importing bmake.
# It will bootstrap the new version,
# capture the generated files we need, and add an after-import
# target to allow the process to be easily repeated.
# The goal is to allow the benefits of autoconf without
# the overhead of running configure.
all: ${.CURDIR}/Makefile
all: after-import
# we rely on bmake
_this := ${MAKEFILE:tA}
BMAKE_SRC := ${.PARSEDIR}
# it helps to know where the top of the tree is.
.if !defined(SRCTOP)
srctop := ${.MAKE.MAKEFILES:M*src/share/mk/sys.mk:H:H:H}
.if !empty(srctop)
SRCTOP := ${srctop}
.endif
.endif
# This lets us match what boot-strap does
.if !defined(HOST_OS)
HOST_OS!= uname
.endif
# .../share/mk will find ${SRCTOP}/share/mk
# if we are within ${SRCTOP}
DEFAULT_SYS_PATH= .../share/mk:/usr/share/mk
BOOTSTRAP_ARGS = \
--with-default-sys-path='${DEFAULT_SYS_PATH}' \
--prefix /usr \
--share /usr/share \
--mksrc none
# run boot-strap with minimal influence
bootstrap: ${BMAKE_SRC}/boot-strap ${MAKEFILE}
HOME=/ ${BMAKE_SRC}/boot-strap ${BOOTSTRAP_ARGS} ${BOOTSTRAP_XTRAS}
touch ${.TARGET}
# Makefiles need a little more tweaking than say config.h
MAKEFILE_SED = sed -e '/^MACHINE/d' \
-e '/^PROG/s,bmake,${.CURDIR:T},' \
-e 's,${SRCTOP},$${SRCTOP},g'
# These are the simple files we want to capture
configured_files= config.h unit-tests/Makefile
after-import: bootstrap ${MAKEFILE}
.for f in ${configured_files:N*Makefile}
@echo Capturing $f
@cmp -s ${.CURDIR}/$f ${HOST_OS}/$f || \
cp ${HOST_OS}/$f ${.CURDIR}/$f
.endfor
.for f in ${configured_files:M*Makefile}
@echo Capturing $f
@${MAKEFILE_SED} ${HOST_OS}/$f > ${.CURDIR}/$f
.endfor
# this needs the most work
${.CURDIR}/Makefile: bootstrap ${MAKEFILE} .PRECIOUS
@echo Generating ${.TARGET:T}
@(echo '# This is a generated file, do NOT edit!'; \
echo '# See ${_this:S,${SRCTOP}/,,}'; \
echo; echo '# look here first for config.h'; \
echo 'CFLAGS+= -I$${.CURDIR}'; echo; \
${MAKEFILE_SED} ${HOST_OS}/Makefile; \
echo; echo '# override some simple things'; \
echo 'BINDIR= /usr/bin'; \
echo 'MANDIR= /usr/share/man'; \
echo; echo '# make sure we get this'; \
echo 'CFLAGS+= $${COPTS.$${.IMPSRC:T}}'; \
echo 'CLEANFILES+= bootstrap'; \
echo; echo 'after-import: ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo ' cd $${.CURDIR} && $${.MAKE} -f ${_this:S,${SRCTOP},\${SRCTOP},}'; \
echo; echo '.-include "Makefile.inc"'; \
echo ) > ${.TARGET:T}.new
@mv ${.TARGET:T}.new ${.TARGET}
.include <bsd.obj.mk>

291
buf.c Normal file
View File

@ -0,0 +1,291 @@
/* $NetBSD: buf.c,v 1.25 2012/04/24 20:26:58 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: buf.c,v 1.25 2012/04/24 20:26:58 sjg 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.25 2012/04/24 20:26:58 sjg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* buf.c --
* Functions for automatically-expanded buffers.
*/
#include "make.h"
#include "buf.h"
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#define BUF_DEF_SIZE 256 /* Default buffer size */
/*-
*-----------------------------------------------------------------------
* Buf_Expand_1 --
* Extend buffer for single byte add.
*
*-----------------------------------------------------------------------
*/
void
Buf_Expand_1(Buffer *bp)
{
bp->size += max(bp->size, 16);
bp->buffer = bmake_realloc(bp->buffer, bp->size);
}
/*-
*-----------------------------------------------------------------------
* Buf_AddBytes --
* Add a number of bytes to the buffer.
*
* Results:
* None.
*
* Side Effects:
* Guess what?
*
*-----------------------------------------------------------------------
*/
void
Buf_AddBytes(Buffer *bp, int numBytes, const Byte *bytesPtr)
{
int count = bp->count;
Byte *ptr;
if (__predict_false(count + numBytes >= bp->size)) {
bp->size += max(bp->size, numBytes + 16);
bp->buffer = bmake_realloc(bp->buffer, bp->size);
}
ptr = bp->buffer + count;
bp->count = count + numBytes;
ptr[numBytes] = 0;
memcpy(ptr, bytesPtr, numBytes);
}
/*-
*-----------------------------------------------------------------------
* Buf_GetAll --
* Get all the available data at once.
*
* Results:
* A pointer to the data and the number of bytes available.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
Byte *
Buf_GetAll(Buffer *bp, int *numBytesPtr)
{
if (numBytesPtr != NULL)
*numBytesPtr = bp->count;
return (bp->buffer);
}
/*-
*-----------------------------------------------------------------------
* Buf_Empty --
* Throw away bytes in a buffer.
*
* Results:
* None.
*
* Side Effects:
* The bytes are discarded.
*
*-----------------------------------------------------------------------
*/
void
Buf_Empty(Buffer *bp)
{
bp->count = 0;
*bp->buffer = 0;
}
/*-
*-----------------------------------------------------------------------
* Buf_Init --
* Initialize a buffer. If no initial size is given, a reasonable
* default is used.
*
* Input:
* size Initial size for the buffer
*
* Results:
* A buffer to be given to other functions in this library.
*
* Side Effects:
* The buffer is created, the space allocated and pointers
* initialized.
*
*-----------------------------------------------------------------------
*/
void
Buf_Init(Buffer *bp, int size)
{
if (size <= 0) {
size = BUF_DEF_SIZE;
}
bp->size = size;
bp->count = 0;
bp->buffer = bmake_malloc(size);
*bp->buffer = 0;
}
/*-
*-----------------------------------------------------------------------
* Buf_Destroy --
* Nuke a buffer and all its resources.
*
* Input:
* buf Buffer to destroy
* freeData TRUE if the data should be destroyed
*
* Results:
* Data buffer, NULL if freed
*
* Side Effects:
* The buffer is freed.
*
*-----------------------------------------------------------------------
*/
Byte *
Buf_Destroy(Buffer *buf, Boolean freeData)
{
Byte *data;
data = buf->buffer;
if (freeData) {
free(data);
data = NULL;
}
buf->size = 0;
buf->count = 0;
buf->buffer = NULL;
return data;
}
/*-
*-----------------------------------------------------------------------
* Buf_DestroyCompact --
* Nuke a buffer and return its data.
*
* Input:
* buf Buffer to destroy
*
* Results:
* Data buffer
*
* Side Effects:
* If the buffer size is much greater than its content,
* a new buffer will be allocated and the old one freed.
*
*-----------------------------------------------------------------------
*/
#ifndef BUF_COMPACT_LIMIT
# define BUF_COMPACT_LIMIT 128 /* worthwhile saving */
#endif
Byte *
Buf_DestroyCompact(Buffer *buf)
{
#if BUF_COMPACT_LIMIT > 0
Byte *data;
if (buf->size - buf->count >= BUF_COMPACT_LIMIT) {
/* We trust realloc to be smart */
data = bmake_realloc(buf->buffer, buf->count + 1);
if (data) {
data[buf->count] = 0;
Buf_Destroy(buf, FALSE);
return data;
}
}
#endif
return Buf_Destroy(buf, FALSE);
}

119
buf.h Normal file
View File

@ -0,0 +1,119 @@
/* $NetBSD: buf.h,v 1.17 2012/04/24 20:26:58 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*-
* buf.h --
* Header for users of the buf library.
*/
#ifndef _BUF_H
#define _BUF_H
typedef char Byte;
typedef struct Buffer {
int size; /* Current size of the 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) 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
#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);
Byte *Buf_DestroyCompact(Buffer *);
#endif /* _BUF_H */

View File

@ -1,6 +1,39 @@
/* $NetBSD: compat.c,v 1.88 2012/06/05 17:31:04 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -36,9 +69,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: compat.c,v 1.88 2012/06/05 17:31:04 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)compat.c 8.3 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.88 2012/06/05 17:31:04 sjg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* compat.c --
@ -53,18 +95,23 @@ static char sccsid[] = "@(#)compat.c 8.3 (Berkeley) 4/28/95";
* thems as need creatin'
*/
#include <stdio.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include "wait.h"
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include "make.h"
#include "hash.h"
#include "dir.h"
#include "job.h"
extern int errno;
#include "pathnames.h"
/*
* The following array is used to make a fast determination of which
@ -75,11 +122,25 @@ extern int errno;
static char meta[256];
static GNode *curTarg = NILGNODE;
static GNode *curTarg = NULL;
static GNode *ENDNode;
static void CompatInterrupt __P((int));
static int CompatRunCommand __P((ClientData, ClientData));
static int CompatMake __P((ClientData, ClientData));
static void CompatInterrupt(int) __dead;
static void
Compat_Init(void)
{
const char *cp;
Shell_Init(); /* setup default shell */
for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
meta[(unsigned char) *cp] = 1;
}
/*
* The null character serves as a sentinel in the string.
*/
meta[0] = 1;
}
/*-
*-----------------------------------------------------------------------
@ -97,19 +158,16 @@ static int CompatMake __P((ClientData, ClientData));
*-----------------------------------------------------------------------
*/
static void
CompatInterrupt (signo)
int signo;
CompatInterrupt(int signo)
{
GNode *gn;
if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
char *p1;
char *file = Var_Value (TARGET, curTarg, &p1);
struct stat st;
if (!noExecute && lstat(file, &st) != -1 && !S_ISDIR(st.st_mode) &&
unlink(file) != -1) {
printf ("*** %s removed\n", file);
if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
char *p1;
char *file = Var_Value(TARGET, curTarg, &p1);
if (!noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
}
if (p1)
free(p1);
@ -119,13 +177,16 @@ CompatInterrupt (signo)
*/
if (signo == SIGINT) {
gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
if (gn != NILGNODE) {
Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
if (gn != NULL) {
Compat_Make(gn, gn);
}
}
}
exit (signo);
if (signo == SIGQUIT)
_exit(signo);
bmake_signal(signo, SIG_DFL);
kill(myPid, signo);
}
/*-
@ -134,6 +195,10 @@ CompatInterrupt (signo)
* Execute the next command for a target. If the command returns an
* error, the node's made field is set to ERROR and creation stops.
*
* Input:
* cmdp Command to execute
* gnp Node from which the command came
*
* Results:
* 0 if the command succeeded, 1 if an error occurred.
*
@ -142,78 +207,96 @@ CompatInterrupt (signo)
*
*-----------------------------------------------------------------------
*/
static int
CompatRunCommand (cmdp, gnp)
ClientData cmdp; /* Command to execute */
ClientData gnp; /* Node from which the command came */
int
CompatRunCommand(void *cmdp, void *gnp)
{
char *cmdStart; /* Start of expanded command */
register char *cp;
char *cp, *bp;
Boolean silent, /* Don't print command */
errCheck; /* Check errors */
union wait reason; /* Reason for child's death */
doIt; /* Execute even if -n */
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 stat; /* Status of fork */
pid_t cpid; /* Child actually found */
pid_t retstat; /* Result of wait */
LstNode cmdNode; /* Node where current command is located */
char **av; /* Argument vector for thing to exec */
const char ** volatile av; /* Argument vector for thing to exec */
char ** volatile mav;/* Copy of the argument vector for freeing */
int argc; /* Number of arguments in av or 0 if not
* dynamically allocated */
Boolean local; /* TRUE if command should be executed
* locally */
char *cmd = (char *) cmdp;
GNode *gn = (GNode *) gnp;
Boolean useShell; /* TRUE if command should be executed
* using a shell */
char * volatile cmd = (char *)cmdp;
GNode *gn = (GNode *)gnp;
/*
* Avoid clobbered variable warnings by forcing the compiler
* to ``unregister'' variables
*/
#if __GNUC__
(void) &av;
(void) &errCheck;
#endif
silent = gn->type & OP_SILENT;
errCheck = !(gn->type & OP_IGNORE);
cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
doIt = FALSE;
cmdNode = Lst_Member(gn->commands, cmd);
cmdStart = Var_Subst(NULL, cmd, gn, FALSE);
/*
* brk_string will return an argv with a NULL in av[1], thus causing
* brk_string will return an argv with a NULL in av[0], thus causing
* execvp to choke and die horribly. Besides, how can we execute a null
* command? In any case, we warn the user that the command expanded to
* nothing (is this the right thing to do?).
*/
if (*cmdStart == '\0') {
free(cmdStart);
Error("%s expands to empty string", cmd);
return(0);
} else {
cmd = cmdStart;
}
Lst_Replace (cmdNode, (ClientData)cmdStart);
cmd = cmdStart;
Lst_Replace(cmdNode, cmdStart);
if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
(void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
(void)Lst_AtEnd(ENDNode->commands, cmdStart);
return(0);
} else if (strcmp(cmdStart, "...") == 0) {
}
if (strcmp(cmdStart, "...") == 0) {
gn->type |= OP_SAVE_CMDS;
return(0);
}
while ((*cmd == '@') || (*cmd == '-')) {
if (*cmd == '@') {
silent = TRUE;
} else {
while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
switch (*cmd) {
case '@':
silent = DEBUG(LOUD) ? FALSE : TRUE;
break;
case '-':
errCheck = FALSE;
break;
case '+':
doIt = TRUE;
if (!meta[0]) /* we came here from jobs */
Compat_Init();
break;
}
cmd++;
}
while (isspace((unsigned char)*cmd))
cmd++;
/*
* If we did not end up with a command, just skip it.
*/
if (!*cmd)
return (0);
#if !defined(MAKE_NATIVE)
/*
* In a non-native build, the host environment might be weird enough
* that it's necessary to go through a shell to get the correct
* behaviour. Or perhaps the shell has been replaced with something
* that does extra logging, and that should not be bypassed.
*/
useShell = TRUE;
#else
/*
* Search for meta characters in the command. If there are no meta
* characters, there's no need to execute a shell to execute the
@ -222,13 +305,15 @@ CompatRunCommand (cmdp, gnp)
for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
continue;
}
useShell = (*cp != '\0');
#endif
/*
* Print the command before echoing if we're not supposed to be quiet for
* this one. We also print the command if -n given.
*/
if (!silent || noExecute) {
printf ("%s\n", cmd);
if (!silent || NoExecute(gn)) {
printf("%s\n", cmd);
fflush(stdout);
}
@ -236,116 +321,180 @@ CompatRunCommand (cmdp, gnp)
* If we're not supposed to execute any commands, this is as far as
* we go...
*/
if (noExecute) {
if (!doIt && NoExecute(gn)) {
return (0);
}
if (*cp != '\0') {
/*
* If *cp isn't the null character, we hit a "meta" character and
* need to pass the command off to the shell. We give the shell the
* -e flag as well as -c if it's supposed to exit when it hits an
* error.
*/
static char *shargv[4] = { "/bin/sh" };
if (DEBUG(JOB))
fprintf(debug_file, "Execute: '%s'\n", cmd);
shargv[1] = (errCheck ? "-ec" : "-c");
again:
if (useShell) {
/*
* We need to pass the command off to the shell, typically
* because the command contains a "meta" character.
*/
static const char *shargv[4];
shargv[0] = shellPath;
/*
* The following work for any of the builtin shell specs.
*/
if (DEBUG(SHELL))
shargv[1] = "-xc";
else
shargv[1] = "-c";
shargv[2] = cmd;
shargv[3] = (char *)NULL;
shargv[3] = NULL;
av = shargv;
argc = 0;
bp = NULL;
mav = NULL;
} else {
/*
* No meta-characters, so no need to exec a shell. Break the command
* into words to form an argument vector we can execute.
* brk_string sticks our name in av[0], so we have to
* skip over it...
*/
av = brk_string(cmd, &argc, TRUE);
av += 1;
mav = brk_string(cmd, &argc, TRUE, &bp);
if (mav == NULL) {
useShell = 1;
goto again;
}
av = (void *)mav;
}
local = TRUE;
#ifdef USE_META
if (useMeta) {
meta_compat_start();
}
#endif
/*
* Fork and execute the single command. If the fork fails, we abort.
*/
cpid = vfork();
cpid = vFork();
if (cpid < 0) {
Fatal("Could not fork");
}
if (cpid == 0) {
if (local) {
execvp(av[0], av);
(void) write (2, av[0], strlen (av[0]));
(void) write (2, ": not found\n", sizeof(": not found"));
} else {
(void)execv(av[0], av);
Check_Cwd(av);
Var_ExportVars();
#ifdef USE_META
if (useMeta) {
meta_compat_child();
}
exit(1);
#endif
if (local)
(void)execvp(av[0], (char *const *)UNCONST(av));
else
(void)execv(av[0], (char *const *)UNCONST(av));
execError("exec", av[0]);
_exit(1);
}
free(cmdStart);
Lst_Replace (cmdNode, (ClientData) NULL);
if (mav)
free(mav);
if (bp)
free(bp);
Lst_Replace(cmdNode, NULL);
#ifdef USE_META
if (useMeta) {
meta_compat_parent();
}
#endif
/*
* The child is off and running. Now all we can do is wait...
*/
while (1) {
while ((stat = wait((int *)&reason)) != cpid) {
if (stat == -1 && errno != EINTR) {
while ((retstat = wait(&reason)) != cpid) {
if (retstat > 0)
JobReapChild(retstat, reason, FALSE); /* not ours? */
if (retstat == -1 && errno != EINTR) {
break;
}
}
if (stat > -1) {
if (retstat > -1) {
if (WIFSTOPPED(reason)) {
status = reason.w_stopval; /* stopped */
status = WSTOPSIG(reason); /* stopped */
} else if (WIFEXITED(reason)) {
status = reason.w_retcode; /* exited */
status = WEXITSTATUS(reason); /* exited */
#if defined(USE_META) && defined(USE_FILEMON_ONCE)
if (useMeta) {
meta_cmd_finish(NULL);
}
#endif
if (status != 0) {
printf ("*** Error code %d", status);
if (DEBUG(ERROR)) {
fprintf(debug_file, "\n*** Failed target: %s\n*** Failed command: ",
gn->name);
for (cp = cmd; *cp; ) {
if (isspace((unsigned char)*cp)) {
fprintf(debug_file, " ");
while (isspace((unsigned char)*cp))
cp++;
} else {
fprintf(debug_file, "%c", *cp);
cp++;
}
}
fprintf(debug_file, "\n");
}
printf("*** Error code %d", status);
}
} else {
status = reason.w_termsig; /* signaled */
printf ("*** Signal %d", status);
}
status = WTERMSIG(reason); /* signaled */
printf("*** Signal %d", status);
}
if (!WIFEXITED(reason) || (status != 0)) {
if (errCheck) {
#ifdef USE_META
if (useMeta) {
meta_job_error(NULL, gn, 0, status);
}
#endif
gn->made = ERROR;
if (keepgoing) {
/*
* Abort the current target, but let others
* continue.
*/
printf (" (continuing)\n");
printf(" (continuing)\n");
}
} else {
/*
* Continue executing commands for this target.
* If we return 0, this will happen...
*/
printf (" (ignored)\n");
printf(" (ignored)\n");
status = 0;
}
}
break;
} else {
Fatal ("error in wait: %d", stat);
Fatal("error in wait: %d: %s", retstat, strerror(errno));
/*NOTREACHED*/
}
}
free(cmdStart);
return (status);
}
/*-
*-----------------------------------------------------------------------
* CompatMake --
* Compat_Make --
* Make a target.
*
* Input:
* gnp The node to make
* pgnp Parent to abort if necessary
*
* Results:
* 0
*
@ -354,16 +503,15 @@ CompatRunCommand (cmdp, gnp)
*
*-----------------------------------------------------------------------
*/
static int
CompatMake (gnp, pgnp)
ClientData gnp; /* The node to make */
ClientData pgnp; /* Parent to abort if necessary */
int
Compat_Make(void *gnp, void *pgnp)
{
GNode *gn = (GNode *) gnp;
GNode *pgn = (GNode *) pgnp;
if (gn->type & OP_USE) {
Make_HandleUse(gn, pgn);
} else if (gn->made == UNMADE) {
GNode *gn = (GNode *)gnp;
GNode *pgn = (GNode *)pgnp;
if (!meta[0]) /* we came here from jobs */
Compat_Init();
if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
/*
* First mark ourselves to be made, then apply whatever transformations
* the suffix module thinks are necessary. Once that's done, we can
@ -372,40 +520,41 @@ CompatMake (gnp, pgnp)
* This is our signal to not attempt to do anything but abort our
* parent as well.
*/
gn->make = TRUE;
gn->flags |= REMAKE;
gn->made = BEINGMADE;
Suff_FindDeps (gn);
Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
if (!gn->make) {
if ((gn->type & OP_MADE) == 0)
Suff_FindDeps(gn);
Lst_ForEach(gn->children, Compat_Make, gn);
if ((gn->flags & REMAKE) == 0) {
gn->made = ABORTED;
pgn->make = FALSE;
return (0);
pgn->flags &= ~REMAKE;
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);
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
if (p1)
free(p1);
}
/*
* All the children were made ok. Now cmtime contains the modification
* time of the newest child, we need to find out if we exist and when
* we were modified last. The criteria for datedness are defined by the
* Make_OODate function.
* All the children were made ok. Now cmgn->mtime contains the
* modification time of the newest child, we need to find out if we
* exist and when we were modified last. The criteria for datedness
* are defined by the Make_OODate function.
*/
if (DEBUG(MAKE)) {
printf("Examining %s...", gn->name);
fprintf(debug_file, "Examining %s...", gn->name);
}
if (! Make_OODate(gn)) {
gn->made = UPTODATE;
if (DEBUG(MAKE)) {
printf("up-to-date.\n");
fprintf(debug_file, "up-to-date.\n");
}
return (0);
goto cohorts;
} else if (DEBUG(MAKE)) {
printf("out-of-date.\n");
fprintf(debug_file, "out-of-date.\n");
}
/*
@ -413,7 +562,7 @@ CompatMake (gnp, pgnp)
* to tell him/her "yes".
*/
if (queryFlag) {
exit (-1);
exit(1);
}
/*
@ -422,33 +571,43 @@ CompatMake (gnp, pgnp)
* Make_DoAllVar().
*/
Make_DoAllVar(gn);
/*
* Alter our type to tell if errors should be ignored or things
* should not be printed so CompatRunCommand knows what to do.
*/
if (Targ_Ignore (gn)) {
if (Targ_Ignore(gn)) {
gn->type |= OP_IGNORE;
}
if (Targ_Silent (gn)) {
if (Targ_Silent(gn)) {
gn->type |= OP_SILENT;
}
if (Job_CheckCommands (gn, Fatal)) {
if (Job_CheckCommands(gn, Fatal)) {
/*
* Our commands are ok, but we still have to worry about the -t
* flag...
*/
if (!touchFlag) {
if (!touchFlag || (gn->type & OP_MAKE)) {
curTarg = gn;
Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
curTarg = NILGNODE;
#ifdef USE_META
if (useMeta && !NoExecute(gn)) {
meta_job_start(NULL, gn);
}
#endif
Lst_ForEach(gn->commands, CompatRunCommand, gn);
curTarg = NULL;
} else {
Job_Touch (gn, gn->type & OP_SILENT);
Job_Touch(gn, gn->type & OP_SILENT);
}
} else {
gn->made = ERROR;
}
#ifdef USE_META
if (useMeta && !NoExecute(gn)) {
meta_job_finish(NULL);
}
#endif
if (gn->made != ERROR) {
/*
@ -458,96 +617,39 @@ CompatMake (gnp, pgnp)
* This is to keep its state from affecting that of its parent.
*/
gn->made = MADE;
#ifndef RECHECK
/*
* We can't re-stat the thing, but we can at least take care of
* rules where a target depends on a source that actually creates
* the target, but only if it has changed, e.g.
*
* parse.h : parse.o
*
* parse.o : parse.y
* yacc -d parse.y
* cc -c y.tab.c
* mv y.tab.o parse.o
* cmp -s y.tab.h parse.h || mv y.tab.h parse.h
*
* In this case, if the definitions produced by yacc haven't
* changed from before, parse.h won't have been updated and
* gn->mtime will reflect the current modification time for
* parse.h. This is something of a kludge, I admit, but it's a
* useful one..
*
* XXX: People like to use a rule like
*
* FRC:
*
* To force things that depend on FRC to be made, so we have to
* check for gn->children being empty as well...
*/
if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
gn->mtime = now;
}
#else
/*
* This is what Make does and it's actually a good thing, as it
* allows rules like
*
* cmp -s y.tab.h parse.h || cp y.tab.h parse.h
*
* to function as intended. Unfortunately, thanks to the stateless
* nature of NFS (and the speed of this program), there are times
* when the modification time of a file created on a remote
* machine will not be modified before the stat() implied by
* the Dir_MTime occurs, thus leading us to believe that the file
* is unchanged, wreaking havoc with files that depend on this one.
*
* I have decided it is better to make too much than to make too
* little, so this stuff is commented out unless you're sure it's
* ok.
* -- ardeb 1/12/88
*/
if (noExecute || Dir_MTime(gn) == 0) {
gn->mtime = now;
}
if (gn->cmtime > gn->mtime)
gn->mtime = gn->cmtime;
if (DEBUG(MAKE)) {
printf("update time: %s\n", Targ_FmtTime(gn->mtime));
}
#endif
pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
if (!(gn->type & OP_EXEC)) {
pgn->childMade = TRUE;
pgn->flags |= CHILDMADE;
Make_TimeStamp(pgn, gn);
}
} else if (keepgoing) {
pgn->make = FALSE;
pgn->flags &= ~REMAKE;
} else {
printf ("\n\nStop.\n");
exit (1);
PrintOnError(gn, "\n\nStop.");
exit(1);
}
} else if (gn->made == ERROR) {
/*
* Already had an error when making this beastie. Tell the parent
* to abort.
*/
pgn->make = FALSE;
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);
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
if (p1)
free(p1);
}
switch(gn->made) {
case BEINGMADE:
Error("Graph cycles through %s\n", gn->name);
Error("Graph cycles through %s", gn->name);
gn->made = ERROR;
pgn->make = FALSE;
pgn->flags &= ~REMAKE;
break;
case MADE:
if ((gn->type & OP_EXEC) == 0) {
pgn->childMade = TRUE;
pgn->flags |= CHILDMADE;
Make_TimeStamp(pgn, gn);
}
break;
@ -561,14 +663,19 @@ CompatMake (gnp, pgnp)
}
}
cohorts:
Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
return (0);
}
/*-
*-----------------------------------------------------------------------
* Compat_Run --
* Initialize this mode and start making.
*
* Input:
* targs List of target nodes to re-create
*
* Results:
* None.
*
@ -578,49 +685,52 @@ CompatMake (gnp, pgnp)
*-----------------------------------------------------------------------
*/
void
Compat_Run(targs)
Lst targs; /* List of target nodes to re-create */
Compat_Run(Lst targs)
{
char *cp; /* Pointer to string of shell meta-characters */
GNode *gn = NULL;/* Current root target */
int errors; /* Number of targets not remade due to errors */
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
signal(SIGINT, CompatInterrupt);
}
if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
signal(SIGTERM, CompatInterrupt);
}
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
signal(SIGHUP, CompatInterrupt);
}
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
signal(SIGQUIT, CompatInterrupt);
}
Compat_Init();
for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
meta[(unsigned char) *cp] = 1;
if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGINT, CompatInterrupt);
}
if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGTERM, CompatInterrupt);
}
if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGHUP, CompatInterrupt);
}
if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
bmake_signal(SIGQUIT, CompatInterrupt);
}
/*
* The null character serves as a sentinel in the string.
*/
meta[0] = 1;
ENDNode = Targ_FindNode(".END", TARG_CREATE);
ENDNode->type = OP_SPECIAL;
/*
* If the user has defined a .BEGIN target, execute the commands attached
* to it.
*/
if (!queryFlag) {
gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
if (gn != NILGNODE) {
Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
if (gn != NULL) {
Compat_Make(gn, gn);
if (gn->made == ERROR) {
PrintOnError(gn, "\n\nStop.");
exit(1);
}
}
}
/*
* For each entry in the list of targets to create, call CompatMake on
* it to create the thing. CompatMake will leave the 'made' field of gn
* Expand .USE nodes right now, because they can modify the structure
* of the tree.
*/
Make_ExpandUse(targs);
/*
* For each entry in the list of targets to create, call Compat_Make on
* it to create the thing. Compat_Make will leave the 'made' field of gn
* in one of several states:
* UPTODATE gn was already up-to-date
* MADE gn was recreated successfully
@ -630,13 +740,13 @@ Compat_Run(targs)
*/
errors = 0;
while (!Lst_IsEmpty (targs)) {
gn = (GNode *) Lst_DeQueue (targs);
CompatMake (gn, gn);
gn = (GNode *)Lst_DeQueue(targs);
Compat_Make(gn, gn);
if (gn->made == UPTODATE) {
printf ("`%s' is up to date.\n", gn->name);
printf("`%s' is up to date.\n", gn->name);
} else if (gn->made == ABORTED) {
printf ("`%s' not remade because of errors.\n", gn->name);
printf("`%s' not remade because of errors.\n", gn->name);
errors += 1;
}
}
@ -645,6 +755,10 @@ Compat_Run(targs)
* If the user has defined a .END target, run its commands.
*/
if (errors == 0) {
Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
Compat_Make(ENDNode, ENDNode);
if (gn->made == ERROR) {
PrintOnError(gn, "\n\nStop.");
exit(1);
}
}
}

1410
cond.c Normal file

File diff suppressed because it is too large Load Diff

314
config.h.in Normal file
View File

@ -0,0 +1,314 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* Path of default shell */
#undef DEFSHELL_CUSTOM
/* Shell spec to use by default */
#undef DEFSHELL_INDEX
/* Define to 1 if you have the <ar.h> header file. */
#undef HAVE_AR_H
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
don't. */
#undef HAVE_DECL_SYS_SIGLIST
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the `dirname' function. */
#undef HAVE_DIRNAME
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
/* Define to 1 if you have the `err' function. */
#undef HAVE_ERR
/* Define to 1 if you have the `errx' function. */
#undef HAVE_ERRX
/* Define to 1 if you have the <err.h> header file. */
#undef HAVE_ERR_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
/* Define to 1 if you have the `getcwd' function. */
#undef HAVE_GETCWD
/* Define to 1 if you have the `getenv' function. */
#undef HAVE_GETENV
/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT
/* Define to 1 if you have the `getwd' function. */
#undef HAVE_GETWD
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `killpg' function. */
#undef HAVE_KILLPG
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the <paths.h> header file. */
#undef HAVE_PATHS_H
/* Define to 1 if you have the <poll.h> header file. */
#undef HAVE_POLL_H
/* Define to 1 if you have the `putenv' function. */
#undef HAVE_PUTENV
/* Define to 1 if you have the <ranlib.h> header file. */
#undef HAVE_RANLIB_H
/* Define to 1 if you have the `realpath' function. */
#undef HAVE_REALPATH
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `setenv' function. */
#undef HAVE_SETENV
/* Define to 1 if you have the `setpgid' function. */
#undef HAVE_SETPGID
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `sigvec' function. */
#undef HAVE_SIGVEC
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the `stresep' function. */
#undef HAVE_STRESEP
/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP
/* Define to 1 if you have the `strtod' function. */
#undef HAVE_STRTOD
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL
/* Define to 1 if `struct stat' is a member of `st_rdev'. */
#undef HAVE_STRUCT_STAT_ST_RDEV
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
#undef HAVE_ST_RDEV
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/uio.h> header file. */
#undef HAVE_SYS_UIO_H
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H
/* Define to 1 if you have the `vprintf' function. */
#undef HAVE_VPRINTF
/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
/* Define to 1 if you have the `wait3' function. */
#undef HAVE_WAIT3
/* Define to 1 if you have the `wait4' function. */
#undef HAVE_WAIT4
/* Define to 1 if you have the `waitpid' function. */
#undef HAVE_WAITPID
/* Define to 1 if you have the `warn' function. */
#undef HAVE_WARN
/* Define to 1 if you have the `warnx' function. */
#undef HAVE_WARNX
/* Define to 1 if `fork' works. */
#undef HAVE_WORKING_FORK
/* Define to 1 if `vfork' works. */
#undef HAVE_WORKING_VFORK
/* define if your compiler has __attribute__ */
#undef HAVE___ATTRIBUTE__
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
#undef TM_IN_SYS_TIME
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
# undef WORDS_BIGENDIAN
# endif
#endif
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define as `fork' if `vfork' does not work. */
#undef vfork

7134
configure vendored Executable file

File diff suppressed because it is too large Load Diff

370
configure.in Normal file
View File

@ -0,0 +1,370 @@
dnl
dnl RCSid:
dnl $Id: configure.in,v 1.44 2012/06/06 17:48:14 sjg Exp $
dnl
dnl Process this file with autoconf to produce a configure script
dnl
AC_INIT([bmake], [20120606], [sjg@NetBSD.org])
AC_CONFIG_HEADER(config.h)
dnl
AC_ARG_WITH(defshell,
[ --with-defshell=SHELL use SHELL by default - must be sh compatible, use sh or ksh to pick the internal definitions],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake DEFSHELL) ;;
no) ;;
*) case "$with_defshell" in
sh) DEFSHELL_INDEX=DEFSHELL_INDEX_SH;; # it's the default anyway
ksh) DEFSHELL_INDEX=DEFSHELL_INDEX_KSH;;
csh) DEFSHELL_INDEX=DEFSHELL_INDEX_CSH;; # kidding right?
*) defshell_path=$with_defshell;; # better be sh compatible!
esac
;;
esac])
dnl
use_meta=yes
AC_ARG_WITH(meta,
[ --without-meta dissable use of meta-mode],
[case "${withval}" in
yes|no) use_meta=${withval};;
*) AC_MSG_ERROR(bad value ${withval} given for meta) ;;
esac])
dnl
AC_ARG_WITH(filemon,
[ --with-filemon=path/filemon.h indicate path to filemon.h for meta-mode],
[ case "/${withval}" in
/no|*/filemon.h) filemon_h="${withval}";;
*/filemon*) filemon_h="${withval}/filemon.h";;
*) AC_MSG_ERROR(bad value ${withval} given for filemon) ;;
esac],
[
OS=`uname -s`
for d in "$srcdir/filemon" "$srcdir/../filemon" "$srcdir/../../sys/dev/filemon"
do
for x in "/$OS" ""
do
filemon_h="$d$x/filemon.h"
test -s "$filemon_h" && break
done
test -s "$filemon_h" && break
done
test -s "${filemon_h:-/dev/null}" || filemon_h=no
])
dnl echo "Note: use_meta=$use_meta filemon_h=$filemon_h" >&6
case "$use_meta" in
yes)
case "$filemon_h" in
*.h) echo "Using: filemon=$filemon_h" >&6;;
esac
;;
esac
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
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
dnl Executable suffix - normally empty; .exe on os2.
AC_SUBST(ac_exe_suffix)dnl
dnl
dnl Check if /bin/sh will pass .MAKE.LEVEL
echo $ECHO_N "checking if sh will pass .MAKE. variables... $ECHO_C" >&6
ok=`env .MAKE.LEVEL=1 /bin/sh -c env | grep LEVEL=`
case "$ok" in
"") echo no >&6; CPPFLAGS="${CPPFLAGS} -DNEED_MAKE_LEVEL_SAFE";;
*) echo yes >&6;;
esac
dnl
dnl AC_C_CROSS
dnl
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
dnl Keep this list sorted
AC_CHECK_HEADERS( \
ar.h \
err.h \
fcntl.h \
paths.h \
poll.h \
ranlib.h \
string.h \
sys/mman.h \
sys/select.h \
sys/socket.h \
sys/time.h \
sys/uio.h \
unistd.h \
utime.h \
)
dnl Both *BSD and Linux have sys/cdefs.h, most do not.
dnl If it is missing, we add -I${srcdir}/missing to CFLAGS
dnl also if sys/cdefs.h does not have __RCSID we need to use ours
dnl but we need to include the host's one too *sigh*
AC_CHECK_HEADER(sys/cdefs.h,
echo $ECHO_N "checking whether sys/cdefs.h is compatible... $ECHO_C" >&6
AC_EGREP_CPP(yes,
[#include <sys/cdefs.h>
#ifdef __RCSID
yes
#endif
],
echo yes >&6,
echo no >&6; CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd` -DNEED_HOST_CDEFS_H"),
CPPFLAGS="${CPPFLAGS} -I`cd ${srcdir}/missing && pwd`")
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C___ATTRIBUTE__
AC_C_BIGENDIAN
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_DECL_SYS_SIGLIST
AC_HEADER_TIME
AC_STRUCT_TM
dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
dnl Keep this list sorted
AC_CHECK_FUNCS( \
err \
errx \
getcwd \
getenv \
getopt \
getwd \
killpg \
mmap \
putenv \
select \
setenv \
setpgid \
setsid \
sigaction \
sigvec \
snprintf \
strerror \
strftime \
strsep \
strtod \
strtol \
unsetenv \
vsnprintf \
wait3 \
wait4 \
waitpid \
warn \
warnx \
)
dnl functions which we may need to provide
AC_REPLACE_FUNCS( \
realpath \
dirname \
stresep \
strlcpy \
)
AC_CHECK_LIB([util], [emalloc],
[ AC_CHECK_LIB([util], [erealloc],
[ AC_CHECK_LIB([util], [estrdup],
[ AC_CHECK_LIB([util], [estrndup],
[ LIBS="$LIBS -lutil"
CPPFLAGS="$CPPFLAGS -DUSE_EMALLOC" ])])])])
dnl
dnl Structures
dnl
AC_HEADER_STAT
AC_STRUCT_ST_RDEV
dnl
dnl we want this for unit-tests/Makefile
echo $ECHO_N "checking if diff -u works... $ECHO_C" >&6
if diff -u /dev/null /dev/null > /dev/null 2>&1; then
diff_u=-u
echo yes >&6
else
diff_u=
echo no >&6
fi
dnl
dnl AC_* don't quite cut it.
dnl
echo "checking for MACHINE & MACHINE_ARCH..." >&6
cat > conftest.$ac_ext <<EOF
#include "confdefs.h"
#include <sys/param.h>
#ifdef MACHINE
machine=MACHINE
#endif
#ifdef MACHINE_ARCH
machine_arch=MACHINE_ARCH
#endif
EOF
default_machine=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 |
egrep machine= | tr -d ' "'`
rm -rf conftest*
if test "$default_machine"; then
eval "$default_machine"
fi
machine=${machine:-`$srcdir/machine.sh`}
machine_arch=${machine_arch:-`$srcdir/machine.sh arch`}
echo "defaults: MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl now allow overrides
dnl
AC_ARG_WITH(machine,
[ --with-machine=MACHINE explicitly set MACHINE],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE) ;;
no) ;;
generic) machine=`$srcdir/machine.sh`;;
*) machine=$with_machine;;
esac])
force_machine=
AC_ARG_WITH(force_machine,
[ --with-force-machine=MACHINE set FORCE_MACHINE],
[case "${withval}" in
yes) force_machine=FORCE_;;
no) ;;
*) force_machine=FORCE_; machine=$with_force_machine;;
esac])
dnl
force_machine_arch=
AC_ARG_WITH(force_machine_arch,
[ --with-force-machine-arch=MACHINE set FORCE_MACHINE_ARCH],
[case "${withval}" in
yes) force_machine_arch=FORCE_;;
no) ;;
*) force_machine_arch=FORCE_; machine_arch=$with_force_machine;;
esac])
dnl
AC_ARG_WITH(machine_arch,
[ --with-machine_arch=MACHINE_ARCH explicitly set MACHINE_ARCH],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake MACHINE_ARCH) ;;
no) ;;
*) machine_arch=$with_machine_arch;;
esac])
dnl
dnl Tell them what we ended up with
dnl
echo "Using: ${force_machine}MACHINE=$machine, MACHINE_ARCH=$machine_arch" 1>&6
dnl
dnl Allow folk to control _PATH_DEFSYSPATH
dnl
default_sys_path=\${prefix}/share/mk
AC_ARG_WITH(default-sys-path,
[ --with-default-sys-path=PATH:DIR:LIST use an explicit _PATH_DEFSYSPATH
MAKESYSPATH is a ':' separated list of directories
that bmake will search for system .mk files.
_PATH_DEFSYSPATH is its default value.],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_DEFSYSPATH) ;;
no) ;;
*) default_sys_path="$with_default_sys_path"
;;
esac])
dnl
dnl Some folk don't like this one
dnl
AC_ARG_WITH(path-objdirprefix,
[ --with-path-objdirprefix=PATH override _PATH_OBJDIRPREFIX],
[case "${withval}" in
yes) AC_MSG_ERROR(bad value ${withval} given for bmake _PATH_OBJDIRPREFIX) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_PATH_OBJDIRPREFIX" ;;
*) CPPFLAGS="$CPPFLAGS \"-D_PATH_OBJDIRPREFIX=\\\"$with_path-objdir\\\"\"" ;;
esac])
dnl
dnl And this can be handy to do with out.
dnl
AC_ARG_ENABLE(pwd-override,
[ --disable-pwd-override disable \$PWD overriding getcwd()],
[case "${enableval}" in
yes) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_PWD_OVERRIDE" ;;
*) AC_MSG_ERROR(bad value ${enableval} given for pwd-override option) ;;
esac])
dnl
dnl Just for grins
dnl
AC_ARG_ENABLE(check-make-chdir,
[ --disable-check-make-chdir disable make trying to guess
when it should automatically cd \${.CURDIR}],
[case "${enableval}" in
yes) ;;
no) CPPFLAGS="$CPPFLAGS -DNO_CHECK_MAKE_CHDIR" ;;
*) AC_MSG_ERROR(bad value ${enableval} given for check-make-chdir option) ;;
esac])
dnl
dnl On non-BSD systems, bootstrap won't work without mk
dnl
AC_ARG_WITH(mksrc,
[ --with-mksrc=PATH tell makefile.boot where to find mk src],
[case "${withval}" in
""|yes|no) ;;
*) test -s $withval/install-mk && mksrc=$withval ||
AC_MSG_ERROR(bad value ${withval} given for mksrc cannot find install-mk)
;;
esac
])
dnl
dnl Now make sure we have a value
dnl
srcdir=`cd $srcdir && pwd`
for mksrc in $mksrc $srcdir/mk $srcdir/../mk mk
do
test -s $mksrc/install-mk || continue
mksrc=`cd $mksrc && pwd`
break
done
mksrc=`echo $mksrc | sed "s,$srcdir,\\\${srcdir},"`
echo "Using: MKSRC=$mksrc" 1>&6
dnl On some systems we want a different default shell by default
if test -x /usr/xpg4/bin/sh; then
defshell_path=${defshell_path:-/usr/xpg4/bin/sh}
fi
if test -n "$defshell_path"; then
echo "Using: SHELL=$defshell_path" >&6
AC_DEFINE_UNQUOTED(DEFSHELL_CUSTOM, "$defshell_path", Path of default shell)
fi
if test -n "$DEFSHELL_INDEX"; then
AC_DEFINE_UNQUOTED(DEFSHELL_INDEX, $DEFSHELL_INDEX, Shell spec to use by default)
fi
dnl
AC_SUBST(machine)
AC_SUBST(force_machine)
AC_SUBST(machine_arch)
AC_SUBST(mksrc)
AC_SUBST(default_sys_path)
AC_SUBST(INSTALL)
AC_SUBST(GCC)
AC_SUBST(diff_u)
AC_SUBST(use_meta)
AC_SUBST(filemon_h)
AC_OUTPUT(Makefile make-bootstrap.sh unit-tests/Makefile)
cat <<EOF
You can now run
sh ./make-bootstrap.sh
to produce a fully functional bmake.
EOF

File diff suppressed because it is too large Load Diff

108
dir.h Normal file
View File

@ -0,0 +1,108 @@
/* $NetBSD: dir.h,v 1.15 2012/04/07 18:29:08 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)dir.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)dir.h 8.1 (Berkeley) 6/6/93
*/
/* dir.h --
*/
#ifndef _DIR
#define _DIR
typedef struct Path {
char *name; /* Name of directory */
int refCount; /* Number of paths with this directory */
int hits; /* the number of times a file in this
* directory has been found */
Hash_Table files; /* Hash table of files in directory */
} Path;
void Dir_Init(const char *);
void Dir_InitCur(const char *);
void Dir_InitDot(void);
void Dir_End(void);
void Dir_SetPATH(void);
Boolean Dir_HasWildcards(char *);
void Dir_Expand(const char *, Lst, Lst);
char *Dir_FindFile(const char *, Lst);
int Dir_FindHereOrAbove(char *, char *, char *, int);
int Dir_MTime(GNode *, Boolean);
Path *Dir_AddDir(Lst, const char *);
char *Dir_MakeFlags(const char *, Lst);
void Dir_ClearPath(Lst);
void Dir_Concat(Lst, Lst);
void Dir_PrintDirectories(void);
void Dir_PrintPath(Lst);
void Dir_Destroy(void *);
void * Dir_CopyDir(void *);
#endif /* _DIR */

95
dirname.c Normal file
View File

@ -0,0 +1,95 @@
/* $NetBSD: dirname.c,v 1.11 2009/11/24 13:34:20 tnozaki Exp $ */
/*-
* Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Klaus Klein and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef HAVE_DIRNAME
#include <sys/cdefs.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif
char *
dirname(char *path)
{
static char result[PATH_MAX];
const char *lastp;
size_t len;
/*
* If `path' is a null pointer or points to an empty string,
* return a pointer to the string ".".
*/
if ((path == NULL) || (*path == '\0'))
goto singledot;
/* Strip trailing slashes, if any. */
lastp = path + strlen(path) - 1;
while (lastp != path && *lastp == '/')
lastp--;
/* Terminate path at the last occurence of '/'. */
do {
if (*lastp == '/') {
/* Strip trailing slashes, if any. */
while (lastp != path && *lastp == '/')
lastp--;
/* ...and copy the result into the result buffer. */
len = (lastp - path) + 1 /* last char */;
if (len > (PATH_MAX - 1))
len = PATH_MAX - 1;
memcpy(result, path, len);
result[len] = '\0';
return (result);
}
} while (--lastp >= path);
/* No /'s found, return a pointer to the string ".". */
singledot:
result[0] = '.';
result[1] = '\0';
return (result);
}
#endif

13
find_lib.sh Executable file
View File

@ -0,0 +1,13 @@
:
re=$1; shift
for lib in $*
do
found=`nm $lib | egrep "$re"`
case "$found" in
"") ;;
*) echo "$lib: $found";;
esac
done

496
for.c Normal file
View File

@ -0,0 +1,496 @@
/* $NetBSD: for.c,v 1.49 2012/06/03 04:29:40 sjg Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: for.c,v 1.49 2012/06/03 04:29:40 sjg 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.49 2012/06/03 04:29:40 sjg Exp $");
#endif
#endif /* not lint */
#endif
/*-
* for.c --
* Functions to handle loops in a makefile.
*
* Interface:
* For_Eval Evaluate the loop in the passed line.
* For_Run Run accumulated loop
*
*/
#include <assert.h>
#include <ctype.h>
#include "make.h"
#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:
*
* .for <variable> in <varlist>
* ...
* .endfor
*
* The trick is to look for the matching end inside for for loop
* To do that, we count the current nesting level of the for loops.
* and the .endfor statements, accumulating all the statements between
* the initial .for loop and the matching .endfor;
* then we evaluate the for loop for each variable in the varlist.
*
* Note that any nested fors are just passed through; they get handled
* recursively in For_Eval when we're expanding the enclosing for in
* For_Run.
*/
static int forLevel = 0; /* Nesting level */
/*
* State of a for loop.
*/
typedef struct _For {
Buffer buf; /* Body of loop */
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 char *
make_str(const char *ptr, int len)
{
char *new_ptr;
new_ptr = bmake_malloc(len + 1);
memcpy(new_ptr, ptr, len);
new_ptr[len] = 0;
return new_ptr;
}
static void
For_Free(For *arg)
{
Buf_Destroy(&arg->buf, TRUE);
strlist_clean(&arg->vars);
strlist_clean(&arg->items);
free(arg->parse_buf);
free(arg);
}
/*-
*-----------------------------------------------------------------------
* For_Eval --
* Evaluate the for loop in the passed line. The line
* looks like this:
* .for <variable> in <varlist>
*
* Input:
* line Line to parse
*
* Results:
* 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.
*
*-----------------------------------------------------------------------
*/
int
For_Eval(char *line)
{
For *new_for;
char *ptr = line, *sub;
int len;
int escapes;
unsigned char ch;
char **words, *word_buf;
int n, nwords;
/* 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;
/*
* we found a for loop, and now we are going to parse it.
*/
new_for = bmake_malloc(sizeof *new_for);
memset(new_for, 0, sizeof *new_for);
/* Grab the variables. Terminate on "in". */
for (;; ptr += len) {
while (*ptr && isspace((unsigned char) *ptr))
ptr++;
if (*ptr == '\0') {
Parse_Error(PARSE_FATAL, "missing `in' in for");
For_Free(new_for);
return -1;
}
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);
}
if (strlist_num(&new_for->vars) == 0) {
Parse_Error(PARSE_FATAL, "no iteration variables in for");
For_Free(new_for);
return -1;
}
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);
/*
* Split into words allowing for quoted strings.
*/
words = brk_string(sub, &nwords, FALSE, &word_buf);
free(sub);
if (words != NULL) {
for (n = 0; n < nwords; n++) {
ptr = words[n];
if (!*ptr)
continue;
escapes = 0;
while ((ch = *ptr++)) {
switch(ch) {
case ':':
case '$':
case '\\':
escapes |= FOR_SUB_ESCAPE_CHAR;
break;
case ')':
escapes |= FOR_SUB_ESCAPE_PAREN;
break;
case /*{*/ '}':
escapes |= FOR_SUB_ESCAPE_BRACE;
break;
}
}
/*
* We have to dup words[n] to maintain the semantics of
* strlist.
*/
strlist_add_str(&new_for->items, bmake_strdup(words[n]), escapes);
}
free(words);
free(word_buf);
if ((len = strlist_num(&new_for->items)) > 0 &&
len % (n = strlist_num(&new_for->vars))) {
Parse_Error(PARSE_FATAL,
"Wrong number of words (%d) in .for substitution list"
" with %d vars", len, n);
/*
* Return 'success' so that the body of the .for loop is
* accumulated.
* Remove all items so that the loop doesn't iterate.
*/
strlist_clean(&new_for->items);
}
}
Buf_Init(&new_for->buf, 0);
accumFor = new_for;
forLevel = 1;
return 1;
}
/*
* Add another line to a .for loop.
* Returns 0 when the matching .endfor is reached.
*/
int
For_Accum(char *line)
{
char *ptr = line;
if (*ptr == '.') {
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
if (strncmp(ptr, "endfor", 6) == 0 &&
(isspace((unsigned char) ptr[6]) || !ptr[6])) {
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: end for %d\n", forLevel);
if (--forLevel <= 0)
return 0;
} else if (strncmp(ptr, "for", 3) == 0 &&
isspace((unsigned char) ptr[3])) {
forLevel++;
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: new loop %d\n", forLevel);
}
}
Buf_AddBytes(&accumFor->buf, strlen(line), line);
Buf_AddByte(&accumFor->buf, '\n');
return 1;
}
/*-
*-----------------------------------------------------------------------
* For_Run --
* Run the for loop, imitating the actions of an include file
*
* Results:
* None.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
static int
for_var_len(const char *var)
{
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;
depth = 1;
for (len = 1; (ch = var[len++]) != 0;) {
if (ch == var_start)
depth++;
else if (ch == var_end && --depth == 0)
return len;
}
/* 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;
}
/* 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, size_t *ret_len)
{
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;
}
continue;
}
if (ch == 0)
break;
/* Probably a single character name, ignore $$ and stupid ones. {*/
if (!arg->short_var || strchr("}):$", ch) != NULL) {
cp++;
continue;
}
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;
}
}
Buf_AddBytes(&cmds, body_end - cmd_cp, cmd_cp);
cp = Buf_Destroy(&cmds, FALSE);
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: loop body:\n%s", cp);
arg->sub_next += strlist_num(&arg->vars);
arg->parse_buf = cp;
*ret_len = strlen(cp);
return cp;
}
void
For_Run(int lineno)
{
For *arg;
arg = accumFor;
accumFor = NULL;
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);
}

179
getopt.c Normal file
View File

@ -0,0 +1,179 @@
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if !defined(HAVE_GETOPT) || defined(WANT_GETOPT_LONG) || defined(BROKEN_GETOPT)
#if defined(LIBC_SCCS) && !defined(lint)
/* static char sccsid[] = "from: @(#)getopt.c 8.2 (Berkeley) 4/2/94"; */
static char *rcsid = "$Id: getopt.c,v 1.3 1999/01/08 02:14:18 sjg Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt = BADCH, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
/*
* getopt --
* Parse argc/argv argument vector.
*/
int
getopt(nargc, nargv, ostr)
int nargc;
char * const *nargv;
const char *ostr;
{
extern char *__progname;
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
#ifndef BSD4_4
if (!__progname) {
if (__progname = strrchr(nargv[0], '/'))
++__progname;
else
__progname = nargv[0];
}
#endif
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-' /* found "--" */
&& !place[1]) { /* and not "--foo" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
!(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int)'-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void)fprintf(stderr,
"%s: illegal option -- %c\n", __progname, optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, optopt);
return (BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}
#endif
#ifdef MAIN
#ifndef BSD4_4
char *__progname;
#endif
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
char *opts = argv[1];
--argc;
++argv;
while ((c = getopt(argc, argv, opts)) != EOF) {
switch (c) {
case '-':
if (optarg)
printf("--%s ", optarg);
break;
case '?':
exit(1);
break;
default:
if (optarg)
printf("-%c %s ", c, optarg);
else
printf("-%c ", c);
break;
}
}
if (optind < argc) {
printf("-- ");
for (; optind < argc; ++optind) {
printf("%s ", argv[optind]);
}
}
printf("\n");
exit(0);
}
#endif

View File

@ -1,6 +1,39 @@
/* $NetBSD: hash.c,v 1.19 2009/01/24 10:59:09 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -36,9 +69,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: hash.c,v 1.19 2009/01/24 10:59:09 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)hash.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: hash.c,v 1.19 2009/01/24 10:59:09 dsl Exp $");
#endif
#endif /* not lint */
#endif
/* hash.c --
*
@ -56,23 +98,30 @@ static char sccsid[] = "@(#)hash.c 8.2 (Berkeley) 4/28/95";
* defined:
*/
static void RebuildTable __P((Hash_Table *));
static void RebuildTable(Hash_Table *);
/*
/*
* The following defines the ratio of # entries to # buckets
* at which we rebuild the table to make it larger.
*/
#define rebuildLimit 8
#define rebuildLimit 3
/*
*---------------------------------------------------------
*
*
* Hash_InitTable --
*
* This routine just sets up the hash table.
*
* Results:
* Input:
* t Structure to to hold table.
* numBuckets How many buckets to create for starters. This
* number is rounded up to a power of two. If
* <= 0, a reasonable default is chosen. The
* table will grow in size later as needed.
*
* Results:
* None.
*
* Side Effects:
@ -82,19 +131,13 @@ static void RebuildTable __P((Hash_Table *));
*/
void
Hash_InitTable(t, numBuckets)
register Hash_Table *t; /* Structure to use to hold table. */
int numBuckets; /* How many buckets to create for starters.
* This number is rounded up to a power of
* two. If <= 0, a reasonable default is
* chosen. The table will grow in size later
* as needed. */
Hash_InitTable(Hash_Table *t, int numBuckets)
{
register int i;
register struct Hash_Entry **hp;
int i;
struct Hash_Entry **hp;
/*
* Round up the size to a power of two.
* Round up the size to a power of two.
*/
if (numBuckets <= 0)
i = 16;
@ -105,7 +148,7 @@ Hash_InitTable(t, numBuckets)
t->numEntries = 0;
t->size = i;
t->mask = i - 1;
t->bucketPtr = hp = (struct Hash_Entry **)emalloc(sizeof(*hp) * i);
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
}
@ -119,7 +162,7 @@ Hash_InitTable(t, numBuckets)
* and frees up the memory space it occupied (except for
* the space in the Hash_Table structure).
*
* Results:
* Results:
* None.
*
* Side Effects:
@ -129,23 +172,22 @@ Hash_InitTable(t, numBuckets)
*/
void
Hash_DeleteTable(t)
Hash_Table *t;
Hash_DeleteTable(Hash_Table *t)
{
register struct Hash_Entry **hp, *h, *nexth = NULL;
register int i;
struct Hash_Entry **hp, *h, *nexth = NULL;
int i;
for (hp = t->bucketPtr, i = t->size; --i >= 0;) {
for (h = *hp++; h != NULL; h = nexth) {
nexth = h->next;
free((char *)h);
free(h);
}
}
free((char *)t->bucketPtr);
free(t->bucketPtr);
/*
* Set up the hash table to cause memory faults on any future access
* attempts until re-initialization.
* attempts until re-initialization.
*/
t->bucketPtr = NULL;
}
@ -157,6 +199,10 @@ Hash_DeleteTable(t)
*
* Searches a hash table for an entry corresponding to key.
*
* Input:
* t Hash table to search.
* key A hash key.
*
* Results:
* The return value is a pointer to the entry for key,
* if key was present in the table. If key was not
@ -169,13 +215,11 @@ Hash_DeleteTable(t)
*/
Hash_Entry *
Hash_FindEntry(t, key)
Hash_Table *t; /* Hash table to search. */
char *key; /* A hash key. */
Hash_FindEntry(Hash_Table *t, const char *key)
{
register Hash_Entry *e;
register unsigned h;
register char *p;
Hash_Entry *e;
unsigned h;
const char *p;
for (h = 0, p = key; *p;)
h = (h << 5) - h + *p++;
@ -183,7 +227,7 @@ Hash_FindEntry(t, 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;
}
/*
@ -194,6 +238,12 @@ Hash_FindEntry(t, key)
* Searches a hash table for an entry corresponding to
* key. If no entry is found, then one is created.
*
* Input:
* t Hash table to search.
* key A hash key.
* newPtr Filled in with TRUE if new entry created,
* FALSE otherwise.
*
* Results:
* The return value is a pointer to the entry. If *newPtr
* isn't NULL, then *newPtr is filled in with TRUE if a
@ -206,15 +256,11 @@ Hash_FindEntry(t, key)
*/
Hash_Entry *
Hash_CreateEntry(t, key, newPtr)
register Hash_Table *t; /* Hash table to search. */
char *key; /* A hash key. */
Boolean *newPtr; /* Filled in with TRUE if new entry created,
* FALSE otherwise. */
Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr)
{
register Hash_Entry *e;
register unsigned h;
register char *p;
Hash_Entry *e;
unsigned h;
const char *p;
int keylen;
struct Hash_Entry **hp;
@ -237,17 +283,17 @@ Hash_CreateEntry(t, key, newPtr)
/*
* The desired entry isn't there. Before allocating a new entry,
* expand the table if necessary (and this changes the resulting
* bucket chain).
* bucket chain).
*/
if (t->numEntries >= rebuildLimit * t->size)
RebuildTable(t);
e = (Hash_Entry *) emalloc(sizeof(*e) + keylen);
e = bmake_malloc(sizeof(*e) + keylen);
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);
(void)strcpy(e->name, p);
t->numEntries++;
if (newPtr != NULL)
@ -273,11 +319,9 @@ Hash_CreateEntry(t, key, newPtr)
*/
void
Hash_DeleteEntry(t, e)
Hash_Table *t;
Hash_Entry *e;
Hash_DeleteEntry(Hash_Table *t, Hash_Entry *e)
{
register Hash_Entry **hp, *p;
Hash_Entry **hp, *p;
if (e == NULL)
return;
@ -285,12 +329,12 @@ Hash_DeleteEntry(t, e)
(p = *hp) != NULL; hp = &p->next) {
if (p == e) {
*hp = p->next;
free((char *)p);
free(p);
t->numEntries--;
return;
}
}
(void) write(2, "bad call to Hash_DeleteEntry\n", 29);
(void)write(2, "bad call to Hash_DeleteEntry\n", 29);
abort();
}
@ -301,7 +345,11 @@ Hash_DeleteEntry(t, e)
* This procedure sets things up for a complete search
* of all entries recorded in the hash table.
*
* Results:
* Input:
* t Table to be searched.
* searchPtr Area in which to keep state about search.
*
* Results:
* The return value is the address of the first entry in
* the hash table, or NULL if the table is empty.
*
@ -314,10 +362,7 @@ Hash_DeleteEntry(t, e)
*/
Hash_Entry *
Hash_EnumFirst(t, searchPtr)
Hash_Table *t; /* Table to be searched. */
register Hash_Search *searchPtr;/* Area in which to keep state
* about search.*/
Hash_EnumFirst(Hash_Table *t, Hash_Search *searchPtr)
{
searchPtr->tablePtr = t;
searchPtr->nextIndex = 0;
@ -331,6 +376,9 @@ Hash_EnumFirst(t, searchPtr)
* Hash_EnumNext --
* This procedure returns successive entries in the hash table.
*
* Input:
* searchPtr Area used to keep state about search.
*
* Results:
* The return value is a pointer to the next HashEntry
* in the table, or NULL when the end of the table is
@ -344,11 +392,9 @@ Hash_EnumFirst(t, searchPtr)
*/
Hash_Entry *
Hash_EnumNext(searchPtr)
register Hash_Search *searchPtr; /* Area used to keep state about
search. */
Hash_EnumNext(Hash_Search *searchPtr)
{
register Hash_Entry *e;
Hash_Entry *e;
Hash_Table *t = searchPtr->tablePtr;
/*
@ -365,7 +411,7 @@ Hash_EnumNext(searchPtr)
*/
while (e == NULL) {
if (searchPtr->nextIndex >= t->size)
return (NULL);
return NULL;
e = t->bucketPtr[searchPtr->nextIndex++];
}
searchPtr->hashEntryPtr = e;
@ -379,7 +425,7 @@ Hash_EnumNext(searchPtr)
* This local routine makes a new hash table that
* is larger than the old one.
*
* Results:
* Results:
* None.
*
* Side Effects:
@ -390,12 +436,11 @@ Hash_EnumNext(searchPtr)
*/
static void
RebuildTable(t)
register Hash_Table *t;
RebuildTable(Hash_Table *t)
{
register Hash_Entry *e, *next = NULL, **hp, **xp;
register int i, mask;
register Hash_Entry **oldhp;
Hash_Entry *e, *next = NULL, **hp, **xp;
int i, mask;
Hash_Entry **oldhp;
int oldsize;
oldhp = t->bucketPtr;
@ -403,7 +448,7 @@ RebuildTable(t)
i <<= 1;
t->size = i;
t->mask = mask = i - 1;
t->bucketPtr = hp = (struct Hash_Entry **) emalloc(sizeof(*hp) * i);
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
for (hp = oldhp, i = oldsize; --i >= 0;) {
@ -414,5 +459,5 @@ RebuildTable(t)
*xp = e;
}
}
free((char *)oldhp);
free(oldhp);
}

View File

@ -1,6 +1,40 @@
/* $NetBSD: hash.h,v 1.10 2009/01/24 10:59:09 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)hash.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -35,7 +69,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)hash.h 8.2 (Berkeley) 4/28/95
* from: @(#)hash.h 8.1 (Berkeley) 6/6/93
*/
/* hash.h --
@ -47,7 +81,7 @@
#ifndef _HASH
#define _HASH
/*
/*
* The following defines one entry in the hash table.
*/
@ -55,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;
@ -69,7 +105,7 @@ typedef struct Hash_Table {
int mask; /* Used to select bits for hashing. */
} Hash_Table;
/*
/*
* The following structure is used by the searching routines
* to record where we are in the search.
*/
@ -85,32 +121,34 @@ typedef struct Hash_Search {
*/
/*
* ClientData Hash_GetValue(h)
* Hash_Entry *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);
* Hash_Entry *h;
* char *val;
/*
* Hash_SetValue(h, val);
* Hash_Entry *h;
* 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
/*
* Hash_Size(n) returns the number of words in an object of n bytes
*/
#define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int))
void Hash_InitTable __P((Hash_Table *, int));
void Hash_DeleteTable __P((Hash_Table *));
Hash_Entry *Hash_FindEntry __P((Hash_Table *, char *));
Hash_Entry *Hash_CreateEntry __P((Hash_Table *, char *, Boolean *));
void Hash_DeleteEntry __P((Hash_Table *, Hash_Entry *));
Hash_Entry *Hash_EnumFirst __P((Hash_Table *, Hash_Search *));
Hash_Entry *Hash_EnumNext __P((Hash_Search *));
void Hash_InitTable(Hash_Table *, int);
void Hash_DeleteTable(Hash_Table *);
Hash_Entry *Hash_FindEntry(Hash_Table *, const char *);
Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *);
void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
Hash_Entry *Hash_EnumNext(Hash_Search *);
#endif /* _HASH */

201
install-sh Executable file
View File

@ -0,0 +1,201 @@
:
# NAME:
# install.sh - portable version of install(1)
#
# SYNOPSIS:
# install [-CNcs] [-f flags] [-i errs] [-o owner] [-g group] [-m mode] file1 file2 ...
# install -d [-i errs] [-o owner] [-g group] [-m mode] directory ...
#
# DESCRIPTION:
# Compatible with BSD install(1). Except that '-c' is always
# true and we always move an already installed target aside as
# this is important on many systems. Recent BSD install(1)
# versions have a '-b' option for this.
#
#
# OPTIONS:
# -b move previous target file aside (always true).
#
# -B "suffix"
# use "suffix" instead of .old for saving existing target.
#
# -c copy rather than move the file into place (always true).
#
# -C compare. Only install if target is missing or
# different.
#
# -N newer. Only install if target is missing or older.
#
# -s strip target
#
# -o "owner"
# make target owned by "owner"
#
# -g "group"
# make target group owned by "group"
#
# -m "mode"
# set permissions to "mode"
#
# -f "flags"
# Pass "flags" onto chflags(1)
#
# -i "errs"
# Ignore errors from steps indicated by "errs" (``s,o,g,m'').
#
# BUGS:
# The '-i' option is to save your sanity when 'bsd.prog.mk'
# insists on haveing a '-o' "owner" option which is doomed to
# fail on many systems. We ignore '-b', '-B' and '-c' options.
#
# AUTHOR:
# Simon J. Gerraty <sjg@quick.com.au>
#
# RCSid:
# $Id: install-sh,v 1.18 2001/03/16 17:33:02 sjg Exp $
#
# @(#) Copyright (c) 1993 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@quick.com.au
#
set -- `getopt B:bpxCNcsdo:g:m:i:f: $*`
Mydir=`dirname $0`
[ -s $Mydir/.installrc ] && . $Mydir/.installrc
owner=:
group=:
mode=:
strip=:
mkdirs=
compare=:
newer=:
chflags=:
LS1=
CP_P=
while [ $# -gt 1 ]
do
case $1 in
--) shift; break;;
-p) CP_P=-p;;
-x) set -x;;
-B) OLD_EXT=$2; shift;;
-C) compare=Different;;
-N) newer=Newer;
# check if /bin/ls supports -1
/bin/ls -1 $0 >/dev/null 2>&1 && LS1=1
;;
-o) owner="${CHOWN:-chown} $2 "; shift;;
-g) group="${CHGRP:-chgrp} $2 "; shift;;
-m) mode="${CHMOD:-chmod} $2 "; shift;;
-s) strip=${STRIP:-strip};;
-d) mkdirs="mkdir -p";;
-i) ignore_err="$ignore_err$2"; shift;;
-f) chflags="${CHFLAGS:-chflags} $2 "; shift;;
esac
shift
done
Newer() {
n=`/bin/ls -t$LS1 $* 2>/dev/null | head -1`
[ $1 = $n ]
}
Different() {
cmp -s $*
[ $? != 0 ]
}
Err() {
case "$ignore_err" in
*$1*) ;;
*) exit 1;;
esac
}
Setem() {
# the order is important
if [ ! -d $1 ]; then
$strip $1 || Err s
fi
$group $1 || Err g
$owner $1 || Err o
$mode $1 || Err m
$chflags $1 || Err f
return 0
}
# a bug in HP-UX's /bin/sh, means we need to re-set $*
# after any calls to add_path()
args="$*"
# all this just for chown!
add_path () { [ -d $1 ] && eval ${2:-PATH}="\$${2:-PATH}:$1"; }
add_path /etc
add_path /usr/etc
add_path /sbin
add_path /usr/sbin
# restore saved $*
set -- $args
# make directories if needed
# and ensure mode etc are as desired
if [ "$mkdirs" ]; then
for d in $*
do
[ ! -d $d ] && $mkdirs $d
Setem $d
done
exit 0 # that's all we do
fi
# install files
if [ $# -gt 2 ]; then
dest_dir=yes
elif [ $# -eq 1 ]; then
echo "what should I do with $*?" >&2
exit 1
fi
# get list of files
while [ $# -gt 1 ]
do
files="$files $1"
shift
done
# last one is dest
dest=$1
shift
if [ "$dest_dir" = yes -a ! -d $dest ]; then
echo "no directory $dest" >&2
exit 1
fi
for f in $files
do
b=`basename $f`
if [ -d $dest ]; then
t=$dest/$b
else
t=$dest
fi
$newer $f $t || continue
$compare $f $t || continue
[ -f $t ] && { mv -f $t $t.old || exit 1; }
{ cp $CP_P $f $t && Setem $t; } || exit 1
done
exit 0

2988
job.c Normal file

File diff suppressed because it is too large Load Diff

272
job.h Normal file
View File

@ -0,0 +1,272 @@
/* $NetBSD: job.h,v 1.40 2010/09/13 15:36:57 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)job.h 8.1 (Berkeley) 6/6/93
*/
/*-
* job.h --
* Definitions pertaining to the running of jobs in parallel mode.
*/
#ifndef _JOB_H_
#define _JOB_H_
#define TMPPAT "makeXXXXXX" /* relative to tmpdir */
#ifdef USE_SELECT
/*
* Emulate poll() in terms of select(). This is not a complete
* emulation but it is sufficient for make's purposes.
*/
#define poll emul_poll
#define pollfd emul_pollfd
struct emul_pollfd {
int fd;
short events;
short revents;
};
#define POLLIN 0x0001
#define POLLOUT 0x0004
int
emul_poll(struct pollfd *fd, int nfd, int timeout);
#endif
/*
* The POLL_MSEC constant determines the maximum number of milliseconds spent
* in poll before coming out to see if a child has finished.
*/
#define POLL_MSEC 5000
/*-
* Job Table definitions.
*
* Each job has several things associated with it:
* 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 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.
* 5) The output is being caught via a pipe and
* the descriptors of our pipe, an array in which output is line
* buffered and the current position in that buffer are all
* maintained for each job.
* 6) A word of flags which determine how the module handles errors,
* echoing, etc. for the job
*
* When a job is finished, the Make_Update function is called on each of the
* parents of the node which was just remade. This takes care of the upward
* traversal of the dependency graph.
*/
struct pollfd;
#ifdef USE_META
# include "meta.h"
#endif
#define JOB_BUFSIZE 1024
typedef struct Job {
int pid; /* The child's process ID */
GNode *node; /* The target the child is making */
LstNode tailCmds; /* The node of the first command to be
* saved when the job has been run */
FILE *cmdFILE; /* When creating the shell script, this is
* where the commands go */
int exit_status; /* from wait4() in signal handler */
char job_state; /* status of the job entry */
#define JOB_ST_FREE 0 /* Job is available */
#define JOB_ST_SETUP 1 /* Job is allocated but otherwise invalid */
#define JOB_ST_RUNNING 3 /* Job is running, pid valid */
#define JOB_ST_FINISHED 4 /* Job is done (ie after SIGCHILD) */
char job_suspended;
short flags; /* Flags to control treatment of job */
#define JOB_IGNERR 0x001 /* Ignore non-zero exits */
#define JOB_SILENT 0x002 /* no output */
#define JOB_SPECIAL 0x004 /* Target is a special one. i.e. run it locally
* if we can't export it and maxLocal is 0 */
#define JOB_IGNDOTS 0x008 /* Ignore "..." lines when processing
* commands */
#define JOB_TRACED 0x400 /* we've sent 'set -x' */
int jobPipe[2]; /* Pipe for readind output from job */
struct pollfd *inPollfd; /* pollfd associated with inPipe */
char outBuf[JOB_BUFSIZE + 1];
/* Buffer for storing the output of the
* job, line by line */
int curPos; /* Current position in op_outBuf */
#ifdef USE_META
struct BuildMon bm;
#endif
} Job;
#define inPipe jobPipe[0]
#define outPipe jobPipe[1]
/*-
* Shell Specifications:
* Each shell type has associated with it the following information:
* 1) The string which must match the last character of the shell name
* for the shell to be considered of this type. The longest match
* wins.
* 2) A command to issue to turn off echoing of command lines
* 3) A command to issue to turn echoing back on again
* 4) What the shell prints, and its length, when given the echo-off
* command. This line will not be printed when received from the shell
* 5) A boolean to tell if the shell has the ability to control
* error checking for individual commands.
* 6) The string to turn this checking on.
* 7) The string to turn it off.
* 8) The command-flag to give to cause the shell to start echoing
* commands right away.
* 9) The command-flag to cause the shell to Lib_Exit when an error is
* detected in one of the commands.
*
* Some special stuff goes on if a shell doesn't have error control. In such
* a case, errCheck becomes a printf template for echoing the command,
* should echoing be on and ignErr becomes another printf template for
* executing the command while ignoring the return status. Finally errOut
* is a printf template for running the command and causing the shell to
* exit on error. If any of these strings are empty when hasErrCtl is FALSE,
* the command will be executed anyway as is and if it causes an error, so be
* it. Any templates setup to echo the command will escape any '$ ` \ "'i
* characters in the command string to avoid common problems with
* echo "%s\n" as a template.
*/
typedef struct Shell {
const char *name; /* the name of the shell. For Bourne and C
* shells, this is used only to find the
* shell description when used as the single
* source of a .SHELL target. For user-defined
* shells, this is the full path of the shell.
*/
Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
const char *echoOff; /* command to turn off echo */
const char *echoOn; /* command to turn it back on again */
const char *noPrint; /* command to skip when printing output from
* shell. This is usually the command which
* was executed to turn off echoing */
int noPLen; /* length of noPrint command */
Boolean hasErrCtl; /* set if can control error checking for
* individual commands */
const char *errCheck; /* string to turn error checking on */
const char *ignErr; /* string to turn off error checking */
const char *errOut; /* string to use for testing exit code */
const char *newline; /* string literal that results in a newline
* character when it appears outside of any
* 'quote' or "quote" characters */
char commentChar; /* character used by shell for comment lines */
/*
* command-line flags
*/
const char *echo; /* echo commands */
const char *exit; /* exit on error */
} Shell;
extern const char *shellPath;
extern const char *shellName;
extern int jobTokensRunning; /* tokens currently "out" */
extern int maxJobs; /* Max jobs we can run */
void Shell_Init(void);
const char *Shell_GetNewline(void);
void Job_Touch(GNode *, Boolean);
Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
#define CATCH_BLOCK 1
void Job_CatchChildren(void);
void Job_CatchOutput(void);
void Job_Make(GNode *);
void Job_Init(void);
Boolean Job_Full(void);
Boolean Job_Empty(void);
ReturnStatus Job_ParseShell(char *);
int Job_Finish(void);
void Job_End(void);
void Job_Wait(void);
void Job_AbortAll(void);
void JobFlagForMigration(int);
void Job_TokenReturn(void);
Boolean Job_TokenWithdraw(void);
void Job_ServerStart(int, int, int);
void Job_SetPrefix(void);
#endif /* _JOB_H_ */

View File

@ -1,6 +1,41 @@
/* $NetBSD: lst.h,v 1.18 2009/01/23 21:58:27 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)lst.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -35,7 +70,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)lst.h 8.2 (Berkeley) 4/28/95
* from: @(#)lst.h 8.1 (Berkeley) 6/6/93
*/
/*-
@ -45,28 +80,20 @@
#ifndef _LST_H_
#define _LST_H_
#include <sprite.h>
#if __STDC__
#include <sys/param.h>
#include <stdlib.h>
#endif
#include "sprite.h"
/*
* basic typedef. This is what the Lst_ functions handle
*/
typedef struct Lst *Lst;
typedef struct LstNode *LstNode;
typedef struct List *Lst;
typedef struct ListNode *LstNode;
#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 ((void (*) __P((ClientData))) 0)
#define NOCOPY ((ClientData (*) __P((ClientData))) 0)
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 */
@ -75,89 +102,88 @@ typedef struct LstNode *LstNode;
* Creation/destruction functions
*/
/* Create a new list */
Lst Lst_Init __P((Boolean));
Lst Lst_Init(Boolean);
/* Duplicate an existing list */
Lst Lst_Duplicate __P((Lst, ClientData (*)(ClientData)));
Lst Lst_Duplicate(Lst, DuplicateProc *);
/* Destroy an old one */
void Lst_Destroy __P((Lst, void (*)(ClientData)));
void Lst_Destroy(Lst, FreeProc *);
/* True if list is empty */
Boolean Lst_IsEmpty __P((Lst));
Boolean Lst_IsEmpty(Lst);
/*
* Functions to modify a list
*/
/* Insert an element before another */
ReturnStatus Lst_Insert __P((Lst, LstNode, ClientData));
ReturnStatus Lst_InsertBefore(Lst, LstNode, void *);
/* Insert an element after another */
ReturnStatus Lst_Append __P((Lst, LstNode, ClientData));
ReturnStatus Lst_InsertAfter(Lst, LstNode, void *);
/* Place an element at the front of a lst. */
ReturnStatus Lst_AtFront __P((Lst, ClientData));
ReturnStatus Lst_AtFront(Lst, void *);
/* Place an element at the end of a lst. */
ReturnStatus Lst_AtEnd __P((Lst, ClientData));
ReturnStatus Lst_AtEnd(Lst, void *);
/* Remove an element */
ReturnStatus Lst_Remove __P((Lst, LstNode));
ReturnStatus Lst_Remove(Lst, LstNode);
/* Replace a node with a new value */
ReturnStatus Lst_Replace __P((LstNode, ClientData));
ReturnStatus Lst_Replace(LstNode, void *);
/* Concatenate two lists */
ReturnStatus Lst_Concat __P((Lst, Lst, int));
ReturnStatus Lst_Concat(Lst, Lst, int);
/*
* Node-specific functions
*/
/* Return first element in list */
LstNode Lst_First __P((Lst));
LstNode Lst_First(Lst);
/* Return last element in list */
LstNode Lst_Last __P((Lst));
LstNode Lst_Last(Lst);
/* Return successor to given element */
LstNode Lst_Succ __P((LstNode));
LstNode Lst_Succ(LstNode);
/* Return predecessor to given element */
LstNode Lst_Prev(LstNode);
/* Get datum from LstNode */
ClientData Lst_Datum __P((LstNode));
void *Lst_Datum(LstNode);
/*
* Functions for entire lists
*/
/* Find an element in a list */
LstNode Lst_Find __P((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 __P((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 __P((Lst, ClientData));
LstNode Lst_Member(Lst, void *);
/* Apply a function to all elements of a lst */
void Lst_ForEach __P((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.
*/
void Lst_ForEachFrom __P((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
* between Lst_Open() and Lst_Close().
*/
/* Open the list */
ReturnStatus Lst_Open __P((Lst));
ReturnStatus Lst_Open(Lst);
/* Next element please */
LstNode Lst_Next __P((Lst));
LstNode Lst_Next(Lst);
/* Done yet? */
Boolean Lst_IsAtEnd __P((Lst));
Boolean Lst_IsAtEnd(Lst);
/* Finish table access */
void Lst_Close __P((Lst));
void Lst_Close(Lst);
/*
* for using the list as a queue
*/
/* Place an element at tail of queue */
ReturnStatus Lst_EnQueue __P((Lst, ClientData));
ReturnStatus Lst_EnQueue(Lst, void *);
/* Remove an element from head of queue */
ClientData Lst_DeQueue __P((Lst));
void *Lst_DeQueue(Lst);
#endif /* _LST_H_ */

0
lst.lib/Makefile Normal file
View File

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstAppend.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstAppend.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAppend.c,v 1.14 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAppend.c --
@ -47,9 +54,14 @@ static char sccsid[] = "@(#)lstAppend.c 8.2 (Berkeley) 4/28/95";
/*-
*-----------------------------------------------------------------------
* Lst_Append --
* Lst_InsertAfter --
* Create a new node and add it to the given list after the given node.
*
* Input:
* l affected list
* ln node after which to append the datum
* d said datum
*
* Results:
* SUCCESS if all went well.
*
@ -57,57 +69,54 @@ static char sccsid[] = "@(#)lstAppend.c 8.2 (Berkeley) 4/28/95";
* 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_Append (l, ln, d)
Lst l; /* affected list */
LstNode ln; /* node after which to append the datum */
ClientData d; /* said datum */
Lst_InsertAfter(Lst l, LstNode ln, void *d)
{
register List list;
register ListNode lNode;
register ListNode nLNode;
if (LstValid (l) && (ln == NILLNODE && LstIsEmpty (l))) {
List list;
ListNode lNode;
ListNode nLNode;
if (LstValid (l) && (ln == NULL && LstIsEmpty (l))) {
goto ok;
}
if (!LstValid (l) || LstIsEmpty (l) || ! LstNodeValid (ln, l)) {
return (FAILURE);
}
ok:
list = (List)l;
lNode = (ListNode)ln;
list = l;
lNode = ln;
PAlloc (nLNode, ListNode);
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 {
nLNode->prevPtr = lNode;
nLNode->nextPtr = lNode->nextPtr;
lNode->nextPtr = nLNode;
if (nLNode->nextPtr != NilListNode) {
if (nLNode->nextPtr != NULL) {
nLNode->nextPtr->prevPtr = nLNode;
}
if (lNode == list->lastPtr) {
list->lastPtr = nLNode;
}
}
return (SUCCESS);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstAtEnd.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstAtEnd.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAtEnd.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAtEnd.c --
@ -44,12 +51,16 @@ static char sccsid[] = "@(#)lstAtEnd.c 8.2 (Berkeley) 4/28/95";
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_AtEnd --
* Add a node to the end of the given list
*
* Input:
* l List to which to add the datum
* d Datum to add
*
* Results:
* SUCCESS if life is good.
*
@ -59,12 +70,10 @@ static char sccsid[] = "@(#)lstAtEnd.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_AtEnd (l, d)
Lst l; /* List to which to add the datum */
ClientData d; /* Datum to add */
Lst_AtEnd(Lst l, void *d)
{
register LstNode end;
end = Lst_Last (l);
return (Lst_Append (l, end, d));
LstNode end;
end = Lst_Last(l);
return (Lst_InsertAfter(l, end, d));
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstAtFront.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstAtFront.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstAtFront.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstAtFront.c --
@ -60,12 +67,10 @@ static char sccsid[] = "@(#)lstAtFront.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_AtFront (l, d)
Lst l;
ClientData d;
Lst_AtFront(Lst l, void *d)
{
register LstNode front;
front = Lst_First (l);
return (Lst_Insert (l, front, d));
LstNode front;
front = Lst_First(l);
return (Lst_InsertBefore(l, front, d));
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstClose.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstClose.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstClose.c,v 1.11 2006/10/27 21:37:25 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstClose.c --
@ -55,6 +62,9 @@ static char sccsid[] = "@(#)lstClose.c 8.2 (Berkeley) 4/28/95";
* Lst_Close --
* Close a list which was opened for sequential access.
*
* Input:
* l The list to close
*
* Results:
* None.
*
@ -64,11 +74,10 @@ static char sccsid[] = "@(#)lstClose.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
void
Lst_Close (l)
Lst l; /* The list to close */
Lst_Close(Lst l)
{
register List list = (List) l;
List list = l;
if (LstValid(l) == TRUE) {
list->isOpen = FALSE;
list->atEnd = Unknown;

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstConcat.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstConcat.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstConcat.c,v 1.16 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* listConcat.c --
@ -55,33 +62,35 @@ static char sccsid[] = "@(#)lstConcat.c 8.2 (Berkeley) 4/28/95";
* If LST_CONCLINK is specified, the second list is destroyed since
* its pointers have been corrupted and the list is no longer useable.
*
* Input:
* l1 The list to which l2 is to be appended
* l2 The list to append to l1
* flags LST_CONCNEW if LstNode's should be duplicated
* LST_CONCLINK if should just be relinked
*
* Results:
* SUCCESS if all went well. FAILURE otherwise.
*
* Side Effects:
* New elements are created and appended the the first list.
* New elements are created and appended the first list.
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Concat (l1, l2, flags)
Lst l1; /* The list to which l2 is to be appended */
Lst l2; /* The list to append to l1 */
int flags; /* LST_CONCNEW if LstNode's should be duplicated
* LST_CONCLINK if should just be relinked */
Lst_Concat(Lst l1, Lst l2, int flags)
{
register ListNode ln; /* original LstNode */
register ListNode nln; /* new LstNode */
register ListNode last; /* the last element in the list. Keeps
ListNode ln; /* original LstNode */
ListNode nln; /* new LstNode */
ListNode last; /* the last element in the list. Keeps
* bookkeeping until the end */
register List list1 = (List)l1;
register List list2 = (List)l2;
List list1 = l1;
List list2 = l2;
if (!LstValid (l1) || !LstValid (l2)) {
return (FAILURE);
}
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
@ -90,7 +99,7 @@ Lst_Concat (l1, l2, 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
@ -100,14 +109,14 @@ Lst_Concat (l1, l2, 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
@ -116,8 +125,8 @@ Lst_Concat (l1, l2, flags)
list1->firstPtr->prevPtr = list1->lastPtr;
list1->lastPtr->nextPtr = list1->firstPtr;
}
free ((Address)l2);
} else if (list2->firstPtr != NilListNode) {
free(l2);
} 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
@ -130,14 +139,14 @@ Lst_Concat (l1, l2, 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;
@ -149,7 +158,7 @@ Lst_Concat (l1, l2, flags)
/*
* Finish bookkeeping. The last new element becomes the last element
* of list one.
* of list one.
*/
list1->lastPtr = last;
@ -163,7 +172,7 @@ Lst_Concat (l1, l2, flags)
list1->lastPtr->nextPtr = list1->firstPtr;
list1->firstPtr->prevPtr = list1->lastPtr;
} else {
last->nextPtr = NilListNode;
last->nextPtr = NULL;
}
if (list2->isCirc) {
@ -173,4 +182,4 @@ Lst_Concat (l1, l2, flags)
return (SUCCESS);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstDatum.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstDatum.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDatum.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDatum.c --
@ -51,21 +58,20 @@ static char sccsid[] = "@(#)lstDatum.c 8.2 (Berkeley) 4/28/95";
* 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
Lst_Datum (ln)
LstNode ln;
void *
Lst_Datum(LstNode ln)
{
if (ln != NILLNODE) {
return (((ListNode)ln)->datum);
if (ln != NULL) {
return ((ln)->datum);
} else {
return ((ClientData) NIL);
return NULL;
}
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstDeQueue.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstDeQueue.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDeQueue.c,v 1.14 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDeQueue.c --
@ -51,7 +58,7 @@ static char sccsid[] = "@(#)lstDeQueue.c 8.2 (Berkeley) 4/28/95";
* 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:
@ -59,21 +66,20 @@ static char sccsid[] = "@(#)lstDeQueue.c 8.2 (Berkeley) 4/28/95";
*
*-----------------------------------------------------------------------
*/
ClientData
Lst_DeQueue (l)
Lst l;
void *
Lst_DeQueue(Lst l)
{
ClientData rd;
register ListNode tln;
tln = (ListNode) Lst_First (l);
if (tln == NilListNode) {
return ((ClientData) NIL);
void *rd;
ListNode tln;
tln = Lst_First(l);
if (tln == NULL) {
return NULL;
}
rd = tln->datum;
if (Lst_Remove (l, (LstNode)tln) == FAILURE) {
return ((ClientData) NIL);
if (Lst_Remove(l, tln) == FAILURE) {
return NULL;
} else {
return (rd);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstDestroy.c,v 1.16 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDestroy.c,v 1.16 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstDestroy.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstDestroy.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDestroy.c,v 1.16 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstDestroy.c --
@ -61,42 +68,34 @@ static char sccsid[] = "@(#)lstDestroy.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
void
Lst_Destroy (l, freeProc)
Lst l;
register void (*freeProc) __P((ClientData));
Lst_Destroy(Lst list, FreeProc *freeProc)
{
register ListNode ln;
register ListNode tln = NilListNode;
register List list = (List)l;
if (l == NILLST || ! l) {
/*
* Note the check for l == (Lst)0 to catch uninitialized static Lst's.
* Gross, but useful.
*/
ListNode ln;
ListNode tln = NULL;
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 ((Address)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 ((Address)ln);
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 ((Address)ln);
free(ln);
}
}
free ((Address)l);
free(list);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstDupl.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstDupl.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstDupl.c,v 1.16 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* listDupl.c --
@ -49,51 +56,52 @@ static char sccsid[] = "@(#)lstDupl.c 8.2 (Berkeley) 4/28/95";
/*-
*-----------------------------------------------------------------------
* 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 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.
*-----------------------------------------------------------------------
*/
Lst
Lst_Duplicate (l, copyProc)
Lst l; /* the list to duplicate */
/* A function to duplicate each ClientData */
ClientData (*copyProc) __P((ClientData));
Lst_Duplicate(Lst l, DuplicateProc *copyProc)
{
register Lst nl;
register ListNode ln;
register List list = (List)l;
Lst nl;
ListNode ln;
List list = l;
if (!LstValid (l)) {
return (NILLST);
return NULL;
}
nl = Lst_Init (list->isCirc);
if (nl == NILLST) {
return (NILLST);
nl = Lst_Init(list->isCirc);
if (nl == NULL) {
return NULL;
}
ln = list->firstPtr;
while (ln != NilListNode) {
if (copyProc != NOCOPY) {
if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) {
return (NILLST);
while (ln != NULL) {
if (copyProc != NULL) {
if (Lst_AtEnd(nl, copyProc(ln->datum)) == FAILURE) {
return NULL;
}
} else if (Lst_AtEnd (nl, ln->datum) == FAILURE) {
return (NILLST);
} else if (Lst_AtEnd(nl, ln->datum) == FAILURE) {
return NULL;
}
if (list->isCirc && ln == list->lastPtr) {
ln = NilListNode;
ln = NULL;
} else {
ln = ln->nextPtr;
}
}
return (nl);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstEnQueue.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstEnQueue.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstEnQueue.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstEnQueue.c--
@ -51,7 +58,7 @@ static char sccsid[] = "@(#)lstEnQueue.c 8.2 (Berkeley) 4/28/95";
* Add the datum to the tail of the given list.
*
* Results:
* SUCCESS or FAILURE as returned by Lst_Append.
* SUCCESS or FAILURE as returned by Lst_InsertAfter.
*
* Side Effects:
* the lastPtr field is altered all the time and the firstPtr field
@ -60,14 +67,12 @@ static char sccsid[] = "@(#)lstEnQueue.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_EnQueue (l, d)
Lst l;
ClientData d;
Lst_EnQueue(Lst l, void *d)
{
if (LstValid (l) == FALSE) {
return (FAILURE);
}
return (Lst_Append (l, Lst_Last(l), d));
return (Lst_InsertAfter(l, Lst_Last(l), d));
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstFind.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstFind.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFind.c,v 1.15 2009/01/23 21:58:28 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFind.c --
@ -52,7 +59,7 @@ static char sccsid[] = "@(#)lstFind.c 8.2 (Berkeley) 4/28/95";
* and the given datum.
*
* Results:
* The found node or NILLNODE if none matches.
* The found node or NULL if none matches.
*
* Side Effects:
* None.
@ -60,11 +67,8 @@ static char sccsid[] = "@(#)lstFind.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_Find (l, d, cProc)
Lst l;
ClientData d;
int (*cProc) __P((ClientData, ClientData));
Lst_Find(Lst l, const void *d, int (*cProc)(const void *, const void *))
{
return (Lst_FindFrom (l, Lst_First(l), d, cProc));
return (Lst_FindFrom(l, Lst_First(l), d, cProc));
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstFindFrom.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstFindFrom.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFindFrom.c,v 1.15 2009/01/23 21:58:28 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFindFrom.c --
@ -53,7 +60,7 @@ static char sccsid[] = "@(#)lstFindFrom.c 8.2 (Berkeley) 4/28/95";
* determine when it has been found.
*
* Results:
* The found node or NILLNODE
* The found node or NULL
*
* Side Effects:
* None.
@ -61,34 +68,23 @@ static char sccsid[] = "@(#)lstFindFrom.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_FindFrom (l, ln, d, cProc)
Lst l;
register LstNode ln;
register ClientData d;
register int (*cProc) __P((ClientData, ClientData));
Lst_FindFrom(Lst l, LstNode ln, const void *d,
int (*cProc)(const void *, const void *))
{
register ListNode tln;
Boolean found = FALSE;
ListNode tln;
if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
return (NILLNODE);
return NULL;
}
tln = (ListNode)ln;
tln = ln;
do {
if ((*cProc) (tln->datum, d) == 0) {
found = TRUE;
break;
} else {
tln = tln->nextPtr;
}
} while (tln != (ListNode)ln && tln != NilListNode);
if (found) {
return ((LstNode)tln);
} else {
return (NILLNODE);
}
if ((*cProc)(tln->datum, d) == 0)
return (tln);
tln = tln->nextPtr;
} while (tln != ln && tln != NULL);
return NULL;
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstFirst.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstFirst.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstFirst.c,v 1.12 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstFirst.c --
@ -51,7 +58,7 @@ static char sccsid[] = "@(#)lstFirst.c 8.2 (Berkeley) 4/28/95";
* 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.
@ -59,13 +66,12 @@ static char sccsid[] = "@(#)lstFirst.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_First (l)
Lst l;
Lst_First(Lst l)
{
if (!LstValid (l) || LstIsEmpty (l)) {
return (NILLNODE);
return NULL;
} else {
return ((LstNode)((List)l)->firstPtr);
return (l->firstPtr);
}
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstForEach.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstForEach.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstForEach.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstForeach.c --
@ -61,12 +68,9 @@ static char sccsid[] = "@(#)lstForEach.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
/*VARARGS2*/
void
Lst_ForEach (l, proc, d)
Lst l;
register int (*proc) __P((ClientData, ClientData));
register ClientData d;
int
Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d)
{
Lst_ForEachFrom(l, Lst_First(l), proc, d);
return Lst_ForEachFrom(l, Lst_First(l), proc, d);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstForEachFrom.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstForEachFrom.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstForEachFrom.c,v 1.17 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* lstForEachFrom.c --
@ -51,7 +58,7 @@ static char sccsid[] = "@(#)lstForEachFrom.c 8.2 (Berkeley) 4/28/95";
* Lst_ForEachFrom --
* Apply the given function to each element of the given list. The
* function should return 0 if traversal should continue and non-
* zero if it should abort.
* zero if it should abort.
*
* Results:
* None.
@ -62,50 +69,57 @@ static char sccsid[] = "@(#)lstForEachFrom.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
/*VARARGS2*/
void
Lst_ForEachFrom (l, ln, proc, d)
Lst l;
LstNode ln;
register int (*proc)();
register ClientData d;
int
Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *),
void *d)
{
register ListNode tln = (ListNode)ln;
register List list = (List)l;
register ListNode next;
ListNode tln = ln;
List list = l;
ListNode next;
Boolean done;
int result;
if (!LstValid (list) || LstIsEmpty (list)) {
return;
return 0;
}
do {
/*
* Take care of having the current element deleted out from under
* us.
*/
next = tln->nextPtr;
/*
* We're done with the traversal if
* - the next node to examine is the first in the queue or
* doesn't exist and
* - nothing's been added after the current node (check this
* after proc() has been called).
*/
done = (next == NULL || next == list->firstPtr);
(void) tln->useCount++;
result = (*proc) (tln->datum, d);
(void) tln->useCount--;
/*
* We're done with the traversal if
* - nothing's been added after the current node and
* - the next node to examine is the first in the queue or
* doesn't exist.
* Now check whether a node has been added.
* Note: this doesn't work if this node was deleted before
* the new node was added.
*/
done = (next == tln->nextPtr &&
(next == NilListNode || next == list->firstPtr));
next = tln->nextPtr;
if (next != tln->nextPtr) {
next = tln->nextPtr;
done = 0;
}
if (tln->flags & LN_DELETED) {
free((char *)tln);
}
tln = next;
} while (!result && !LstIsEmpty(list) && !done);
return result;
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstInit.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstInit.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstInit.c,v 1.12 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* init.c --
@ -50,6 +57,9 @@ static char sccsid[] = "@(#)lstInit.c 8.2 (Berkeley) 4/28/95";
* Lst_Init --
* Create and initialize a new list.
*
* Input:
* circ TRUE if the list should be made circular
*
* Results:
* The created list.
*
@ -59,18 +69,17 @@ static char sccsid[] = "@(#)lstInit.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
Lst
Lst_Init(circ)
Boolean circ; /* TRUE if the list should be made circular */
Lst_Init(Boolean circ)
{
register List nList;
List nList;
PAlloc (nList, List);
nList->firstPtr = NilListNode;
nList->lastPtr = NilListNode;
nList->firstPtr = NULL;
nList->lastPtr = NULL;
nList->isOpen = FALSE;
nList->isCirc = circ;
nList->atEnd = Unknown;
return ((Lst)nList);
return (nList);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstInsert.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstInsert.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstInsert.c,v 1.14 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstInsert.c --
@ -47,10 +54,15 @@ static char sccsid[] = "@(#)lstInsert.c 8.2 (Berkeley) 4/28/95";
/*-
*-----------------------------------------------------------------------
* Lst_Insert --
* Lst_InsertBefore --
* Insert a new node with the given piece of data before the given
* node in the given list.
*
* Input:
* l list to manipulate
* ln node before which to insert d
* d datum to be inserted
*
* Results:
* SUCCESS or FAILURE.
*
@ -61,53 +73,50 @@ static char sccsid[] = "@(#)lstInsert.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Insert (l, ln, d)
Lst l; /* list to manipulate */
LstNode ln; /* node before which to insert d */
ClientData d; /* datum to be inserted */
Lst_InsertBefore(Lst l, LstNode ln, void *d)
{
register ListNode nLNode; /* new lnode for d */
register ListNode lNode = (ListNode)ln;
register List list = (List)l;
ListNode nLNode; /* new lnode for d */
ListNode lNode = ln;
List list = l;
/*
* 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)) {
return (FAILURE);
}
ok:
PAlloc (nLNode, ListNode);
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;
if (lNode == list->firstPtr) {
list->firstPtr = nLNode;
}
}
return (SUCCESS);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstInt.h,v 1.20 2009/01/24 14:43:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -33,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)lstInt.h 8.2 (Berkeley) 4/28/95
* from: @(#)lstInt.h 8.1 (Berkeley) 6/6/93
*/
/*-
@ -43,29 +41,28 @@
#ifndef _LSTINT_H_
#define _LSTINT_H_
#include "lst.h"
#include "../lst.h"
#include "../make_malloc.h"
typedef struct ListNode {
struct ListNode *prevPtr; /* previous element in list */
struct ListNode *nextPtr; /* next in list */
short useCount:8, /* Count of functions using the node.
unsigned int useCount:8, /* Count of functions using the node.
* 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;
typedef struct {
typedef struct List {
ListNode firstPtr; /* first node in list */
ListNode lastPtr; /* last node in list */
Boolean isCirc; /* true if the list should be considered
@ -75,36 +72,34 @@ typedef struct {
*/
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'
*/
#define PAlloc(var,ptype) var = (ptype) malloc (sizeof (*var))
#define PAlloc(var,ptype) var = (ptype) bmake_malloc(sizeof *(var))
/*
* LstValid (l) --
* Return TRUE if the list l is valid
*/
#define LstValid(l) (((Lst)l == NILLST) ? FALSE : TRUE)
#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) ((((LstNode)ln) == NILLNODE) ? FALSE : TRUE)
#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_
#endif /* _LSTINT_H_ */

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstIsAtEnd.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstIsAtEnd.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstIsAtEnd.c,v 1.13 2008/02/15 21:29:50 christos Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstIsAtEnd.c --
@ -70,10 +77,9 @@ static char sccsid[] = "@(#)lstIsAtEnd.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
Boolean
Lst_IsAtEnd (l)
Lst l;
Lst_IsAtEnd(Lst l)
{
register List list = (List) l;
List list = l;
return (!LstValid (l) || !list->isOpen ||
(list->atEnd == Head) || (list->atEnd == Tail));

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstIsEmpty.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstIsEmpty.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstIsEmpty.c,v 1.11 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstIsEmpty.c --
@ -56,13 +63,12 @@ static char sccsid[] = "@(#)lstIsEmpty.c 8.2 (Berkeley) 4/28/95";
* 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
Lst_IsEmpty (l)
Lst l;
Lst_IsEmpty(Lst l)
{
return ( ! LstValid (l) || LstIsEmpty(l));
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstLast.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstLast.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstLast.c,v 1.12 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstLast.c --
@ -51,7 +58,7 @@ static char sccsid[] = "@(#)lstLast.c 8.2 (Berkeley) 4/28/95";
* 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.
@ -59,13 +66,12 @@ static char sccsid[] = "@(#)lstLast.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_Last (l)
Lst l;
Lst_Last(Lst l)
{
if (!LstValid(l) || LstIsEmpty (l)) {
return (NILLNODE);
return NULL;
} else {
return ((LstNode)((List)l)->lastPtr);
return (l->lastPtr);
}
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstMember.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstMember.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstMember.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstMember.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstMember.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* lstMember.c --
@ -46,24 +53,22 @@ static char sccsid[] = "@(#)lstMember.c 8.2 (Berkeley) 4/28/95";
#include "lstInt.h"
LstNode
Lst_Member (l, d)
Lst l;
ClientData d;
Lst_Member(Lst l, void *d)
{
List list = (List) l;
register ListNode lNode;
List list = l;
ListNode lNode;
lNode = list->firstPtr;
if (lNode == NilListNode) {
return NILLNODE;
if (lNode == NULL) {
return NULL;
}
do {
if (lNode->datum == d) {
return (LstNode)lNode;
return lNode;
}
lNode = lNode->nextPtr;
} while (lNode != NilListNode && lNode != list->firstPtr);
} while (lNode != NULL && lNode != list->firstPtr);
return NILLNODE;
return NULL;
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstNext.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstNext.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstNext.c,v 1.12 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstNext.c --
@ -56,8 +63,8 @@ static char sccsid[] = "@(#)lstNext.c 8.2 (Berkeley) 4/28/95";
* 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:
@ -66,20 +73,19 @@ static char sccsid[] = "@(#)lstNext.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_Next (l)
Lst l;
Lst_Next(Lst l)
{
register ListNode tln;
register List list = (List)l;
ListNode tln;
List list = 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.
@ -89,14 +95,14 @@ Lst_Next (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...
*/
@ -108,7 +114,7 @@ Lst_Next (l)
list->atEnd = Middle;
}
}
return ((LstNode)tln);
return (tln);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstOpen.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstOpen.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstOpen.c --
@ -59,22 +66,21 @@ static char sccsid[] = "@(#)lstOpen.c 8.2 (Berkeley) 4/28/95";
* 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.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Open (l)
register Lst l;
Lst_Open(Lst l)
{
if (LstValid (l) == FALSE) {
return (FAILURE);
}
((List) l)->isOpen = TRUE;
((List) l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
((List) l)->curPtr = NilListNode;
(l)->isOpen = TRUE;
(l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
(l)->curPtr = NULL;
return (SUCCESS);
}

View File

@ -1,8 +1,8 @@
/* $NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
@ -15,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,37 +30,50 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstPrev.c,v 1.3 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstPrev.c --
* return the predecessor to a given node
*/
#include "lstInt.h"
/*-
*-----------------------------------------------------------------------
* Lst_Prev --
* Return the predecessor to the given node on its list.
*
* @(#)dir.h 8.2 (Berkeley) 4/28/95
* Results:
* The predecessor of the node, if it exists (note that on a circular
* list, if the node is the only one in the list, it is its own
* predecessor).
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
LstNode
Lst_Prev(LstNode ln)
{
if (ln == NULL) {
return NULL;
} else {
return (ln->prevPtr);
}
}
/* dir.h --
*/
#ifndef _DIR
#define _DIR
typedef struct Path {
char *name; /* Name of directory */
int refCount; /* Number of paths with this directory */
int hits; /* the number of times a file in this
* directory has been found */
Hash_Table files; /* Hash table of files in directory */
} Path;
void Dir_Init __P((void));
void Dir_End __P((void));
Boolean Dir_HasWildcards __P((char *));
void Dir_Expand __P((char *, Lst, Lst));
char *Dir_FindFile __P((char *, Lst));
int Dir_MTime __P((GNode *));
void Dir_AddDir __P((Lst, char *));
char *Dir_MakeFlags __P((char *, Lst));
void Dir_ClearPath __P((Lst));
void Dir_Concat __P((Lst, Lst));
void Dir_PrintDirectories __P((void));
void Dir_PrintPath __P((Lst));
void Dir_Destroy __P((ClientData));
ClientData Dir_CopyDir __P((ClientData));
#endif /* _DIR */

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstRemove.c,v 1.14 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstRemove.c,v 1.14 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstRemove.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstRemove.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstRemove.c,v 1.14 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstRemove.c --
@ -54,35 +61,33 @@ static char sccsid[] = "@(#)lstRemove.c 8.2 (Berkeley) 4/28/95";
* 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.
*
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Remove (l, ln)
Lst l;
LstNode ln;
Lst_Remove(Lst l, LstNode ln)
{
register List list = (List) l;
register ListNode lNode = (ListNode) ln;
List list = l;
ListNode lNode = ln;
if (!LstValid (l) ||
!LstNodeValid (ln, l)) {
return (FAILURE);
}
/*
* 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;
}
/*
* if either the firstPtr or lastPtr of the list point to this node,
* adjust them accordingly
@ -97,12 +102,12 @@ Lst_Remove (l, 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;
}
}
@ -113,19 +118,19 @@ Lst_Remove (l, ln)
* this case). The list is, therefore, empty and is marked as such
*/
if (list->firstPtr == lNode) {
list->firstPtr = NilListNode;
list->firstPtr = NULL;
}
/*
* note that the datum is unmolested. The caller must free it as
* necessary and as expected.
*/
if (lNode->useCount == 0) {
free ((Address)ln);
free(ln);
} else {
lNode->flags |= LN_DELETED;
}
return (SUCCESS);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstReplace.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstReplace.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstReplace.c,v 1.13 2009/01/23 21:26:30 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstReplace.c --
@ -59,14 +66,12 @@ static char sccsid[] = "@(#)lstReplace.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
ReturnStatus
Lst_Replace (ln, d)
register LstNode ln;
ClientData d;
Lst_Replace(LstNode ln, void *d)
{
if (ln == NILLNODE) {
if (ln == NULL) {
return (FAILURE);
} else {
((ListNode) ln)->datum = d;
(ln)->datum = d;
return (SUCCESS);
}
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -13,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -34,9 +32,18 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)lstSucc.c 8.2 (Berkeley) 4/28/95";
#if 0
static char sccsid[] = "@(#)lstSucc.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: lstSucc.c,v 1.13 2008/12/13 15:19:29 dsl Exp $");
#endif
#endif /* not lint */
#endif
/*-
* LstSucc.c --
@ -48,7 +55,7 @@ static char sccsid[] = "@(#)lstSucc.c 8.2 (Berkeley) 4/28/95";
/*-
*-----------------------------------------------------------------------
* Lst_Succ --
* Return the sucessor to the given node on its list.
* Return the successor to the given node on its list.
*
* Results:
* The successor of the node, if it exists (note that on a circular
@ -61,13 +68,12 @@ static char sccsid[] = "@(#)lstSucc.c 8.2 (Berkeley) 4/28/95";
*-----------------------------------------------------------------------
*/
LstNode
Lst_Succ (ln)
LstNode ln;
Lst_Succ(LstNode ln)
{
if (ln == NILLNODE) {
return (NILLNODE);
if (ln == NULL) {
return NULL;
} else {
return ((LstNode) ((ListNode) ln)->nextPtr);
return (ln->nextPtr);
}
}

96
machine.sh Executable file
View File

@ -0,0 +1,96 @@
:
# derrived from /etc/rc_d/os.sh
# RCSid:
# $Id: machine.sh,v 1.16 2010/10/17 00:05:51 sjg Exp $
#
# @(#) Copyright (c) 1994-2002 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@crufty.net
#
OS=`uname`
OSREL=`uname -r`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
machine=`uname -p 2>/dev/null || uname -m`
MACHINE=
# there is at least one case of `uname -p` outputting
# a bunch of usless drivel
case "$machine" in
unknown|*[!A-Za-z0-9_-]*)
machine=`uname -m`
;;
esac
# Great! Solaris keeps moving arch(1)
# we need this here, and it is not always available...
Which() {
# some shells cannot correctly handle `IFS`
# in conjunction with the for loop.
_dirs=`IFS=:; echo ${2:-$PATH}`
for d in $_dirs
do
test -x $d/$1 && { echo $d/$1; break; }
done
}
case $OS in
OpenBSD)
MACHINE=$OS$OSMAJOR.$machine
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
MACHINE_ARCH=`$arch -s`;
;;
*BSD)
MACHINE=$OS$OSMAJOR.$machine
;;
SunOS)
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
test "$arch" && machine_arch=`$arch`
case "$OSREL" in
4.0*) MACHINE_ARCH=$machine_arch MACHINE=$machine_arch;;
4*) MACHINE_ARCH=$machine_arch;;
esac
;;
HP-UX)
MACHINE_ARCH=`IFS="/-."; set $machine; echo $1`
;;
Interix)
MACHINE=i386
MACHINE_ARCH=i386
;;
UnixWare)
OSREL=`uname -v`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
MACHINE_ARCH=`uname -m`
;;
Linux)
case "$machine" in
i?86) MACHINE_ARCH=i386;;# does anyone really care about 686 vs 586?
esac
;;
esac
MACHINE=${MACHINE:-$OS$OSMAJOR}
MACHINE_ARCH=${MACHINE_ARCH:-$machine}
(
case "$0" in
arch*) echo $MACHINE_ARCH;;
*)
case "$1" in
"") echo $MACHINE;;
*) echo $MACHINE_ARCH;;
esac
;;
esac
) | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz

2078
main.c Normal file

File diff suppressed because it is too large Load Diff

84
make-bootstrap.sh.in Executable file
View File

@ -0,0 +1,84 @@
#!/bin/sh
set -e
srcdir=@srcdir@
DEFAULT_SYS_PATH="@default_sys_path@"
case "@use_meta@" in
yes) XDEFS="-DUSE_META ${XDEFS}";;
esac
CC="@CC@"
CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS}"
MAKE_VERSION=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' Makefile`
MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \
-D@force_machine@MACHINE=\"@machine@\" -DMACHINE_ARCH=\"@machine_arch@\" \
-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\""
LDFLAGS="@LDFLAGS@"
LIBS="@LIBS@"
do_compile2() {
obj="$1"; shift
src="$1"; shift
echo ${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
}
do_compile() {
obj="$1"; shift
src=`basename "$obj" .o`.c
for d in "$srcdir" "$srcdir/lst.lib"
do
test -s "$d/$src" || continue
do_compile2 "$obj" "$d/$src" "$@" || exit 1
return
done
echo "Unknown object file '$obj'" >&2
exit 1
}
do_link() {
output="$1"; shift
echo ${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
}
BASE_OBJECTS="arch.o buf.o compat.o cond.o dir.o for.o getopt hash.o \
job.o make.o make_malloc.o parse.o sigcompat.o str.o strlist.o \
suff.o targ.o trace.o var.o util.o"
LST_OBJECTS="lstAppend.o lstDupl.o lstInit.o lstOpen.o \
lstAtEnd.o lstEnQueue.o lstInsert.o lstAtFront.o lstIsAtEnd.o \
lstClose.o lstFind.o lstIsEmpty.o lstRemove.o lstConcat.o \
lstFindFrom.o lstLast.o lstReplace.o lstFirst.o lstDatum.o \
lstForEach.o lstMember.o lstSucc.o lstDeQueue.o lstForEachFrom.o \
lstDestroy.o lstNext.o lstPrev.o"
LIB_OBJECTS="@LIBOBJS@"
do_compile main.o ${MDEFS}
for o in ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
do
do_compile "$o"
done
case "@use_meta@" in
yes)
case "@filemon_h@" in
*/filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";;
esac
do_compile meta.o ${FDEFS}
BASE_OBJECTS="meta.o ${BASE_OBJECTS}"
;;
esac
do_link bmake main.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}

View File

@ -1,6 +1,40 @@
/* $NetBSD: config.h,v 1.21 2012/03/31 00:12:24 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -35,11 +69,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)config.h 8.2 (Berkeley) 4/28/95
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
*/
#define DEFSHELL 1 /* Bourne shell */
/*
* DEFMAXJOBS
* DEFMAXLOCAL
@ -78,15 +110,53 @@
* re-made, causing later targets to appear up-to-date. On systems
* that don't have this problem, you should defined this. Under
* NFS you probably should not, unless you aren't exporting jobs.
*
* POSIX
* If the POSIX standard for Make is to be followed. There are
* several areas that I dislike, hence this constant.
*/
#define LIBSUFF ".a"
#define RECHECK
#ifndef RANLIBMAG
#define RANLIBMAG "__.SYMDEF"
/*
* POSIX
* Adhere to the POSIX 1003.2 draft for the make(1) program.
* - Use MAKEFLAGS instead of MAKE to pick arguments from the
* environment.
* - Allow empty command lines if starting with tab.
*/
#define POSIX
/*
* SYSVINCLUDE
* Recognize system V like include directives [include "filename"]
* SYSVVARSUB
* Recognize system V like ${VAR:x=y} variable substitutions
*/
#define SYSVINCLUDE
#define SYSVVARSUB
/*
* GMAKEEXPORT
* Recognize gmake like variable export directives [export <VAR>=<VALUE>]
*/
#define GMAKEEXPORT
/*
* SUNSHCMD
* Recognize SunOS and Solaris:
* VAR :sh= CMD # Assign VAR to the command substitution of CMD
* ${VAR:sh} # Return the command substitution of the value
* # of ${VAR}
*/
#define SUNSHCMD
/*
* USE_IOVEC
* We have writev(2)
*/
#ifdef HAVE_SYS_UIO_H
# define USE_IOVEC
#endif
#if defined(MAKE_NATIVE) && !defined(__ELF__)
# ifndef RANLIBMAG
# define RANLIBMAG "__.SYMDEF"
# endif
#endif
/*#define POSIX*/

2061
make.1 Normal file

File diff suppressed because it is too large Load Diff

1561
make.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,40 @@
/* $NetBSD: make.h,v 1.88 2012/06/04 20:34:20 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)make.h 8.3 (Berkeley) 6/13/95
*/
/*
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -35,7 +69,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)make.h 8.3 (Berkeley) 6/13/95
* from: @(#)make.h 8.3 (Berkeley) 6/13/95
*/
/*-
@ -46,27 +80,63 @@
#ifndef _MAKE_H_
#define _MAKE_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <ctype.h>
#ifndef MAKE_BOOTSTRAP
#include <sys/cdefs.h>
#else
#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos /* full-blown ANSI C */
#else
#define __P(protos) () /* traditional C preprocessor */
#endif
#endif
#if __STDC__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <unistd.h>
#include <sys/cdefs.h>
#if !defined(__GNUC_PREREQ__)
#if defined(__GNUC__)
#define __GNUC_PREREQ__(x, y) \
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
(__GNUC__ > (x)))
#else /* defined(__GNUC__) */
#define __GNUC_PREREQ__(x, y) 0
#endif /* defined(__GNUC__) */
#endif /* !defined(__GNUC_PREREQ__) */
#if !defined(__unused)
#if __GNUC_PREREQ__(2, 7)
#define __unused __attribute__((__unused__))
#else
#define __unused /* delete */
#endif
#endif
#if !defined(__dead)
#define __dead
#endif
#include "sprite.h"
#include "lst.h"
#include "config.h"
#include "hash.h"
#include "make-conf.h"
#include "buf.h"
#include "make_malloc.h"
/*
* some vendors don't have this --sjg
*/
#if defined(S_IFDIR) && !defined(S_ISDIR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#if defined(sun) && (defined(__svr4__) || defined(__SVR4))
#define POSIX_SIGNALS
#endif
/*-
* The structure for an individual graph node. Each node has several
@ -80,80 +150,90 @@
* 7) the number of its children that are, as yet, unmade
* 8) its modification time
* 9) the modification time of its youngest child (qv. make.c)
* 10) a list of nodes for which this is a source
* 11) a list of nodes on which this depends
* 10) a list of nodes for which this is a source (parents)
* 11) a list of nodes on which this depends (children)
* 12) a list of nodes that depend on this, as gleaned from the
* transformation rules.
* 13) a list of nodes of the same name created by the :: operator
* 14) a list of nodes that must be made (if they're made) before
* this node can be, but that do no enter into the datedness of
* transformation rules (iParents)
* 13) a list of ancestor nodes, which includes parents, iParents,
* and recursive parents of parents
* 14) a list of nodes of the same name created by the :: operator
* 15) a list of nodes that must be made (if they're made) before
* this node can be, but that do not enter into the datedness of
* this node.
* 15) a list of nodes that must be made (if they're made) after
* 16) a list of nodes that must be made (if they're made) before
* this node or any child of this node can be, but that do not
* enter into the datedness of this node.
* 17) a list of nodes that must be made (if they're made) after
* this node is, but that do not depend on this node, in the
* normal sense.
* 16) a Lst of ``local'' variables that are specific to this target
* 18) a Lst of ``local'' variables that are specific to this target
* and this target only (qv. var.c [$@ $< $?, etc.])
* 17) a Lst of strings that are commands to be given to a shell
* to create this target.
* 19) a Lst of strings that are commands to be given to a shell
* to create this target.
*/
typedef struct GNode {
char *name; /* The target's name */
char *uname; /* The unexpanded name of a .USE node */
char *path; /* The full pathname of the file */
int type; /* Its type (see the OP flags, below) */
Boolean make; /* TRUE if this target needs to be remade */
enum {
UNMADE, BEINGMADE, MADE, UPTODATE, ERROR, ABORTED,
CYCLE, ENDCYCLE,
int flags;
#define REMAKE 0x1 /* this target needs to be (re)made */
#define CHILDMADE 0x2 /* children of this target were made */
#define FORCE 0x4 /* children don't exist, and we pretend made */
#define DONE_WAIT 0x8 /* Set by Make_ProcessWait() */
#define DONE_ORDER 0x10 /* Build requested by .ORDER processing */
#define FROM_DEPEND 0x20 /* Node created from .depend */
#define DONE_ALLSRC 0x40 /* We do it once only */
#define CYCLE 0x1000 /* Used by MakePrintStatus */
#define DONECYCLE 0x2000 /* Used by MakePrintStatus */
enum enum_made {
UNMADE, DEFERRED, REQUESTED, BEINGMADE,
MADE, UPTODATE, ERROR, ABORTED
} made; /* Set to reflect the state of processing
* on this node:
* UNMADE - Not examined yet
* DEFERRED - Examined once (building child)
* REQUESTED - on toBeMade list
* BEINGMADE - Target is already being made.
* Indicates a cycle in the graph. (compat
* mode only)
* Indicates a cycle in the graph.
* MADE - Was out-of-date and has been made
* UPTODATE - Was already up-to-date
* ERROR - An error occured while it was being
* ERROR - An error occurred while it was being
* made (used only in compat mode)
* ABORTED - The target was aborted due to
* an error making an inferior (compat).
* CYCLE - Marked as potentially being part of
* a graph cycle. If we come back to a
* node marked this way, it is printed
* and 'made' is changed to ENDCYCLE.
* ENDCYCLE - the cycle has been completely
* printed. Go back and unmark all its
* members.
*/
Boolean childMade; /* TRUE if one of this target's children was
* made */
int unmade; /* The number of unmade children */
int mtime; /* Its modification time */
int cmtime; /* The modification time of its youngest
* child */
time_t mtime; /* Its modification time */
struct GNode *cmgn; /* The youngest child */
Lst iParents; /* Links to parents for which this is an
* implied source, if any */
Lst cohorts; /* Other nodes for the :: operator */
Lst parents; /* Nodes that depend on this one */
Lst children; /* Nodes on which this one depends */
Lst successors; /* Nodes that must be made after this one */
Lst preds; /* Nodes that must be made before this one */
Lst order_pred; /* .ORDER nodes we need made */
Lst order_succ; /* .ORDER nodes who need us */
Lst context; /* The local variables */
char cohort_num[8]; /* #n for this cohort */
int unmade_cohorts;/* # of unmade instances on the
cohorts list */
struct GNode *centurion; /* Pointer to the first instance of a ::
node; only set when on a cohorts list */
unsigned int checked; /* Last time we tried to makle this node */
Hash_Table context; /* The local variables */
Lst commands; /* Creation commands */
struct _Suff *suffix; /* Suffix for the node (determined by
* Suff_FindDeps and opaque to everyone
* but the Suff module) */
const char *fname; /* filename where the GNode got defined */
int lineno; /* line number where the GNode got defined */
} 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
@ -161,7 +241,7 @@ typedef struct GNode {
* placed in the 'type' field of each node. Any node that has
* a 'type' field which satisfies the OP_NOP function was never never on
* the lefthand side of an operator, though it may have been on the
* righthand side...
* righthand side...
*/
#define OP_DEPENDS 0x00000001 /* Execution of commands depends on
* kids (:) */
@ -181,18 +261,27 @@ typedef struct GNode {
#define OP_PRECIOUS 0x00000080 /* Don't remove the target when
* interrupted */
#define OP_SILENT 0x00000100 /* Don't echo commands when executed */
#define OP_MAKE 0x00000200 /* Target is a recurrsive make so its
#define OP_MAKE 0x00000200 /* Target is a recursive make so its
* commands should always be executed when
* it is out of date, regardless of the
* state of the -n or -t flags */
#define OP_JOIN 0x00000400 /* Target is out-of-date only if any of its
* children was out-of-date */
#define OP_MADE 0x00000800 /* Assume the children of the node have
* been already made */
#define OP_SPECIAL 0x00001000 /* Special .BEGIN, .END, .INTERRUPT */
#define OP_USEBEFORE 0x00002000 /* Like .USE, only prepend commands */
#define OP_INVISIBLE 0x00004000 /* The node is invisible to its parents.
* I.e. it doesn't show up in the parents's
* local variables. */
#define OP_NOTMAIN 0x00008000 /* The node is exempt from normal 'main
* target' processing in parse.c */
#define OP_PHONY 0x00010000 /* Not a file target; run always */
#define OP_NOPATH 0x00020000 /* Don't search for file in the path */
#define OP_WAIT 0x00040000 /* .WAIT phony node */
#define OP_NOMETA 0x00080000 /* .NOMETA do not create a .meta file */
#define OP_META 0x00100000 /* .META we _do_ want a .meta file */
#define OP_NOMETA_CMP 0x00200000 /* Do not compare commands in .meta file */
/* Attributes applied by PMake */
#define OP_TRANSFORM 0x80000000 /* The node is a transformation rule */
#define OP_MEMBER 0x40000000 /* Target is a member of an archive */
@ -203,34 +292,28 @@ typedef struct GNode {
* commands for a target */
#define OP_SAVE_CMDS 0x04000000 /* Saving commands on .END (Compat) */
#define OP_DEPS_FOUND 0x02000000 /* Already processed by Suff_FindDeps */
#define OP_MARK 0x01000000 /* Node found while expanding .ALLSRC */
#define NoExecute(gn) ((gn->type & OP_MAKE) ? noRecursiveExecute : noExecute)
/*
* OP_NOP will return TRUE if the node with the given type was not the
* object of a dependency operator
*/
#define OP_NOP(t) (((t) & OP_OPMASK) == 0x00000000)
#define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
/*
* The TARG_ constants are used when calling the Targ_FindNode and
* Targ_FindList functions in targ.c. They simply tell the functions what to
* 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_CREATE 0x01 /* create node if not found */
#define TARG_NOCREATE 0x00 /* don't create it */
/*
* There are several places where expandable buffers are used (parse.c and
* var.c). This constant is merely the starting point for those buffers. If
* lines tend to be much shorter than this, it would be best to reduce BSIZE.
* If longer, it should be increased. Reducing it will cause more copying to
* be done for longer lines, but will save space for shorter ones. In any
* case, it ought to be a power of two simply because most storage allocation
* schemes allocate in powers of two.
*/
#define MAKE_BSIZE 256 /* starting size for expandable buffers */
#define TARG_CREATE 0x01 /* create node if not found */
#define TARG_NOHASH 0x02 /* don't look in/add to hash table */
/*
* These constants are all used by the Str_Concat function to decide how the
@ -239,11 +322,10 @@ typedef struct GNode {
* be used instead of a space. If neither is given, no intervening characters
* will be placed between the two strings in the final output. If the
* STR_DOFREE bit is set, the two input strings will be freed before
* Str_Concat returns.
* Str_Concat returns.
*/
#define STR_ADDSPACE 0x01 /* add a space when Str_Concat'ing */
#define STR_DOFREE 0x02 /* free source strings after concatenation */
#define STR_ADDSLASH 0x04 /* add a slash when Str_Concat'ing */
#define STR_ADDSLASH 0x02 /* add a slash when Str_Concat'ing */
/*
* Error levels for parsing. PARSE_FATAL means the process cannot continue
@ -279,7 +361,7 @@ typedef struct GNode {
#define DPREFIX "*D" /* directory part of PREFIX */
/*
* Global Variables
* Global Variables
*/
extern Lst create; /* The list of target names specified on the
* command line. used to resolve #if
@ -291,28 +373,34 @@ extern Boolean compatMake; /* True if we are make compatible */
extern Boolean ignoreErrors; /* True if should ignore all errors */
extern Boolean beSilent; /* True if should print no commands */
extern Boolean noExecute; /* True if should execute nothing */
extern Boolean noRecursiveExecute; /* True if should execute nothing */
extern Boolean allPrecious; /* True if every target is precious */
extern Boolean keepgoing; /* True if should continue on unaffected
* portions of the graph when have an error
* in one portion */
extern Boolean touchFlag; /* TRUE if targets should just be 'touched'
* if out of date. Set by the -t flag */
extern Boolean usePipes; /* TRUE if should capture the output of
* subshells by means of pipes. Otherwise it
* is routed to temporary files from which it
* is retrieved when the shell exits */
extern Boolean queryFlag; /* TRUE if we aren't supposed to really make
* anything, just see if the targets are out-
* of-date */
extern Boolean doing_depend; /* TRUE if processing .depend */
extern Boolean checkEnvFirst; /* TRUE if environment should be searched for
* variables before the global context */
extern Boolean jobServer; /* a jobServer already exists */
extern Boolean parseWarnFatal; /* TRUE if makefile parsing warnings are
* treated as errors */
extern Boolean varNoExportEnv; /* TRUE if we should not export variables
* set on the command line to the env. */
extern GNode *DEFAULT; /* .DEFAULT rule */
extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g
* in the Makefile itself */
extern GNode *VAR_CMD; /* Variables defined on the command line */
extern GNode *VAR_FOR; /* Iteration variables */
extern char var_Error[]; /* Value returned by Var_Parse when an error
* is encountered. It actually points to
* an empty string, so naive callers needn't
@ -323,44 +411,101 @@ extern time_t now; /* The time at the start of this whole
extern Boolean oldVars; /* Do old-style variable substitution */
extern Lst sysIncPath; /* The system include path. */
extern Lst defIncPath; /* The default include path. */
extern char curdir[]; /* Startup directory */
extern char *progname; /* The program name */
extern char *makeDependfile; /* .depend */
extern char **savedEnv; /* if we replaced environ this will be non-NULL */
/*
* We cannot vfork() in a child of vfork().
* Most systems do not enforce this but some do.
*/
#define vFork() ((getpid() == myPid) ? vfork() : fork())
extern pid_t myPid;
#define MAKEFLAGS ".MAKEFLAGS"
#define MAKEOVERRIDES ".MAKEOVERRIDES"
#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 */
#define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
#define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
#define MAKE_MODE ".MAKE.MODE"
#ifdef NEED_MAKE_LEVEL_SAFE
# define MAKE_LEVEL_SAFE "_MAKE_LEVEL" /* some shells will not pass .MAKE. */
#endif
/*
* debug control:
* There is one bit per module. It is up to the module what debug
* information to print.
*/
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_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_META 0x04000
#define DEBUG_GRAPH3 0x10000
#define DEBUG_SCRIPT 0x20000
#define DEBUG_PARSE 0x40000
#define DEBUG_CWD 0x80000
#ifdef __STDC__
#define CONCAT(a,b) a##b
#else
#define I(a) a
#define CONCAT(a,b) I(a)b
#endif /* __STDC__ */
#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 __P((GNode *, GNode *));
Boolean Make_OODate __P((GNode *));
int Make_HandleUse __P((GNode *, GNode *));
void Make_Update __P((GNode *));
void Make_DoAllVar __P((GNode *));
Boolean Make_Run __P((Lst));
int Make_TimeStamp(GNode *, GNode *);
Boolean Make_OODate(GNode *);
void Make_ExpandUse(Lst);
time_t Make_Recheck(GNode *);
void Make_HandleUse(GNode *, GNode *);
void Make_Update(GNode *);
void Make_DoAllVar(GNode *);
Boolean Make_Run(Lst);
char * Check_Cwd_Cmd(const char *);
void Check_Cwd(const char **);
void PrintOnError(GNode *, const char *);
void Main_ExportMAKEFLAGS(Boolean);
Boolean Main_SetObjdir(const char *);
int mkTempFile(const char *, char **);
int str2Lst_Append(Lst, char *, const char *);
#ifdef __GNUC__
#define UNCONST(ptr) ({ \
union __unconst { \
const void *__cp; \
void *__p; \
} __d; \
__d.__cp = ptr, __d.__p; })
#else
#define UNCONST(ptr) (void *)(ptr)
#endif
#ifndef MIN
#define MIN(a, b) ((a < b) ? a : b)
#endif
#ifndef MAX
#define MAX(a, b) ((a > b) ? a : b)
#endif
#endif /* _MAKE_H_ */

119
make_malloc.c Normal file
View File

@ -0,0 +1,119 @@
/* $NetBSD: make_malloc.c,v 1.7 2012/05/18 02:28:16 sjg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef MAKE_NATIVE
#include <sys/cdefs.h>
__RCSID("$NetBSD: make_malloc.c,v 1.7 2012/05/18 02:28:16 sjg Exp $");
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "make_malloc.h"
#ifndef USE_EMALLOC
/*
* enomem --
* die when out of memory.
*/
extern char *progname;
static void
enomem(void)
{
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(ENOMEM));
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

41
make_malloc.h Normal file
View File

@ -0,0 +1,41 @@
/* $NetBSD: make_malloc.h,v 1.4 2009/01/24 14:43:29 dsl Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef 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

1346
meta.c Normal file

File diff suppressed because it is too large Load Diff

54
meta.h Normal file
View File

@ -0,0 +1,54 @@
/* $NetBSD: meta.h,v 1.2 2011/03/30 22:03:49 sjg Exp $ */
/*
* Things needed for 'meta' mode.
*/
/*
* Copyright (c) 2009-2010, Juniper Networks, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
typedef struct BuildMon {
char meta_fname[MAXPATHLEN];
int filemon_fd;
int mon_fd;
FILE *mfp;
} BuildMon;
extern Boolean useMeta;
struct Job; /* not defined yet */
void meta_init(const char *);
void meta_job_start(struct Job *, GNode *);
void meta_job_child(struct Job *);
void meta_job_error(struct Job *, GNode *, int, int);
void meta_job_output(struct Job *, char *, const char *);
void meta_cmd_finish(void *);
void meta_job_finish(struct Job *);
Boolean meta_oodate(GNode *, Boolean);
void meta_compat_start(void);
void meta_compat_child(void);
void meta_compat_parent(void);

314
mkdeps.sh Executable file
View File

@ -0,0 +1,314 @@
:
# NAME:
# mkdeps - generate dependencies
#
# SYNOPSIS:
# mkdeps [options] file ...
#
# DESCRIPTION:
# This script updates "makefile" with dependencies for
# "file"(s). It borrows ideas from various makedepend scripts
# and should be compatible with most.
#
# By default we use grep to extract include file names from
# source files. We source an "rc" file '$Mydir/.${Myname}rc' which
# can contain variable assignments such as:
#.nf
#
# cpp_c=/usr/lib/cpp
# cpp_cc=g++ -E
# ...
#
#.fi
# If the variable 'cpp_$suffix' is set, we use it as our cpp in
# place of grep. The program referenced by these variables are
# expected to produce output like:
#.nf
#
# # 10 \"/usr/include/stdio.h\" 1
#
#.fi
# This allows us to skip most of our processing. For lex,yacc
# and other source files, grep is probably just as quick and
# certainly more portable.
#
# If the "rc" file does not exist, we create it and attempt to
# find cpp or an equivalent cc invocation to assign to 'cpp_c'.
#
# AUTHOR:
# Simon J. Gerraty <sjg@zen.void.oz.au>
#
# RCSid:
# $Id: mkdeps.sh,v 1.23 2002/11/29 06:58:59 sjg Exp $
#
# @(#) Copyright (c) 1993 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@zen.void.oz.au
#
Myname=`basename $0 .sh`
Mydir=`dirname $0`
case `echo -n .` in
-n*) N=; C="\c";;
*) N=-n; C=;;
esac
cc_include=-I/usr/include
TF=/tmp/dep.$$
EF=/tmp/deperr.$$
> $EF
case "$*" in
*-n*) # don't use rc file
rc=/dev/null
norc=yes;;
*)
rc=$Mydir/.${Myname}rc
;;
esac
update=
Include=include
if [ x"$norc" = x -a -f $rc ]; then
. $rc
else
# if /usr/lib/cpp or equivalent is available it is better than
# grepping .c files.
# See what (if anything) works on this system...
echo : > $rc
echo "# pre-processor for .c files" >> $rc
# try a couple of sane places first
for d in /usr/libexec /usr/lib /usr/bin /lib /usr/ccs/bin
do
cpp_c=$d/cpp
[ -x $cpp_c ] && break
done
if [ -x $cpp_c ]; then
echo cpp_c=$cpp_c >> $rc
else
cpp_c=
# rats see if cc can be used
echo "#include <stdio.h>" > /tmp/f$$.c
echo "main() { return 0; }" >> /tmp/f$$.c
# try some sensible args to cc
for arg in -E -P -M
do
ok=`${REALCC:-${CC:-cc}} $arg /tmp/f$$.c 2>/dev/null | grep '^#.*stdio.h' | tail -1`
case "$ok" in
"") ;;
*)
cpp_c="${REALCC:-${CC:-cc}} $arg"
echo cpp_c="'$cpp_c'" >> $rc
break;;
esac
done
rm -f /tmp/f$$.c
fi
fi
clean_up() {
trap "" 2 3
trap 0
if [ -s $EF ]; then
egrep -vi "included from|warning" $EF > ${EF}2
if [ -s ${EF}2 ]; then
cat $EF >&2
rm -f .depend
ests=1
fi
fi
rm -f $TF $EF*
exit ${ests:-0}
}
# this lot does not work on HPsUX - complain to Hp.
trap clean_up 0
trap exit 2 3
get_incs() {
case "$cpp" in
grep)
# set IGNORE="<" to skip system includes
egrep '^#[ ]*include' $* | egrep -v "$IGNORE" | \
sed -e 's/^.*include[^"<]*["<]//' -e 's/[">].*//g';;
*)
# $cpp (eg. /usr/lib/cpp or cc -E) should produce output like:
# 1 "/usr/include/stdio.h" 2
# set IGNORE=/usr/include to skip system includes
$cpp $cpp_opts $cc_include $* 2>> $EF | egrep '^#.*\.h"' | sed 's,^#.*"\(.*\)".*,\1,' |
egrep -v "$IGNORE" | sort -u;;
esac
}
gen_deps() {
llen=$1
shift
for ifile in $*
do
case "$cpp" in
grep)
# this lot is not needed if not using grep.
for dir in $srcdir $dirlist /usr/include
do
[ -f "$dir/$ifile" ] && break
done
if [ ! -f "$dir/$ifile" ]; then
# produce a useful error message (useful to emacs or error)
iline=`grep -n ".*include.*[\"<]$ifile[\">]" $file | cut -d: -f1`
echo "\"$file\", line $iline: cannot find include file \"$ifile\"" >> $EF
# no point adding to dependency list as the resulting makefile
# would not work anyway...
continue
fi
ifile=$dir/$ifile
# check whether we have done it yet
case `grep "$ifile" $TF` in
"") echo "$ifile" >> $TF;;
*) continue;; # no repeats...
esac
;;
esac
len=`expr "$ifile " : '.*'`
if [ "`expr $llen + $len`" -gt ${width:-76} ]; then
echo "\\" >> .depend
echo $N " $C" >> .depend
llen=8
fi
echo $N "$ifile $C" >> .depend
llen=`expr $llen + $len`
case "$cpp" in
grep)
# this lot is not needed unless using grep.
ilist=`get_incs $ifile` # recurse needed?
[ "$ilist" ] && llen=`gen_deps $llen $ilist`
;;
esac
done
echo $llen
}
for f in makefile Makefile
do
test -s $f && { MAKEFILE=$f; break; }
done
MAKEFILE=${MAKEFILE:-makefile}
IGNORE=${IGNORE:-"^-"} # won't happen
obj=o
cpp_opts= # incase cpp != grep
vpath=
append=
progDep=
set -- `getopt "AanNV:s:w:o:I:D:b:f:i:p" "$@"`
for key in "$@"
do
case $key in
--) shift; break;;
-A) Include=;; # cat .depend >> $MAKEFILE
-a) append=yes; shift;;
-n) shift;; # ignore rc
-N) update=no; shift;; # don't update $MAKEFILE
-I) cpp_opts="$cpp_opts$1$2 "; dirlist="$dirlist $2"; shift 2;;
-o) obj=$2; shift 2;;
-s) shift 2;; # can't handle it anyway...
-w) width=$2; shift 2;;
-f) MAKEFILE=$2; shift 2;;
-b) BASEDIR=$2; shift 2;;
-i) IGNORE="$2"; shift 2;; # ignore headers matching this...
-D) cpp_opts="$cpp_opts$1$2 "; shift 2;;
-V) VPATH="$2"; shift 2;; # where to look for files
-p) progDep=yes; shift;;
esac
done
[ "$VPATH" ] && vpath=`IFS=:; set -- $VPATH; echo $*`
[ "$append" ] || > .depend
for file in $*
do
cpp=
suffix=`expr $file : '.*\.\([^.]*\)'`
eval cpp=\"\${cpp_${suffix}:-grep}\"
if [ ! -f $file -a "$vpath" ]; then
for d in . $vpath
do
[ -f $d/$file ] && { file=$d/$file; break; }
done
fi
srcdir=`dirname $file`
base=`basename $file .$suffix`
ilist=`get_incs $file`
if [ "$ilist" ]; then
> $TF
if [ "$progDep" ]; then
echo "$base: $file \\" >> .depend
else
echo "$base.$obj: $file \\" >> .depend
fi
echo $N " $C" >> .depend
llen=8
llen=`gen_deps $llen $ilist`
echo >> .depend
echo >> .depend
elif [ "$progDep" ]; then
echo "$base: $file" >> .depend
echo >> .depend
fi
done
if [ -s .depend ]; then
# ./foo.h looks ugly
mv .depend $TF
{ test "$BASEDIR" && sed -e "s;$BASEDIR;\$(BASEDIR);g" $TF || cat $TF; } |
sed 's;\([^.]\)\./;\1;g' > .depend
#
# Save the manually updated section of the makefile
#
if [ x$update != xno ]; then
trap "" 2 # don't die if we got this far
# if make doesn't support include, then append our deps...
depended=`grep 'include.*\.depend' $MAKEFILE`
test "$depended" && clean_up
sed '/^# DO NOT DELETE.*depend.*$/,$d' < $MAKEFILE > $TF
mv $TF $MAKEFILE
cat <<! >> $MAKEFILE
# DO NOT DELETE THIS LINE -- make depend depends on it
# Do not edit anything below, it was added automagically by $Myname.
!
case "$Include" in
"") cat .depend >> $MAKEFILE;;
.include) echo '.include ".depend"' >> $MAKEFILE;;
include) echo include .depend >> $MAKEFILE;;
esac
fi
fi
clean_up

206
nonints.h Normal file
View File

@ -0,0 +1,206 @@
/* $NetBSD: nonints.h,v 1.63 2011/09/16 15:38:04 joerg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)nonints.h 8.3 (Berkeley) 3/19/94
*/
/*-
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)nonints.h 8.3 (Berkeley) 3/19/94
*/
#ifndef MAKE_NATIVE
#undef __attribute__
#define __attribute__(x)
#endif
/* arch.c */
ReturnStatus Arch_ParseArchive(char **, Lst, GNode *);
void Arch_Touch(GNode *);
void Arch_TouchLib(GNode *);
time_t Arch_MTime(GNode *);
time_t Arch_MemMTime(GNode *);
void Arch_FindLib(GNode *, Lst);
Boolean Arch_LibOODate(GNode *);
void Arch_Init(void);
void Arch_End(void);
int Arch_IsLib(GNode *);
/* compat.c */
int CompatRunCommand(void *, void *);
void Compat_Run(Lst);
int Compat_Make(void *, void *);
/* cond.c */
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);
/* job.c */
#ifdef WAIT_T
void JobReapChild(pid_t, WAIT_T, Boolean);
#endif
/* main.c */
void Main_ParseArgLine(const char *);
void MakeMode(const char *);
int main(int, char **);
char *Cmd_Exec(const char *, const char **);
void Error(const char *, ...) __attribute__((__format__(__printf__, 1, 2)));
void Fatal(const char *, ...)
__attribute__((__format__(__printf__, 1, 2),__noreturn__));
void Punt(const char *, ...)
__attribute__((__format__(__printf__, 1, 2),__noreturn__));
void DieHorribly(void) __attribute__((__noreturn__));
int PrintAddr(void *, void *);
void Finish(int) __dead;
int eunlink(const char *);
void execError(const char *, const char *);
char *getTmpdir(void);
/* parse.c */
void Parse_Error(int, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
Boolean Parse_AnyExport(void);
Boolean Parse_IsVar(char *);
void Parse_DoVar(char *, GNode *);
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 *, size_t *), void *);
Lst Parse_MainName(void);
/* str.c */
char *str_concat(const char *, const char *, int);
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);
/* suff.c */
void Suff_ClearSuffixes(void);
Boolean Suff_IsTransform(char *);
GNode *Suff_AddTransform(char *);
int Suff_EndTransform(void *, void *);
void Suff_AddSuffix(char *, GNode **);
Lst Suff_GetPath(char *);
void Suff_DoPaths(void);
void Suff_AddInclude(char *);
void Suff_AddLib(char *);
void Suff_FindDeps(GNode *);
Lst Suff_FindPath(GNode *);
void Suff_SetNull(char *);
void Suff_Init(void);
void Suff_End(void);
void Suff_PrintAll(void);
/* targ.c */
void Targ_Init(void);
void Targ_End(void);
Lst Targ_List(void);
GNode *Targ_NewGN(const char *);
GNode *Targ_FindNode(const char *, int);
Lst Targ_FindList(Lst, int);
Boolean Targ_Ignore(GNode *);
Boolean Targ_Silent(GNode *);
Boolean Targ_Precious(GNode *);
void Targ_SetMain(GNode *);
int Targ_PrintCmd(void *, void *);
int Targ_PrintNode(void *, void *);
char *Targ_FmtTime(time_t);
void Targ_PrintType(int);
void Targ_PrintGraph(int);
void Targ_Propagate(void);
void Targ_Propagate_Wait(void);
/* var.c */
void Var_Delete(const char *, GNode *);
void Var_Set(const char *, const char *, GNode *, int);
void Var_Append(const char *, const char *, GNode *);
Boolean Var_Exists(const char *, GNode *);
char *Var_Value(const char *, GNode *, char **);
char *Var_Parse(const char *, GNode *, Boolean, int *, void **);
char *Var_Subst(const char *, const char *, GNode *, Boolean);
char *Var_GetTail(const char *);
char *Var_GetHead(const char *);
void Var_Init(void);
void Var_End(void);
void Var_Dump(GNode *);
void Var_ExportVars(void);
void Var_Export(char *, int);
void Var_UnExport(char *);
/* util.c */
void (*bmake_signal(int, void (*)(int)))(int);

228
os.sh Executable file
View File

@ -0,0 +1,228 @@
:
# NAME:
# os.sh - operating system specifics
#
# DESCRIPTION:
# This file is included at the start of processing. Its role is
# to set the variables OS, OSREL, OSMAJOR, MACHINE and MACHINE_ARCH to
# reflect the current system.
#
# It also sets variables such as MAILER, LOCAL_FS, PS_AXC to hide
# certain aspects of different UNIX flavours.
#
# SEE ALSO:
# site.sh,funcs.sh
#
# AUTHOR:
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: os.sh,v 1.44 2010/06/29 15:37:21 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@crufty.net
#
# this lets us skip sourcing it again
_OS_SH=:
OS=`uname`
OSREL=`uname -r`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
MACHINE=`uname -m`
MACHINE_ARCH=`uname -p 2>/dev/null || echo $MACHINE`
# there is at least one case of `uname -p` outputting
# a bunch of usless drivel
case "$MACHINE_ARCH" in
*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";;
esac
# we need this here, and it is not always available...
Which() {
case "$1" in
-*) t=$1; shift;;
*) t=-x;;
esac
case "$1" in
/*) test $t $1 && echo $1;;
*)
# some shells cannot correctly handle `IFS`
# in conjunction with the for loop.
_dirs=`IFS=:; echo ${2:-$PATH}`
for d in $_dirs
do
test $t $d/$1 && { echo $d/$1; break; }
done
;;
esac
}
# tr is insanely non-portable wrt char classes, so we need to
# spell out the alphabet. sed y/// would work too.
toUpper() {
${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}
toLower() {
${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}
K=
case $OS in
AIX) # everyone loves to be different...
OSMAJOR=`uname -v`
OSREL="$OSMAJOR.`uname -r`"
LOCAL_FS=jfs
PS_AXC=-e
SHARE_ARCH=$OS/$OSMAJOR.X
;;
SunOS)
CHOWN=`Which chown /usr/etc:/usr/bin`
export CHOWN
# Great! Solaris keeps moving arch(1)
# should just bite the bullet and use uname -p
arch=`Which arch /usr/bin:/usr/ucb`
MAILER=/usr/ucb/Mail
LOCAL_FS=4.2
case "$OSREL" in
4.0*)
# uname -m just says sun which could be anything
# so use arch(1).
MACHINE_ARCH=`arch`
MACHINE=$MACHINE_ARCH
;;
4*)
MACHINE_ARCH=`arch`
;;
5*)
K=-k
LOCAL_FS=ufs
MAILER=mailx
PS_AXC=-e
# can you believe that ln on Solaris defaults to
# overwriting an existing file!!!!! We want one that works!
test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
# wonderful, 5.8's tr again require's []'s
# but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
# use toUpper/toLower instead.
;;
esac
case "$OS/$MACHINE_ARCH" in
*sun386) SHARE_ARCH=$MACHINE_ARCH;;
esac
;;
*BSD)
K=-k
MAILER=/usr/bin/Mail
LOCAL_FS=local
case "$-" in
*i*) ;;
*) ENV=;;
esac
# NetBSD at least has good backward compatability
# so NetBSD/i386 is good enough
case $OS in
NetBSD) SHARE_ARCH=$OS/${MACHINE_ARCH:-$MACHINE};;
OpenBSD)
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
MACHINE_ARCH=`$arch -s`
;;
esac
NAWK=awk
export NAWK
;;
HP-UX)
TMP_DIRS="/tmp /usr/tmp"
LOCAL_FS=hfs
MAILER=mailx
# don't rely on /bin/sh, its broken
_shell=/bin/ksh; ENV=
# also, no one would be interested in OSMAJOR=A
case "$OSREL" in
?.09*) OSMAJOR=9; PS_AXC=-e;;
?.10*) OSMAJOR=10; PS_AXC=-e;;
esac
;;
IRIX)
LOCAL_FS=efs
;;
Interix)
MACHINE=i386
MACHINE_ARCH=i386
;;
UnixWare)
OSREL=`uname -v`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
MACHINE_ARCH=`uname -m`
;;
Linux)
# Not really any such thing as Linux, but
# this covers red-hat and hopefully others.
case $MACHINE in
i?86) MACHINE_ARCH=i386;; # we don't care about i686 vs i586
esac
LOCAL_FS=ext2
PS_AXC=axc
[ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
;;
QNX)
case $MACHINE in
x86pc) MACHINE_ARCH=i386;;
esac
;;
Haiku)
case $MACHINE in
BeBox) MACHINE_ARCH=powerpc;;
BeMac) MACHINE_ARCH=powerpc;;
BePC) MACHINE_ARCH=i386;;
esac
;;
esac
HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
case "$HOSTNAME" in
*.*) HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
*) HOST=$HOSTNAME;;
esac
TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
# we mount server:/share/arch/$SHARE_ARCH as /usr/local
SHARE_ARCH=${SHARE_ARCH:-$OS/$OSMAJOR.X/$MACHINE_ARCH}
LN=${LN:-ln}
TR=${TR:-tr}
# Some people like have /share/$HOST_TARGET/bin etc.
HOST_TARGET=`echo ${OS}${OSMAJOR}-${MACHINE_ARCH} | toLower`
export HOST_TARGET
case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
export HOSTNAME HOST
export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
export LN SHARE_ARCH TR
case /$0 in
*/os.sh)
for v in $*
do
eval vv=\$$v
echo "$v='$vv'"
done
;;
esac

3122
parse.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,5 @@
/* $NetBSD: pathnames.h,v 1.17 2009/04/11 09:41:18 apb Exp $ */
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -10,11 +12,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -30,10 +28,35 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pathnames.h 8.2 (Berkeley) 4/28/95
* from: @(#)pathnames.h 5.2 (Berkeley) 6/1/90
* $Id: pathnames.h,v 1.13 2009/08/26 23:43:42 sjg Exp $
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef MAKE_NATIVE
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#endif
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
#define _PATH_OBJDIR "obj"
#define _PATH_OBJDIRPREFIX "/usr/obj"
#ifndef _PATH_DEFSHELLDIR
#define _PATH_DEFSHELLDIR "/bin"
#endif
#define _PATH_DEFSYSMK "sys.mk"
#define _PATH_DEFSYSPATH "/usr/share/mk"
#define _path_defsyspath "/usr/share/mk:/usr/local/share/mk:/opt/share/mk"
#ifndef _PATH_DEFSYSPATH
# ifdef _PATH_PREFIX_SYSPATH
# define _PATH_DEFSYSPATH _PATH_PREFIX_SYSPATH ":" _path_defsyspath
# else
# define _PATH_DEFSYSPATH _path_defsyspath
# endif
#endif
#ifndef _PATH_TMP
#define _PATH_TMP "/tmp/" /* with trailing slash */
#endif

32
ranlib.h Normal file
View File

@ -0,0 +1,32 @@
/* @(#)ranlib.h 1.6 88/08/19 SMI; from UCB 4.1 83/05/03 */
/* $Id: ranlib.h,v 1.5 2005/11/01 02:35:15 sjg Exp $ */
/*
* Structure of the __.SYMDEF table of contents for an archive.
* __.SYMDEF begins with a word giving the number of ranlib structures
* which immediately follow, and then continues with a string
* table consisting of a word giving the number of bytes of strings
* which follow and then the strings themselves.
* The ran_strx fields index the string table whose first byte is numbered 0.
*/
#if !defined(IRIX) && !defined(__digital__) && !defined(__osf__)
#ifndef _ranlib_h
#define _ranlib_h
#if 0
#define RANLIBMAG "!<arch>\n__.SYMDEF" /* archive file name */
#endif
#define RANLIBMAG "__.SYMDEF" /* archive file name */
#define RANLIBSKEW 3 /* creation time offset */
struct ranlib {
union {
off_t ran_strx; /* string table index of */
char *ran_name; /* symbol defined by */
} ran_un;
off_t ran_off; /* library member at this offset */
};
#endif /*!_ranlib_h*/
#endif

196
realpath.c Normal file
View File

@ -0,0 +1,196 @@
/* $Id: realpath.c,v 1.2 2010/04/21 17:47:49 sjg Exp $ */
/* from: $NetBSD: getcwd.c,v 1.45 2007/10/26 19:48:14 christos Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1995
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef HAVE_REALPATH
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
/*
* char *realpath(const char *path, char resolved[MAXPATHLEN]);
*
* Find the real name of path, by removing all ".", ".." and symlink
* components. Returns (resolved) on success, or (NULL) on failure,
* in which case the path which caused trouble is left in (resolved).
*/
char *
realpath(const char *path, char *resolved)
{
struct stat sb;
int idx = 0, n, nlnk = 0;
const char *q;
char *p, wbuf[2][MAXPATHLEN];
size_t len;
if (!path || !resolved || path == resolved)
return (NULL);
/*
* Build real path one by one with paying an attention to .,
* .. and symbolic link.
*/
/*
* `p' is where we'll put a new component with prepending
* a delimiter.
*/
p = resolved;
if (*path == 0) {
*p = 0;
errno = ENOENT;
return (NULL);
}
/* If relative path, start from current working directory. */
if (*path != '/') {
/* check for resolved pointer to appease coverity */
if (resolved && getcwd(resolved, MAXPATHLEN) == NULL) {
p[0] = '.';
p[1] = 0;
return (NULL);
}
len = strlen(resolved);
if (len > 1)
p += len;
}
loop:
/* Skip any slash. */
while (*path == '/')
path++;
if (*path == 0) {
if (p == resolved)
*p++ = '/';
*p = 0;
return (resolved);
}
/* Find the end of this component. */
q = path;
do
q++;
while (*q != '/' && *q != 0);
/* Test . or .. */
if (path[0] == '.') {
if (q - path == 1) {
path = q;
goto loop;
}
if (path[1] == '.' && q - path == 2) {
/* Trim the last component. */
if (p != resolved)
while (*--p != '/')
;
path = q;
goto loop;
}
}
/* Append this component. */
if (p - resolved + 1 + q - path + 1 > MAXPATHLEN) {
errno = ENAMETOOLONG;
if (p == resolved)
*p++ = '/';
*p = 0;
return (NULL);
}
p[0] = '/';
memcpy(&p[1], path,
/* LINTED We know q > path. */
q - path);
p[1 + q - path] = 0;
/*
* If this component is a symlink, toss it and prepend link
* target to unresolved path.
*/
if (lstat(resolved, &sb) == -1) {
return (NULL);
}
if (S_ISLNK(sb.st_mode)) {
if (nlnk++ >= MAXSYMLINKS) {
errno = ELOOP;
return (NULL);
}
n = readlink(resolved, wbuf[idx], sizeof(wbuf[0]) - 1);
if (n < 0)
return (NULL);
if (n == 0) {
errno = ENOENT;
return (NULL);
}
/* Append unresolved path to link target and switch to it. */
if (n + (len = strlen(q)) + 1 > sizeof(wbuf[0])) {
errno = ENAMETOOLONG;
return (NULL);
}
memcpy(&wbuf[idx][n], q, len + 1);
path = wbuf[idx];
idx ^= 1;
/* If absolute symlink, start from root. */
if (*path == '/')
p = resolved;
goto loop;
}
if (*q == '/' && !S_ISDIR(sb.st_mode)) {
errno = ENOTDIR;
return (NULL);
}
/* Advance both resolved and unresolved path. */
p += 1 + q - path;
path = q;
goto loop;
}
#endif

154
setenv.c Normal file
View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE_SETENV
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)setenv.c 5.6 (Berkeley) 6/4/91";*/
static char *rcsid = "$Id: setenv.c,v 1.5 1996/09/04 22:10:42 sjg Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/*
* __findenv --
* Returns pointer to value associated with name, if any, else NULL.
* Sets offset to be the offset of the name/value combination in the
* environmental array, for use by setenv(3) and unsetenv(3).
* Explicitly removes '=' in argument name.
*
* This routine *should* be a static; don't use it.
*/
static char *
__findenv(name, offset)
register char *name;
int *offset;
{
extern char **environ;
register int len;
register char **P, *C;
for (C = name, len = 0; *C && *C != '='; ++C, ++len);
for (P = environ; *P; ++P)
if (!strncmp(*P, name, len))
if (*(C = *P + len) == '=') {
*offset = P - environ;
return(++C);
}
return(NULL);
}
/*
* setenv --
* Set the value of the environmental variable "name" to be
* "value". If rewrite is set, replace any current value.
*/
setenv(name, value, rewrite)
register const char *name;
register const char *value;
int rewrite;
{
extern char **environ;
static int alloced; /* if allocated space before */
register char *C;
int l_value, offset;
char *__findenv();
if (*value == '=') /* no `=' in value */
++value;
l_value = strlen(value);
if ((C = __findenv(name, &offset))) { /* find if already exists */
if (!rewrite)
return (0);
if (strlen(C) >= l_value) { /* old larger; copy over */
while (*C++ = *value++);
return (0);
}
} else { /* create new slot */
register int cnt;
register char **P;
for (P = environ, cnt = 0; *P; ++P, ++cnt);
if (alloced) { /* just increase size */
environ = (char **)realloc((char *)environ,
(size_t)(sizeof(char *) * (cnt + 2)));
if (!environ)
return (-1);
}
else { /* get new space */
alloced = 1; /* copy old entries into it */
P = (char **)malloc((size_t)(sizeof(char *) *
(cnt + 2)));
if (!P)
return (-1);
bcopy(environ, P, cnt * sizeof(char *));
environ = P;
}
environ[cnt + 1] = NULL;
offset = cnt;
}
for (C = (char *)name; *C && *C != '='; ++C); /* no `=' in name */
if (!(environ[offset] = /* name + `=' + value */
malloc((size_t)((int)(C - name) + l_value + 2))))
return (-1);
for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
;
for (*C++ = '='; *C++ = *value++; )
;
return (0);
}
/*
* unsetenv(name) --
* Delete environmental variable "name".
*/
void
unsetenv(name)
const char *name;
{
extern char **environ;
register char **P;
int offset;
char *__findenv();
while (__findenv(name, &offset)) /* if set multiple times */
for (P = &environ[offset];; ++P)
if (!(*P = *(P + 1)))
break;
}
#endif

325
sigcompat.c Normal file
View File

@ -0,0 +1,325 @@
/*
* NAME:
* sigcompat - BSD compat signals via POSIX
*
* SYNOPSIS:
* void (*signal(int "sig", void (*"handler")(int)))(int);
* int sigsetmask(int "mask");
* int sigblock(int "mask");
* int sigpause(int "mask");
* int sigvec(int "signo", struct sigvec *"sv", struct sigvec *"osv");
*
* DESCRIPTION:
* These implement the old BSD routines via the POSIX equivalents.
* This module can be used to provide the missing routines, or if
* 'FORCE_POSIX_SIGNALS' is defined, force use of these.
*
* Note that signal() is identical to my Signal() routine except
* for checking for recursion. Within libsig, signal() just
* calls Signal().
*
* BUGS:
* This package assumes POSIX signal handling is available and
* NOT implemeneted using these routines. To be safe, we check
* for recursion and abort(3) if detected.
*
* Sadly, on some systems, sigset_t is an array, and we cannot
* test for this via #if sizeof(sigset_t) ..., so unless
* 'SIGSET_T_INT' is defined, we have to assume the worst and use
* memcpy(3) to handle args and return values.
*
* HISTORY:
* These routines originate from BSD, and are derrived from the
* NetBSD 1.1 implementation. They have been seriously hacked to
* make them portable to other systems.
*
* AUTHOR:
* Simon J. Gerraty <sjg@crufty.net>
*/
/*
* @(#)Copyright (c) 1994, Simon J. Gerraty.
*
* This is free software. It comes with NO WARRANTY.
* Permission to use, modify and distribute this source code
* is granted subject to the following conditions.
* 1/ that the above copyright notice and this notice
* are preserved in all copies and that due credit be given
* to the author.
* 2/ that any changes to this code are clearly commented
* as such so that the author does not get blamed for bugs
* other than his own.
*
* Please send copies of changes and bug-fixes to:
* sjg@crufty.net
*/
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#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.23 2011/02/14 00:07:11 sjg Exp $";
#endif /* LIBC_SCCS and not lint */
#undef signal
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <sys/cdefs.h>
#include "assert.h"
#ifndef ASSERT
# define ASSERT assert
#endif
#ifdef NDEBUG
# define _DBUG(x)
#else
# define _DBUG(x) x
#endif
#ifndef SA_RESTART
# define SA_RESTART 2
#endif
#ifndef SV_INTERRUPT
# define SV_INTERRUPT SA_RESTART
#endif
#ifndef MASK_T
# if defined(__hpux__) || defined(__hpux)
# define MASK_T long
# else
# define MASK_T int
# endif
#endif
/* I just hate HPsUX */
#if (defined(__HPUX_VERSION) && __HPUX_VERSION > 9) || defined(__hpux)
# define PAUSE_MASK_T int
#else
# define PAUSE_MASK_T MASK_T
#endif
#ifndef SIG_HDLR
# define SIG_HDLR void
#endif
#ifdef FORCE_POSIX_SIGNALS
#if !(defined(libsig) || defined(libsjg))
/*
* This little block is almost identical to Signal(),
* and make this module standalone.
* We don't use it in libsig by default, as some apps might use both
* and expect _SignalFlags to be used by both.
*/
#ifndef SIGNAL_FLAGS
# define SIGNAL_FLAGS 0 /* no auto-restart */
#endif
int _signalFlags = SIGNAL_FLAGS;
SIG_HDLR(*signal(int sig, SIG_HDLR(*handler)(int)))(int)
{
_DBUG(static int depth_signal = 0);
struct sigaction act, oact;
int n;
_DBUG(++depth_signal);
ASSERT(depth_signal < 2);
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = _signalFlags;
n = sigaction(sig, &act, &oact);
_DBUG(--depth_signal);
if (n < 0)
return (SIG_ERR);
return (oact.sa_handler);
}
#else
SIG_HDLR(*signal(int sig, SIG_HDLR(*handler)(int)))(int)
{
extern SIG_HDLR(*Signal(int, void (*)(int)))(int);
_DBUG(static int depth_signal = 0);
SIG_HDLR(*old) __P((int));
_DBUG(++depth_signal);
ASSERT(depth_signal < 2);
old = Signal(sig, handler);
_DBUG(--depth_signal);
return old;
}
#endif
#endif
/*
* on some systems, sigset_t is an array...
* it would be nicer if we could do
* #if sizeof(sigset_t) > sizeof(MASK_T)
*/
#ifdef SIGSET_T_INT
# define ss2m(ss) (MASK_T) *(ss)
# define m2ss(ss, m) *ss = (sigset_t) *(m)
#else
static MASK_T
ss2m(sigset_t *ss)
{
MASK_T ma[(sizeof(sigset_t) / sizeof(MASK_T)) + 1];
memcpy((char *) ma, (char *) ss, sizeof(sigset_t));
return ma[0];
}
static void
m2ss(sigset_t *ss, MASK_T *m)
{
if (sizeof(sigset_t) > sizeof(MASK_T))
memset((char *) ss, 0, sizeof(sigset_t));
memcpy((char *) ss, (char *) m, sizeof(MASK_T));
}
#endif
#if !defined(HAVE_SIGSETMASK) || defined(FORCE_POSIX_SIGNALS)
MASK_T
sigsetmask(MASK_T mask)
{
_DBUG(static int depth_sigsetmask = 0);
sigset_t m, omask;
int n;
_DBUG(++depth_sigsetmask);
ASSERT(depth_sigsetmask < 2);
m2ss(&m, &mask);
n = sigprocmask(SIG_SETMASK, (sigset_t *) & m, (sigset_t *) & omask);
_DBUG(--depth_sigsetmask);
if (n)
return (n);
return ss2m(&omask);
}
MASK_T
sigblock(MASK_T mask)
{
_DBUG(static int depth_sigblock = 0);
sigset_t m, omask;
int n;
_DBUG(++depth_sigblock);
ASSERT(depth_sigblock < 2);
if (mask)
m2ss(&m, &mask);
n = sigprocmask(SIG_BLOCK, (sigset_t *) ((mask) ? &m : 0), (sigset_t *) & omask);
_DBUG(--depth_sigblock);
if (n)
return (n);
return ss2m(&omask);
}
#undef sigpause /* Linux at least */
PAUSE_MASK_T
sigpause(PAUSE_MASK_T mask)
{
_DBUG(static int depth_sigpause = 0);
sigset_t m;
PAUSE_MASK_T n;
_DBUG(++depth_sigpause);
ASSERT(depth_sigpause < 2);
m2ss(&m, &mask);
n = sigsuspend(&m);
_DBUG(--depth_sigpause);
return n;
}
#endif
#if defined(HAVE_SIGVEC) && defined(FORCE_POSIX_SIGNALS)
int
sigvec(int signo, struct sigvec *sv, struct sigvec *osv)
{
_DBUG(static int depth_sigvec = 0);
int ret;
struct sigvec nsv;
_DBUG(++depth_sigvec);
ASSERT(depth_sigvec < 2);
if (sv) {
nsv = *sv;
nsv.sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */
}
ret = sigaction(signo, sv ? (struct sigaction *) & nsv : NULL,
(struct sigaction *) osv);
_DBUG(--depth_sigvec);
if (ret == 0 && osv)
osv->sv_flags ^= SV_INTERRUPT; /* !SA_INTERRUPT */
return (ret);
}
#endif
#ifdef MAIN
# ifndef sigmask
# define sigmask(n) ((unsigned int)1 << (((n) - 1) & (32 - 1)))
# endif
int
main(int argc, char *argv[])
{
MASK_T old = 0;
printf("expect: old=0,old=2\n");
fflush(stdout);
signal(SIGQUIT, SIG_IGN);
old = sigblock(sigmask(SIGINT));
printf("old=%d,", old);
old = sigsetmask(sigmask(SIGALRM));
printf("old=%d\n", old);
}
#endif
#endif

View File

@ -1,6 +1,40 @@
/* $NetBSD: sprite.h,v 1.11 2009/01/23 21:26:30 dsl Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)sprite.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -35,7 +69,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)sprite.h 8.2 (Berkeley) 4/28/95
* from: @(#)sprite.h 8.1 (Berkeley) 6/6/93
*/
/*
@ -56,10 +90,10 @@
typedef int Boolean;
#ifndef TRUE
#define TRUE 1
#endif TRUE
#endif /* TRUE */
#ifndef FALSE
#define FALSE 0
#endif FALSE
#endif /* FALSE */
/*
* Functions that must return a status can return a ReturnStatus to
@ -69,7 +103,7 @@ typedef int Boolean;
typedef int ReturnStatus;
/*
* The following statuses overlap with the first 2 generic statuses
* The following statuses overlap with the first 2 generic statuses
* defined in status.h:
*
* SUCCESS There was no error.
@ -79,33 +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
#define USER_NIL 0
#ifndef NULL
#define NULL 0
#endif NULL
/*
* An address is just a pointer in C. It is defined as a character pointer
* so that address arithmetic will work properly, a byte at a time.
*/
typedef char *Address;
/*
* ClientData is an uninterpreted word. It is defined as an int so that
* kdbx will not interpret client data as a string. Unlike an "Address",
* 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 */

View File

@ -1,6 +1,38 @@
/* $NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*-
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
@ -36,46 +68,21 @@
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
static char sccsid[] = "@(#)str.c 8.6 (Berkeley) 4/28/95";
#endif /* not lint */
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: str.c,v 1.34 2012/03/03 23:16:47 dholland Exp $");
#endif
#endif /* not lint */
#endif
#include "make.h"
static char **argv, *buffer;
static int argmax, curlen;
/*
* str_init --
* Initialize the strings package
*
*/
void
str_init()
{
char *p1;
argv = (char **)emalloc((argmax = 50) * sizeof(char *));
argv[0] = Var_Value(".MAKE", VAR_GLOBAL, &p1);
}
/*
* str_end --
* Cleanup the strings package
*
*/
void
str_end()
{
if (argv[0]) {
free(argv[0]);
free((Address) argv);
}
if (buffer)
free(buffer);
}
/*-
* str_concat --
* concatenate the two strings, inserting a space or slash between them,
@ -85,19 +92,17 @@ str_end()
* the resulting string in allocated space.
*/
char *
str_concat(s1, s2, flags)
char *s1, *s2;
int flags;
str_concat(const char *s1, const char *s2, int flags)
{
register int len1, len2;
register char *result;
int len1, len2;
char *result;
/* get the length of both strings */
len1 = strlen(s1);
len2 = strlen(s2);
/* allocate length plus separator plus EOS */
result = emalloc((u_int)(len1 + len2 + 2));
result = bmake_malloc((u_int)(len1 + len2 + 2));
/* copy first string into place */
memcpy(result, s1, len1);
@ -114,11 +119,6 @@ str_concat(s1, s2, flags)
/* copy second string plus EOS into place */
memcpy(result + len1, s2, len2 + 1);
/* free original strings */
if (flags & STR_DOFREE) {
(void)free(s1);
(void)free(s2);
}
return(result);
}
@ -128,51 +128,60 @@ str_concat(s1, s2, flags)
* spaces) taking quotation marks into account. Leading tabs/spaces
* are ignored.
*
* If expand is TRUE, quotes are removed and escape sequences
* such as \r, \t, etc... are expanded.
*
* returns --
* Pointer to the array of pointers to the words. To make life easier,
* the first word is always the value of the .MAKE variable.
* Pointer to the array of pointers to the words.
* Memory containing the actual words in *buffer.
* Both of these must be free'd by the caller.
* Number of words in *store_argc.
*/
char **
brk_string(str, store_argc, expand)
register char *str;
int *store_argc;
Boolean expand;
brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
{
register int argc, ch;
register char inquote, *p, *start, *t;
int argc, ch;
char inquote, *start, *t;
const char *p;
int len;
int argmax = 50, curlen = 0;
char **argv = bmake_malloc((argmax + 1) * sizeof(char *));
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
continue;
/* allocate room for a copy of the string */
if ((len = strlen(str) + 1) > curlen) {
if (buffer)
free(buffer);
buffer = emalloc(curlen = len);
}
if ((len = strlen(str) + 1) > curlen)
*buffer = bmake_malloc(curlen = len);
/*
* copy the string; at the same time, parse backslashes,
* quotes and build the argument list.
*/
argc = 1;
argc = 0;
inquote = '\0';
for (p = str, start = t = buffer;; ++p) {
for (p = str, start = t = *buffer;; ++p) {
switch(ch = *p) {
case '"':
case '\'':
if (inquote)
if (inquote) {
if (inquote == ch)
inquote = '\0';
else
break;
}
else {
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;
}
}
@ -201,24 +210,32 @@ brk_string(str, store_argc, expand)
*t++ = '\0';
if (argc == argmax) {
argmax *= 2; /* ramp up fast */
if (!(argv = (char **)realloc(argv,
argmax * sizeof(char *))))
enomem();
argv = (char **)bmake_realloc(argv,
(argmax + 1) * sizeof(char *));
}
argv[argc++] = start;
start = (char *)NULL;
if (ch == '\n' || ch == '\0')
start = NULL;
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 */
continue;
ch = *++p;
break;
}
switch (ch = *++p) {
case '\0':
case '\n':
@ -248,27 +265,29 @@ brk_string(str, store_argc, expand)
start = t;
*t++ = (char) ch;
}
done: argv[argc] = (char *)NULL;
done: argv[argc] = NULL;
*store_argc = argc;
return(argv);
}
/*
* Str_FindSubstring -- See if a string contains a particular substring.
*
*
* Input:
* string String to search.
* substring Substring to find in string.
*
* Results: If string contains substring, the return value is the location of
* the first matching instance of substring in string. If string doesn't
* contain substring, the return value is NULL. Matching is done on an exact
* character-for-character basis with no wildcards or special characters.
*
*
* Side effects: None.
*/
char *
Str_FindSubstring(string, substring)
register char *string; /* String to search. */
char *substring; /* Substring to find in string */
Str_FindSubstring(const char *string, const char *substring)
{
register char *a, *b;
const char *a, *b;
/*
* First scan quickly through the two strings looking for a single-
@ -282,30 +301,30 @@ Str_FindSubstring(string, substring)
a = string;
for (;;) {
if (*b == 0)
return(string);
return UNCONST(string);
if (*a++ != *b++)
break;
}
b = substring;
}
return((char *) NULL);
return NULL;
}
/*
* Str_Match --
*
*
* See if a particular string matches a particular pattern.
*
*
* Results: Non-zero is returned if string matches pattern, 0 otherwise. The
* matching operation permits the following special characters in the
* pattern: *?\[] (see the man page for details on what these mean).
*
*
* XXX this function does not detect or report malformed patterns.
*
* Side effects: None.
*/
int
Str_Match(string, pattern)
register char *string; /* String */
register char *pattern; /* Pattern */
Str_Match(const char *string, const char *pattern)
{
char c2;
@ -396,8 +415,13 @@ thisCharOK: ++pattern;
/*-
*-----------------------------------------------------------------------
* Str_SYSVMatch --
* Check word against pattern for a match (% is wild),
*
* Check word against pattern for a match (% is wild),
*
* Input:
* word Word to examine
* pattern Pattern to examine against
* len Number of characters to substitute
*
* Results:
* Returns the beginning position of a match or null. The number
* of characters matched is returned in len.
@ -408,19 +432,16 @@ thisCharOK: ++pattern;
*-----------------------------------------------------------------------
*/
char *
Str_SYSVMatch(word, pattern, len)
char *word; /* Word to examine */
char *pattern; /* Pattern to examine against */
int *len; /* Number of characters to substitute */
Str_SYSVMatch(const char *word, const char *pattern, int *len)
{
char *p = pattern;
char *w = word;
char *m;
const char *p = pattern;
const char *w = word;
const char *m;
if (*p == '\0') {
/* Null pattern is the whole string */
*len = strlen(w);
return w;
return UNCONST(w);
}
if ((m = strchr(p, '%')) != NULL) {
@ -434,7 +455,7 @@ Str_SYSVMatch(word, pattern, len)
if (*++p == '\0') {
/* No more pattern, return the rest of the string */
*len = strlen(w);
return w;
return UNCONST(w);
}
}
@ -444,10 +465,10 @@ Str_SYSVMatch(word, pattern, len)
do
if (strcmp(p, w) == 0) {
*len = w - m;
return m;
return UNCONST(m);
}
while (*w++ != '\0');
return NULL;
}
@ -458,7 +479,7 @@ Str_SYSVMatch(word, pattern, len)
* Substitute '%' on the pattern with len characters from src.
* If the pattern does not contain a '%' prepend len characters
* from src.
*
*
* Results:
* None
*
@ -468,24 +489,20 @@ Str_SYSVMatch(word, pattern, len)
*-----------------------------------------------------------------------
*/
void
Str_SYSVSubst(buf, pat, src, len)
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);
}

89
stresep.c Normal file
View File

@ -0,0 +1,89 @@
/* $NetBSD: stresep.c,v 1.2 2007/12/06 22:07:07 seb Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/cdefs.h>
#include <assert.h>
#include <string.h>
#if !defined(HAVE_STRESEP)
char * stresep(char **stringp, const char *delim, int esc);
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim. If esc is not NUL, then
* the characters followed by esc are ignored and are not taken into account
* when splitting the string.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no more tokens).
*
* If *stringp is NULL, stresep returns NULL.
*/
char *
stresep(char **stringp, const char *delim, int esc)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
if (stringp == NULL || delim == NULL)
return NULL;
if ((s = *stringp) == NULL)
return NULL;
for (tok = s;;) {
c = *s++;
while (esc != '\0' && c == esc) {
(void)strcpy(s - 1, s);
c = *s++;
}
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return tok;
}
} while (sc != 0);
}
}
#endif

63
strlcpy.c Normal file
View File

@ -0,0 +1,63 @@
/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef HAVE_STRLCPY
#include <sys/cdefs.h>
#include <sys/types.h>
#include <string.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
if (!dst || !src)
return 0;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif

93
strlist.c Normal file
View File

@ -0,0 +1,93 @@
/* $NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $ */
/*-
* Copyright (c) 2008 - 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by David Laight.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $");
#endif /* not lint */
#endif
#include <stddef.h>
#include <stdlib.h>
#include "strlist.h"
#include "make_malloc.h"
void
strlist_init(strlist_t *sl)
{
sl->sl_num = 0;
sl->sl_max = 0;
sl->sl_items = NULL;
}
void
strlist_clean(strlist_t *sl)
{
char *str;
int i;
STRLIST_FOREACH(str, sl, i)
free(str);
free(sl->sl_items);
sl->sl_num = 0;
sl->sl_max = 0;
sl->sl_items = NULL;
}
void
strlist_add_str(strlist_t *sl, char *str, unsigned int info)
{
unsigned int n;
strlist_item_t *items;
if (str == NULL)
return;
n = sl->sl_num + 1;
sl->sl_num = n;
items = sl->sl_items;
if (n >= sl->sl_max) {
items = bmake_realloc(items, (n + 7) * sizeof *sl->sl_items);
sl->sl_items = items;
sl->sl_max = n + 6;
}
items += n - 1;
items->si_str = str;
items->si_info = info;
items[1].si_str = NULL; /* STRLIST_FOREACH() terminator */
}

62
strlist.h Normal file
View File

@ -0,0 +1,62 @@
/* $NetBSD: strlist.h,v 1.3 2009/01/16 21:15:34 dsl Exp $ */
/*-
* Copyright (c) 2008 - 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by David Laight.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _STRLIST_H
#define _STRLIST_H
typedef struct {
char *si_str;
unsigned int si_info;
} strlist_item_t;
typedef struct {
unsigned int sl_num;
unsigned int sl_max;
strlist_item_t *sl_items;
} strlist_t;
void strlist_init(strlist_t *);
void strlist_clean(strlist_t *);
void strlist_add_str(strlist_t *, char *, unsigned int);
#define strlist_num(sl) ((sl)->sl_num)
#define strlist_str(sl, n) ((sl)->sl_items[n].si_str)
#define strlist_info(sl, n) ((sl)->sl_items[n].si_info)
#define strlist_set_info(sl, n, v) ((void)((sl)->sl_items[n].si_info = (v)))
#define STRLIST_FOREACH(v, sl, index) \
if ((sl)->sl_items != NULL) \
for (index = 0; (v = strlist_str(sl, index)) != NULL; index++)
#endif /* _STRLIST_H */

File diff suppressed because it is too large Load Diff

848
targ.c Normal file
View File

@ -0,0 +1,848 @@
/* $NetBSD: targ.c,v 1.56 2010/11/25 21:31:09 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: targ.c,v 1.56 2010/11/25 21:31:09 christos 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.56 2010/11/25 21:31:09 christos Exp $");
#endif
#endif /* not lint */
#endif
/*-
* targ.c --
* Functions for maintaining the Lst allTargets. Target nodes are
* kept in two structures: a Lst, maintained by the list library, and a
* hash table, maintained by the hash library.
*
* Interface:
* Targ_Init Initialization procedure.
*
* Targ_End Cleanup the module
*
* Targ_List Return the list of all targets so far.
*
* Targ_NewGN Create a new GNode for the passed target
* (string). The node is *not* placed in the
* hash table, though all its fields are
* initialized.
*
* Targ_FindNode Find the node for a given target, creating
* and storing it if it doesn't exist and the
* flags are right (TARG_CREATE)
*
* Targ_FindList Given a list of names, find nodes for all
* of them. If a name doesn't exist and the
* TARG_NOCREATE flag was given, an error message
* is printed. Else, if a name doesn't exist,
* its node is created.
*
* Targ_Ignore Return TRUE if errors should be ignored when
* creating the given target.
*
* Targ_Silent Return TRUE if we should be silent when
* creating the given target.
*
* Targ_Precious Return TRUE if the target is precious and
* should not be removed if we are interrupted.
*
* Targ_Propagate Propagate information between related
* nodes. Should be called after the
* makefiles are parsed but before any
* action is taken.
*
* Debugging:
* Targ_PrintGraph Print out the entire graphm all variables
* and statistics for the directory cache. Should
* print something for suffixes, too, but...
*/
#include <stdio.h>
#include <time.h>
#include "make.h"
#include "hash.h"
#include "dir.h"
static Lst allTargets; /* the list of all targets found so far */
#ifdef CLEANUP
static Lst allGNs; /* List of all the GNodes */
#endif
static Hash_Table targets; /* a hash table of same */
#define HTSIZE 191 /* initial size of hash table */
static int TargPrintOnlySrc(void *, void *);
static int TargPrintName(void *, void *);
#ifdef CLEANUP
static void TargFreeGN(void *);
#endif
static int TargPropagateCohort(void *, void *);
static int TargPropagateNode(void *, void *);
/*-
*-----------------------------------------------------------------------
* Targ_Init --
* Initialize this module
*
* Results:
* None
*
* Side Effects:
* The allTargets list and the targets hash table are initialized
*-----------------------------------------------------------------------
*/
void
Targ_Init(void)
{
allTargets = Lst_Init(FALSE);
Hash_InitTable(&targets, HTSIZE);
}
/*-
*-----------------------------------------------------------------------
* Targ_End --
* Finalize this module
*
* Results:
* None
*
* Side Effects:
* All lists and gnodes are cleared
*-----------------------------------------------------------------------
*/
void
Targ_End(void)
{
#ifdef CLEANUP
Lst_Destroy(allTargets, NULL);
if (allGNs)
Lst_Destroy(allGNs, TargFreeGN);
Hash_DeleteTable(&targets);
#endif
}
/*-
*-----------------------------------------------------------------------
* Targ_List --
* Return the list of all targets
*
* Results:
* The list of all targets.
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
Lst
Targ_List(void)
{
return allTargets;
}
/*-
*-----------------------------------------------------------------------
* Targ_NewGN --
* Create and initialize a new graph node
*
* Input:
* name the name to stick in the new node
*
* Results:
* An initialized graph node with the name field filled with a copy
* of the passed name
*
* Side Effects:
* The gnode is added to the list of all gnodes.
*-----------------------------------------------------------------------
*/
GNode *
Targ_NewGN(const char *name)
{
GNode *gn;
gn = bmake_malloc(sizeof(GNode));
gn->name = bmake_strdup(name);
gn->uname = NULL;
gn->path = NULL;
if (name[0] == '-' && name[1] == 'l') {
gn->type = OP_LIB;
} else {
gn->type = 0;
}
gn->unmade = 0;
gn->unmade_cohorts = 0;
gn->cohort_num[0] = 0;
gn->centurion = NULL;
gn->made = UNMADE;
gn->flags = 0;
gn->checked = 0;
gn->mtime = 0;
gn->cmgn = NULL;
gn->iParents = Lst_Init(FALSE);
gn->cohorts = Lst_Init(FALSE);
gn->parents = Lst_Init(FALSE);
gn->children = Lst_Init(FALSE);
gn->order_pred = Lst_Init(FALSE);
gn->order_succ = Lst_Init(FALSE);
Hash_InitTable(&gn->context, 0);
gn->commands = Lst_Init(FALSE);
gn->suffix = NULL;
gn->lineno = 0;
gn->fname = NULL;
#ifdef CLEANUP
if (allGNs == NULL)
allGNs = Lst_Init(FALSE);
Lst_AtEnd(allGNs, gn);
#endif
return (gn);
}
#ifdef CLEANUP
/*-
*-----------------------------------------------------------------------
* TargFreeGN --
* Destroy a GNode
*
* Results:
* None.
*
* Side Effects:
* None.
*-----------------------------------------------------------------------
*/
static void
TargFreeGN(void *gnp)
{
GNode *gn = (GNode *)gnp;
free(gn->name);
if (gn->uname)
free(gn->uname);
if (gn->path)
free(gn->path);
/* gn->fname points to name allocated when file was opened, don't free */
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, NULL);
free(gn);
}
#endif
/*-
*-----------------------------------------------------------------------
* Targ_FindNode --
* Find a node in the list using the given name for matching
*
* Input:
* name the name to find
* flags flags governing events when target not
* found
*
* Results:
* 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
*
* Side Effects:
* Sometimes a node is created and added to the list
*-----------------------------------------------------------------------
*/
GNode *
Targ_FindNode(const char *name, int flags)
{
GNode *gn; /* node in that element */
Hash_Entry *he = NULL; /* New or used hash entry for node */
Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */
/* an entry for the node */
if (!(flags & (TARG_CREATE | TARG_NOHASH))) {
he = Hash_FindEntry(&targets, name);
if (he == NULL)
return NULL;
return (GNode *)Hash_GetValue(he);
}
if (!(flags & TARG_NOHASH)) {
he = Hash_CreateEntry(&targets, name, &isNew);
if (!isNew)
return (GNode *)Hash_GetValue(he);
}
gn = Targ_NewGN(name);
if (!(flags & TARG_NOHASH))
Hash_SetValue(he, gn);
Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
(void)Lst_AtEnd(allTargets, gn);
if (doing_depend)
gn->flags |= FROM_DEPEND;
return gn;
}
/*-
*-----------------------------------------------------------------------
* Targ_FindList --
* Make a complete list of GNodes from the given list of names
*
* Input:
* name list of names to find
* flags flags used if no node is found for a given name
*
* Results:
* A complete list of graph nodes corresponding to all instances of all
* the names in names.
*
* Side Effects:
* If flags is TARG_CREATE, nodes will be created for all names in
* names which do not yet have graph nodes. If flags is TARG_NOCREATE,
* an error message will be printed for each name which can't be found.
* -----------------------------------------------------------------------
*/
Lst
Targ_FindList(Lst names, int flags)
{
Lst nodes; /* result list */
LstNode ln; /* name list element */
GNode *gn; /* node in tLn */
char *name;
nodes = Lst_Init(FALSE);
if (Lst_Open(names) == FAILURE) {
return (nodes);
}
while ((ln = Lst_Next(names)) != NULL) {
name = (char *)Lst_Datum(ln);
gn = Targ_FindNode(name, flags);
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
* encountered in the makefile.
*/
(void)Lst_AtEnd(nodes, gn);
} else if (flags == TARG_NOCREATE) {
Error("\"%s\" -- target unknown.", name);
}
}
Lst_Close(names);
return (nodes);
}
/*-
*-----------------------------------------------------------------------
* Targ_Ignore --
* Return true if should ignore errors when creating gn
*
* Input:
* gn node to check for
*
* Results:
* TRUE if should ignore errors
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
Boolean
Targ_Ignore(GNode *gn)
{
if (ignoreErrors || gn->type & OP_IGNORE) {
return (TRUE);
} else {
return (FALSE);
}
}
/*-
*-----------------------------------------------------------------------
* Targ_Silent --
* Return true if be silent when creating gn
*
* Input:
* gn node to check for
*
* Results:
* TRUE if should be silent
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
Boolean
Targ_Silent(GNode *gn)
{
if (beSilent || gn->type & OP_SILENT) {
return (TRUE);
} else {
return (FALSE);
}
}
/*-
*-----------------------------------------------------------------------
* Targ_Precious --
* See if the given target is precious
*
* Input:
* gn the node to check
*
* Results:
* TRUE if it is precious. FALSE otherwise
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
Boolean
Targ_Precious(GNode *gn)
{
if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) {
return (TRUE);
} else {
return (FALSE);
}
}
/******************* DEBUG INFO PRINTING ****************/
static GNode *mainTarg; /* the main target, as set by Targ_SetMain */
/*-
*-----------------------------------------------------------------------
* Targ_SetMain --
* Set our idea of the main target we'll be creating. Used for
* debugging output.
*
* Input:
* gn The main target we'll create
*
* Results:
* None.
*
* Side Effects:
* "mainTarg" is set to the main target's node.
*-----------------------------------------------------------------------
*/
void
Targ_SetMain(GNode *gn)
{
mainTarg = gn;
}
static int
TargPrintName(void *gnp, void *pflags __unused)
{
GNode *gn = (GNode *)gnp;
fprintf(debug_file, "%s%s ", gn->name, gn->cohort_num);
return 0;
}
int
Targ_PrintCmd(void *cmd, void *dummy)
{
fprintf(debug_file, "\t%s\n", (char *)cmd);
return (dummy ? 0 : 0);
}
/*-
*-----------------------------------------------------------------------
* Targ_FmtTime --
* Format a modification time in some reasonable way and return it.
*
* Results:
* The time reformatted.
*
* Side Effects:
* The time is placed in a static area, so it is overwritten
* with each call.
*
*-----------------------------------------------------------------------
*/
char *
Targ_FmtTime(time_t tm)
{
struct tm *parts;
static char buf[128];
parts = localtime(&tm);
(void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
return(buf);
}
/*-
*-----------------------------------------------------------------------
* Targ_PrintType --
* Print out a type field giving only those attributes the user can
* set.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
void
Targ_PrintType(int type)
{
int tbit;
#define PRINTBIT(attr) case CONCAT(OP_,attr): fprintf(debug_file, "." #attr " "); break
#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, "." #attr " "); break
type &= ~OP_OPMASK;
while (type) {
tbit = 1 << (ffs(type) - 1);
type &= ~tbit;
switch(tbit) {
PRINTBIT(OPTIONAL);
PRINTBIT(USE);
PRINTBIT(EXEC);
PRINTBIT(IGNORE);
PRINTBIT(PRECIOUS);
PRINTBIT(SILENT);
PRINTBIT(MAKE);
PRINTBIT(JOIN);
PRINTBIT(INVISIBLE);
PRINTBIT(NOTMAIN);
PRINTDBIT(LIB);
/*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, ".MEMBER "); break;
PRINTDBIT(ARCHV);
PRINTDBIT(MADE);
PRINTDBIT(PHONY);
}
}
}
static const char *
made_name(enum enum_made made)
{
switch (made) {
case UNMADE: return "unmade";
case DEFERRED: return "deferred";
case REQUESTED: return "requested";
case BEINGMADE: return "being made";
case MADE: return "made";
case UPTODATE: return "up-to-date";
case ERROR: return "error when made";
case ABORTED: return "aborted";
default: return "unknown enum_made value";
}
}
/*-
*-----------------------------------------------------------------------
* TargPrintNode --
* print the contents of a node
*-----------------------------------------------------------------------
*/
int
Targ_PrintNode(void *gnp, void *passp)
{
GNode *gn = (GNode *)gnp;
int pass = passp ? *(int *)passp : 0;
fprintf(debug_file, "# %s%s, flags %x, type %x, made %d\n",
gn->name, gn->cohort_num, gn->flags, gn->type, gn->made);
if (gn->flags == 0)
return 0;
if (!OP_NOP(gn->type)) {
fprintf(debug_file, "#\n");
if (gn == mainTarg) {
fprintf(debug_file, "# *** MAIN TARGET ***\n");
}
if (pass >= 2) {
if (gn->unmade) {
fprintf(debug_file, "# %d unmade children\n", gn->unmade);
} else {
fprintf(debug_file, "# No unmade children\n");
}
if (! (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
if (gn->mtime != 0) {
fprintf(debug_file, "# last modified %s: %s\n",
Targ_FmtTime(gn->mtime),
made_name(gn->made));
} else if (gn->made != UNMADE) {
fprintf(debug_file, "# non-existent (maybe): %s\n",
made_name(gn->made));
} else {
fprintf(debug_file, "# unmade\n");
}
}
if (!Lst_IsEmpty (gn->iParents)) {
fprintf(debug_file, "# implicit parents: ");
Lst_ForEach(gn->iParents, TargPrintName, NULL);
fprintf(debug_file, "\n");
}
} else {
if (gn->unmade)
fprintf(debug_file, "# %d unmade children\n", gn->unmade);
}
if (!Lst_IsEmpty (gn->parents)) {
fprintf(debug_file, "# parents: ");
Lst_ForEach(gn->parents, TargPrintName, NULL);
fprintf(debug_file, "\n");
}
if (!Lst_IsEmpty (gn->order_pred)) {
fprintf(debug_file, "# order_pred: ");
Lst_ForEach(gn->order_pred, TargPrintName, NULL);
fprintf(debug_file, "\n");
}
if (!Lst_IsEmpty (gn->order_succ)) {
fprintf(debug_file, "# order_succ: ");
Lst_ForEach(gn->order_succ, TargPrintName, NULL);
fprintf(debug_file, "\n");
}
fprintf(debug_file, "%-16s", gn->name);
switch (gn->type & OP_OPMASK) {
case OP_DEPENDS:
fprintf(debug_file, ": "); break;
case OP_FORCE:
fprintf(debug_file, "! "); break;
case OP_DOUBLEDEP:
fprintf(debug_file, ":: "); break;
}
Targ_PrintType(gn->type);
Lst_ForEach(gn->children, TargPrintName, NULL);
fprintf(debug_file, "\n");
Lst_ForEach(gn->commands, Targ_PrintCmd, NULL);
fprintf(debug_file, "\n\n");
if (gn->type & OP_DOUBLEDEP) {
Lst_ForEach(gn->cohorts, Targ_PrintNode, &pass);
}
}
return (0);
}
/*-
*-----------------------------------------------------------------------
* TargPrintOnlySrc --
* Print only those targets that are just a source.
*
* Results:
* 0.
*
* Side Effects:
* The name of each file is printed preceded by #\t
*
*-----------------------------------------------------------------------
*/
static int
TargPrintOnlySrc(void *gnp, void *dummy __unused)
{
GNode *gn = (GNode *)gnp;
if (!OP_NOP(gn->type))
return 0;
fprintf(debug_file, "#\t%s [%s] ",
gn->name, gn->path ? gn->path : gn->name);
Targ_PrintType(gn->type);
fprintf(debug_file, "\n");
return 0;
}
/*-
*-----------------------------------------------------------------------
* Targ_PrintGraph --
* print the entire graph. heh heh
*
* Input:
* pass Which pass this is. 1 => no processing
* 2 => processing done
*
* Results:
* none
*
* Side Effects:
* lots o' output
*-----------------------------------------------------------------------
*/
void
Targ_PrintGraph(int pass)
{
fprintf(debug_file, "#*** Input graph:\n");
Lst_ForEach(allTargets, Targ_PrintNode, &pass);
fprintf(debug_file, "\n\n");
fprintf(debug_file, "#\n# Files that are only sources:\n");
Lst_ForEach(allTargets, TargPrintOnlySrc, NULL);
fprintf(debug_file, "#*** Global Variables:\n");
Var_Dump(VAR_GLOBAL);
fprintf(debug_file, "#*** Command-line Variables:\n");
Var_Dump(VAR_CMD);
fprintf(debug_file, "\n");
Dir_PrintDirectories();
fprintf(debug_file, "\n");
Suff_PrintAll();
}
/*-
*-----------------------------------------------------------------------
* TargPropagateNode --
* Propagate information from a single node to related nodes if
* appropriate.
*
* Input:
* gnp The node that we are processing.
*
* Results:
* Always returns 0, for the benefit of Lst_ForEach().
*
* Side Effects:
* Information is propagated from this node to cohort or child
* nodes.
*
* If the node was defined with "::", then TargPropagateCohort()
* will be called for each cohort node.
*
* If the node has recursive predecessors, then
* TargPropagateRecpred() will be called for each recursive
* predecessor.
*-----------------------------------------------------------------------
*/
static int
TargPropagateNode(void *gnp, void *junk __unused)
{
GNode *gn = (GNode *)gnp;
if (gn->type & OP_DOUBLEDEP)
Lst_ForEach(gn->cohorts, TargPropagateCohort, gnp);
return (0);
}
/*-
*-----------------------------------------------------------------------
* TargPropagateCohort --
* Propagate some bits in the type mask from a node to
* a related cohort node.
*
* Input:
* cnp The node that we are processing.
* gnp Another node that has cnp as a cohort.
*
* Results:
* Always returns 0, for the benefit of Lst_ForEach().
*
* Side Effects:
* cnp's type bitmask is modified to incorporate some of the
* bits from gnp's type bitmask. (XXX need a better explanation.)
*-----------------------------------------------------------------------
*/
static int
TargPropagateCohort(void *cgnp, void *pgnp)
{
GNode *cgn = (GNode *)cgnp;
GNode *pgn = (GNode *)pgnp;
cgn->type |= pgn->type & ~OP_OPMASK;
return (0);
}
/*-
*-----------------------------------------------------------------------
* Targ_Propagate --
* Propagate information between related nodes. Should be called
* after the makefiles are parsed but before any action is taken.
*
* Results:
* none
*
* Side Effects:
* Information is propagated between related nodes throughout the
* graph.
*-----------------------------------------------------------------------
*/
void
Targ_Propagate(void)
{
Lst_ForEach(allTargets, TargPropagateNode, NULL);
}

116
trace.c Normal file
View File

@ -0,0 +1,116 @@
/* $NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Sommerfeld
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: trace.c,v 1.11 2008/12/28 18:31:51 christos Exp $");
#endif /* not lint */
#endif
/*-
* trace.c --
* handle logging of trace events generated by various parts of make.
*
* Interface:
* Trace_Init Initialize tracing (called once during
* the lifetime of the process)
*
* Trace_End Finalize tracing (called before make exits)
*
* Trace_Log Log an event about a particular make job.
*/
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include "make.h"
#include "job.h"
#include "trace.h"
static FILE *trfile;
static pid_t trpid;
char *trwd;
static const char *evname[] = {
"BEG",
"END",
"ERR",
"JOB",
"DON",
"INT",
};
void
Trace_Init(const char *pathname)
{
char *p1;
if (pathname != NULL) {
trpid = getpid();
trwd = Var_Value(".CURDIR", VAR_GLOBAL, &p1);
trfile = fopen(pathname, "a");
}
}
void
Trace_Log(TrEvent event, Job *job)
{
struct timeval rightnow;
if (trfile == NULL)
return;
gettimeofday(&rightnow, NULL);
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) {
fprintf(trfile, " %s %d %x %x", job->node->name,
job->pid, job->flags, job->node->type);
}
fputc('\n', trfile);
fflush(trfile);
}
void
Trace_End(void)
{
if (trfile != NULL)
fclose(trfile);
}

49
trace.h Normal file
View File

@ -0,0 +1,49 @@
/* $NetBSD: trace.h,v 1.3 2008/04/28 20:24:14 martin Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Bill Sommerfeld
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*-
* trace.h --
* Definitions pertaining to the tracing of jobs in parallel mode.
*/
typedef enum {
MAKESTART,
MAKEEND,
MAKEERROR,
JOBSTART,
JOBEND,
MAKEINTR
} TrEvent;
void Trace_Init(const char *);
void Trace_Log(TrEvent, Job *);
void Trace_End(void);

95
unit-tests/Makefile.in Normal file
View File

@ -0,0 +1,95 @@
# $Id: Makefile.in,v 1.37 2011/10/01 20:30:30 sjg Exp $
#
# $NetBSD: Makefile,v 1.33 2011/09/29 23:38:04 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
#
# all: run all the tests
# test: run 'all', capture output and compare to expected results
# accept: move generated output to expected results
#
# Adding a test case.
# Each feature should get its own set of tests in its own suitably
# named makefile which should be added to SUBFILES to hook it in.
#
srcdir= @srcdir@
.MAIN: all
UNIT_TESTS:= ${srcdir}
# Simple sub-makefiles - we run them as a black box
# keep the list sorted.
SUBFILES= \
comment \
cond1 \
error \
export \
export-all \
doterror \
dotwait \
forsubst \
hash \
misc \
moderrs \
modmatch \
modmisc \
modorder \
modts \
modword \
phony-end \
posix \
qequals \
sysv \
ternary \
unexport \
unexport-env \
varcmd
all: ${SUBFILES}
flags.doterror=
# the tests are actually done with sub-makes.
.PHONY: ${SUBFILES}
.PRECIOUS: ${SUBFILES}
${SUBFILES}:
-@${.MAKE} ${flags.$@:U-k} -f ${UNIT_TESTS}/$@
clean:
rm -f *.out *.fail *.core
.-include <bsd.obj.mk>
TEST_MAKE?= ${.MAKE}
TOOL_SED?= sed
TOOL_TR?= tr
TOOL_DIFF?= diff
DIFF_FLAGS?= @diff_u@
# ensure consistent results from sort(1)
LC_ALL= C
LANG= C
.export LANG LC_ALL
# The driver.
# We always pretend .MAKE was called 'make'
# and strip ${.CURDIR}/ from the output
# and replace anything after 'stopped in' with unit-tests
# so the results can be compared.
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' \
-e 's,${UNIT_TESTS:C/\./\\\./g}/,,g' > ${.TARGET}.out || { \
tail ${.TARGET}.out; mv ${.TARGET}.out ${.TARGET}.fail; exit 1; }
${TOOL_DIFF} ${DIFF_FLAGS} ${UNIT_TESTS}/${.TARGET}.exp ${.TARGET}.out
accept:
mv test.out ${srcdir}/test.exp

31
unit-tests/comment Normal file
View File

@ -0,0 +1,31 @@
# This is a comment
.if ${MACHINE_ARCH} == something
FOO=bar
.endif
#\
Multiline comment
BAR=# defined
FOOBAR= # defined
# This is an escaped comment \
that keeps going until the end of this line
# Another escaped comment \
that \
goes \
on
# This is NOT an escaped comment due to the double backslashes \\
all: hi foo bar
@echo comment testing done
hi:
@echo comment testing start
foo:
@echo this is $@
bar:
@echo This is how a comment looks: '# comment'

109
unit-tests/cond1 Normal file
View File

@ -0,0 +1,109 @@
# $Id: cond1,v 1.1.1.3 2011/03/06 00:04:58 sjg Exp $
# hard code these!
TEST_UNAME_S= NetBSD
TEST_UNAME_M= sparc
TEST_MACHINE= i386
.if ${TEST_UNAME_S}
Ok=var,
.endif
.if ("${TEST_UNAME_S}")
Ok+=(\"var\"),
.endif
.if (${TEST_UNAME_M} != ${TEST_MACHINE})
Ok+=(var != var),
.endif
.if ${TEST_UNAME_M} != ${TEST_MACHINE}
Ok+= var != var,
.endif
.if !((${TEST_UNAME_M} != ${TEST_MACHINE}) && defined(X))
Ok+= !((var != var) && defined(name)),
.endif
# from bsd.obj.mk
MKOBJ?=no
.if ${MKOBJ} == "no"
o= no
Ok+= var == "quoted",
.else
.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
.if defined(notMAKEOBJDIRPREFIX)
o=${MAKEOBJDIRPREFIX}${__curdir}
.else
o= ${MAKEOBJDIR}
.endif
.endif
o= o
.endif
# repeat the above to check we get the same result
.if ${MKOBJ} == "no"
o2= no
.else
.if defined(notMAKEOBJDIRPREFIX) || defined(norMAKEOBJDIR)
.if defined(notMAKEOBJDIRPREFIX)
o2=${MAKEOBJDIRPREFIX}${__curdir}
.else
o2= ${MAKEOBJDIR}
.endif
.endif
o2= o
.endif
PRIMES=2 3 5 7 11
NUMBERS=1 2 3 4 5
n=2
.if ${PRIMES:M$n} == ""
X=not
.else
X=
.endif
.if ${MACHINE_ARCH} == no-such
A=one
.else
.if ${MACHINE_ARCH} == not-this
.if ${MACHINE_ARCH} == something-else
A=unlikely
.else
A=no
.endif
.endif
A=other
# We expect an extra else warning - we're not skipping here
.else
A=this should be an error
.endif
.if $X != ""
.if $X == not
B=one
.else
B=other
# We expect an extra else warning - we are skipping here
.else
B=this should be an error
.endif
.else
B=unknown
.endif
.if "quoted" == quoted
C=clever
.else
C=dim
.endif
.if defined(nosuch) && ${nosuch:Mx} != ""
# this should not happen
.info nosuch is x
.endif
all:
@echo "$n is $X prime"
@echo "A='$A' B='$B' C='$C' o='$o,${o2}'"
@echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
@echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:} prime${.newline}@}"
@echo "${"${DoNotQuoteHere:U0}" > 0:?OK:No}"
@echo "${${NoSuchNumber:U42} > 0:?OK:No}"

20
unit-tests/doterror Normal file
View File

@ -0,0 +1,20 @@
# $Id: doterror,v 1.1.1.1 2010/04/08 17:43:00 sjg Exp $
.BEGIN:
@echo At first, I am
.END:
@echo not reached
.ERROR:
@echo "$@: Looks like '${.ERROR_TARGET}' is upset."
all: happy sad
happy:
@echo $@
sad:
@echo and now: $@; exit 1

61
unit-tests/dotwait Normal file
View File

@ -0,0 +1,61 @@
# $NetBSD: dotwait,v 1.1 2006/02/26 22:45:46 apb Exp $
THISMAKEFILE:= ${.PARSEDIR}/${.PARSEFILE}
TESTS= simple recursive shared cycle
PAUSE= sleep 1
# Use a .for loop rather than dependencies here, to ensure
# that the tests are run one by one, with parallelism
# only within tests.
# Ignore "--- target ---" lines printed by parallel make.
all:
.for t in ${TESTS}
@${.MAKE} -f ${THISMAKEFILE} -j4 $t | grep -v "^--- "
.endfor
#
# Within each test, the names of the sub-targets follow these
# conventions:
# * If it's expected that two or more targets may be made in parallel,
# then the target names will differ only in an alphabetic component
# such as ".a" or ".b".
# * If it's expected that two or more targets should be made in sequence
# then the target names will differ in numeric components, such that
# lexical ordering of the target names matches the expected order
# in which the targets should be made.
#
# Targets may echo ${PARALLEL_TARG} to print a modified version
# of their own name, in which alphabetic components like ".a" or ".b"
# are converted to ".*". Two targets that are expected to
# be made in parallel will thus print the same strings, so that the
# output is independent of the order in which these targets are made.
#
PARALLEL_TARG= ${.TARGET:C/\.[a-z]/.*/g:Q}
.DEFAULT:
@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
_ECHOUSE: .USE
@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
# simple: no recursion, no cycles
simple: simple.1 .WAIT simple.2
# recursive: all children of the left hand side of the .WAIT
# must be made before any child of the right hand side.
recursive: recursive.1.99 .WAIT recursive.2.99
recursive.1.99: recursive.1.1.a recursive.1.1.b _ECHOUSE
recursive.2.99: recursive.2.1.a recursive.2.1.b _ECHOUSE
# shared: both shared.1.99 and shared.2.99 depend on shared.0.
# shared.0 must be made first, even though it is a child of
# the right hand side of the .WAIT.
shared: shared.1.99 .WAIT shared.2.99
shared.1.99: shared.0 _ECHOUSE
shared.2.99: shared.2.1 shared.0 _ECHOUSE
# cycle: the cyclic dependency must not cause infinite recursion
# leading to stack overflow and a crash.
cycle: cycle.1.99 .WAIT cycle.2.99
cycle.2.99: cycle.2.98 _ECHOUSE
cycle.2.98: cycle.2.97 _ECHOUSE
cycle.2.97: cycle.2.99 _ECHOUSE

10
unit-tests/error Normal file
View File

@ -0,0 +1,10 @@
# $Id: error,v 1.1.1.2 2010/05/24 23:36:03 sjg Exp $
.info just FYI
.warning this could be serious
.error this is fatal
all:
.info.html:
@echo this should be ignored

22
unit-tests/export Normal file
View File

@ -0,0 +1,22 @@
# $Id: export,v 1.1.1.1 2007/10/08 20:30:12 sjg Exp $
UT_TEST=export
UT_FOO=foo${BAR}
UT_FU=fubar
UT_ZOO=hoopie
UT_NO=all
# belive it or not, we expect this one to come out with $UT_FU unexpanded.
UT_DOLLAR= This is $$UT_FU
.export UT_FU UT_FOO
.export UT_DOLLAR
# this one will be ignored
.export .MAKE.PID
BAR=bar is ${UT_FU}
.MAKE.EXPORTED+= UT_ZOO UT_TEST
all:
@env | grep '^UT_' | sort

23
unit-tests/export-all Normal file
View File

@ -0,0 +1,23 @@
# $Id: export-all,v 1.1.1.2 2010/04/21 04:26:14 sjg Exp $
UT_OK=good
UT_F=fine
# the old way to do :tA
M_tAbad = C,.*,cd & \&\& 'pwd',:sh
# the new
M_tA = tA
here := ${.PARSEDIR}
# this will cause trouble (recursing if we let it)
UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T}
# this will be ok
UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T}
.export
.include "export"
UT_TEST=export-all
UT_ALL=even this gets exported

10
unit-tests/forsubst Normal file
View File

@ -0,0 +1,10 @@
# $Id: forsubst,v 1.1.1.1 2009/10/07 18:53:35 sjg Exp $
all: for-subst
here := ${.PARSEDIR}
# this should not run foul of the parser
.for file in ${.PARSEFILE}
for-subst: ${file:S;^;${here}/;g}
@echo ".for with :S;... OK"
.endfor

18
unit-tests/hash Normal file
View File

@ -0,0 +1,18 @@
STR1=
STR2= a
STR3= ab
STR4= abc
STR5= abcd
STR6= abcde
STR7= abcdef
STR8= abcdefghijklmnopqrstuvwxyz
all:
@echo ${STR1:hash}
@echo ${STR2:hash}
@echo ${STR3:hash}
@echo ${STR4:hash}
@echo ${STR5:hash}
@echo ${STR6:hash}
@echo ${STR7:hash}
@echo ${STR8:hash}

Some files were not shown because too many files have changed in this diff Show More