summaryrefslogtreecommitdiff
path: root/contrib/gdiffmk
diff options
context:
space:
mode:
authorwl <wl>2005-01-16 01:43:21 +0000
committerwl <wl>2005-01-16 01:43:21 +0000
commitf3c2b628c51d752ac48a7bf3f1f55f53bb8e0360 (patch)
tree804a0e53afd414f0cdbb103930f2e175d7db1d24 /contrib/gdiffmk
parent940a3010722f6433f60124dc130440d34f8472e4 (diff)
downloadgroff-f3c2b628c51d752ac48a7bf3f1f55f53bb8e0360.tar.gz
* gdiffmk.sh: Add the -D, -M, and -B options, which provide actions
akin to nrchbar. Thanks to Larry Kollar (http://home.alltel.net/kollar/groff/). * gdiffmk.man: Updated. * tests/runtests.in: Added tests for gdiffmk's -D, -M, and -B options. * tests/baseline8, tests/baseline9, tests/baseline10: New files.
Diffstat (limited to 'contrib/gdiffmk')
-rw-r--r--contrib/gdiffmk/ChangeLog13
-rw-r--r--contrib/gdiffmk/README9
-rw-r--r--contrib/gdiffmk/gdiffmk.man46
-rw-r--r--contrib/gdiffmk/gdiffmk.sh121
-rw-r--r--contrib/gdiffmk/tests/runtests.in28
-rw-r--r--contrib/gdiffmk/tests/test_baseline1026
-rw-r--r--contrib/gdiffmk/tests/test_baseline826
-rw-r--r--contrib/gdiffmk/tests/test_baseline926
8 files changed, 259 insertions, 36 deletions
diff --git a/contrib/gdiffmk/ChangeLog b/contrib/gdiffmk/ChangeLog
index e3b2a4a4..44884e78 100644
--- a/contrib/gdiffmk/ChangeLog
+++ b/contrib/gdiffmk/ChangeLog
@@ -1,3 +1,16 @@
+2005-01-13 Mike Bianchi <MBianchi@Foveal.com>
+
+ * gdiffmk.sh: Add the -D, -M, and -B options, which provide actions
+ akin to nrchbar.
+ Thanks to Larry Kollar (http://home.alltel.net/kollar/groff/).
+
+ * gdiffmk.man: Updated.
+
+ * tests/runtests.in: Added tests for gdiffmk's -D, -M, and -B
+ options.
+
+ * tests/baseline8, tests/baseline9, tests/baseline10: New files.
+
2004-12-16 Mike Bianchi <MBianchi@Foveal.com>
* tests/runtests.in: Fix typo (s/$(srcdir)/${srcdir}/).
diff --git a/contrib/gdiffmk/README b/contrib/gdiffmk/README
index 357bbbc2..b46c2227 100644
--- a/contrib/gdiffmk/README
+++ b/contrib/gdiffmk/README
@@ -1,13 +1,16 @@
gdiffmk is approximately a recreation of the original Bell Labs/AT&T diffmk
command for troff/nroff documents, with enhancements.
-It should not be confused with diffmk commands that operate on XML.
+It should not be confused with `diffmk' commands that operate on XML.
The inspiration for this code was a Perl 2 version written in 1989 by Randal
L. Schwartz. See
-
landfield.com/software/comp.sources.misc/archive-name/volume06/diffmk.p.gz
+The command also attempts to reproduce some of the functionality of the old
+`nrchbar' command. See
+ open-systems.ufl.edu/mirrors/ftp.isc.org/usenet/comp.sources.unix/volume10/nrchbar.Z
+
Thanks to Werner Lemberg for help in making the package more portable and
fit into the GNU groff source structure.
@@ -22,7 +25,7 @@ argument gives the usage.
----------------------------------------------------------------------------
-Copyright (C) 2004 Free Software Foundation, Inc.
+Copyright (C) 2004, 2005 Free Software Foundation, Inc.
Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
This file is part of the gdiffmk utility, which is part of groff.
diff --git a/contrib/gdiffmk/gdiffmk.man b/contrib/gdiffmk/gdiffmk.man
index a813cf04..e00fd45b 100644
--- a/contrib/gdiffmk/gdiffmk.man
+++ b/contrib/gdiffmk/gdiffmk.man
@@ -1,5 +1,5 @@
.ig \"-*- nroff -*-
-Copyright (C) 2004 Free Software Foundation, Inc.
+Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of the gdiffmk utility, which is part of groff.
Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
@@ -43,14 +43,19 @@ gdiffmk \- mark differences between groff/nroff/troff files
.OP \-a \%addmark
.OP \-c \%changemark
.OP \-d \%deletemark
+[\ \c
+.B \-D
+.OP \-B
+.OP \-M "\ mark1 mark2"
+]
.OP \-x \%diffcmd
.OP \-\-
.OP \-\-help
-.OP \-\-version
+.OP \%\-\-version
.I \%file1
.I \%file2
-[
-.I \%output
+[\ \c
+.IR \%output \ \c
]
.br
.ad \na
@@ -112,6 +117,20 @@ Default:
.BR + .
.
.TP
+.B \-B
+By default, the deleted texts marked by the
+.B \-D
+option end
+with an added troff break command,
+.BR .br ,
+to ensure that the deletions are marked properly.
+This is the only way to guarantee that deletions and small
+changes get flagged.
+This option directs the program not to insert these breaks; it makes no
+sense to use it without
+.BR \-D .
+.
+.TP
.BI \-c changemark
Use the
.I changemark
@@ -128,6 +147,20 @@ Default:
.BR * .
.
.TP
+.B \-D
+Show the deleted portions from changed and deleted text.
+Default delimiting marks:
+.BR "[[" " .\&.\&.\&. " "]]" .
+.
+.TP
+.BI \-M " mark1 mark2
+Change the delimiting marks for the
+.B \-D
+option.
+It makes no sense to use this option without
+.BR \-D .
+.
+.TP
.BI \-x diffcmd
Use the
.I diffcmd
@@ -137,7 +170,8 @@ and
.IR file2 .
In particular,
.I diffcmd
-should accept the
+should accept the GNU
+.B diff
.BI \-D name
option.
Default:
@@ -213,7 +247,7 @@ Free Documentation License (FDL).
.
.
.SH COPYRIGHT
-Copyright \(co 2004 Free Software Foundation, Inc.
+Copyright \(co 2004, 2005 Free Software Foundation, Inc.
.
.LP
.B gdiffmk
diff --git a/contrib/gdiffmk/gdiffmk.sh b/contrib/gdiffmk/gdiffmk.sh
index 4f494412..37879235 100644
--- a/contrib/gdiffmk/gdiffmk.sh
+++ b/contrib/gdiffmk/gdiffmk.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright (C) 2004 Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005 Free Software Foundation, Inc.
# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
# This file is part of the gdiffmk utility, which is part of groff.
@@ -36,17 +36,25 @@ FILE1 and FILE2 are compared, using \`diff', and FILE2 is output with
groff \`.mc' requests added to indicate how it is different from FILE1.
FILE1 Previous version of the groff file. \`-' means standard input.
- FILE2 Current version of the groff file. \`-' means standard input.
+ FILE2 Current version of the groff file. \`-' means standard input.
Either FILE1 or FILE2 can be standard input, but not both.
OUTPUT Copy of FILE2 with \`.mc' commands added.
\`-' means standard output (the default).
OPTIONS:
- -a addmark Mark for added groff source lines. Default: +.
- -c changemark Mark for changed groff source lines. Default: |.
- -d deletemark Mark for deleted groff source lines. Default: *.
- -x diffcmd Use a different diff(1) command;
- one that accepts the \`-Dname' option, such as GNU diff.
+ -a ADDMARK Mark for added groff source lines. Default: \`+'.
+ -c CHANGEMARK Mark for changed groff source lines. Default: \`|'.
+ -d DELETEMARK Mark for deleted groff source lines. Default: \`*'.
+
+ -D Show the deleted portions from changed and deleted text.
+ Default delimiting marks: \`[[' .... \`]]'.
+ -B By default, the deleted texts marked by the \`-D' option end
+ with an added troff \`.br\' command. This option prevents
+ the added \`.br\'.
+ -M MARK1 MARK2 Change the delimiting marks for the \`-D' option.
+
+ -x DIFFCMD Use a different diff(1) command;
+ one that accepts the \`-Dname' option, such as GNU diff.
--version Print version information on the standard output and exit.
--help Print this message on the standard error.
"
@@ -124,9 +132,11 @@ function WouldClobber {
fi
}
-addmark='+'
-changemark='|'
-deletemark='*'
+ADDMARK='+'
+CHANGEMARK='|'
+DELETEMARK='*'
+MARK1='[['
+MARK2=']]'
function RequiresArgument {
# Process flags that take either concatenated or
@@ -148,24 +158,38 @@ function RequiresArgument {
}
badoption=
-diffcmd=diff
+DIFFCMD=diff
+D_option=
+br=.br
for OPTION
do
case "${OPTION}" in
-a*)
- addmark=$( RequiresArgument "${OPTION}" $2 ) &&
+ ADDMARK=$( RequiresArgument "${OPTION}" $2 ) &&
shift
;;
-c*)
- changemark=$( RequiresArgument "${OPTION}" $2 ) &&
+ CHANGEMARK=$( RequiresArgument "${OPTION}" $2 ) &&
shift
;;
-d*)
- deletemark=$( RequiresArgument "${OPTION}" $2 ) &&
+ DELETEMARK=$( RequiresArgument "${OPTION}" $2 ) &&
shift
;;
+ -D )
+ D_option=D_option
+ ;;
+ -M )
+ shift
+ MARK1=$1
+ shift
+ MARK2=$1
+ ;;
+ -B )
+ br=.
+ ;;
-x* )
- diffcmd=$( RequiresArgument "${OPTION}" $2 ) &&
+ DIFFCMD=$( RequiresArgument "${OPTION}" $2 ) &&
shift
;;
--version)
@@ -193,10 +217,10 @@ do
shift
done
-${diffcmd} -Dx /dev/null /dev/null >/dev/null 2>&1 ||
- Usage "The \`${diffcmd}' program does not accept" \
+${DIFFCMD} -Dx /dev/null /dev/null >/dev/null 2>&1 ||
+ Usage "The \`${DIFFCMD}' program does not accept" \
"the required \`-Dname' option.
-Use GNU diff instead. See the \`-x diffcmd' option."
+Use GNU diff instead. See the \`-x DIFFCMD' option."
if test -n "${badoption}"
then
@@ -239,23 +263,70 @@ fi
# To make a very unlikely label even more unlikely ...
label=__diffmk_$$__
-diff -D"${label}" -- ${FILE1} ${FILE2} |
- sed -n '
+sed_script='
+ /^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ {
+ /^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/
+ /^#endif \/\* '"${label}"'/ s/.*/.mc/
+ p
+ d
+ }
+ /^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ {
+ /^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ {
+ /^#else \/\* '"${label}"'/ s/.*/.mc '"${CHANGEMARK}"'/
+ /^#endif \/\* '"${label}"'/ s/.*/.mc/
+ p
+ d
+ }
+ /^#endif \/\* \(not\|!\) '"${label}"'/ {
+ s/.*/.mc '"${DELETEMARK}"'/p
+ a\
+.mc
+ }
+ d
+ }
+ p
+ '
+
+if [ ${D_option} ]
+then
+ sed_script='
/^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ {
- /^#ifdef '"${label}"'/ s/.*/.mc '"${addmark}"'/
+ /^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/
/^#endif \/\* '"${label}"'/ s/.*/.mc/
p
d
}
/^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ {
+ /^#ifndef '"${label}"'/ {
+ i\
+'"${MARK1}"'
+ d
+ }
+ /^#else \/\* '"${label}"'/ ! {
+ /^#endif \/\* [!not ]*'"${label}"'/ ! {
+ p
+ d
+ }
+ }
/^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ {
- /^#else \/\* '"${label}"'/ s/.*/.mc '"${changemark}"'/
+ /^#else \/\* '"${label}"'/ {
+ i\
+'"${MARK2}"'\
+'"${br}"'
+ s/.*/.mc '"${CHANGEMARK}"'/
+ a\
+.mc '"${CHANGEMARK}"'
+ d
+ }
/^#endif \/\* '"${label}"'/ s/.*/.mc/
p
d
}
/^#endif \/\* \(not\|!\) '"${label}"'/ {
- s/.*/.mc '"${deletemark}"'/p
+ i\
+'"${MARK2}"'\
+'"${br}"'
+ s/.*/.mc '"${DELETEMARK}"'/p
a\
.mc
}
@@ -263,5 +334,9 @@ diff -D"${label}" -- ${FILE1} ${FILE2} |
}
p
'
+fi
+
+diff -D"${label}" -- ${FILE1} ${FILE2} |
+ sed -n "${sed_script}"
# EOF
diff --git a/contrib/gdiffmk/tests/runtests.in b/contrib/gdiffmk/tests/runtests.in
index a6ad6d3b..200a95b1 100644
--- a/contrib/gdiffmk/tests/runtests.in
+++ b/contrib/gdiffmk/tests/runtests.in
@@ -8,7 +8,7 @@ command=../gdiffmk
# Test the number of arguments and the first argument.
case $#-$1 in
1-clean )
- rm -fv test_result? tmp_file?
+ rm -fv test_result* tmp_file*
exit 0
;;
1-run )
@@ -25,11 +25,14 @@ run Run the tests.
esac
function TestResult {
- if diff $1 $2
+ if cmp -s $1 $2
then
echo $2 PASSED
else
- echo $2 TEST FAILED '\a'
+ echo ''
+ echo $2 TEST FAILED
+ diff $1 $2
+ echo ''
fi
}
@@ -72,7 +75,24 @@ TestResult ${srcdir}/test_baseline6 ${ResultFile}
# Test for accidental file overwrite.
ResultFile=test_result7
cp ${srcdir}/file2 tmp_file7
-${command} -aA -dD -cC ${srcdir}/file1 tmp_file7 tmp_file7 >${ResultFile} 2>&1
+${command} -aA -dD -cC ${srcdir}/file1 tmp_file7 tmp_file7 \
+ >${ResultFile} 2>&1
TestResult ${srcdir}/test_baseline7 ${ResultFile}
+# Test -D option
+ResultFile=test_result8
+${command} -D ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
+TestResult ${srcdir}/test_baseline8 ${ResultFile}
+
+# Test -D and -M options
+ResultFile=test_result9
+${command} -D -M '<<<<' '>>>>' \
+ ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
+TestResult ${srcdir}/test_baseline9 ${ResultFile}
+
+# Test -D and -B options
+ResultFile=test_result10
+${command} -D -B ${srcdir}/file1 ${srcdir}/file2 >${ResultFile} 2>&1
+TestResult ${srcdir}/test_baseline10 ${ResultFile}
+
# EOF
diff --git a/contrib/gdiffmk/tests/test_baseline10 b/contrib/gdiffmk/tests/test_baseline10
new file mode 100644
index 00000000..b523f452
--- /dev/null
+++ b/contrib/gdiffmk/tests/test_baseline10
@@ -0,0 +1,26 @@
+.ll 25
+.pl 20
+.nf
+file1 and file2 #1
+[[
+file1 only
+]]
+.
+.mc |
+file2 only
+file2 only
+.mc
+file1 and file2 #2
+.mc +
+file2 only
+.mc
+file1 and file2 #3
+[[
+file1 only
+file1 only
+]]
+.
+.mc *
+.mc
+file1 and file2 #4
+file1 and file2 #5
diff --git a/contrib/gdiffmk/tests/test_baseline8 b/contrib/gdiffmk/tests/test_baseline8
new file mode 100644
index 00000000..9846dd58
--- /dev/null
+++ b/contrib/gdiffmk/tests/test_baseline8
@@ -0,0 +1,26 @@
+.ll 25
+.pl 20
+.nf
+file1 and file2 #1
+[[
+file1 only
+]]
+.br
+.mc |
+file2 only
+file2 only
+.mc
+file1 and file2 #2
+.mc +
+file2 only
+.mc
+file1 and file2 #3
+[[
+file1 only
+file1 only
+]]
+.br
+.mc *
+.mc
+file1 and file2 #4
+file1 and file2 #5
diff --git a/contrib/gdiffmk/tests/test_baseline9 b/contrib/gdiffmk/tests/test_baseline9
new file mode 100644
index 00000000..50fe57d6
--- /dev/null
+++ b/contrib/gdiffmk/tests/test_baseline9
@@ -0,0 +1,26 @@
+.ll 25
+.pl 20
+.nf
+file1 and file2 #1
+<<<<
+file1 only
+>>>>
+.br
+.mc |
+file2 only
+file2 only
+.mc
+file1 and file2 #2
+.mc +
+file2 only
+.mc
+file1 and file2 #3
+<<<<
+file1 only
+file1 only
+>>>>
+.br
+.mc *
+.mc
+file1 and file2 #4
+file1 and file2 #5