[net.sources] patch version 1.5, part 2 of 2

lwall@sdcrdcf.UUCP (08/02/86)

#! /bin/sh

# Make a new directory for the patch sources, cd to it, and run kits 1 thru 2 
# through sh.  When all 2 kits have been run, read README.

echo "This is patch kit 2 (of 2).  If kit 2 is complete, the line"
echo '"'"End of kit 2 (of 2)"'" will echo at the end.'
echo ""
export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
echo Extracting Configure
sed >Configure <<'!STUFFY!FUNK!' -e 's/X//'
X#! /bin/sh
X#
X# If these # comments don't work, trim them.  Don't worry about the other
X# shell scripts, Configure will trim # comments from them for you.
X#
X# $Header: Configure,v 1.1 86/08/01 20:18:15 lwall Exp $
X#
X# $Log:	Configure,v $
X# Revision 1.1  86/08/01  20:18:15  lwall
X# Initial revision
X# 
X
X# Yes, you may rip this off to use in other distribution packages.
X
Xeunice=''
Xeunicefix=''
Xloclist=''
Xexpr=''
Xsed=''
Xecho=''
Xcat=''
Xrm=''
Xmv=''
Xcp=''
Xtail=''
Xtr=''
Xmkdir=''
Xsort=''
Xuniq=''
Xgrep=''
Xtrylist=''
Xtest=''
Xinews=''
Xegrep=''
Xmore=''
Xpg=''
XMcc=''
Xvi=''
Xmore=''
Xbin=''
Xcc=''
Xcontains=''
Xcpp=''
Xiandd=''
Xlibc=''
Xmansrc=''
Xmanext=''
Xn=''
Xc=''
Xnovoid=''
Xregisters=''
Xreg1=''
Xreg2=''
Xreg3=''
Xreg4=''
Xreg5=''
Xreg6=''
Xreg7=''
Xreg8=''
Xreg9=''
Xreg10=''
Xreg11=''
Xreg12=''
Xreg13=''
Xreg14=''
Xreg15=''
Xreg16=''
Xregisters=''
Xspitshell=''
Xshsharp=''
Xsharpbang=''
Xstartsh=''
Xpackage=''
XCONFIG=''
X
Xpackage=patch
X
Xecho "Beginning of configuration questions for $package kit."
X: Eunice requires " " instead of "", can you believe it
Xecho " "
X
X: sanity checks
XPATH='.:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc'
Xexport PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
X
Xif test ! -t 0; then
X    echo "Say 'sh Configure', not 'sh <Configure'"
X    exit 1
Xfi
X
X: some greps do not return status, grrr.
Xecho "grimblepritz" >grimble
Xif grep blurfldyick grimble >/dev/null 2>&1 ; then
X    contains=contains
Xelse
X    if grep grimblepritz grimble >/dev/null 2>&1 ; then
X	contains=grep
X    else
X	contains=contains
X    fi
Xfi
Xrm grimble
X: the following should work in any shell
Xcase $contains in
Xcontains*)
X    echo " "
X    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
X    cat >contains <<'EOSS'
Xgrep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
XEOSS
Xchmod 755 contains
Xesac
X
X: first determine how to suppress newline on echo command
Xecho "Checking echo to see how to suppress newlines..."
X(echo "hi there\c" ; echo " ") >.echotmp
Xif $contains c .echotmp >/dev/null 2>&1 ; then
X    echo "...using -n."
X    n='-n'
X    c=''
Xelse
X    echo "...using \\\c."
X    n=''
X    c='\c'
Xfi
Xecho $n "Type carriage return to continue.  Your cursor should be here-->$c"
Xread ans
Xrm .echotmp
X
X: now set up to do reads with possible shell escape
X: if this does not work on your machine, 1,$ s/. myread/read ans/
Xcat <<EOSC >myread
Xans='!'
Xwhile expr "X\$ans" : "X!" >/dev/null; do
X    read ans
X    case "\$ans" in
X    !)
X	sh
X	echo " "
X	echo $n "Your answer: $c"
X	;;
X    !*)
X	set \`expr "X\$ans" : "X!\(.*\)\$"\`
X	sh -c "\$*"
X	echo " "
X	echo $n "Your answer: $c"
X	;;
X    esac
Xdone
XEOSC
X
X: general instructions
Xcat <<EOH
X 
XThis installation shell script will examine your system and ask you questions
Xto determine how $package and any auxiliary files should be installed.  If you
Xget stuck on a question, you may use a ! shell escape to start a subshell or
Xexecute a command.  Many of the questions will have default answers in
Xsquare brackets--typing carriage return will give you the default.
X
XOn some of the questions which ask for file or directory names you are
Xallowed to use the ~name construct to specify the login directory belonging
Xto "name", even if you don't have a shell which knows about that.  Questions
Xwhere this is allowed will be marked "(~name ok)".
X
XMuch effort has been expended to ensure that this shell script will run
Xon any Unix system.  If despite that it blows up on you, your best bet is
Xto edit Configure and run it again.  (Trying to install this package
Xwithout having run Configure may be well nigh impossible.)  Also, let me
X(lwall@sdcrdcf.UUCP) know how I blew it.
X
XThis installation script affects things in two ways: 1) it may do direct
Xvariable substitutions on some of the files included in this kit, and
X2) it builds a config.h file for inclusion in C programs.  You may edit
Xany of these files as the need arises after running this script.
X
XEOH
Xecho $n "[Type carriage return to continue] $c"
X. myread
X
X: get old answers, if there is a config file out there
Xif test -f config.sh; then
X    echo " "
X    echo "(Fetching default answers from your old config.sh file...)"
X    . config.sh
Xfi
X
X: get list of predefined functions in a handy place
Xecho " "
Xif test -f /lib/libc.a; then
X    echo "Your C library is in /lib/libc.a.  You're normal."
X    libc=/lib/libc.a
Xelse
X    if test -f /usr/lib/libc.a; then
X	echo "Your C library is in /usr/lib/libc.a, of all places."
X	libc=/usr/lib/libc.a
X    else
X	if test -f "$libc"; then
X	    echo "Your C library is in $libc, like you said before."
X	else
X	    cat <<'EOM'
X 
XI can't seem to find your C library.  I've looked for /lib/libc.a and
X/usr/lib/libc.a, but neither of those are there.  What is the full name
XEOM
X	    echo $n "of your C library? $c"
X	    . myread
X	    libc="$ans"
X	fi
X    fi
Xfi
Xecho " "
Xecho $n "Extracting names from $libc for later perusal...$c"
Xif ar t $libc > libc.list; then
X    echo "done"
Xelse
X    echo " "
X    echo "The archiver doesn't think $libc is a reasonable library."
X    exit 1
Xfi
X
X: make some quick guesses about what we are up against
Xecho " "
Xecho $n "Hmm...  $c"
Xif $contains SIGTSTP /usr/include/signal.h >/dev/null 2>&1 ; then
X    echo "Looks kind of like a BSD system, but we'll see..."
X    echo exit 0 >bsd
X    echo exit 1 >usg
X    echo exit 1 >v7
Xelse
X    if $contains fcntl.o libc.list >/dev/null 2>&1 ; then
X	echo "Looks kind of like a USG system, but we'll see..."
X	echo exit 1 >bsd
X	echo exit 0 >usg
X	echo exit 1 >v7
X    else
X	echo "Looks kind of like a version 7 system, but we'll see..."
X	echo exit 1 >bsd
X	echo exit 1 >usg
X	echo exit 0 >v7
X    fi
Xfi
Xif $contains vmssystem.o libc.list >/dev/null 2>&1 ; then
X    cat <<'EOI'
XThere is, however, a strange, musty smell in the air that reminds me of
Xsomething...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
XEOI
X    echo "exit 0" >eunice
X    eunicefix=unixtovms
X    eunice=define
X: it so happens the Eunice I know will not run shell scripts in Unix format
Xelse
X    echo " "
X    echo "Congratulations.  You aren't running Eunice."
X    eunicefix=':'
X    eunice=undef
X    echo "exit 1" >eunice
Xfi
Xchmod 755 bsd usg v7 eunice
X$eunicefix bsd usg v7 eunice
X
X: see if sh knows # comments
Xecho " "
Xecho "Checking your sh to see if it knows about # comments..."
Xif sh -c '#' >/dev/null 2>&1 ; then
X    echo "Your sh handles # comments correctly."
X    shsharp=true
X    spitshell=cat
X    echo " "
X    echo "Okay, let's see if #! works on this system..."
X    echo "#!/bin/echo hi" > try
X    $eunicefix try
X    chmod 755 try
X    try > today
X    if test -s today; then
X	echo "It does."
X	sharpbang='#!'
X    else
X	echo "#! /bin/echo hi" > try
X	$eunicefix try
X	chmod 755 try
X	try > today
X	if test -s today; then
X	    echo "It does."
X	    sharpbang='#! '
X	else
X	    echo "It doesn't."
X	    sharpbang=': use '
X	fi
X    fi
Xelse
X    echo "Your sh doesn't grok # comments--I will strip them later on."
X    shsharp=false
X    echo "exec grep -v '^#'" >spitshell
X    chmod 755 spitshell
X    $eunicefix spitshell
X    spitshell=`pwd`/spitshell
X    echo "I presume that if # doesn't work, #! won't work either!"
X    sharpbang=': use '
Xfi
X
X: figure out how to guarantee sh startup
Xecho " "
Xecho "Checking out how to guarantee sh startup..."
Xstartsh=$sharpbang'/bin/sh'
Xecho "Let's see if '$startsh' works..."
Xcat >try <<EOSS
X$startsh
Xset abc
Xtest "$?abc" != 1
XEOSS
X
Xchmod 755 try
X$eunicefix try
Xif try; then
X    echo "Yup, it does."
Xelse
X    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
Xfi
Xrm -f try today
X
X: find out where common programs are
Xecho " "
Xecho "Locating common programs..."
Xpth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /etc /usr/lib"
Xcat <<EOSC >loc
X$startsh
Xthing=\$1
Xshift
Xdflt=\$1
Xshift
Xfor dir in \$*; do
X    case "\$thing" in
X    .)
X	if test -d \$dir/\$thing; then
X	    echo \$dir
X	    exit 0
X	fi
X	;;
X    *)
X	if test -f \$dir/\$thing; then
X	    echo \$dir/\$thing
X	    exit 0
X	fi
X	;;
X    esac
Xdone
Xecho \$dflt
Xexit 1
XEOSC
Xchmod 755 loc
X$eunicefix loc
Xloclist="
Xexpr
Xsed
Xecho
Xcat
Xrm
Xgrep
X"
Xtrylist="
Xtest
XMcc
X"
Xfor file in $loclist; do
X    xxx=`loc $file $file $pth`
X    eval $file=$xxx
X    case "$xxx" in
X    /*)
X	echo $file is in $xxx.
X	;;
X    *)
X	echo "I don't know where $file is.  I hope it's in everyone's PATH."
X	;;
X    esac
Xdone
Xecho " "
Xecho "Don't worry if any of the following aren't found..."
Xfor file in $trylist; do
X    xxx=`loc $file $file $pth`
X    eval $file=$xxx
X    case "$xxx" in
X    /*)
X	echo $file is in $xxx.
X	;;
X    *)
X	echo "I don't see $file out there, offhand."
X	;;
X    esac
Xdone
Xcase $egrep in
Xegrep)
X    echo "Substituting grep for egrep."
X    egrep=$grep
X    ;;
Xesac
Xcase $test in
Xtest)
X    echo "Hopefully test is built into your sh."
X    ;;
X/bin/test)
X    echo " "
X    echo $n 'Is your "test" built into sh? [n] (OK to guess) '"$c"
X    . myread
X    case $ans in
X    y*) test=test ;;
X    esac
X    ;;
X*)
X    test=test
X    ;;
Xesac
Xcase $echo in
Xecho)
X    echo "Hopefully echo is built into your sh."
X    ;;
X/bin/echo)
X    echo " "
X    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
X    $echo $n "hi there$c" >foo1
X    echo $n "hi there$c" >foo2
X    if cmp foo1 foo2 >/dev/null 2>&1; then
X	echo "They are compatible.  In fact, they may be identical."
X    else
X	echo "They are not compatible--the echo builtin will be used."
X	echo=echo
X    fi
X    $rm -f foo1 foo2
X    ;;
X*)
X    echo=echo
X    ;;
Xesac
X
X: set up shell script to do ~ expansion
Xcat >filexp <<EOSS
X$startsh
X: expand filename
Xcase \$1 in
X~/*|~)
X    $echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
X    ;;
X~*)
X    if $test -f /bin/csh; then
X	/bin/csh -f -c "glob \$1"
X	$echo ""
X    else
X	name=\`$expr x\$1 : '..\([^/]*\)'\`
X	dir=\`$sed </etc/passwd -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}'\`
X	if $test ! -d "\$dir"; then
X	    me=\`basename \$0\`
X	    $echo "\$me: can't locate home directory for: \$name" >&2
X	    exit 1
X	fi
X	case \$1 in
X	*/*)
X	    $echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
X	    ;;
X	*)
X	    $echo \$dir
X	    ;;
X	esac
X    fi
X    ;;
X*)
X    $echo \$1
X    ;;
Xesac
XEOSS
Xchmod 755 filexp
X$eunicefix filexp
X
X: determine where public executables go
Xcase "$bin" in
X'')
X    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
X    ;;
X*)  dflt="$bin"
X    ;;
Xesac
Xbin='blurfl/dyick'
Xwhile $test ! -d "$bin" ; do
X    case $bin in
X      blurfl*) ;;
X      *) $echo "$bin does not appear to exist." ;;
X    esac
X    $echo " "
X    $echo $n "Where do you want to put the public executables? [$dflt] $c"
X    . myread
X    bin="$ans"
X    bin=`filexp $bin`
X    case $bin in
X      '') bin=$dflt ;;
X    esac
Xdone
X
X: determine where manual pages go
Xcase "$mansrc" in
X'')
X    dflt=`loc . /usr/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1 /usr/man/man1`
X    ;;
X*)  dflt="$mansrc"
X    ;;
Xesac
Xmansrc='blurfl/dyick'
Xwhile $test ! -d "$mansrc" ; do
X    case $mansrc in
X      blurfl*) ;;
X      *) $echo "$mansrc does not appear to exist." ;;
X    esac
X    $echo " "
X    $echo $n "Where do the manual pages (source) go? [$dflt] $c"
X    . myread
X    mansrc=`filexp "$ans"`
X    case $mansrc in
X      '') mansrc=$dflt ;;
X    esac
Xdone
Xcase "$mansrc" in
X*l)
X    manext=l
X    ;;
X*n)
X    manext=n
X    ;;
X*)
X    manext=1
X    ;;
Xesac
X
X: see if we need a special compiler
X$echo " "
Xif usg; then
X    case "$cc" in
X    '')
X	case "$Mcc" in
X	/*) dflt='Mcc'
X	    ;;
X	*)
X	    if $contains '\-M' $mansrc/cc.1 >/dev/null 2>&1 ; then
X		dflt='cc -M'
X	    else
X		dflt='cc'
X	    fi
X	    ;;
X	esac
X	;;
X    *)  dflt="$cc";;
X    esac
X    $cat <<'EOM'
X 
XOn some systems the default C compiler will not resolve multiple global
Xreferences that happen to have the same name.  On some such systems the
X"Mcc" command may be used to force these to be resolved.  On other systems
Xa "cc -M" command is required.  What command will force resolution on
XEOM
X    $echo $n "this system? [$dflt] $c"
X    . myread
X    cc="$ans"
X    case "$cc" in
X	'') cc="$dflt" ;;
X    esac
Xelse
X    $echo "Not a USG system--assuming cc can resolve multiple definitions."
X    cc=cc
Xfi
X
X: see how we invoke the C preprocessor
Xecho " "
Xecho "Checking to see how your C preprocessor is invoked..."
Xcat <<'EOT' >testcpp.c
X#define ABC abc
X#define XYZ xyz
XABC.XYZ
XEOT
Xecho 'Maybe "cc -E" will work...'
Xcc -E testcpp.c >testcpp.out 2>&1
Xif $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
X    echo "Yup, it does."
X    cpp='cc -E'
Xelse
X    echo 'Nope...maybe "cc -P" will work...'
X    cc -P testcpp.c >testcpp.out 2>&1
X    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
X	echo "Yup, that does."
X	cpp='cc -P'
X    else
X	echo 'Nixed again...maybe "/lib/cpp" will work...'
X	/lib/cpp testcpp.c >testcpp.out 2>&1
X	if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
X	    echo "Hooray, it works!  I was beginning to wonder."
X	    cpp='/lib/cpp'
X	else
X	    echo 'Hmm...maybe you already told me...'
X	    case "$cpp" in
X	    '') ;;
X	    *) $cpp testcpp.c >testcpp.out 2>&1;;
X	    esac
X	    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
X		echo "Hooray, you did!  I was beginning to wonder."
X	    else
X		echo $n "Nope. I can't find a C preprocessor.  Name one: $c"
X		. myread
X		cpp="$ans"
X		$cpp testcpp.c >testcpp.out 2>&1
X		if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
X		    echo "OK, that will do."
X		else
X		    echo "Sorry, I can't get that to work.  Go find one."
X		    exit 1
X		fi
X	    fi
X	fi
X    fi
Xfi
Xrm -f testcpp.c testcpp.out
X
X: check for pdp11
Xecho " "
Xif usg; then
X    : pdp11 is already defined
Xelse
X    cat <<'EOT' >pdp11.c
X#ifdef pdp11
Xexit 0
X#else
Xexit 1
X#endif
XEOT
X    $cpp pdp11.c | grep exit >pdp11
X    chmod 755 pdp11
X    $eunicefix pdp11
X    rm pdp11.c
Xfi
Xif pdp11; then
X    echo "This looks like a pdp11 to me."
Xelse
X    echo "This doesn't look like a pdp11 to me."
Xfi
X
X: see if we should throw a -i into the Makefile
X$echo " "
Xif pdp11; then
X    if $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1 ; then
X	$echo $n "Your system appears to have separate I and D space.  Is this true? [y] $c"
X	. myread
X	case $ans in
X	    n*|f*) iandd='' ;;
X	    *)     iandd='-i' ;;
X	esac
X    else
X	$echo "Your system appears to NOT have separate I and D space."
X	$echo $n "Is this correct? [y] $c"
X	. myread
X	case $ans in
X	    n*|f*) iandd='-i' ;;
X	    *)     iandd='' ;;
X	esac
X    fi
Xelse
X    $echo "Not a pdp11--assuming no separate I and D."
Xfi
X
X: check for void type
X$echo " "
X$echo "Checking to see if your C compiler groks the void type..."
X$cat >try.c <<'EOCP'
Xvoid main();
XEOCP
Xif cc -c try.c >/dev/null 2>&1 ; then
X    novoid='undef'
X    $echo "Yup, it does."
Xelse
X    novoid='define'
X    $echo "Nope, it doesn't (boo hiss).  I will substitute int."
Xfi
X$rm try.*
X
X: see how many registers declarations we want to use
X$echo " "
Xcase "$registers" in
X'')
X    if pdp11; then
X	dflt=3
X    else
X	dflt=6
X    fi
X    ;;
X*)  dflt=$registers ;;
Xesac
Xcat <<EOM
X 
XDifferent C compilers on different machines pay attention to different
Xnumbers of register declarations.  How many register declarations in
XEOM
X$echo $n "each routine does your C compiler pay attention to? [$dflt] $c"
X. myread
Xcase "$ans" in
X'') ans=$dflt;;
Xesac
Xregisters=$ans
Xreg1=''
Xawk "END { for (i=1; i<=16; i++) printf \"reg%d=''\n\", i}" </dev/null >.foo
X. .foo
Xawk "END { for (i=1; i<=$registers; i++) printf \"reg%d=register\n\", i}" \
X	</dev/null >.foo
X. .foo
Xrm -f .foo
X
X
X$echo " "
X$echo "End of configuration questions."
X$echo " "
X
X: create config.sh file
X$echo " "
X$echo "Creating config.sh..."
X$spitshell <<EOT >config.sh
X$startsh
X# config.sh
X# This file was produced by running the Configure script.
X
Xeunice='$eunice'
Xeunicefix='$eunicefix'
Xloclist='$loclist'
Xexpr='$expr'
Xsed='$sed'
Xecho='$echo'
Xcat='$cat'
Xrm='$rm'
Xmv='$mv'
Xcp='$cp'
Xtail='$tail'
Xtr='$tr'
Xmkdir='$mkdir'
Xsort='$sort'
Xuniq='$uniq'
Xgrep='$grep'
Xtrylist='$trylist'
Xtest='$test'
Xinews='$inews'
Xegrep='$egrep'
Xmore='$more'
Xpg='$pg'
XMcc='$Mcc'
Xvi='$vi'
Xmore='$more'
Xbin='$bin'
Xcc='$cc'
Xcontains='$contains'
Xcpp='$cpp'
Xiandd='$iandd'
Xlibc='$libc'
Xmansrc='$mansrc'
Xmanext='$manext'
Xn='$n'
Xc='$c'
Xnovoid='$novoid'
Xregisters='$registers'
Xreg1='$reg1'
Xreg2='$reg2'
Xreg3='$reg3'
Xreg4='$reg4'
Xreg5='$reg5'
Xreg6='$reg6'
Xreg7='$reg7'
Xreg8='$reg8'
Xreg9='$reg9'
Xreg10='$reg10'
Xreg11='$reg11'
Xreg12='$reg12'
Xreg13='$reg13'
Xreg14='$reg14'
Xreg15='$reg15'
Xreg16='$reg16'
Xregisters='$registers'
Xspitshell='$spitshell'
Xshsharp='$shsharp'
Xsharpbang='$sharpbang'
Xstartsh='$startsh'
Xpackage='$package'
XCONFIG=true
XEOT
X
X: create config.h file
X$echo " "
X$echo "Creating config.h..."
X$cat <<EOT >config.h
X/* config.h
X * This file was produced by running the Configure script.
X * Feel free to modify any of this as the need arises.
X */
X
X
X/* How many register declarations are paid attention to? */
X
X#define Reg1 $reg1
X#define Reg2 $reg2
X#define Reg3 $reg3
X#define Reg4 $reg4
X#define Reg5 $reg5
X#define Reg6 $reg6
X#define Reg7 $reg7
X#define Reg8 $reg8
X#define Reg9 $reg9
X#define Reg10 $reg10
X#define Reg11 $reg11
X#define Reg12 $reg12
X#define Reg13 $reg13
X#define Reg14 $reg14
X#define Reg15 $reg15
X#define Reg16 $reg16
X
X#$novoid	void int	/* is void to be avoided? */
XEOT
X
XCONFIG=true
X
Xif $contains '\.SH' MANIFEST >/dev/null 2>&1; then
X    $echo " "
X    $echo "Doing variable substitutions on various files..."
X    $echo " "
X    set `$grep <MANIFEST '\.SH' | awk '{print $1}'`
X    for file in $*; do
X	. $file
X    done
Xfi
X
Xif $contains '^depend:' Makefile >/dev/null 2>&1; then
X    $echo " "
X    $echo 'Now you need to generate make dependencies by running "make depend".'
X    $echo 'You might prefer to run it in background: "make depend > makedepend.out &"'
X    $echo $n "Would you like me to run it for you (it takes quite a while)? [n] $c" 
X    . myread
X    case "$ans" in
X    y*) make depend;;
X    esac
Xfi
X
X$rm -f libc.list kit*isdone
X
Xif test -f Makefile; then
X    $echo "Now you must run a make."
Xelse
X    $echo "Done."
Xfi
X: end of Configure
!STUFFY!FUNK!
echo Extracting patch.man
cat >patch.man <<'!STUFFY!FUNK!'
''' $Header: patch.man,v 1.4 86/08/01 19:23:22 lwall Exp $
''' 
''' $Log:	patch.man,v $
''' Revision 1.4  86/08/01  19:23:22  lwall
''' Documented -v, -p, -F.
''' Added notes to patch senders.
''' 
''' Revision 1.3  85/03/26  15:11:06  lwall
''' Frozen.
''' 
''' Revision 1.2.1.4  85/03/12  16:14:27  lwall
''' Documented -p.
''' 
''' Revision 1.2.1.3  85/03/12  16:09:41  lwall
''' Documented -D.
''' 
''' Revision 1.2.1.2  84/12/05  11:06:55  lwall
''' Added -l switch, and noted bistability bug.
''' 
''' Revision 1.2.1.1  84/12/04  17:23:39  lwall
''' Branch for sdcrdcf changes.
''' 
''' Revision 1.2  84/12/04  17:22:02  lwall
''' Baseline version.
''' 
.de Sh
.br
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp
.if t .sp .5v
.if n .sp
..
'''
'''     Set up \*(-- to give an unbreakable dash;
'''     string Tr holds user defined translation string.
'''     Bell System Logo is used as a dummy character.
'''
.ie n \{\
.tr \(bs-\*(Tr
.ds -- \(bs-
.if (\n(.H=4u)&(1m=24u) .ds -- \(bs\h'-12u'\(bs\h'-12u'-\" diablo 10 pitch
.if (\n(.H=4u)&(1m=20u) .ds -- \(bs\h'-12u'\(bs\h'-8u'-\" diablo 12 pitch
.ds L" ""
.ds R" ""
.ds L' '
.ds R' '
'br\}
.el\{\
.ds -- \(em\|
.tr \*(Tr
.ds L" ``
.ds R" ''
.ds L' `
.ds R' '
'br\}
.TH PATCH 1 LOCAL
.SH NAME
patch - a program for applying a diff file to an original
.SH SYNOPSIS
.B patch
[options] orig patchfile [+ [options] orig]
.sp
but usually just
.sp
.B patch
<patchfile
.SH DESCRIPTION
.I Patch
will take a patch file containing any of the three forms of difference
listing produced by the
.I diff
program and apply those differences to an original file, producing a patched
version.
By default, the patched version is put in place of the original, with
the original file backed up to the same name with the
extension \*(L".orig\*(R", or as specified by the
.B -b
switch.
You may also specify where you want the output to go with a
.B -o
switch.
If
.I patchfile
is omitted, or is a hyphen, the patch will be read from standard input.
.PP
Upon startup, patch will attempt to determine the type of the diff listing,
unless over-ruled by a
.BR -c ,
.BR -e ,
or
.B -n
switch.
Context diffs and normal diffs are applied by the
.I patch
program itself, while ed diffs are simply fed to the
.I ed
editor via a pipe.
.PP
.I Patch
will try to skip any leading garbage, apply the diff,
and then skip any trailing garbage.
Thus you could feed an article or message containing a
diff listing to
.IR patch ,
and it should work.
If the entire diff is indented by a consistent amount,
this will be taken into account.
.PP
With context diffs, and to a lesser extent with normal diffs,
.I patch
can detect when the line numbers mentioned in the patch are incorrect,
and will attempt to find the correct place to apply each hunk of the patch.
As a first guess, it takes the line number mentioned for the hunk, plus or
minus any offset used in applying the previous hunk.
If that is not the correct place,
.I patch
will scan both forwards and backwards for a set of lines matching the context
given in the hunk.
First
.I patch
looks for a place where all lines of the context match.
If no such place is found, and it's a context diff, and the maximum fuzz factor
is set to 1 or more, then another scan takes place ignoring the first and last
line of context.
If that fails, and the maximum fuzz factor is set to 2 or more,
the first two and last two lines of context are ignored,
and another scan is made.
(The default maximum fuzz factor is 2.)
If
.I patch
cannot find a place to install that hunk of the patch, it will put the
hunk out to a reject file, which normally is the name of the output file
plus \*(L".rej\*(R".
(Note that the rejected hunk will come out in context diff form whether the
input patch was a context diff or a normal diff.
If the input was a normal diff, many of the contexts will simply be null.)
The line numbers on the hunks in the reject file may be different than
in the patch file: they reflect the approximate location patch thinks the
failed hunks belong in the new file rather than the old one.
.PP
As each hunk is completed, you will be told whether the hunk succeeded or
failed, and which line (in the new file)
.I patch
thought the hunk should go on.
If this is different from the line number specified in the diff you will
be told the offset.
A single large offset MAY be an indication that a hunk was installed in the
wrong place.
You will also be told if a fuzz factor was used to make the match, in which
case you should also be slightly suspicious.
.PP
If no original file is specified on the command line,
.I patch
will try to figure out from the leading garbage what the name of the file
to edit is.
In the header of a context diff, the filename is found from lines beginning
with \*(L"***\*(R" or \*(L"---\*(R", with the shortest name of an existing
file winning.
Only context diffs have lines like that, but if there is an \*(L"Index:\*(R"
line in the leading garbage,
.I patch
will try to use the filename from that line.
The context diff header takes precedence over an Index line.
If no filename can be intuited from the leading garbage, you will be asked
for the name of the file to patch.
.PP
(If the original file cannot be found, but a suitable SCCS or RCS file is
handy,
.I patch
will attempt to get or check out the file.)
.PP
Additionally, if the leading garbage contains a \*(L"Prereq: \*(R" line,
.I patch
will take the first word from the prerequisites line (normally a version
number) and check the input file to see if that word can be found.
If not,
.I patch
will ask for confirmation before proceeding.
.PP
The upshot of all this is that you should be able to say, while in a news
interface, the following:
.Sp
	| patch -d /usr/src/local/blurfl
.Sp
and patch a file in the blurfl directory directly from the article containing
the patch.
.PP
If the patch file contains more than one patch,
.I patch
will try to apply each of them as if they came from separate patch files.
This means, among other things, that it is assumed that the name of the file
to patch must be determined for each diff listing,
and that the garbage before each diff listing will
be examined for interesting things such as filenames and revision level, as
mentioned previously.
You can give switches (and another original file name) for the second and
subsequent patches by separating the corresponding argument lists
by a \*(L'+\*(R'.
(The argument list for a second or subsequent patch may not specify a new
patch file, however.)
.PP
.I Patch
recognizes the following switches:
.TP 5
.B \-b
causes the next argument to be interpreted as the backup extension, to be
used in place of \*(L".orig\*(R".
.TP 5
.B \-c
forces
.I patch
to interpret the patch file as a context diff.
.TP 5
.B \-d
causes
.I patch
to interpret the next argument as a directory, and cd to it before doing
anything else.
.TP 5
.B \-D
causes
.I patch
to use the "#ifdef...#endif" construct to mark changes.
The argument following will be used as the differentiating symbol.
Note that, unlike the C compiler, there must be a space between the
.B \-D
and the argument.
.TP 5
.B \-e
forces
.I patch
to interpret the patch file as an ed script.
.TP 5
.B \-f
forces
.I patch
to assume that the user knows exactly what he or she is doing, and to not
ask any questions.
It does not suppress commentary, however.
Use
.B \-s
for that.
.TP 5
.B \-F<number>
sets the maximum fuzz factor.
This switch only applied to context diffs, and causes
.I patch
to ignore up to that many lines in looking for places to install a hunk.
Note that a larger fuzz factor increases the odds of a faulty patch.
The default fuzz factor is 2, and it may not be set to more than
the number of lines of context in the context diff, ordinarily 3.
.TP 5
.B \-l
causes the pattern matching to be done loosely, in case the tabs and
spaces have been munged in your input file.
Any sequence of whitespace in the pattern line will match any sequence
in the input file.
Normal characters must still match exactly.
Each line of the context must still match a line in the input file.
.TP 5
.B \-n
forces
.I patch
to interpret the patch file as a normal diff.
.TP 5
.B \-o
causes the next argument to be interpreted as the output file name.
.TP 5
.B \-p<number>
sets the pathname strip count,
which controls how pathnames found in the patch file are treated, in case
the you keep your files in a different directory than the person who sent
out the patch.
The strip count specifies how many backslashes are to be stripped from
the front of the pathname.
(Any intervening directory names also go away.)
For example, supposing the filename in the patch file was
.sp
	/u/howard/src/blurfl/blurfl.c
.sp
setting
.B \-p
or
.B \-p0
gives the entire pathname unmodified,
.B \-p1
gives
.sp
	u/howard/src/blurfl/blurfl.c
.sp
without the leading slash,
.B \-p4
gives
.sp
	blurfl/blurfl.c
.sp
and not specifying
.B \-p
at all just gives you "blurfl.c".
Whatever you end up with is looked for either in the current directory,
or the directory specified by the
.B \-d
switch.
.TP 5
.B \-r
causes the next argument to be interpreted as the reject file name.
.TP 5
.B \-R
tells
.I patch
that this patch was created with the old and new files swapped.
(Yes, I'm afraid that does happen occasionally, human nature being what it
is.)
.I Patch
will attempt to swap each hunk around before applying it.
Rejects will come out in the swapped format.
The
.B \-R
switch will not work with ed diff scripts because there is too little
information to reconstruct the reverse operation.
.Sp
If the first hunk of a patch fails,
.I patch
will reverse the hunk to see if it can be applied that way.
If it can, you will be asked if you want to have the
.B \-R
switch set.
If it can't, the patch will continue to be applied normally.
(Note: this method cannot detect a reversed patch if it is a normal diff
and if the first command is an append (i.e. it should have been a delete)
since appends always succeed, due to the fact that a null context will match
anywhere.
Luckily, most patches add or change lines rather than delete them, so most
reversed normal diffs will begin with a delete, which will fail, triggering
the heuristic.)
.TP 5
.B \-s
makes
.I patch
do its work silently, unless an error occurs.
.TP 5
.B \-v
causes
.I patch
to print out it's revision header and patch level.
.TP 5
.B \-x<number>
sets internal debugging flags, and is of interest only to
.I patch
patchers.
.SH ENVIRONMENT
No environment variables are used by
.IR patch .
.SH FILES
/tmp/patch*
.SH SEE ALSO
diff(1)
.SH NOTES FOR PATCH SENDERS
There are several things you should bear in mind if you are going to
be sending out patches.
First, you can save people a lot of grief by keeping a patchlevel.h file
which is patched to increment the patch level as the first diff in the
patch file you send out.
If you put a Prereq: line in with the patch, it won't let them apply
patches out of order without some warning.
Second, make sure you've specified the filenames right, either in a
context diff header, or with an Index: line.
If you are patching something in a subdirectory, be sure to tell the patch
user to specify a 
.B \-p
switch as needed.
Third, you can create a file by sending out a diff that compares a
null file to the file you want to create.
This will only work if the file you want to create doesn't exist already in
the target directory.
Fourth, take care not to send out reversed patches, since it makes people wonder
whether they already applied the patch.
Fifth, while you may be able to get away with putting 582 diff listings into
one file, it is probably wiser to group related patches into separate files in
case something goes haywire.
.SH DIAGNOSTICS
Too many to list here, but generally indicative that
.I patch
couldn't parse your patch file.
.PP
The message \*(L"Hmm...\*(R" indicates that there is unprocessed text in
the patch file and that
.I patch
is attempting to intuit whether there is a patch in that text and, if so,
what kind of patch it is.
.SH CAVEATS
.I Patch
cannot tell if the line numbers are off in an ed script, and can only detect
bad line numbers in a normal diff when it finds a \*(L"change\*(R" or
a \*(L"delete\*(R" command.
A context diff using fuzz factor 3 may have the same problem.
Until a suitable interactive interface is added, you should probably do
a context diff in these cases to see if the changes made sense.
Of course, compiling without errors is a pretty good indication that the patch
worked, but not always.
.PP
.I Patch
usually produces the correct results, even when it has to do a lot of
guessing.
However, the results are guaranteed to be correct only when the patch is
applied to exactly the same version of the file that the patch was
generated from.
.SH BUGS
Could be smarter about partial matches, excessively \&deviant offsets and
swapped code, but that would take an extra pass.
.PP
If code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
#endif),
.I patch
is incapable of patching both versions, and, if it works at all, will likely
patch the wrong one, and tell you that it succeeded to boot.
.PP
If you apply a patch you've already applied,
.I patch
will think it is a reversed patch, and offer to un-apply the patch.
This could be construed as a feature.
!STUFFY!FUNK!
echo Extracting README
cat >README <<'!STUFFY!FUNK!'
			Patch Kit, Version 1.5

		    Copyright (c) 1985, Larry Wall

You may copy the patch kit in whole or in part as long as you don't try to
make money off it, or pretend that you wrote it.
--------------------------------------------------------------------------

Please read all the directions below before you proceed any further, and
then follow them carefully.  Failure to do so may void your warranty. :-)

After you have unpacked your kit, you should have all the files listed
in MANIFEST.

Installation

1)  Run Configure.  This will figure out various things about your system.
    Some things Configure will figure out for itself, other things it will
    ask you about.  It will then proceed to make config.h, config.sh, and
    Makefile.

    You might possibly have to trim # comments from the front of Configure
    if your sh doesn't handle them, but all other # comments will be taken
    care of.

2)  Glance through config.h and common.h to make sure system dependencies
    are correct.  Most of them should have been taken care of by running
    the Configure script.

    If you have any additional changes to make to the C definitions, they
    can be done in the Makefile, or in config.h.

3)  make

    This will attempt to make patch in the current directory.

4)  make install

    This will put patch into a public directory (normally /usr/local/bin).
    It will also try to put the man pages in a reasonable place.

5)  Read the manual entry before running patch.

6)  IMPORTANT!  Help save the world!  Communicate any problems and
    suggested patches to me, lwall@sdcrdcf.UUCP (Larry Wall), so we can
    keep the world in sync.  If you have a problem, there's someone else
    out there who either has had or will have the same problem.

    If possible, send in patches such that the patch program will apply them.
    Context diffs are the best, then normal diffs.  Don't send ed scripts--
    I've probably changed my copy since the version you have.

    Watch for patch patches in net.sources.bugs or net.news.b.  Patches
    will generally be appliable (is that a word?) by the patch program.  If
    you are just now bringing up patch and aren't sure how many patches
    there are, write to me and I'll send any you don't have.


NEW FEATURES IN THIS RELEASE

(Correct) support for 4.3-style context diffs.
Files can be created from scratch.
You can specify a fuzz-factor for context matching.
You can force patch to ask no questions.
You can specify how much of the leading pathname to strip off filenames.
Uses a Configure script for greater portability.
You are now asked if you want to apply a reversed patch.
!STUFFY!FUNK!
echo Extracting Makefile.SH
cat >Makefile.SH <<'!STUFFY!FUNK!'
case $CONFIG in
    '') . config.sh ;;
esac
echo "Extracting Makefile (with variable substitutions)"
cat >Makefile <<!GROK!THIS!
# $Header: Makefile.SH,v 1.1 86/08/01 20:18:35 lwall Exp $
#
# $Log:	Makefile.SH,v $
Revision 1.1  86/08/01  20:18:35  lwall
Initial revision


CC = $cc
bin = $bin
mansrc = $mansrc
manext = $manext
CFLAGS = $iandd -O
LDFLAGS = $iandd

!GROK!THIS!
cat >>Makefile <<'!NO!SUBS!'

public = patch
private = 
manpages = patch.man
util = Makefile

c = patch.c

obj = patch.o

lintflags = -phbvxac

addedbyconf = Makefile.old bsd config.h config.sh eunice loc pdp11 usg v7

# grrr
SHELL = /bin/sh

.c.o:
	$(CC) -c $(CFLAGS) $*.c

all: $(public) $(private) $(util)
	touch all

patch: $(obj)
	$(CC) $(LDFLAGS) $(obj) $(libs) -o patch

# won't work with csh
install: patch
	export PATH || exit 1
	- mv $(bin)/patch $(bin)/patch.old
	- if test `pwd` != $(bin); then cp $(public) $(bin); fi
	cd $(bin); chmod 755 $(public)
	- if test `pwd` != $(mansrc); then \
for page in $(manpages); do \
cp $$page $(mansrc)/`basename $$page .man`.$(manext); \
done; \
fi

clean:
	rm -f *.o

realclean:
	rm -f patch *.o core $(addedbyconf)

# The following lint has practically everything turned on.  Unfortunately,
# you have to wade through a lot of mumbo jumbo that can't be suppressed.
# If the source file has a /*NOSTRICT*/ somewhere, ignore the lint message
# for that spot.

lint:
	lint $(lintflags) $(defs) $(c) > patch.fuzz

!NO!SUBS!
$eunicefix Makefile
!STUFFY!FUNK!
echo Extracting MANIFEST
cat >MANIFEST <<'!STUFFY!FUNK!'
After all the patch kits are run you should have the following files:

Filename		Kit Description
--------		--- -----------
Configure                2  A shell script that installs everything system dependent.
MANIFEST                 2  This list of files.
Makefile.SH              2  The makefile.
README                   2  Installation instructions.
patch.c                  1  The patch program.
patch.man                2  Manual page for patch.
patchlevel.h             2  The patch level of the patch program.
!STUFFY!FUNK!
echo Extracting patchlevel.h
cat >patchlevel.h <<'!STUFFY!FUNK!'
#define PATCHLEVEL 0

!STUFFY!FUNK!
echo ""
echo "End of kit 2 (of 2)"
cat /dev/null >kit2isdone
config=true
for iskit in 1 2; do
    if test -f kit${iskit}isdone; then
	echo "You have run kit ${iskit}."
    else
	echo "You still need to run kit ${iskit}."
	config=false
    fi
done
case $config in
    true)
	echo "You have run all your kits.  Please read README and then type Configure."
	chmod 755 Configure
	;;
esac
: I do not append .signature, but someone might mail this.
exit