2 # Copyright (C) 2004-2014 Free Software Foundation, Inc.
3 # Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
5 # This file is part of the gdiffmk utility, which is part of groff.
7 # groff is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # groff is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 # License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This file is part of GNU gdiffmk.
31 Usage: ${cmd} [ OPTIONS ] FILE1 FILE2 [ OUTPUT ]
32 Place difference marks into the new version of a groff/nroff/troff document.
33 FILE1 and FILE2 are compared, using \`diff', and FILE2 is output with
34 groff \`.mc' requests added to indicate how it is different from FILE1.
36 FILE1 Previous version of the groff file. \`-' means standard input.
37 FILE2 Current version of the groff file. \`-' means standard input.
38 Either FILE1 or FILE2 can be standard input, but not both.
39 OUTPUT Copy of FILE2 with \`.mc' commands added.
40 \`-' means standard output (the default).
43 -a ADDMARK Mark for added groff source lines. Default: \`+'.
44 -c CHANGEMARK Mark for changed groff source lines. Default: \`|'.
45 -d DELETEMARK Mark for deleted groff source lines. Default: \`*'.
47 -D Show the deleted portions from changed and deleted text.
48 Default delimiting marks: \`[[' .... \`]]'.
49 -B By default, the deleted texts marked by the \`-D' option end
50 with an added troff \`.br' command. This option prevents
52 -M MARK1 MARK2 Change the delimiting marks for the \`-D' option.
54 -x DIFFCMD Use a different diff(1) command;
55 one that accepts the \`-Dname' option, such as GNU diff.
56 --version Print version information on the standard output and exit.
57 --help Print this message on the standard error.
74 # Usage: FileRead exit_code filename
76 # Check for existence and readability of given file name.
77 # If not found or not readable, print message and exit with EXIT_CODE.
87 Exit $1 "File \`$2' not found."
91 Exit $1 "File \`$2' not readable."
96 # Usage: FileCreate exit_code filename
98 # Create the given filename if it doesn't exist.
99 # If unable to create or write, print message and exit with EXIT_CODE.
107 if ! touch "$2" 2>/dev/null
111 Exit $1 "File \`$2' not created; " \
112 "Cannot write directory \`$( dirname "$2" )'."
114 Exit $1 "File \`$2' not writeable."
125 if test "$1" -ef "$3"
128 "The $2 and OUTPUT arguments both point to the same file," \
129 "\`$1', and it would be overwritten."
139 RequiresArgument () {
140 # Process flags that take either concatenated or
144 expr "$1" : '-.\(.*\)'
151 Exit 255 "Option \`$1' requires a value."
166 ADDMARK=$( RequiresArgument "${OPTION}" $2 ) &&
170 CHANGEMARK=$( RequiresArgument "${OPTION}" $2 ) &&
174 DELETEMARK=$( RequiresArgument "${OPTION}" $2 ) &&
181 MARK1=$( RequiresArgument "${OPTION}" $2 ) &&
185 Usage "Option \`-M' is missing the MARK2 value."
194 DIFFCMD=$( RequiresArgument "${OPTION}" $2 ) &&
198 echo "GNU ${cmd} (groff) version @VERSION@"
205 # What follows -- are file arguments
213 badoption="${cmd}: invalid option \`$1'"
222 ${DIFFCMD} -Dx /dev/null /dev/null >/dev/null 2>&1 ||
223 Usage "The \`${DIFFCMD}' program does not accept" \
224 "the required \`-Dname' option.
225 Use GNU diff instead. See the \`-x DIFFCMD' option."
227 if test -n "${badoption}"
232 if test "$#" -lt 2 -o "$#" -gt 3
234 Usage "Incorrect number of arguments."
237 if test "1$1" = 1- -a "2$2" = 2-
239 Usage "Both FILE1 and FILE2 are \`-'."
245 FileRead 1 "${FILE1}"
246 FileRead 2 "${FILE2}"
252 # output goes to standard output
255 # output goes to a file
256 WouldClobber "${FILE1}" FILE1 "$3"
257 WouldClobber "${FILE2}" FILE2 "$3"
265 # To make a very unlikely label even more unlikely ...
269 /^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ {
270 /^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/
271 /^#endif \/\* '"${label}"'/ s/.*/.mc/
275 /^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ {
276 /^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ {
277 /^#else \/\* '"${label}"'/ s/.*/.mc '"${CHANGEMARK}"'/
278 /^#endif \/\* '"${label}"'/ s/.*/.mc/
282 /^#endif \/\* \(not\|!\) '"${label}"'/ {
283 s/.*/.mc '"${DELETEMARK}"'/p
295 /^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ {
296 /^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/
297 /^#endif \/\* '"${label}"'/ s/.*/.mc/
301 /^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ {
302 /^#ifndef '"${label}"'/ {
307 /^#else \/\* '"${label}"'/ ! {
308 /^#endif \/\* [!not ]*'"${label}"'/ ! {
313 /^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ {
314 /^#else \/\* '"${label}"'/ {
318 s/.*/.mc '"${CHANGEMARK}"'/
320 .mc '"${CHANGEMARK}"'
323 /^#endif \/\* '"${label}"'/ s/.*/.mc/
327 /^#endif \/\* \(not\|!\) '"${label}"'/ {
331 s/.*/.mc '"${DELETEMARK}"'/p
341 diff -D"${label}" -- ${FILE1} ${FILE2} |
342 sed -n "${sed_script}"
347 ########################################################################