[BACK]Return to patch.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / patch

Annotation of src/usr.bin/patch/patch.1, Revision 1.33

1.33    ! jmc         1: .\"    $OpenBSD: patch.1,v 1.32 2018/06/22 15:37:15 zhuk Exp $
1.6       jmc         2: .\" Copyright 1986, Larry Wall
                      3: .\"
                      4: .\" Redistribution and use in source and binary forms, with or without
                      5: .\" modification, are permitted provided that the following condition
                      6: .\" is met:
                      7: .\"  1. Redistributions of source code must retain the above copyright
                      8: .\"     notice, this condition and the following disclaimer.
1.7       deraadt     9: .\"
1.6       jmc        10: .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     11: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     12: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     13: .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     14: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     15: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     16: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     17: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     18: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     19: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     20: .\" SUCH DAMAGE.
                     21: .\"
1.33    ! jmc        22: .Dd $Mdocdate: June 22 2018 $
1.9       jmc        23: .Dt PATCH 1
                     24: .Os
                     25: .Sh NAME
                     26: .Nm patch
                     27: .Nd apply a diff file to an original
                     28: .Sh SYNOPSIS
                     29: .Nm patch
1.18      sobrado    30: .Bk -words
                     31: .Op Fl bCcEeflNnRstuv
                     32: .Op Fl B Ar backup-prefix
                     33: .Op Fl D Ar symbol
                     34: .Op Fl d Ar directory
                     35: .Op Fl F Ar max-fuzz
                     36: .Op Fl i Ar patchfile
                     37: .Op Fl o Ar out-file
                     38: .Op Fl p Ar strip-count
                     39: .Op Fl r Ar rej-name
                     40: .Op Fl V Cm t | nil | never
                     41: .Op Fl x Ar number
                     42: .Op Fl z Ar backup-ext
                     43: .Op Fl Fl posix
