[hackers] [sbase][PATCH v2] Documentation and whitespace improvements to patch(1)

From: Mattias Andrée <maandree_AT_kth.se>
Date: Mon, 11 Sep 2017 21:08:09 +0200

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
 patch.1 | 70 ++++++++++++++++++++++++++++++++---------------------------------
 patch.c |  9 ++++-----
 2 files changed, 38 insertions(+), 41 deletions(-)
diff --git a/patch.1 b/patch.1
index df2bf63..ba1cb35 100644
--- a/patch.1
+++ b/patch.1
_AT_@ -22,37 +22,34 @@
 applies patches to files from difference listings
-produces by
+produced by
 .Xr diff 1 .
 will skip any garbage unless the
 .Ar patchfile
 consists entirely of garbage.
-Garbage is any data that does not conform to any
-of the supported difference listings formats.
+Garbage is any data that does not conform to
+the supported difference listing formats.
-supprts the all difference listings formats
+supports all difference listing formats
 specified in
 .Xr diff 1p
+except for the
 .Fl f
 flag in
 .Xr diff 1p .
-shall, unless the
-.Ar file
-is specify, figure out from mentions of filenames
-in the
-.Ar patchfile
-which files to patch. As an extension to the
+patch shall figure out which files to patch from the
+mentions of filenames in the patch, unless the files
+are specified explicitly. As an extension to the
 standard, this implementation of
 can determine the filename by looking at the
 \fIdiff\fP-lines that are produced by
 .Xr diff 1
-when comparing directories. If however, the
+when comparing directories. However, if the
 .Ar file
 is specified, all patches in the
 .Ar patchfile
_AT_@ -61,7 +58,7 @@ shall be applied to that
 .Bl -tag -width Ds
 .It Fl b
-Back up files before the first time they a patch
+Back up files before the first time that a patch
 is applied to them. The backups will have the
 suffix \fI.orig\fP.
 .It Fl c
_AT_@ -105,7 +102,7 @@ can be \fI1\fP or \fI0\fP to use
 (swap those lines if
 .Ar define
-is \fI0\fP) instead of 
+is \fI0\fP) instead of
 .Bd -literal -offset left
     #ifdef \fIdefine\fP
     #ifndef \fIdefine\fP
_AT_@ -128,12 +125,13 @@ and
 are swapped.
-does not guarantee that a patch C source code file
-will be at least a syntactically correct after patching
-as before patching. Despite this being implied by
-the standard. The syntactically correctness can be
-broken when edits are made on lines splitted using
-line continuation, made in comments, or span
+does not guarantee that a patched C source
+code file will be at least as syntactically
+correct after patching as it was before,
+despite this being implied by the standard.
+The syntactic correctness can be broken
+when edits are made on lines split using line
+continuation, made in comments, or spanning
 CPP conditional directives.
 .It Fl e
 Treat anything that is not conforming to the
_AT_@ -145,13 +143,13 @@ Read the
 .Ar patchfile
 instead of standard output.
 .It Fl l
-Any sequnce of whitespace, of at least length 1,
-in the input file file shall match any sequnce
-of whitespace, of at least length 1 in the
+Any sequence of whitespace of at least length 1
+in the input file shall match any sequence
+of whitespace of at least length 1 in the
 difference script when testing if lines match.
-Additionally any whitespace at the beginning of
+Additionally, any whitespace at the beginning of
 a line or at the end of a line is ignored when
-matching lines, the former case is an extension
+matching lines. The former case is an extension
 of the standard.
 .It Fl n
 Treat anything that is not conforming to the
_AT_@ -160,7 +158,7 @@ normal format as garbage.
 Ignore already applied hunks. POSIX specifies
 that already applied patches shall be ignored
 if this flag is used. A hunk is a contiguous
-portion of a patch. A patch is a signal
+portion of a patch. A patch is a single
 file-comparison output from
 .Xr diff 1 .
 .It Fl o Ar outfile
