MPE/iX Shell and Utilities Reference Manual, Vol 2

patch(1) MPE/iX Shell and Utilities patch(1)
NAME
patch — change file using diff output
SYNOPSIS
patch [–bceflNnRsv][–B prefix][–D symbol][–d dir][–F n]
[–i patchfile][–o outfile][–p n][–r rejectfile][file]
DESCRIPTION
patch reads a patchfile which contains output from diff describing changes from an old
text file to a new text file. patch then applies those changes to another text file. Typically,
you use patch if you are keeping parallel versions of a file. When you make changes to one
file, you can use patch to incorporate those changes into other versions of the file.
If you do not specify either the –b or –B options, patch tries to change the original file
directly. If you do not specify –c, –e,or–n, patch looks at the format of the diff output
and tries to determine which type of output the patchfile contains.
If you do not specify a file to be patched and the patchfile is not in context format, patch
prompts you for the name of the file you want to patch. If the patchfile is in context format,
patch tries to determine the file name on its own. The first two lines of a context patchfile
give the names of the old and new files that diff compared. If only one of the files exists,
patch patches that file; if neither exists or both do, patch checks for a line starting with the
string Index: before prompting you for the name of the file to patch.
With a context format patchfile, patch can recognize when line numbers given in the patch-
file do not match line numbers in the file being patched. Thus it can patch a file with line
counts that do not match the old file that was used by diff. To do this, it takes these steps:
For each section to be changed, patch starts with the line number found in the patchfile,
plus or minus any adjustment that must be made for the previous section.
If the line at this location does not match the line in the patchfile, patch scans forward
and backward for a line that does match. If it finds a matching line, patch makes the
appropriate changes. patch also remembers the adjustment it had to make to find the
matching line, and uses this adjustment in the next section to be changed.
If patch cannot find a line matching the one in the patchfile, it tries to find the line using
the lines given as context. It ignores the first and last lines of the context and searches
again. If it finds a match this time, it makes the change and remembers the adjustment.
If a search ignoring the first and last lines of the context fails, patch searches one more
time, ignoring the first two and last two lines of the context. If it finds a match, it makes
the changes and remembers the adjustment
1-408 Commands and Utilities