1.9       jmc        44: .Op Ar origfile Op Ar patchfile
1.18      sobrado    45: .Ek
1.9       jmc        46: .Nm patch
                     47: .Pf \*(Lt Ar patchfile
                     48: .Sh DESCRIPTION
                     49: .Nm
1.1       deraadt    50: will take a patch file containing any of the four forms of difference
                     51: listing produced by the
1.9       jmc        52: .Xr diff 1
                     53: program and apply those differences to an original file,
                     54: producing a patched version.
1.1       deraadt    55: If
1.9       jmc        56: .Ar patchfile
1.17      millert    57: is omitted, or is a hyphen, the patch will be read from the standard input.
1.9       jmc        58: .Pp
                     59: .Nm
1.23      jmc        60: will attempt to determine the type of the diff listing, unless overruled by a
1.9       jmc        61: .Fl c ,
                     62: .Fl e ,
                     63: .Fl n ,
1.1       deraadt    64: or
1.9       jmc        65: .Fl u
1.11      millert    66: option.
1.9       jmc        67: .Pp
1.17      millert    68: If the
                     69: .Ar patchfile
                     70: contains more than one patch,
1.9       jmc        71: .Nm
1.1       deraadt    72: will try to apply each of them as if they came from separate patch files.
                     73: This means, among other things, that it is assumed that the name of the file
1.17      millert    74: to patch must be determined for each diff listing, and that the garbage before
                     75: each diff listing will be examined for interesting things such as file names
                     76: and revision level (see the section on
                     77: .Sx Filename Determination
                     78: below).
1.9       jmc        79: .Pp
1.11      millert    80: The options are as follows:
1.9       jmc        81: .Bl -tag -width Ds
1.18      sobrado    82: .It Xo
                     83: .Fl B Ar backup-prefix ,
                     84: .Fl Fl prefix Ar backup-prefix
                     85: .Xc
                     86: Causes the next argument to be interpreted as a prefix to the backup file
                     87: name.
                     88: If this argument is specified, any argument to
                     89: .Fl z
                     90: will be ignored.
1.12      millert    91: .It Fl b , Fl Fl backup
                     92: Save a backup copy of the file before it is modified.
                     93: By default the original file is saved with a backup extension of
                     94: .Qq .orig
                     95: unless the file already has a numbered backup, in which case a numbered
                     96: backup is made.
                     97: This is equivalent to specifying
1.18      sobrado    98: .Qo Fl V Cm existing Qc .
1.22      jmc        99: This option is currently the default, unless
                    100: .Fl -posix
                    101: is specified.
1.32      zhuk      102: .It Fl C , Fl Fl check , Fl Fl dry-run
1.18      sobrado   103: Checks that the patch would apply cleanly, but does not modify anything.
1.9       jmc       104: .It Fl c , Fl Fl context
                    105: Forces
                    106: .Nm
1.1       deraadt   107: to interpret the patch file as a context diff.
1.18      sobrado   108: .It Xo
                    109: .Fl D Ar symbol ,
                    110: .Fl Fl ifdef Ar symbol
                    111: .Xc
1.9       jmc       112: Causes
                    113: .Nm
                    114: to use the
                    115: .Qq #ifdef...#endif
                    116: construct to mark changes.
1.1       deraadt   117: The argument following will be used as the differentiating symbol.
                    118: Note that, unlike the C compiler, there must be a space between the
1.9       jmc       119: .Fl D
1.1       deraadt   120: and the argument.
1.18      sobrado   121: .It Xo
                    122: .Fl d Ar directory ,
                    123: .Fl Fl directory Ar directory
                    124: .Xc
                    125: Causes
                    126: .Nm
1.21      jmc       127: to interpret the next argument as a directory,
                    128: and change working directory to it before doing anything else.
1.18      sobrado   129: .It Fl E , Fl Fl remove-empty-files
                    130: Causes
                    131: .Nm
                    132: to remove output files that are empty after the patches have been applied.
                    133: This option is useful when applying patches that create or remove files.
1.9       jmc       134: .It Fl e , Fl Fl ed
                    135: Forces
                    136: .Nm
                    137: to interpret the patch file as an
                    138: .Xr ed 1
                    139: script.
1.18      sobrado   140: .It Xo
                    141: .Fl F Ar max-fuzz ,
                    142: .Fl Fl fuzz Ar max-fuzz
                    143: .Xc
                    144: Sets the maximum fuzz factor.
                    145: This option only applies to context diffs, and causes
1.9       jmc       146: .Nm
1.18      sobrado   147: to ignore up to that many lines in looking for places to install a hunk.
                    148: Note that a larger fuzz factor increases the odds of a faulty patch.
                    149: The default fuzz factor is 2, and it may not be set to more than
                    150: the number of lines of context in the context diff, ordinarily 3.
1.9       jmc       151: .It Fl f , Fl Fl force
                    152: Forces
                    153: .Nm
1.1       deraadt   154: to assume that the user knows exactly what he or she is doing, and to not
1.9       jmc       155: ask any questions.
                    156: It assumes the following:
                    157: skip patches for which a file to patch can't be found;
                    158: patch files even though they have the wrong version for the
                    159: .Qq Prereq:
                    160: line in the patch;
                    161: and assume that patches are not reversed even if they look like they are.
1.1       deraadt   162: This option does not suppress commentary; use
1.9       jmc       163: .Fl s
1.1       deraadt   164: for that.
1.9       jmc       165: .It Xo
1.18      sobrado   166: .Fl i Ar patchfile ,
                    167: .Fl Fl input Ar patchfile
1.9       jmc       168: .Xc
1.15      millert   169: Causes the next argument to be interpreted as the input file name
                    170: (i.e. a patchfile).
1.9       jmc       171: .It Fl l , Fl Fl ignore-whitespace
                    172: Causes the pattern matching to be done loosely, in case the tabs and
1.1       deraadt   173: spaces have been munged in your input file.
                    174: Any sequence of whitespace in the pattern line will match any sequence
                    175: in the input file.
                    176: Normal characters must still match exactly.
                    177: Each line of the context must still match a line in the input file.
1.9       jmc       178: .It Fl N , Fl Fl forward
                    179: Causes
                    180: .Nm
1.1       deraadt   181: to ignore patches that it thinks are reversed or already applied.
                    182: See also
1.9       jmc       183: .Fl R .
1.18      sobrado   184: .It Fl n , Fl Fl normal
                    185: Forces
                    186: .Nm
                    187: to interpret the patch file as a normal diff.
                    188: .It Xo
                    189: .Fl o Ar out-file ,
                    190: .Fl Fl output Ar out-file
                    191: .Xc
1.9       jmc       192: Causes the next argument to be interpreted as the output file name.
                    193: .It Xo
1.18      sobrado   194: .Fl p Ar strip-count ,
                    195: .Fl Fl strip Ar strip-count
1.9       jmc       196: .Xc
                    197: Sets the pathname strip count,
                    198: which controls how pathnames found in the patch file are treated,
                    199: in case you keep your files in a different directory than the person who sent
1.1       deraadt   200: out the patch.
                    201: The strip count specifies how many slashes are to be stripped from
                    202: the front of the pathname.
                    203: (Any intervening directory names also go away.)
1.17      millert   204: For example, supposing the file name in the patch file was
1.9       jmc       205: .Pa /u/howard/src/blurfl/blurfl.c :
                    206: .Pp
                    207: Setting
                    208: .Fl p Ns Ar 0
                    209: gives the entire pathname unmodified.
                    210: .Pp
                    211: .Fl p Ns Ar 1
1.1       deraadt   212: gives
1.9       jmc       213: .Pp
                    214: .D1 Pa u/howard/src/blurfl/blurfl.c
                    215: .Pp
                    216: without the leading slash.
                    217: .Pp
                    218: .Fl p Ns Ar 4
1.1       deraadt   219: gives
1.9       jmc       220: .Pp
                    221: .D1 Pa blurfl/blurfl.c
                    222: .Pp
                    223: Not specifying
                    224: .Fl p
                    225: at all just gives you
                    226: .Pa blurfl.c ,
                    227: unless all of the directories in the leading path
                    228: .Pq Pa u/howard/src/blurfl
                    229: exist and that path is relative,
1.1       deraadt   230: in which case you get the entire pathname unmodified.
                    231: Whatever you end up with is looked for either in the current directory,
                    232: or the directory specified by the
1.9       jmc       233: .Fl d
1.11      millert   234: option.
1.9       jmc       235: .It Fl R , Fl Fl reverse
                    236: Tells
                    237: .Nm
1.1       deraadt   238: that this patch was created with the old and new files swapped.
                    239: (Yes, I'm afraid that does happen occasionally, human nature being what it
                    240: is.)
1.9       jmc       241: .Nm
1.1       deraadt   242: will attempt to swap each hunk around before applying it.
                    243: Rejects will come out in the swapped format.
                    244: The
1.9       jmc       245: .Fl R
1.11      millert   246: option will not work with ed diff scripts because there is too little
1.1       deraadt   247: information to reconstruct the reverse operation.
1.9       jmc       248: .Pp
1.1       deraadt   249: If the first hunk of a patch fails,
1.9       jmc       250: .Nm
1.1       deraadt   251: will reverse the hunk to see if it can be applied that way.
                    252: If it can, you will be asked if you want to have the
1.9       jmc       253: .Fl R
1.11      millert   254: option set.
1.1       deraadt   255: If it can't, the patch will continue to be applied normally.
                    256: (Note: this method cannot detect a reversed patch if it is a normal diff
                    257: and if the first command is an append (i.e. it should have been a delete)
                    258: since appends always succeed, due to the fact that a null context will match
                    259: anywhere.
                    260: Luckily, most patches add or change lines rather than delete them, so most
                    261: reversed normal diffs will begin with a delete, which will fail, triggering
                    262: the heuristic.)
1.9       jmc       263: .It Xo
1.18      sobrado   264: .Fl r Ar rej-name ,
                    265: .Fl Fl reject-file Ar rej-name
                    266: .Xc
                    267: Causes the next argument to be interpreted as the reject file name.
                    268: .It Xo
1.9       jmc       269: .Fl s , Fl Fl quiet ,
                    270: .Fl Fl silent
                    271: .Xc
                    272: Makes
                    273: .Nm
1.1       deraadt   274: do its work silently, unless an error occurs.
1.17      millert   275: .It Fl t , Fl Fl batch
                    276: Similar to
                    277: .Fl f ,
                    278: in that it suppresses questions, but makes some different assumptions:
                    279: skip patches for which a file to patch can't be found (the same as
                    280: .Fl f ) ;
                    281: skip patches for which the file has the wrong version for the
                    282: .Qq Prereq:
                    283: line in the patch;
                    284: and assume that patches are reversed if they look like they are.
