Subject: v07i040: Release 2.0 of patch, Part03/03 Newsgroups: mod.sources Approved: mirror!rs Submitted by: sdcrdcf!lwall (Larry Wall) Mod.sources: Volume 7, Issue 40 Archive-name: patch2/Part03 Here is the official 2.0 release of patch. It supersedes the 1.5 beta version posted to net.sources, and the version that comes with 4.3bsd. Larry Wall sdcrdcf!lwall --------------------------CUT HERE--------------------------- #! /bin/sh # Make a new directory for the patch sources, cd to it, and run kits 1 thru 3 # through sh. When all 3 kits have been run, read README. echo "This is patch kit 3 (of 3). If kit 3 is complete, the line" echo '"'"End of kit 3 (of 3)"'" will echo at the end.' echo "" export PATH || (echo "You didn't use sh, you clunch." ; kill $$) echo Extracting common.h sed >common.h <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: common.h,v 2.0 86/09/17 15:36:39 lwall Exp $ X * X * $Log: common.h,v $ X * Revision 2.0 86/09/17 15:36:39 lwall X * Baseline for netwide release. X * X */ X X#define DEBUGGING X X#include "config.h" X X/* shut lint up about the following when return value ignored */ X X#define Signal (void)signal X#define Unlink (void)unlink X#define Lseek (void)lseek X#define Fseek (void)fseek X#define Fstat (void)fstat X#define Pclose (void)pclose X#define Close (void)close X#define Fclose (void)fclose X#define Fflush (void)fflush X#define Sprintf (void)sprintf X#define Mktemp (void)mktemp X#define Strcpy (void)strcpy X#define Strcat (void)strcat X X#include X#include X#include X#include X#include X#include X X/* constants */ X X#define TRUE (1) X#define FALSE (0) X X#define MAXHUNKSIZE 100000 /* is this enough lines? */ X#define INITHUNKMAX 125 /* initial dynamic allocation size */ X#define MAXLINELEN 1024 X#define BUFFERSIZE 1024 X#define ORIGEXT ".orig" X#define SCCSPREFIX "s." X#define GET "get -e %s" X#define RCSSUFFIX ",v" X#define CHECKOUT "co -l %s" X X/* handy definitions */ X X#define Null(t) ((t)0) X#define Nullch Null(char *) X#define Nullfp Null(FILE *) X#define Nulline Null(LINENUM) X X#define Ctl(ch) ((ch) & 037) X X#define strNE(s1,s2) (strcmp(s1, s2)) X#define strEQ(s1,s2) (!strcmp(s1, s2)) X#define strnNE(s1,s2,l) (strncmp(s1, s2, l)) X#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) X X/* typedefs */ X Xtypedef char bool; Xtypedef long LINENUM; /* must be signed */ Xtypedef unsigned MEM; /* what to feed malloc */ X X/* globals */ X XEXT int Argc; /* guess */ XEXT char **Argv; XEXT int Argc_last; /* for restarting plan_b */ XEXT char **Argv_last; X XEXT struct stat filestat; /* file statistics area */ XEXT int filemode INIT(0644); X XEXT char buf[MAXLINELEN]; /* general purpose buffer */ XEXT FILE *ofp INIT(Nullfp); /* output file pointer */ XEXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ X XEXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ XEXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ X X#define MAXFILEC 2 XEXT int filec INIT(0); /* how many file arguments? */ XEXT char *filearg[MAXFILEC]; XEXT bool ok_to_create_file INIT(FALSE); XEXT char *bestguess INIT(Nullch); /* guess at correct filename */ X XEXT char *outname INIT(Nullch); XEXT char rejname[128]; X XEXT char *origext INIT(Nullch); X XEXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX"); XEXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */ XEXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX"); XEXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX"); XEXT bool toutkeep INIT(FALSE); XEXT bool trejkeep INIT(FALSE); X XEXT LINENUM last_offset INIT(0); X#ifdef DEBUGGING XEXT int debug INIT(0); X#endif XEXT LINENUM maxfuzz INIT(2); XEXT bool force INIT(FALSE); XEXT bool verbose INIT(TRUE); XEXT bool reverse INIT(FALSE); XEXT bool noreverse INIT(FALSE); XEXT bool skip_rest_of_patch INIT(FALSE); XEXT int strippath INIT(957); XEXT bool canonicalize INIT(FALSE); X X#define CONTEXT_DIFF 1 X#define NORMAL_DIFF 2 X#define ED_DIFF 3 X#define NEW_CONTEXT_DIFF 4 XEXT int diff_type INIT(0); X XEXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ XEXT char if_defined[128]; /* #ifdef xyzzy */ XEXT char not_defined[128]; /* #ifndef xyzzy */ XEXT char else_defined[] INIT("#else\n");/* #else */ XEXT char end_defined[128]; /* #endif xyzzy */ X XEXT char *revision INIT(Nullch); /* prerequisite revision, if any */ X Xchar *malloc(); Xchar *realloc(); Xchar *strcpy(); Xchar *strcat(); Xchar *sprintf(); /* usually */ Xlong atol(); Xlong lseek(); Xchar *mktemp(); !STUFFY!FUNK! echo Extracting README sed >README <<'!STUFFY!FUNK!' -e 's/X//' X Patch Kit, Version 2.0 X X Copyright (c) 1986, Larry Wall X XYou may copy the patch kit in whole or in part as long as you don't try to Xmake money off it, or pretend that you wrote it. X-------------------------------------------------------------------------- X XPlease read all the directions below before you proceed any further, and Xthen follow them carefully. Failure to do so may void your warranty. :-) X XAfter you have unpacked your kit, you should have all the files listed Xin MANIFEST. X XInstallation X X1) Run Configure. This will figure out various things about your system. X Some things Configure will figure out for itself, other things it will X ask you about. It will then proceed to make config.h, config.sh, and X Makefile. X X You might possibly have to trim # comments from the front of Configure X if your sh doesn't handle them, but all other # comments will be taken X care of. X X If you don't have sh, you'll have to rip the prototype of config.h out X of Configure and generate the defines by hand. X X2) Glance through config.h to make sure system dependencies are correct. X Most of them should have been taken care of by running the Configure script. X X If you have any additional changes to make to the C definitions, they X can be done in the Makefile, or in config.h. Bear in mind that they may X get undone next time you run Configure. X X3) make X X This will attempt to make patch in the current directory. X X4) make install X X This will put patch into a public directory (normally /usr/local/bin). X It will also try to put the man pages in a reasonable place. It will not X nroff the man page, however. X X5) Read the manual entry before running patch. X X6) IMPORTANT! Help save the world! Communicate any problems and X suggested patches to me, lwall@sdcrdcf.UUCP (Larry Wall), so we can X keep the world in sync. If you have a problem, there's someone else X out there who either has had or will have the same problem. X X If possible, send in patches such that the patch program will apply them. X Context diffs are the best, then normal diffs. Don't send ed scripts-- X I've probably changed my copy since the version you have. X X Watch for patch patches in net.sources.bugs. Patches will generally be X in a form usable by the patch program. If you are just now bringing up X patch and aren't sure how many patches there are, write to me and I'll X send any you don't have. Your current patch level is shown in patchlevel.h. X X XNEW FEATURES IN THIS RELEASE X X(Correct) support for 4.3bsd-style context diffs. XFiles can be created from scratch. XYou can specify a fuzz-factor for context matching. XYou can force patch to ask no questions. XYou can specify how much of the leading pathname to strip off filenames. XUses a Configure script for greater portability. XYou are now asked if you want to apply a reversed patch. XNo limit (apart from memory) on the size of hunks. !STUFFY!FUNK! echo Extracting Makefile.SH sed >Makefile.SH <<'!STUFFY!FUNK!' -e 's/X//' Xcase $CONFIG in X '') . config.sh ;; Xesac Xecho "Extracting Makefile (with variable substitutions)" Xcat >Makefile <>Makefile <<'!NO!SUBS!' X Xpublic = patch Xprivate = Xmanpages = patch.man Xutil = Makefile X Xc = patch.c pch.c inp.c version.c util.c X Xobj = patch.o pch.o inp.o util.o version.o X Xlintflags = -phbvxac X Xaddedbyconf = Makefile.old bsd config.h config.sh eunice loc pdp11 usg v7 X X# grrr XSHELL = /bin/sh X X.c.o: X $(CC) -c $(CFLAGS) $*.c X Xall: $(public) $(private) $(util) X touch all X Xpatch: $(obj) X $(CC) $(LDFLAGS) $(obj) $(libs) -o patch X X# won't work with csh Xinstall: patch X export PATH || exit 1 X - mv $(bin)/patch $(bin)/patch.old X - if test `pwd` != $(bin); then cp $(public) $(bin); fi X cd $(bin); chmod 755 $(public) X - if test `pwd` != $(mansrc); then \ Xfor page in $(manpages); do \ Xcp $$page $(mansrc)/`basename $$page .man`.$(manext); \ Xdone; \ Xfi X Xclean: X rm -f *.o *.orig core X Xrealclean: X rm -f patch *.o *.orig core $(addedbyconf) X X# The following lint has practically everything turned on. Unfortunately, X# you have to wade through a lot of mumbo jumbo that can't be suppressed. X# If the source file has a /*NOSTRICT*/ somewhere, ignore the lint message X# for that spot. X Xlint: X lint $(lintflags) $(defs) $(c) > patch.fuzz X Xpatch.o: config.h common.h patch.c inp.h pch.h util.h version.h Xpch.o: config.h common.h pch.c pch.h util.h Xinp.o: config.h common.h inp.c inp.h util.h Xutil.o: config.h common.h util.c util.h Xversion.o: config.h common.h version.c version.h patchlevel.h util.h X X!NO!SUBS! X$eunicefix Makefile !STUFFY!FUNK! echo Extracting MANIFEST sed >MANIFEST <<'!STUFFY!FUNK!' -e 's/X//' XAfter all the patch kits are run you should have the following files: X XFilename Kit Description X-------- --- ----------- XConfigure 1 A shell script that installs everything system dependent. XEXTERN.h 1 Toggle .h files to look foreign. XINTERN.h 3 Toggle .h files to look domestic. XMANIFEST 3 This list of files. XMakefile.SH 3 The makefile. XREADME 3 Installation instructions. Xcommon.h 3 Common definitions. Xconfig.H 3 Sample config.h, in case Configure won't run. Xinp.c 2 Input file abstract data type routines. Xinp.h 3 Public defs for above. Xpatch.c 2 The patch program. Xpatch.man 2 Manual page for patch. Xpatchlevel.h 3 The patch level of the patch program. Xpch.c 1 Patch abstract data type routines. Xpch.h 3 Public defs for above. Xutil.c 2 Utility routines. Xutil.h 1 Public defs for above. Xversion.c 3 Version number routine. Xversion.h 3 Public defs for above. !STUFFY!FUNK! echo Extracting pch.h sed >pch.h <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: pch.h,v 2.0 86/09/17 15:39:57 lwall Exp $ X * X * $Log: pch.h,v $ X * Revision 2.0 86/09/17 15:39:57 lwall X * Baseline for netwide release. X * X */ X XEXT FILE *pfp INIT(Nullfp); /* patch file pointer */ X Xvoid re_patch(); Xvoid open_patch_file(); Xvoid set_hunkmax(); Xvoid grow_hunkmax(); Xbool there_is_another_patch(); Xint intuit_diff_type(); Xvoid next_intuit_at(); Xvoid skip_to(); Xbool another_hunk(); Xbool pch_swap(); Xchar *pfetch(); Xshort pch_line_len(); XLINENUM pch_first(); XLINENUM pch_ptrn_lines(); XLINENUM pch_newfirst(); XLINENUM pch_repl_lines(); XLINENUM pch_end(); XLINENUM pch_context(); XLINENUM pch_hunk_beg(); Xchar pch_char(); Xchar *pfetch(); Xchar *pgets(); !STUFFY!FUNK! echo Extracting config.H sed >config.H <<'!STUFFY!FUNK!' -e 's/X//' 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#/*undef EUNICE /* no file linking? */ X#/*undef VMS X X#/*undef index strchr /* cultural */ X#/*undef rindex strrchr /* differences? */ X X#/*undef void int /* is void to be avoided? */ X X/* How many register declarations are paid attention to? */ X X#define Reg1 register X#define Reg2 register X#define Reg3 register X#define Reg4 register X#define Reg5 register X#define Reg6 register X#define Reg7 X#define Reg8 X#define Reg9 X#define Reg10 X#define Reg11 X#define Reg12 X#define Reg13 X#define Reg14 X#define Reg15 X#define Reg16 X !STUFFY!FUNK! echo Extracting version.c sed >version.c <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: version.c,v 2.0 86/09/17 15:40:11 lwall Exp $ X * X * $Log: version.c,v $ X * Revision 2.0 86/09/17 15:40:11 lwall X * Baseline for netwide release. X * X */ X X#include "EXTERN.h" X#include "common.h" X#include "util.h" X#include "INTERN.h" X#include "patchlevel.h" X#include "version.h" X X/* Print out the version number and die. */ X Xvoid Xversion() X{ X extern char rcsid[]; X X#ifdef lint X rcsid[0] = rcsid[0]; X#else X fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL); X#endif X} !STUFFY!FUNK! echo Extracting inp.h sed >inp.h <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: inp.h,v 2.0 86/09/17 15:37:25 lwall Exp $ X * X * $Log: inp.h,v $ X * Revision 2.0 86/09/17 15:37:25 lwall X * Baseline for netwide release. X * X */ X XEXT LINENUM input_lines INIT(0); /* how long is input file in lines */ XEXT LINENUM last_frozen_line INIT(0); /* how many input lines have been */ X /* irretractibly output */ X Xbool rev_in_string(); Xvoid scan_input(); Xbool plan_a(); /* returns false if insufficient memory */ Xvoid plan_b(); Xchar *ifetch(); X !STUFFY!FUNK! echo Extracting INTERN.h sed >INTERN.h <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: INTERN.h,v 2.0 86/09/17 15:35:58 lwall Exp $ X * X * $Log: INTERN.h,v $ X * Revision 2.0 86/09/17 15:35:58 lwall X * Baseline for netwide release. X * X */ X X#undef EXT X#define EXT X X#undef INIT X#define INIT(x) = x X X#define DOINIT !STUFFY!FUNK! echo Extracting version.h sed >version.h <<'!STUFFY!FUNK!' -e 's/X//' X/* $Header: version.h,v 2.0 86/09/17 15:40:14 lwall Exp $ X * X * $Log: version.h,v $ X * Revision 2.0 86/09/17 15:40:14 lwall X * Baseline for netwide release. X * X */ X Xvoid version(); !STUFFY!FUNK! echo Extracting patchlevel.h sed >patchlevel.h <<'!STUFFY!FUNK!' -e 's/X//' X#define PATCHLEVEL 0 !STUFFY!FUNK! echo "" echo "End of kit 3 (of 3)" cat /dev/null >kit3isdone config=true for iskit in 1 2 3; 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