diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 19:44:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 19:44:05 +0000 |
commit | d318611dd6f23fcfedd50e9b9e24620b102ba96a (patch) | |
tree | 8b9eef82ca40fdd5a8deeabf07572074c236095d /contrib/gdiffmk | |
parent | Initial commit. (diff) | |
download | groff-d318611dd6f23fcfedd50e9b9e24620b102ba96a.tar.xz groff-d318611dd6f23fcfedd50e9b9e24620b102ba96a.zip |
Adding upstream version 1.23.0.upstream/1.23.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/gdiffmk')
-rw-r--r-- | contrib/gdiffmk/ChangeLog | 212 | ||||
-rw-r--r-- | contrib/gdiffmk/README | 53 | ||||
-rw-r--r-- | contrib/gdiffmk/gdiffmk.1.man | 304 | ||||
-rw-r--r-- | contrib/gdiffmk/gdiffmk.am | 59 | ||||
-rw-r--r-- | contrib/gdiffmk/gdiffmk.sh | 367 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline | 17 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.10 | 26 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.6 | 17 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.6a | 17 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.7 | 2 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.8 | 26 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.9 | 26 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/baseline.9a | 26 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/file1 | 11 | ||||
-rw-r--r-- | contrib/gdiffmk/tests/file2 | 11 | ||||
-rwxr-xr-x | contrib/gdiffmk/tests/runtests.sh | 187 |
16 files changed, 1361 insertions, 0 deletions
diff --git a/contrib/gdiffmk/ChangeLog b/contrib/gdiffmk/ChangeLog new file mode 100644 index 0000000..bc968bb --- /dev/null +++ b/contrib/gdiffmk/ChangeLog @@ -0,0 +1,212 @@ +2023-02-09 G. Branden Robinson <g.branden.robinson@gmail.com> + + Revise test regime. Reduce amount of indirection required to + run a test, and directly use the same script for standalone and + Automake-integrated testing. + + * tests/gdiffmk_tests.sh: Delete. + * tests/runtests.sh: Revise to search for test artifact input + and output directories (source vs. build). Drop argument + processing, converting two modes ("run" and "clean") into one + {run, with cleaning afterward}. Also ensure we use the build + directory to construct "tmp_file.7". Update authorship credit + so that Mike Bianchi isn't asked to support it. + + * tests/baseline.7: Update expected test output. + + * gdiffmk.am (TESTS): Run "runtests.sh" instead of + "gdiffmk_tests.sh". + (clean-local, clean_gdiffmk_check): Drop targets now that the + test script cleans up after itself. + +2023-02-06 G. Branden Robinson <g.branden.robinson@gmail.com> + + * tests/runtests.sh: Refactor file handling. Use narrower globs + to match the file names actually used; they are suffixed with a + dot and a number, not a number alone. Honor $TMPDIR when + creating the even-more-temporary file. Revise trap setup so + that the trap handler cannot be interrupted if it is already + running. Call the handler, then commit suicide with SIGINT. + Use symbolic names for signals, not numbers. Call new CleanUp + function before exiting normally. + (CleanUp): Pull temporary file clean-up logic into new function. + Also delete the even-more-temporary file used in test 1. + +2022-10-18 G. Branden Robinson <g.branden.robinson@gmail.com> + + * gdiffmk.sh: Drop "GNU" from version information, since this + program resides in groff's "contrib" directory. + +2018-02-28 Werner LEMBERG <wl@gnu.org> + + * gdiffmk.am (gdiffmk): Use $(AM_V_GEN) to silence file generation. + +2015-08-22 Bernd Warken <groff-bernd.warken-72@web.de> + + * gdiffmk.1.man: Rename `gdiffmk.man'. + + * gdiffmk.am: Include renaming. + +2015-08-05 Bernd Warken <groff-bernd.warken-72@web.de> + + * gdiffmk.am: Add `Last update'. Setup Emacs mode. + +2015-04-13 Mike Bianchi <MBianchi@Foveal.com> + More fixes to Savannah bug #44768. + + * gdiffmk.sh: + replace + for OPTION with while [ $# -gt 0 ] + + test -e ... with test -f + + use ${DIFFCMD} for the last diff + add + -s SEDCMD option + OPTION="$1" + + many other cosmetic changes documented in the bug Discussion. + especially: + capitalize variables e.g. CMD=`basename $0` + + fix make check tests within gdiffmk + * tests/gdiffmk_tests.sh + add set -e + fails if ${abs_top_builddir} not set or incorrect + + * tests/runtests.sh + add test 6a + # Different values for addmark, changemark, deletemark + # Alternate format of -a -c and -d flag arguments + + add test 9a + # Test -D and -M options + # Alternate format of -M argument. + + add printout of failure count + add exit with failure exit_code if any test fails + +2015-04-10 Werner LEMBERG <wl@gnu.org> + + Fix Savannah bug #44768. + + * gdiffmk.sh: Remove bash's $(...) with classic `...`. + Patch by Peter Bray. + +2015-04-03 Werner LEMBERG <wl@gnu.org + + * gdiffmk.man: Make it work in compatibility mode. + +2014-09-03 Bernd Warken <groff-bernd.warken-72@web.de> + + * all `gdiffmk' source files: Add and improve the copying + information. Remove last update. Add Emacs setting if necessary. + +2014-03-30 Steffen Nurpmeso <sdaoden@yandex.com> + + * Makefile.sub: Put straight error-prevention prefixes for `rm'. + +2009-09-22 Colin Watson <cjwatson@debian.org> + + * gdiffmk.sh: Don't use bash specific syntax. + +2008-01-04 Werner LEMBERG <wl@gnu.org> + + * gdiffmk.man: Replace .URL with .UR/.UE. + Replace .MTO with .MT/.ME. + Don't include www.tmac. + +2006-09-13 Werner LEMBERG <wl@gnu.org> + + * tests/test_baseline*: Renamed to... + * tests/baseline.*: This. + + * tests/runtests.in: Updated. + +2006-02-26 Claudio Fontana <claudio@gnu.org> + + * Makefile.sub: Add DESTDIR to install and uninstall targets + to support staged installations. + +2005-05-16 Keith Marshall <keith.d.marshall@ntlworld.com> + + * gdiffmk.sh: Add space in shebang, conforming + to portability recommendation in autoconf docs. + * tests/runtests.in: Likewise. + +2005-01-16 Mike Bianchi <MBianchi@Foveal.com> + + * gdiffmk.sh (Usage): Fix typos. + <top>: Allow `-M<arg1> <arg2>' also. + + * gdiffmk.man: Updated. + +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}/). + +2004-12-15 Werner LEMBERG <wl@gnu.org> + + The configure script now generates tests/runtests. + + * tests/tests.sh: Renamed to... + * tests/runtests.in: This. + Add proper $srcdir prefixes to make it run from build directory. + * README, Makefile.sub (CLEANADD), tests/test_baseline7: Updated. + +2004-12-14 Werner LEMBERG <wl@gnu.org> + + * gdiffmk.sh: Make sed pattern work with alternate result of GNU + diff's -D option, using `!' instead of `not' in #endif comments. + (Exit): Use prefix for each emitted message line. + +2004-12-14 Mike Bianchi <MBianchi@Foveal.com> + + * tests/*: New files for testing gdiffmk. + + * README, gdiffmk.man, gdiffmk.sh: Updated. + Minor fixes. + +2004-12-13 Mike Bianchi <MBianchi@Foveal.com> + + Add `-x' command line option to select a diff program. + + * gdiffmk.sh: Add code to handle `-x'. + Move test for working `diff' down. + Fix sed pattern -- `.mc *' needs to be followed by `.mc .'. + (Usage): Updated. + * gdiffmk.man: Updated. + +2004-12-12 Mike Bianchi <MBianchi@Foveal.com> + + * README: New file. + +2004-12-11 Mike Bianchi <MBianchi@Foveal.com> + + First import of gdiffmk files. + +Copyright 2004-2020 Free Software Foundation, Inc. + +Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. + +Local Variables: +fill-column: 72 +mode: change-log +version-control: never +End: +vim:set autoindent textwidth=72: diff --git a/contrib/gdiffmk/README b/contrib/gdiffmk/README new file mode 100644 index 0000000..d2214dd --- /dev/null +++ b/contrib/gdiffmk/README @@ -0,0 +1,53 @@ +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. + +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. + +Gnu diff(1) with the -Dname option does all of the work and sed(1) +translates the output into something groff/troff/nroff can handle. + +Note the BUGS on the man page. + +The 'tests' directory contains simple tests. 'runtests run' runs them and +compares the output against baseline files. Calling 'runtests' without +argument gives the usage. + +---------------------------------------------------------------------------- + +Copyright (C) 2004-2020 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. + +groff is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +groff is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +License for more details. + +You should have received a copy of the GNU General Public License +along with groff; see the files COPYING and LICENSE in the top +directory of the groff source. If not, write to the Free Software +Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. + +##### Editor settings +Local Variables: +fill-column: 72 +mode: text +End: +vim: set textwidth=72: diff --git a/contrib/gdiffmk/gdiffmk.1.man b/contrib/gdiffmk/gdiffmk.1.man new file mode 100644 index 0000000..36f30b7 --- /dev/null +++ b/contrib/gdiffmk/gdiffmk.1.man @@ -0,0 +1,304 @@ +.TH gdiffmk @MAN1EXT@ "@MDATE@" "groff @VERSION@" +.SH Name +gdiffmk \- mark differences between +.IR groff / nroff / troff +files +. +. +.\" ==================================================================== +.\" Legal Terms +.\" ==================================================================== +.\" +.\" Copyright (C) 2004-2020 Free Software Foundation, Inc. +.\" +.\" This file is part of gdiffmk, which is part of groff, the GNU roff +.\" type-setting system. +.\" +.\" This program is free software: you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation, either version 3 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, but +.\" WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +.\" General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program. If not, see +.\" <http://www.gnu.org/licenses/>. +. +. +.\" Save and disable compatibility mode (for, e.g., Solaris 10/11). +.do nr *groff_gdiffmk_1_man_C \n[.cp] +.cp 0 +. +.\" Define fallback for groff 1.23's MR macro if the system lacks it. +.nr do-fallback 0 +.if !\n(.f .nr do-fallback 1 \" mandoc +.if \n(.g .if !d MR .nr do-fallback 1 \" older groff +.if !\n(.g .nr do-fallback 1 \" non-groff *roff +.if \n[do-fallback] \{\ +. de MR +. ie \\n(.$=1 \ +. I \%\\$1 +. el \ +. IR \%\\$1 (\\$2)\\$3 +. . +.\} +.rr do-fallback +. +. +.\" ==================================================================== +.SH Synopsis +.\" ==================================================================== +. +.SY gdiffmk +.RB [ \-a\~\c +.IR add-mark ] +.RB [ \-c\~\c +.IR change-mark ] +.RB [ \-d\~\c +.IR delete-mark ] +.RB [ \-x\~\c +.IR diff-command ] +.RB [ \-D +.RB [ \-B ] +.RB [ \-M +.IR "mark1 mark2" ]] +.RB [ \-\- ] +.I file1 +.I file2 +.RI [ output ] +.YS +. +. +.SY gdiffmk +.B \-\-help +.YS +. +. +.SY gdiffmk +.B \-\-version +.YS +. +. +.\" ==================================================================== +.SH Description +.\" ==================================================================== +. +.I gdiffmk +compares two +.MR roff @MAN7EXT@ +documents, +.I file1 +and +.IR file2 , +and creates a +.I roff +document consisting of +.I file2 +with added margin character +.RB ( .mc ) +requests indicating output lines that differ from +.I file1. +. +If the +.I file1 +or +.I file2 +argument is +.RB \[lq] \- \[rq], +.I gdiffmk +reads the standard input stream for that input. +. +If the +.I output +operand is present, +.I gdiffmk +writes output to a file of that name. +. +If it is +.RB \[lq] \- \[rq] +or absent, +.I gdiffmk +writes output to the standard output stream. +. +.RB \[lq] \- \[rq] +cannot be both an input and output operand. +. +. +.\" ==================================================================== +.SH Options +.\" ==================================================================== +. +.B \-\-help +displays a usage message +and +.B \-\-version +shows version information; +both exit afterward. +. +. +.TP +.BI \-a\~ add-mark +Use +.I add-mark +for source lines not in +.I file1 +but present in +.IR file2 . +. +Default: +.RB \[lq] + \[rq]. +. +. +.TP +.B \-B +By default, +the deleted texts marked by the +.B \-D +option end with an added +.I roff +break request, +.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\~ change-mark +Use +.I change-mark +for changed source lines. +. +Default: +.RB \[lq] | \[rq]. +. +. +.TP +.BI \-d\~ delete-mark +Use the +.I delete-mark +for deleted source lines. +. +Default: +.RB \[lq] * \[rq]. +. +.TP +.B \-D +Show the deleted portions from changed and deleted text. +. +. +.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 . +. +Default delimiting marks: +.RB \[lq] [[ "\[rq] .\|.\|.\& \[lq]" ]] \[rq]. +. +. +.TP +.BI \-x\~ diff-command +Use the +.I diff-command +command to perform the comparison of +.I file1 +and +.IR file2 . +. +In particular, +.I diff-command +should accept the GNU +.MR diff 1 +.B \-D +option. +. +Default: +.BR diff . +. +. +.TP +.B \-\- +Treat all subsequent arguments as file names, +even if they begin with +.RB \[lq] \- \[rq]. +. +. +.\" ==================================================================== +.SH Bugs +.\" ==================================================================== +. +The output is not necessarily compatible with all macro packages +and all preprocessors. +. +A workaround that often overcomes preprocessor problems is to run +.I gdiffmk +on the output of all the preprocessors instead of the input source. +. +. +.LP +.I gdiffmk +relies on the +.B \-D +option of GNU +.I diff +to make a merged \[lq]#ifdef\[rq] output format. +. +Busybox +.I diff +is known to not support it. +. +Also see the +.BI \-x\~ diff-command +option. +. +. +.\" ==================================================================== +.SH Authors +.\" ==================================================================== +. +.I gdiffmk +was written by +.MT MBianchi@\:Foveal\:.com +Mike Bianchi +.ME , +now retired. +. +It is maintained by the +.I groff +developers. +. +. +.\" ==================================================================== +.SH "See also" +.\" ==================================================================== +. +.MR groff @MAN1EXT@ , +.MR nroff @MAN1EXT@ , +.MR gtroff @MAN1EXT@ , +.MR roff @MAN7EXT@ , +.MR diff @MAN1EXT@ +. +. +.\" Restore compatibility mode (for, e.g., Solaris 10/11). +.cp \n[*groff_gdiffmk_1_man_C] +.do rr *groff_gdiffmk_1_man_C +. +. +.\" Local Variables: +.\" fill-column: 72 +.\" mode: nroff +.\" End: +.\" vim: set filetype=groff textwidth=72: diff --git a/contrib/gdiffmk/gdiffmk.am b/contrib/gdiffmk/gdiffmk.am new file mode 100644 index 0000000..46f224b --- /dev/null +++ b/contrib/gdiffmk/gdiffmk.am @@ -0,0 +1,59 @@ +# Automake rules for 'gdiffmk' (integration into the groff source tree) +# +# Copyright (C) 2004-2020 Free Software Foundation, Inc. +# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>> +# Automake migration by Bertrand Garrigues +# +# This file is part of the gdiffmk utility, which is part of groff. +# +# groff is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# groff is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +######################################################################## +gdiffmk_srcdir = $(top_srcdir)/contrib/gdiffmk +bin_SCRIPTS += gdiffmk +TESTS += contrib/gdiffmk/tests/runtests.sh +man1_MANS += contrib/gdiffmk/gdiffmk.1 +EXTRA_DIST += \ + contrib/gdiffmk/gdiffmk.1.man \ + contrib/gdiffmk/ChangeLog \ + contrib/gdiffmk/README \ + contrib/gdiffmk/gdiffmk.sh \ + contrib/gdiffmk/tests/runtests.sh \ + contrib/gdiffmk/tests/baseline \ + contrib/gdiffmk/tests/baseline.6 \ + contrib/gdiffmk/tests/baseline.6a \ + contrib/gdiffmk/tests/baseline.7 \ + contrib/gdiffmk/tests/baseline.8 \ + contrib/gdiffmk/tests/baseline.9 \ + contrib/gdiffmk/tests/baseline.9a \ + contrib/gdiffmk/tests/baseline.10 \ + contrib/gdiffmk/tests/file1 \ + contrib/gdiffmk/tests/file2 + +gdiffmk: $(gdiffmk_srcdir)/gdiffmk.sh + $(AM_V_GEN)sed -e "s|[@]BINDIR[@]|$(bindir)|g" \ + -e "s|[@]VERSION[@]|$(VERSION)|g" \ + -e "s|[@]HAVE_TEST_EF_OPTION[@]|$(HAVE_TEST_EF_OPTION)|g" \ + -e "s|[@]BASH_PROG[@]|$(BASH_PROG)|g" \ + -e "s|[@]DIFF_PROG[@]|$(DIFF_PROG)|g" \ + -e $(SH_SCRIPT_SED_CMD) $(gdiffmk_srcdir)/gdiffmk.sh \ + >$@ \ + && chmod +x $@ + + +# Local Variables: +# mode: makefile-automake +# fill-column: 72 +# End: +# vim: set autoindent filetype=automake textwidth=72: diff --git a/contrib/gdiffmk/gdiffmk.sh b/contrib/gdiffmk/gdiffmk.sh new file mode 100644 index 0000000..2473fb1 --- /dev/null +++ b/contrib/gdiffmk/gdiffmk.sh @@ -0,0 +1,367 @@ +#!@BASH_PROG@ +# Copyright (C) 2004-2020 Free Software Foundation, Inc. +# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>> +# Thanks to Peter Bray for debugging. + +# This file is part of the gdiffmk utility, which is part of groff. + +# groff is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# groff is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This file is part of GNU gdiffmk. + + +CMD=`basename $0` + +Usage () { + if test $# -gt 0 + then + echo >&2 "${CMD}: $@" + fi + echo >&2 "\ + +Usage: ${CMD} [ OPTIONS ] FILE1 FILE2 [ OUTPUT ] +Place difference marks into the new version of a groff/nroff/troff document. +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. + Either FILE1 or FILE2 can be standard input, but not both. + OUTPUT Copy of FILE2 with '.mc' commands added. + '-' means standard output (the default). + If the shell's 'test' does not support option -ef, OUTPUT + can only be the standard output. + +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: '*'. + + -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. + -s SEDCMD Use a different sed(1) command; + such as GNU sed. + --version Print version information on the standard output and exit. + --help Print this message on the standard error. +" + exit 255 +} + + +Exit () { + exitcode=$1 + shift + for arg + do + echo >&2 "${CMD}: $1" + shift + done + exit ${exitcode} +} + +# Usage: FileRead exit_code filename +# +# Check for existence and readability of given file name. +# If not found or not readable, print message and exit with EXIT_CODE. +FileRead () { + case "$2" in + -) + return + ;; + esac + + if test ! -f "$2" + then + Exit $1 "File '$2' not found." + fi + if test ! -r "$2" + then + Exit $1 "File '$2' not readable." + fi +} + + +# Usage: FileCreate exit_code filename +# +# Create the given filename if it doesn't exist. +# If unable to create or write, print message and exit with EXIT_CODE. +FileCreate () { + case "$2" in + -) + return + ;; + esac + + touch "$2" 2>/dev/null + if test $? -ne 0 + then + if test ! -f "$2" + then + Exit $1 "File '$2' not created; " \ + "Cannot write directory '`dirname "$2"`'." + fi + Exit $1 "File '$2' not writeable." + fi +} + +WouldClobber () { + case "$2" in + -) + return + ;; + esac + + # BASH_PROG is set to /bin/sh if bash was not found + if test "$HAVE_TEST_EF_OPTION" = "no" -a "$BASH_PROG" = "/bin/sh" + then + Exit 3 \ + "Your shell does support test -ef, [OUTPUT] can only be the" \ + "standard output." + else + if test "$1" -ef "$3" + then + Exit 3 \ + "The $2 and OUTPUT arguments both point to the same file," \ + "'$1', and it would be overwritten." + fi + fi +} + +ADDMARK='+' +CHANGEMARK='|' +DELETEMARK='*' +MARK1='[[' +MARK2=']]' + +RequiresArgument () { + # Process flags that take either concatenated or + # separated values. + case "$1" in + -??*) + expr "$1" : '-.\(.*\)' + return 1 + ;; + esac + + if test $# -lt 2 + then + Exit 255 "Option '$1' requires a value." + fi + + echo "$2" + return 0 +} + +HAVE_TEST_EF_OPTION=@HAVE_TEST_EF_OPTION@ +BASH_PROG=@BASH_PROG@ +BADOPTION= +DIFFCMD=@DIFF_PROG@ +SEDCMD=sed +D_option= +br=.br +while [ $# -gt 0 ] +do + OPTION="$1" + case "${OPTION}" in + -a*) + ADDMARK=`RequiresArgument "${OPTION}" "$2"` && + shift + ;; + -c*) + CHANGEMARK=`RequiresArgument "${OPTION}" "$2"` && + shift + ;; + -d*) + DELETEMARK=`RequiresArgument "${OPTION}" "$2"` && + shift + ;; + -D ) + D_option=D_option + ;; + -M* ) + MARK1=`RequiresArgument "${OPTION}" "$2"` && + shift + if [ $# -lt 2 ] + then + Usage "Option '-M' is missing the MARK2 value." + fi + MARK2="$2" + shift + ;; + -B ) + br=. + ;; + -s* ) + SEDCMD=`RequiresArgument "${OPTION}" "$2"` && + shift + ;; + -x* ) + DIFFCMD=`RequiresArgument "${OPTION}" "$2"` && + shift + ;; + --version) + echo "${CMD} (groff) version @VERSION@" + exit 0 + ;; + --help) + Usage + ;; + --) + # What follows -- are file arguments + shift + break + ;; + -) + break + ;; + -*) + BADOPTION="${CMD}: invalid option '$1'" + ;; + *) + break + ;; + esac + shift +done + +${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. You can also +install GNU diff as gdiff on your system" + +if test -n "${BADOPTION}" +then + Usage "${BADOPTION}" +fi + +if test $# -lt 2 -o $# -gt 3 +then + Usage "Incorrect number of arguments." +fi + +if test "1$1" = "1-" -a "2$2" = "2-" +then + Usage "Both FILE1 and FILE2 are '-'." +fi + +FILE1="$1" +FILE2="$2" + +FileRead 1 "${FILE1}" +FileRead 2 "${FILE2}" + +if test $# = 3 +then + case "$3" in + -) + # output goes to standard output + ;; + *) + # output goes to a file + WouldClobber "${FILE1}" FILE1 "$3" + WouldClobber "${FILE2}" FILE2 "$3" + + FileCreate 3 "$3" + exec >$3 + ;; + esac +fi + +# To make a very unlikely LABEL even more unlikely ... +LABEL=__diffmk_$$__ + +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}"'/ + /^#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}"'/ { + i\ +'"${MARK2}"'\ +'"${br}"' + s/.*/.mc '"${CHANGEMARK}"'/ + a\ +.mc '"${CHANGEMARK}"' + d + } + /^#endif \/\* '"${LABEL}"'/ s/.*/.mc/ + p + d + } + /^#endif \/\* [!not ]*'"${LABEL}"'/ { + i\ +'"${MARK2}"'\ +'"${br}"' + s/.*/.mc '"${DELETEMARK}"'/p + a\ +.mc + } + d + } + p + ' +fi + +${DIFFCMD} -D"${LABEL}" -- "${FILE1}" "${FILE2}" | + ${SEDCMD} -n "${SED_SCRIPT}" + +# EOF diff --git a/contrib/gdiffmk/tests/baseline b/contrib/gdiffmk/tests/baseline new file mode 100644 index 0000000..6b32992 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline @@ -0,0 +1,17 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +.mc | +file2 only +file2 only +.mc +file1 and file2 #2 +.mc + +file2 only +.mc +file1 and file2 #3 +.mc * +.mc +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/baseline.10 b/contrib/gdiffmk/tests/baseline.10 new file mode 100644 index 0000000..b523f45 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.10 @@ -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/baseline.6 b/contrib/gdiffmk/tests/baseline.6 new file mode 100644 index 0000000..3156961 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.6 @@ -0,0 +1,17 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +.mc C +file2 only +file2 only +.mc +file1 and file2 #2 +.mc A +file2 only +.mc +file1 and file2 #3 +.mc D +.mc +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/baseline.6a b/contrib/gdiffmk/tests/baseline.6a new file mode 100644 index 0000000..3156961 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.6a @@ -0,0 +1,17 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +.mc C +file2 only +file2 only +.mc +file1 and file2 #2 +.mc A +file2 only +.mc +file1 and file2 #3 +.mc D +.mc +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/baseline.7 b/contrib/gdiffmk/tests/baseline.7 new file mode 100644 index 0000000..4a83af6 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.7 @@ -0,0 +1,2 @@ +gdiffmk: The FILE2 and OUTPUT arguments both point to the same file, +gdiffmk: './contrib/gdiffmk/tests/tmp_file.7', and it would be overwritten. diff --git a/contrib/gdiffmk/tests/baseline.8 b/contrib/gdiffmk/tests/baseline.8 new file mode 100644 index 0000000..9846dd5 --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.8 @@ -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/baseline.9 b/contrib/gdiffmk/tests/baseline.9 new file mode 100644 index 0000000..50fe57d --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.9 @@ -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/baseline.9a b/contrib/gdiffmk/tests/baseline.9a new file mode 100644 index 0000000..50fe57d --- /dev/null +++ b/contrib/gdiffmk/tests/baseline.9a @@ -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/file1 b/contrib/gdiffmk/tests/file1 new file mode 100644 index 0000000..ba6a4be --- /dev/null +++ b/contrib/gdiffmk/tests/file1 @@ -0,0 +1,11 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +file1 only +file1 and file2 #2 +file1 and file2 #3 +file1 only +file1 only +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/file2 b/contrib/gdiffmk/tests/file2 new file mode 100644 index 0000000..54e95ee --- /dev/null +++ b/contrib/gdiffmk/tests/file2 @@ -0,0 +1,11 @@ +.ll 25 +.pl 20 +.nf +file1 and file2 #1 +file2 only +file2 only +file1 and file2 #2 +file2 only +file1 and file2 #3 +file1 and file2 #4 +file1 and file2 #5 diff --git a/contrib/gdiffmk/tests/runtests.sh b/contrib/gdiffmk/tests/runtests.sh new file mode 100755 index 0000000..51cf855 --- /dev/null +++ b/contrib/gdiffmk/tests/runtests.sh @@ -0,0 +1,187 @@ +#! /bin/sh +# +# A very simple function test for gdiffmk.sh. +# +# Copyright (C) 2004-2020, 2023 Free Software Foundation, Inc. +# Written by Mike Bianchi <MBianchi@Foveal.com>. +# Subsequent modifications by G. Branden Robinson. + +# This file is part of the gdiffmk utility, which is part of groff. + +# groff is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# groff is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This file is part of GNU gdiffmk. + +# abs_top_out_dir is set by AM_TESTS_ENVIRONMENT (defined in +# Makefile.am) when running "make check". + +gdiffmk=${abs_top_out_dir:-.}/gdiffmk + +# Locate directory containing our test artifacts. +in_dir= + +for srcroot in . .. ../.. +do + # Look for a source file characteristic of the groff source tree. + if ! [ -f "$srcroot"/ChangeLog.115 ] + then + continue + fi + + d=$srcroot/contrib/gdiffmk/tests + if [ -d "$d" ] + then + in_dir=$d + break + fi +done + +# If we can't find it, we can't test. +if [ -z "$in_dir" ] +then + echo "$0: cannot locate test artifact input directory" >&2 + exit 77 # skip +fi + +# Locate directory where we'll put the test output. +out_dir= + +for buildroot in . .. ../.. +do + d=$buildroot/contrib/gdiffmk/tests + if [ -d "$d" ] + then + out_dir=$d + break + fi +done + +# If we can't find it, we can't test. +if [ -z "$out_dir" ] +then + echo "$0: cannot locate test artifact output directory" >&2 + exit 77 # skip +fi + +exit_code=0 # Success +failure_count=0 + +TestResult () { + if cmp -s $1 $2 + then + echo $2 PASSED + else + echo '' + echo $2 TEST FAILED + diff $1 $2 + echo '' + exit_code=1 # Failure + failure_count=`expr ${failure_count} + 1` + fi +} + +CleanUp () { + rm -f ${out_dir}/result.* ${out_dir}/tmp_file.* ${tmpfile} +} + +tmpfile=${TMPDIR:-/tmp}/$$ +trap 'trap "" HUP INT QUIT TERM; CleanUp; kill -s INT $$' \ + HUP INT QUIT TERM + +# Run tests. + +# 3 file arguments +ResultFile=${out_dir}/result.1 +${gdiffmk} ${in_dir}/file1 ${in_dir}/file2 ${ResultFile} 2>${tmpfile} +cat ${tmpfile} >>${ResultFile} +TestResult ${in_dir}/baseline ${ResultFile} + +# OUTPUT to stdout by default +ResultFile=${out_dir}/result.2 +${gdiffmk} ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline ${ResultFile} + +# OUTPUT to stdout via - argument +ResultFile=${out_dir}/result.3 +${gdiffmk} ${in_dir}/file1 ${in_dir}/file2 - >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline ${ResultFile} + +# FILE1 from standard input via - argument +ResultFile=${out_dir}/result.4 +${gdiffmk} - ${in_dir}/file2 <${in_dir}/file1 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline ${ResultFile} + + +# FILE2 from standard input via - argument +ResultFile=${out_dir}/result.5 +${gdiffmk} ${in_dir}/file1 - <${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline ${ResultFile} + + +# Different values for addmark, changemark, deletemark +ResultFile=${out_dir}/result.6 +${gdiffmk} -aA -cC -dD ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.6 ${ResultFile} + + +# Different values for addmark, changemark, deletemark +# Alternate format of -a -c and -d flag arguments +ResultFile=${out_dir}/result.6a +${gdiffmk} -a A -c C -d D ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.6a ${ResultFile} + + +# Test for accidental file overwrite. +ResultFile=${out_dir}/result.7 +TempFile=${out_dir}/tmp_file.7 +cp ${in_dir}/file2 "$TempFile" +${gdiffmk} -aA -dD -cC ${in_dir}/file1 "$TempFile" "$TempFile" \ + >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.7 ${ResultFile} + + +# Test -D option +ResultFile=${out_dir}/result.8 +${gdiffmk} -D ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.8 ${ResultFile} + + +# Test -D and -M options +ResultFile=${out_dir}/result.9 +${gdiffmk} -D -M '<<<<' '>>>>' \ + ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.9 ${ResultFile} + + +# Test -D and -M options +# Alternate format of -M argument. +ResultFile=${out_dir}/result.9a +${gdiffmk} -D -M'<<<<' '>>>>' \ + ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.9a ${ResultFile} + + +# Test -D and -B options +ResultFile=${out_dir}/result.10 +${gdiffmk} -D -B ${in_dir}/file1 ${in_dir}/file2 >${ResultFile} 2>&1 +TestResult ${in_dir}/baseline.10 ${ResultFile} + + +echo failure_count ${failure_count} + +# You can comment out the following line to examine failing cases. +CleanUp + +exit ${exit_code} + +# vim:set ai et sw=4 ts=4 tw=72: |