1.9       jmc       285: .It Fl u , Fl Fl unified
                    286: Forces
                    287: .Nm
1.1       deraadt   288: to interpret the patch file as a unified context diff (a unidiff).
1.18      sobrado   289: .It Xo
                    290: .Fl V Cm t | nil | never ,
                    291: .Fl Fl version-control Cm t | nil | never
                    292: .Xc
1.9       jmc       293: Causes the next argument to be interpreted as a method for creating
                    294: backup file names.
                    295: The type of backups made can also be given in the
1.17      millert   296: .Ev PATCH_VERSION_CONTROL
                    297: or
1.9       jmc       298: .Ev VERSION_CONTROL
1.17      millert   299: environment variables, which are overridden by this option.
1.1       deraadt   300: The
1.9       jmc       301: .Fl B
1.1       deraadt   302: option overrides this option, causing the prefix to always be used for
                    303: making backup file names.
1.17      millert   304: The values of the
                    305: .Ev PATCH_VERSION_CONTROL
                    306: and
1.9       jmc       307: .Ev VERSION_CONTROL
1.17      millert   308: environment variables and the argument to the
1.9       jmc       309: .Fl V
                    310: option are like the GNU Emacs
                    311: .Dq version-control
                    312: variable; they also recognize synonyms that are more descriptive.
                    313: The valid values are (unique abbreviations are accepted):
                    314: .Bl -tag -width Ds -offset indent
