From 69f17780904dcd65e8786b0e206899ed504b5371 Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Sat, 11 Dec 2004 17:02:50 +0000 Subject: [PATCH] Import Mike's `gdiffmk' package. * contrib/gdiffmk/*: New files. * Makefile.in (OTHERDIRS): Add contrib/gdiffmk. * NEWS: Updated. --- ChangeLog | 8 ++ Makefile.in | 3 +- NEWS | 7 ++ contrib/gdiffmk/Makefile.sub | 47 ++++++++ contrib/gdiffmk/gdiffmk.man | 222 ++++++++++++++++++++++++++++++++++++++ contrib/gdiffmk/gdiffmk.sh | 252 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 538 insertions(+), 1 deletion(-) create mode 100644 contrib/gdiffmk/Makefile.sub create mode 100644 contrib/gdiffmk/gdiffmk.man create mode 100644 contrib/gdiffmk/gdiffmk.sh diff --git a/ChangeLog b/ChangeLog index 6b32226a..95049b04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-12-10 Werner LEMBERG + + Import Mike's `gdiffmk' package. + + * contrib/gdiffmk/*: New files. + * Makefile.in (OTHERDIRS): Add contrib/gdiffmk. + * NEWS: Updated. + 2004-12-08 Werner LEMBERG Import Keith's `pdfmark' package. Integration is very preliminary. diff --git a/Makefile.in b/Makefile.in index 8bdd9f3a..57428cda 100644 --- a/Makefile.in +++ b/Makefile.in @@ -530,7 +530,8 @@ OTHERDIRS=\ contrib/grap2graph \ contrib/groffer \ contrib/mom \ - contrib/pdfmark + contrib/pdfmark \ + contrib/gdiffmk ALLDIRS=$(INCDIRS) $(LIBDIRS) $(PROGDIRS) \ $(DEVDIRS) $(XDEVDIRS) $(OTHERDEVDIRS) $(TTYDEVDIRS) $(OTHERDIRS) EXTRADIRS=\ diff --git a/NEWS b/NEWS index 65587de2..448ba97c 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,13 @@ Groffer o A security problem (reported as CAN-2004-0969) has been fixed. +Gdiffmk +------- + +o A new script contributed by Mike Bianchi. It compares two groff, nroff, + or troff documents and creates an output with added margin characters + (using `.mc') to indicate the differences. + Macro packages -------------- 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: /contrib/gdiffmk/Makefile.sub + +# Last update: 11 December 2004 + +# Copyright (C) 2004 Free Software Foundation, Inc. +# Written by Mike Bianchi > + +# 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 -- 2.11.4.GIT