Path: utzoo!mnetor!uunet!husc6!purdue!i.cc.purdue.edu!j.cc.purdue.edu!ain From: ain@j.cc.purdue.edu (Patrick White) Newsgroups: comp.sources.amiga Subject: patch (docs) Message-ID: <6615@j.cc.purdue.edu> Date: 6 Mar 88 07:57:17 GMT Organization: PUCC Land, USA Lines: 1060 Approved: ain@j.cc.purdue.edu (Pat White) Program Name: patch (docs) Submitted By: Johan Widen Summary: This is patch ported to the Amiga. Poster Boy: Pat White (ain@j.cc.purdue.edu) NOTES: I've separated this from the origional zoo that it was sent in so we can post the bin and src separately.. and made the docs a separate shar too. -- Pat White (co-moderator comp.sources/binaries.amiga) UUCP: j.cc.purdue.edu!ain BITNET: PATWHITE@PURCCVM PHONE: (317) 743-8421 U.S. Mail: 320 Brown St. apt. 406, West Lafayette, IN 47906 ======================================== # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # README # patch.man.nroffed # README.lwall # WARNING # README.880212 # MANIFEST # patch.man # This archive created: Sun Mar 6 02:38:00 1988 # By: Patrick White (PUCC Land, USA) echo shar: extracting README '(769 characters)' cat << \SHAR_EOF > README This is a port of the UNIX patch program to the Amiga. Patch is an expert at updating source files by applying context diffs to them (context diffs are produced by the BSD UNIX program diff). Acknowledgements: Larry Wall is the author of patch. Peter da Silva is the author of the file requester. Matt Dillon has improved the file requester code and is the author of newwildcmp.c. The files filereq.c and newwildcmp.c are from Matt Dillon's original posting of the disk cataloger "files". Compiling: I have only compiled this with the Lattice compiler. Modifications for the Manx compiler should be straight forward. Warning: Please read the file 'WARNING' before you use patch. 23-JAN-88 Johan Widen USENET: jw@sics.se SHAR_EOF if test 769 -ne "`wc -c README`" then echo shar: error transmitting README '(should have been 769 characters)' fi echo shar: extracting patch.man.nroffed '(14782 characters)' cat << \SHAR_EOF > patch.man.nroffed PATCH(1) UNIX Programmer's Manual PATCH(1) NAME patch - a program for applying a diff file to an original SYNOPSIS patch [options] orig patchfile [+ [options] orig] but usually just patch sets the maximum fuzz factor. This switch only applied to context diffs, and causes _p_a_t_c_h 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. -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. -n forces _p_a_t_c_h to interpret the patch file as a normal diff. Printed 3/6/88 LOCAL 3 PATCH(1) UNIX Programmer's Manual PATCH(1) -N causes _p_a_t_c_h to ignore patches that it thinks are reversed or already applied. See also -R . -o causes the next argument to be interpreted as the out- put file name. -p sets the pathname strip count, which controls how path- names 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 speci- fies 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 /u/howard/src/blurfl/blurfl.c setting -p or -p0 gives the entire pathname unmodified, -p1 gives u/howard/src/blurfl/blurfl.c without the leading slash, -p4 gives blurfl/blurfl.c and not specifying -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 -d switch. -r causes the next argument to be interpreted as the reject file name. -R tells _p_a_t_c_h that this patch was created with the old and new files swapped. (Yes, I'm afraid that does hap- pen occasionally, human nature being what it is.) _P_a_t_c_h will attempt to swap each hunk around before applying it. Rejects will come out in the swapped format. The -R switch will not work with ed diff scripts because there is too little information to reconstruct the reverse operation. If the first hunk of a patch fails, _p_a_t_c_h 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 -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 Printed 3/6/88 LOCAL 4 PATCH(1) UNIX Programmer's Manual PATCH(1) 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.) -s makes _p_a_t_c_h do its work silently, unless an error occurs. -S causes _p_a_t_c_h to ignore this patch from the patch file, but continue on looking for the next patch in the file. Thus patch -S + -S + sets internal debugging flags, and is of interest only to _p_a_t_c_h patchers. ENVIRONMENT No environment variables are used by _p_a_t_c_h. FILES /tmp/patch* SEE ALSO diff(1) 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 -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. Printed 3/6/88 LOCAL 5 PATCH(1) UNIX Programmer's Manual PATCH(1) DIAGNOSTICS Too many to list here, but generally indicative that _p_a_t_c_h couldn't parse your patch file. The message "Hmm..." indicates that there is unprocessed text in the patch file and that _p_a_t_c_h is attempting to intuit whether there is a patch in that text and, if so, what kind of patch it is. CAVEATS _P_a_t_c_h 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 "change" or a "delete" command. A con- text 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. _P_a_t_c_h 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 gen- erated from. BUGS Could be smarter about partial matches, excessively deviant offsets and swapped code, but that would take an extra pass. If code has been duplicated (for instance with #ifdef OLD- CODE ... #else ... #endif), _p_a_t_c_h 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. If you apply a patch you've already applied, _p_a_t_c_h will think it is a reversed patch, and offer to un-apply the patch. This could be construed as a feature. Printed 3/6/88 LOCAL 6 SHAR_EOF if test 14782 -ne "`wc -c patch.man.nroffed`" then echo shar: error transmitting patch.man.nroffed '(should have been 14782 characters)' fi echo shar: extracting README.lwall '(2963 characters)' cat << \SHAR_EOF > README.lwall Patch Kit, Version 2.0 Copyright (c) 1986, 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. If you don't have sh, you'll have to rip the prototype of config.h out of Configure and generate the defines by hand. 2) Glance through config.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. Bear in mind that they may get undone next time you run Configure. 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. It will not nroff the man page, however. 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. Patches will generally be in a form usable 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. Your current patch level is shown in patchlevel.h. NEW FEATURES IN THIS RELEASE (Correct) support for 4.3bsd-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. No limit (apart from memory) on the size of hunks. SHAR_EOF if test 2963 -ne "`wc -c README.lwall`" then echo shar: error transmitting README.lwall '(should have been 2963 characters)' fi echo shar: extracting WARNING '(426 characters)' cat << \SHAR_EOF > WARNING WARNING: This program may destroy your files. The business of patch is to update source files. Bugs may have been introduced when patch was ported to the Amiga. Although I am not aware of any dangerous bugs at present, they may well be there! Always backup your files before you apply patch to them. I disclaim any responsibility for damages caused by the use of patch. 23-JAN-88 Johan Widen USENET: jw@sics.se SHAR_EOF if test 426 -ne "`wc -c WARNING`" then echo shar: error transmitting WARNING '(should have been 426 characters)' fi echo shar: extracting README.880212 '(160 characters)' cat << \SHAR_EOF > README.880212 12-FEB-88 The following diffs fix a moderately serious bug in patch for the Amiga. Patch did not remove all file locks. Johan Widen USENET: jw@sics.se SHAR_EOF if test 160 -ne "`wc -c README.880212`" then echo shar: error transmitting README.880212 '(should have been 160 characters)' fi echo shar: extracting MANIFEST '(204 characters)' cat << \SHAR_EOF > MANIFEST MANIFEST README WARNING README.lwall patch.man Makefile EXTERN.h INTERN.h common.h config.h filereq.c inp.c inp.h newwildcmp.c patch.c patchlevel.h pch.c pch.h request.c util.c util.h version.c version.h SHAR_EOF if test 204 -ne "`wc -c MANIFEST`" then echo shar: error transmitting MANIFEST '(should have been 204 characters)' fi echo shar: extracting patch.man '(13700 characters)' cat << \SHAR_EOF > patch.man ''' $Header: patch.man,v 2.0 86/09/17 15:39:09 lwall Exp $ ''' ''' $Log: patch.man,v $ ''' Revision 2.0 86/09/17 15:39:09 lwall ''' Baseline for netwide release. ''' ''' 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 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 \-N causes .I patch to ignore patches that it thinks are reversed or already applied. See also .B \-R . .TP 5 .B \-o causes the next argument to be interpreted as the output file name. .TP 5 .B \-p 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 \-S causes .I patch to ignore this patch from the patch file, but continue on looking for the next patch in the file. Thus .sp patch -S + -S + 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. SHAR_EOF if test 13700 -ne "`wc -c patch.man`" then echo shar: error transmitting patch.man '(should have been 13700 characters)' fi # End of shell archive exit 0