summaryrefslogtreecommitdiff
path: root/contrib/gdiffmk
diff options
context:
space:
mode:
authorwl <wl>2004-12-11 17:02:50 +0000
committerwl <wl>2004-12-11 17:02:50 +0000
commit172573a56a47140a09ffcb9e43f822d6f5ed5872 (patch)
tree47adea8a979b3f83929de674cd7e5766aa050d22 /contrib/gdiffmk
parentd875c5a2b735d1f21536257712693f39b0565120 (diff)
downloadgroff-172573a56a47140a09ffcb9e43f822d6f5ed5872.tar.gz
Import Mike's `gdiffmk' package.
* contrib/gdiffmk/*: New files. * Makefile.in (OTHERDIRS): Add contrib/gdiffmk. * NEWS: Updated.
Diffstat (limited to 'contrib/gdiffmk')
-rw-r--r--contrib/gdiffmk/Makefile.sub47
-rw-r--r--contrib/gdiffmk/gdiffmk.man222
-rw-r--r--contrib/gdiffmk/gdiffmk.sh252
3 files changed, 521 insertions, 0 deletions
diff --git a/contrib/gdiffmk/Makefile.sub b/contrib/gdiffmk/Makefile.sub
new file mode 100644
index 00000000..188c896b
--- /dev/null
+++ b/contrib/gdiffmk/Makefile.sub
@@ -0,0 +1,47 @@
+# Makefile.sub for `gdiffmk' (integration into the groff source tree)
+
+# File position: <groff-source>/contrib/gdiffmk/Makefile.sub
+
+# Last update: 11 December 2004
+
+# Copyright (C) 2004 Free Software Foundation, Inc.
+# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>>
+
+# This file 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 2, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+########################################################################
+
+MAN1=gdiffmk.n
+CLEANADD=gdiffmk
+
+all: gdiffmk
+
+gdiffmk: gdiffmk.sh
+ rm -f $@; \
+ sed -e "s|@BINDIR@|$(bindir)|g" \
+ -e "s|@VERSION@|$(version)$(revision)|g" \
+ -e $(SH_SCRIPT_SED_CMD) $(srcdir)/gdiffmk.sh >$@; \
+ chmod +x $@
+
+install_data: gdiffmk
+ -test -d $(bindir) || $(mkinstalldirs) $(bindir)
+ -rm -f $(bindir)/gdiffmk
+ $(INSTALL_SCRIPT) gdiffmk $(bindir)/gdiffmk
+
+uninstall_sub:
+ -rm -f $(bindir)/gdiffmk
diff --git a/contrib/gdiffmk/gdiffmk.man b/contrib/gdiffmk/gdiffmk.man
new file mode 100644
index 00000000..27295cbd
--- /dev/null
+++ b/contrib/gdiffmk/gdiffmk.man
@@ -0,0 +1,222 @@
+.ig \"-*- nroff -*-
+Copyright (C) 1989-1995, 2004 Free Software Foundation, Inc.
+
+Permission is granted to make and distribute verbatim copies of
+this manual provided the copyright notice and this permission notice
+are preserved on all copies.
+
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be included in
+translations approved by the Free Software Foundation instead of in
+the original English.
+..
+.
+.do mso www.tmac
+.
+.TH GDIFFMK @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@"
+.
+.
+.SH NAME
+gdiffmk \- mark differences between groff/nroff/troff files
+.
+.
+.SH SYNOPSIS
+.nr a \n(.j
+.ad l
+.nr i \n(.i
+.in +\w'\fBgdiffmk 'u
+.ti \niu
+.B gdiffmk
+.de OP
+. ie \\n(.$-1 .RI "[\ \fB\\$1\fP" "\\$2" "\ ]"
+. el .RB "[\ " "\\$1" "\ ]"
+..
+.OP \-a \%addmark
+.OP \-c \%changemark
+.OP \-d \%deletemark
+.OP \-\-
+.OP \-\-help
+.OP \-\-version
+.I \%file1
+.I \%file2
+[
+.I \%output
+]
+.
+.
+.SH DESCRIPTION
+.B gdiffmk
+compares two
+.BR groff (1),
+.BR nroff (1),
+or
+.BR troff (1)
+documents,
+.I file1
+and
+.IR file2 ,
+and creates an output which is
+.I file2
+with added `margin character' (.mc) commands that indicate the differences.
+.
+.LP
+If the
+.I output
+filename is present,
+the output is written there.
+If it is
+.B \-
+or absent the output is written to the standard output.
+.
+.LP
+If the
+.I file1
+or
+.I file2
+argument is
+.B \-
+the standard input is read for that input.
+Clearly both cannot be
+.BR \- .
+.
+.LP
+Note that the output is not necessarily compatible with all macro packages
+and all preprocessors.
+See the
+.B BUGS
+section below.
+.
+.
+.SH OPTIONS
+.TP
+.BI \-a addmark
+Use the
+.I addmark
+for source lines not in
+.I file1
+but present in
+.IR file2 .
+Default:
+.BR + .
+.
+.TP
+.BI \-c changemark
+Use the
+.I changemark
+for changed source lines.
+Default:
+.BR | .
+.
+.TP
+.BI \-d deletemark
+Use the
+.I deletemark
+for deleted source lines.
+Default:
+.BR * .
+.
+.TP
+.B \-\-
+All the following arguments are treated as file names,
+even if they begin with
+.BR \- .
+.
+.TP
+.B \-\-help
+Print a usage message on standard error output and exit.
+.
+.TP
+.B \-\-version
+Print version information on the standard output and exit.
+.
+.
+.SH BUGS
+The output is not necessarily compatible with all macro packages
+and all preprocessors.
+A workaround that is often successful against preprocessor problems
+is to run
+.B gdiffmk
+on the output of all the preprocessors instead of the input source.
+.
+.LP
+.B gdiffmk
+relies on the
+.B \-D
+option of GNU
+.BR diff (1)
+to make a merged `#ifdef' output format.
+It hasn't been tested whether other versions of
+.BR diff (1)
+do support this option.
+.
+.LP
+Report bugs to bug-groff@gnu.org.
+Include a complete, self-contained example that will allow the bug to
+be reproduced, and say which version of
+.B gdiffmk
+you are using.
+.
+.
+.SH AUTHORS
+This document was written and is maintained by
+.MTO MBianchi@Foveal.com "Mike Bianchi" .
+.
+.LP
+This document is distributed under the terms of the FDL (GNU Free
+Documentation License) version 1.1 or later.
+You should have received a copy of the FDL on your system, it is also
+available on-line at the
+.URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
+.
+.LP
+.B gdiffmk
+is part of the
+.I groff
+GNU free software project.
+All parts of the
+.I groff package
+are protected by GNU copyleft licenses.
+The software files are distributed under the terms of the GNU General
+Public License (GPL), while the documentation files mostly use the GNU
+Free Documentation License (FDL).
+.
+.
+.SH COPYRIGHT
+Copyright \(co 2004 Free Software Foundation, Inc.
+.
+.LP
+.B gdiffmk
+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 2, or (at your option) any later
+version.
+.
+.LP
+.B gdiffmk
+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.
+.
+.LP
+You should have received a copy of the GNU General Public License along
+with groff; see the file COPYING.
+If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+.
+.
+.SH "SEE ALSO"
+.BR groff (@MAN1EXT@),
+.BR nroff (@MAN1EXT@),
+.BR gtroff (@MAN1EXT@),
+.BR diff (@MAN1EXT@)
+.
+.\" Local Variables:
+.\" mode: nroff
+.\" End:
diff --git a/contrib/gdiffmk/gdiffmk.sh b/contrib/gdiffmk/gdiffmk.sh
new file mode 100644
index 00000000..a055ace3
--- /dev/null
+++ b/contrib/gdiffmk/gdiffmk.sh
@@ -0,0 +1,252 @@
+#!/bin/sh
+# This file is part of GNU gdiffmk.
+#
+# GNU gdiffmk 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 2, or (at your option) any
+# later version.
+#
+# GNU gdiffmk 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 gdiffmk; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc.
+# 59 Temple Place - Suite 330
+# Boston, MA 02111-1307, USA.
+
+
+cmd=$( basename $0 )
+
+diff -Dx /dev/null /dev/null >/dev/null 2>&1 ||
+ {
+ echo >&2 "${cmd}: " \
+ "The \`diff' program does not accept " \
+ "the required -DNAME option."
+ echo >&2 "${cmd}: " \
+ "Use GNU diff instead."
+ exit 126
+ }
+
+function 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).
+
+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: *.
+ --version Print version information on standard output and exit.
+ --help Print this message on standard error.
+"
+ exit 255
+}
+
+
+function Exit {
+ exitcode=$1
+ shift
+ echo >&2 "${cmd}: $@"
+ 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.
+function FileRead {
+ case "$2" in
+ -)
+ return
+ ;;
+ esac
+
+ if test ! -e "$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.
+function FileCreate {
+ case "$2" in
+ -)
+ return
+ ;;
+ esac
+
+ if ! touch "$2" 2>/dev/null
+ then
+ if test ! -e "$2"
+ then
+ Exit $1 "File \`$2' not created; " \
+ "Cannot write directory \`$( dirname "$2" )'."
+ fi
+ Exit $1 "File \`$2' not writeable."
+ fi
+}
+
+function WouldClobber {
+ case "$2" in
+ -)
+ return
+ ;;
+ esac
+
+ if test "$1" -ef "$3"
+ then
+ Exit 3 "\`$3' is the same as \`$2' and would be clobbered."
+ fi
+}
+
+addmark='+'
+changemark='|'
+deletemark='*'
+
+function 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
+}
+
+badoption=
+for option
+do
+ case "${option}" in
+ -a*)
+ addmark=$( RequiresArgument "${option}" $2 ) &&
+ shift
+ ;;
+ -c*)
+ changemark=$( RequiresArgument "${option}" $2 ) &&
+ shift
+ ;;
+ -d*)
+ deletemark=$( RequiresArgument "${option}" $2 ) &&
+ shift
+ ;;
+ --version)
+ echo "GNU ${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
+
+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_$$__
+
+diff -D"${label}" -- ${FILE1} ${FILE2} |
+ sed -n '
+ /^#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
+ d
+ }
+ p
+ '
+
+# EOF