_AT_@ -169,13 +167,13 @@ Store resulting files from patches to
 instead of to the patched file itself.
 If the patchfile patches multiple files,
 the results are concatenated. If a patchfile
-patches a file multiple times. Intermediary
+patches a file multiple times, intermediary
 results are also stored.
 As an extension to the standard, you may use
 non-regular files such as \fI/dev/stdout\fP
 and \fI/dev/null\fP. \fI/dev/null\fP can be
-used to preform a dryrun.
+used to perform a dryrun.
 .It Fl p Ar num
 Remove the first
 .Ar num
_AT_@ -183,8 +181,8 @@ components from filenames that appear in the
 patchfile. Any leading / is regarded as the
 first component. If
 .Ar num
-is 0, the entire filename is used. If this flag
-is not used, only the basename is used.
+is 0, the entire filename is used. Without
+this flag only basename is used.
 .It Fl r Ar rejectfile
 Save rejected hunks to
 .Ar rejectfile
_AT_@ -210,10 +208,10 @@ default even for unified context patches.
 Files that become empty as a result of a patch
-are not remove.
+are not removed.
 Symbolic links are treated as regular files,
-provided that they lead to regular files.
+provided that they link to regular files.
 Timestamps that appear in diff headers are not
_AT_@ -222,18 +220,18 @@ Encapsulated patches, and patches with CRLF
 line breaks \(em or any other string \(em rather
 than LF line breaks are not supported.
-In this implementation, when the user is promted,
+In this implementation, when the user is prompted,
 the message is printed to \fI/dev/tty\fP, rather
 than \fI/dev/stdout\fP despite POSIX's mandate.
 This is to make it possible to use \fI/dev/stdout\fP
 as the output file.
 Unportable characters in filenames are supported
-by parsing as C string literals.
+by parsing them as C string literals.
 In this implementation, the
 .Fl D
-flag can be used with \fIed\fP-script.
+flag can be used with \fIed\fP-scripts.
 .Xr diff 1 ,
 .Xr ed 1
_AT_@ -242,7 +240,7 @@ The
 utility is compliant with the
 .St -p1003.1-2013
-specification except from some above noted exceptions.
+specification except for the exceptions noted above.
 .Op Fl fU
diff --git a/patch.c b/patch.c
index 9c44a7d..c118dc9 100644
--- a/patch.c
+++ b/patch.c
_AT_@ -21,7 +21,8 @@
  *    (we interpret that trailing whitespace should be ignored.)
  * -  Files in /dev/ are not considered as existing files. This is
  *    checked before -p and -d are applied.
- * 
+ * -  SCCS is dead and is therefore not supported.
+ *
  * I have choosen not to support git diff-files.
  * CVE-2010-4651 is recognised as user error, not as a security issue.
_AT_@ -292,7 +293,7 @@ parse_diff_line(char *str, char **old, char **new)
 	 * We will just assume that the two last arguments in `str` are sanely
 	 * formatted. All other ways to parse it will surely result in utter madness.
-	 * 
+	 *
 	 * The POSIX standard does not actually require or suggest supporting this,
 	 * but it is required to figure out the filename automatically for some diff
 	 * outputs since diff(1p) does not output the "Index:" string...
_AT_@ -958,8 +959,6 @@ parse_patchfile(struct patchset *ps, struct line *lines)
 		if (Rflag && format == ED)
 			enprintf(FAILURE, "-R cannot be used with ed scripts.\n");
-		/* TODO Step 4 of "Filename Determination" under EXTENDED DESCRIPTION in patch(1p). */
 	if (only_garbage)
_AT_@ -1549,7 +1548,7 @@ parse_ed_script(struct patch *patch, struct file_data *file)
 		case 'a':
 		case 'i':
-		  	count = 0;
+			count = 0;
 			for (add = 0; !lineeq(ed->lines[i + add], "."); add++);
 			hunk->lines = enrealloc(FAILURE, hunk->lines,
Received on Mon Sep 11 2017 - 21:08:09 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 11 2017 - 21:12:41 CEST