1.18      sobrado   315: .It Cm t , numbered
1.1       deraadt   316: Always make numbered backups.
1.18      sobrado   317: .It Cm nil , existing
1.9       jmc       318: Make numbered backups of files that already have them,
                    319: simple backups of the others.
1.18      sobrado   320: .It Cm never , simple
1.1       deraadt   321: Always make simple backups.
1.9       jmc       322: .El
1.18      sobrado   323: .It Fl v , Fl Fl version
                    324: Causes
                    325: .Nm
                    326: to print out its revision header and patch level.
1.9       jmc       327: .It Xo
1.18      sobrado   328: .Fl x Ar number ,
                    329: .Fl Fl debug Ar number
1.9       jmc       330: .Xc
                    331: Sets internal debugging flags, and is of interest only to
                    332: .Nm
1.1       deraadt   333: patchers.
1.18      sobrado   334: .It Xo
                    335: .Fl z Ar backup-ext ,
                    336: .Fl Fl suffix Ar backup-ext
                    337: .Xc
1.12      millert   338: Causes the next argument to be interpreted as the backup extension, to be
                    339: used in place of
                    340: .Qq .orig .
1.17      millert   341: .It Fl Fl posix
                    342: Enables strict
1.24      jmc       343: .St -p1003.1-2008
1.17      millert   344: conformance, specifically:
                    345: .Bl -enum
                    346: .It
                    347: Backup files are not created unless the
                    348: .Fl b
                    349: option is specified.
                    350: .It
                    351: If unspecified, the file name used is the first of the old, new and
                    352: index files that exists.
                    353: .El
                    354: .El
                    355: .Ss Patch Application
                    356: .Nm
                    357: will try to skip any leading garbage, apply the diff,
                    358: and then skip any trailing garbage.
                    359: Thus you could feed an article or message containing a
                    360: diff listing to
                    361: .Nm patch ,
                    362: and it should work.
                    363: If the entire diff is indented by a consistent amount,
                    364: this will be taken into account.
                    365: .Pp
                    366: With context diffs, and to a lesser extent with normal diffs,
                    367: .Nm
                    368: can detect when the line numbers mentioned in the patch are incorrect,
                    369: and will attempt to find the correct place to apply each hunk of the patch.
                    370: As a first guess, it takes the line number mentioned for the hunk, plus or
                    371: minus any offset used in applying the previous hunk.
                    372: If that is not the correct place,
                    373: .Nm
                    374: will scan both forwards and backwards for a set of lines matching the context
                    375: given in the hunk.
                    376: First
                    377: .Nm
                    378: looks for a place where all lines of the context match.
                    379: If no such place is found, and it's a context diff, and the maximum fuzz factor
                    380: is set to 1 or more, then another scan takes place ignoring the first and last
                    381: line of context.
                    382: If that fails, and the maximum fuzz factor is set to 2 or more,
                    383: the first two and last two lines of context are ignored,
                    384: and another scan is made.
                    385: .Pq The default maximum fuzz factor is 2.
                    386: .Pp
                    387: If
                    388: .Nm
                    389: cannot find a place to install that hunk of the patch, it will put the hunk
                    390: out to a reject file, which normally is the name of the output file plus
                    391: .Qq .rej .
                    392: (Note that the rejected hunk will come out in context diff form whether the
                    393: input patch was a context diff or a normal diff.
                    394: If the input was a normal diff, many of the contexts will simply be null.)
                    395: The line numbers on the hunks in the reject file may be different than
                    396: in the patch file: they reflect the approximate location patch thinks the
                    397: failed hunks belong in the new file rather than the old one.
                    398: .Pp
                    399: As each hunk is completed, you will be told whether the hunk succeeded or
                    400: failed, and which line (in the new file)
                    401: .Nm
                    402: thought the hunk should go on.
                    403: If this is different from the line number specified in the diff,
                    404: you will be told the offset.
                    405: A single large offset MAY be an indication that a hunk was installed in the
                    406: wrong place.
                    407: You will also be told if a fuzz factor was used to make the match, in which
                    408: case you should also be slightly suspicious.
                    409: .Ss Filename Determination
                    410: If no original file is specified on the command line,
                    411: .Nm
                    412: will try to figure out from the leading garbage what the name of the file
                    413: to edit is.
                    414: When checking a prospective file name, pathname components are stripped
                    415: as specified by the
                    416: .Fl p
                    417: option and the file's existence and writability are checked relative
                    418: to the current working directory (or the directory specified by the
                    419: .Fl d
                    420: option).
                    421: .Pp
                    422: If the diff is a context or unified diff,
                    423: .Nm
                    424: is able to determine the old and new file names from the diff header.
                    425: For context diffs, the
                    426: .Dq old
                    427: file is specified in the line beginning with
                    428: .Qq ***
                    429: and the
                    430: .Dq new
                    431: file is specified in the line beginning with
                    432: .Qq --- .
                    433: For a unified diff, the
                    434: .Dq old
                    435: file is specified in the line beginning with
                    436: .Qq ---
                    437: and the
                    438: .Dq new
                    439: file is specified in the line beginning with
                    440: .Qq +++ .
                    441: If there is an
                    442: .Qq Index:
                    443: line in the leading garbage (regardless of the diff type),
                    444: .Nm
                    445: will use the file name from that line as the
                    446: .Dq index
                    447: file.
                    448: .Pp
                    449: .Nm
                    450: will choose the file name by performing the following steps, with the first
                    451: match used:
                    452: .Bl -enum
                    453: .It
                    454: If
                    455: .Nm
                    456: is operating in strict
1.24      jmc       457: .St -p1003.1-2008
1.17      millert   458: mode, the first of the
                    459: .Dq old ,
                    460: .Dq new
                    461: and
                    462: .Dq index
                    463: file names that exist is used.
                    464: Otherwise,
                    465: .Nm
                    466: will examine either the
                    467: .Dq old
                    468: and
                    469: .Dq new
                    470: file names or, for a non-context diff, the
                    471: .Dq index
                    472: file name, and choose the file name with the fewest path components,
                    473: the shortest basename, and the shortest total file name length (in that order).
                    474: .It
                    475: If no suitable file was found to patch, the patch file is a context or
                    476: unified diff, and the old file was zero length, the new file name is
                    477: created and used.
                    478: .It
                    479: If the file name still cannot be determined,
                    480: .Nm
                    481: will prompt the user for the file name to use.
1.9       jmc       482: .El
1.17      millert   483: .Pp
                    484: Additionally, if the leading garbage contains a
                    485: .Qq Prereq:\ \&
                    486: line,
                    487: .Nm
                    488: will take the first word from the prerequisites line (normally a version
                    489: number) and check the input file to see if that word can be found.
                    490: If not,
                    491: .Nm
                    492: will ask for confirmation before proceeding.
                    493: .Pp
                    494: The upshot of all this is that you should be able to say, while in a news
                    495: interface, the following:
                    496: .Pp
                    497: .Dl | patch -d /usr/src/local/blurfl
                    498: .Pp
                    499: and patch a file in the blurfl directory directly from the article containing
                    500: the patch.
                    501: .Ss Backup Files
                    502: By default, the patched version is put in place of the original, with
                    503: the original file backed up to the same name with the extension
                    504: .Qq .orig ,
                    505: or as specified by the
                    506: .Fl B ,
                    507: .Fl V ,
                    508: or
                    509: .Fl z
                    510: options.
                    511: The extension used for making backup files may also be specified in the
                    512: .Ev SIMPLE_BACKUP_SUFFIX
                    513: environment variable, which is overridden by the options above.
                    514: .Pp
                    515: If the backup file is a symbolic or hard link to the original file,
                    516: .Nm
                    517: creates a new backup file name by changing the first lowercase letter
                    518: in the last component of the file's name into uppercase.
                    519: If there are no more lowercase letters in the name,
                    520: it removes the first character from the name.
                    521: It repeats this process until it comes up with a
                    522: backup file that does not already exist or is not linked to the original file.
                    523: .Pp
                    524: You may also specify where you want the output to go with the
                    525: .Fl o
                    526: option; if that file already exists, it is backed up first.
                    527: .Ss Notes For Patch Senders
1.1       deraadt   528: There are several things you should bear in mind if you are going to
1.9       jmc       529: be sending out patches:
                    530: .Pp
                    531: First, you can save people a lot of grief by keeping a
                    532: .Pa patchlevel.h
                    533: file which is patched to increment the patch level as the first diff in the
1.1       deraadt   534: patch file you send out.
1.9       jmc       535: If you put a
                    536: .Qq Prereq:
                    537: line in with the patch, it won't let them apply
1.1       deraadt   538: patches out of order without some warning.
1.9       jmc       539: .Pp
1.17      millert   540: Second, make sure you've specified the file names right, either in a
1.9       jmc       541: context diff header, or with an
                    542: .Qq Index:
                    543: line.
1.1       deraadt   544: If you are patching something in a subdirectory, be sure to tell the patch
1.4       aaron     545: user to specify a
1.9       jmc       546: .Fl p
1.11      millert   547: option as needed.
1.9       jmc       548: .Pp
1.1       deraadt   549: Third, you can create a file by sending out a diff that compares a
                    550: null file to the file you want to create.
                    551: This will only work if the file you want to create doesn't exist already in
                    552: the target directory.
1.9       jmc       553: .Pp
1.1       deraadt   554: Fourth, take care not to send out reversed patches, since it makes people wonder
                    555: whether they already applied the patch.
1.9       jmc       556: .Pp
1.1       deraadt   557: Fifth, while you may be able to get away with putting 582 diff listings into
                    558: one file, it is probably wiser to group related patches into separate files in
                    559: case something goes haywire.
1.9       jmc       560: .Sh ENVIRONMENT
1.17      millert   561: .Bl -tag -width "PATCH_VERSION_CONTROL" -compact
                    562: .It Ev POSIXLY_CORRECT
                    563: When set,
                    564: .Nm
                    565: behaves as if the
                    566: .Fl Fl posix
                    567: option has been specified.
                    568: .It Ev SIMPLE_BACKUP_SUFFIX
                    569: Extension to use for backup file names instead of
                    570: .Qq .orig .
1.9       jmc       571: .It Ev TMPDIR
                    572: Directory to put temporary files in; default is
                    573: .Pa /tmp .
1.17      millert   574: .It Ev PATCH_VERSION_CONTROL
                    575: Selects when numbered backup files are made.
1.9       jmc       576: .It Ev VERSION_CONTROL
1.17      millert   577: Same as
                    578: .Ev PATCH_VERSION_CONTROL .
1.9       jmc       579: .El
                    580: .Sh FILES
1.17      millert   581: .Bl -tag -width "$TMPDIR/patch*" -compact
1.9       jmc       582: .It Pa $TMPDIR/patch*
1.17      millert   583: .Nm
                    584: temporary files
                    585: .It Pa /dev/tty
                    586: used to read input when
                    587: .Nm
                    588: prompts the user
1.9       jmc       589: .El
1.26      jmc       590: .Sh EXIT STATUS
                    591: The
                    592: .Nm
                    593: utility exits with one of the following values:
                    594: .Pp
                    595: .Bl -tag -width Ds -offset indent -compact
                    596: .It 0
                    597: Successful completion.
                    598: .It 1
                    599: One or more lines were written to a reject file.
                    600: .It \*(Gt1
                    601: An error occurred.
                    602: .El
                    603: .Pp
                    604: When applying a set of patches in a loop it behooves you to check this
                    605: exit status so you don't apply a later patch to a partially patched file.
1.9       jmc       606: .Sh DIAGNOSTICS
1.1       deraadt   607: Too many to list here, but generally indicative that
1.9       jmc       608: .Nm
1.1       deraadt   609: couldn't parse your patch file.
1.9       jmc       610: .Pp
                    611: The message
                    612: .Qq Hmm...
                    613: indicates that there is unprocessed text in the patch file and that
                    614: .Nm
1.1       deraadt   615: is attempting to intuit whether there is a patch in that text and, if so,
                    616: what kind of patch it is.
1.9       jmc       617: .Sh SEE ALSO
                    618: .Xr diff 1
1.19      jmc       619: .Sh STANDARDS
                    620: The
                    621: .Nm
                    622: utility is compliant with the
1.24      jmc       623: .St -p1003.1-2008
1.27      jmc       624: specification,
                    625: except as detailed above for the
1.22      jmc       626: .Fl -posix
1.27      jmc       627: option.
1.19      jmc       628: .Pp
                    629: The flags
1.25      jmc       630: .Op Fl BCEFfstVvxz
1.19      jmc       631: and
                    632: .Op Fl -posix
                    633: are extensions to that specification.
1.9       jmc       634: .Sh AUTHORS
1.13      millert   635: .An Larry Wall
1.9       jmc       636: with many other contributors.
                    637: .Sh CAVEATS
                    638: .Nm
1.1       deraadt   639: cannot tell if the line numbers are off in an ed script, and can only detect
1.9       jmc       640: bad line numbers in a normal diff when it finds a
                    641: .Qq change
                    642: or a
                    643: .Qq delete
                    644: command.
1.1       deraadt   645: A context diff using fuzz factor 3 may have the same problem.
                    646: Until a suitable interactive interface is added, you should probably do
                    647: a context diff in these cases to see if the changes made sense.
                    648: Of course, compiling without errors is a pretty good indication that the patch
                    649: worked, but not always.
1.9       jmc       650: .Pp
                    651: .Nm
1.1       deraadt   652: usually produces the correct results, even when it has to do a lot of
                    653: guessing.
                    654: However, the results are guaranteed to be correct only when the patch is
                    655: applied to exactly the same version of the file that the patch was
                    656: generated from.
1.9       jmc       657: .Sh BUGS
                    658: Could be smarter about partial matches, excessively deviant offsets and
1.1       deraadt   659: swapped code, but that would take an extra pass.
1.9       jmc       660: .Pp
                    661: Check patch mode
                    662: .Pq Fl C
1.3       espie     663: will fail if you try to check several patches in succession that build on
1.9       jmc       664: each other.
1.17      millert   665: The entire
1.9       jmc       666: .Nm
1.17      millert   667: code would have to be restructured to keep temporary files around so that it
                    668: can handle this situation.
1.9       jmc       669: .Pp
1.1       deraadt   670: If code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
                    671: #endif),
1.9       jmc       672: .Nm
1.29      jmc       673: is incapable of patching both versions and, if it works at all, will likely
1.1       deraadt   674: patch the wrong one, and tell you that it succeeded to boot.
1.9       jmc       675: .Pp
1.1       deraadt   676: If you apply a patch you've already applied,
1.9       jmc       677: .Nm
1.1       deraadt   678: will think it is a reversed patch, and offer to un-apply the patch.
                    679: This could be construed as a feature.