Whamcloud - gitweb
Updated changebar generation to preserve nesting.
authorgord-fig <gord-fig>
Wed, 14 Aug 2002 00:29:45 +0000 (00:29 +0000)
committergord-fig <gord-fig>
Wed, 14 Aug 2002 00:29:45 +0000 (00:29 +0000)
lustre/doc/Makefile.am
lustre/doc/chbar.sh
lustre/doc/postbar [new file with mode: 0755]

index 4c4e97d..06080e8 100644 (file)
@@ -7,7 +7,11 @@ LYX2PS = lyx --export ps
 LYX2TEX = lyx --export latex
 LYX2TXT = lyx --export text
 LYX2HTML = lyx --export html
-SUFFIXES = .lin .lyx .pdf .ps .sgml .html .txt .tex .fig .eps
+LATEX = latex
+DVIPS = dvips
+PS2PDF = ps2pdf
+TEXEXPAND = texexpand
+SUFFIXES = .lin .lyx .pdf .ps .sgml .html .txt .tex .fig .eps .dvi
 
 DOCS = lustre.pdf lustre-HOWTO.txt
 IMAGES =  sys_open.eps sys_write.eps sys_mount.eps cache1.eps cache2.eps intermezzocache.eps intermezzofilesys.eps meta.eps metadata1.eps networklayer.eps bigpicture.eps intermezzo.eps mds.eps portals.eps client.eps layering.eps metadata.eps sb.eps cow.eps lockacq.eps obdfs.eps snapsetup.eps dirbodyapi.eps loraid.eps ost.eps updates.eps hotmigrate.eps lustreclusters.eps osthw.eps portals-lib.eps lockqueues.eps lockexample1.eps lockexample2.eps lockexample3.eps lockexample4.eps lockseverity.eps
@@ -16,10 +20,12 @@ LYXFILES= lustre.lin evolution.lyx  llocks.lyx mgmt.lyx uncertain.lyx\
        glossary.lyx   lustre-debugging.lyx  network.lyx\
        intro.lyx      obdspec.lyx recovery.lyx
 
-MAINTAINERCLEANFILES =  $(IMAGES) $(DOCS) $(GENERATED)
-GENERATED = lustre-HOWTO.lyx lustre.lyx
+MAINTAINERCLEANFILES =  $(IMAGES) $(DOCS) $(VERSIONED)
+CLEANFILES = *.aux *.tex doc.old/*.aux doc.old/*.tex
+VERSIONED = lustre-HOWTO.lyx lustre.lyx doc.old/lustre-HOWTO.lyx doc.old/lustre.lyx
+GENERATED = $(VERSIONED) lustre-full.tex lustre-chbar.tex
 
-EXTRA_DIST = lyxchbar.sh chbar.sh $(DOCS) $(IMAGES) $(LYXFILES) lustre.bib
+EXTRA_DIST = chbar.sh postbar $(DOCS) $(IMAGES) $(LYXFILES) lustre.bib
 
 all: $(DOCS)
 
@@ -30,25 +36,34 @@ addversion = sed -e 's|@T''AG@|$(tag)|g; s|@VER''SION@|$(VERSION)|g; s|@DA''TE@|
 
 # Regenerate when the $(VERSION) or $Name:  $ changes.
 .INTERMEDIATE: $(GENERATED)
-$(GENERATED) : %.lyx: %.lin Makefile
+$(VERSIONED) : %.lyx: %.lin Makefile
        $(addversion) $< > $@
 
 .lyx.pdf:
-       @$(LYX2PDF) $< || printf "\n*** Warning: not creating PDF docs; install lyx to rectify this\n"
+       @echo $(LYX2PDF) $< && $(LYX2PDF) $< || printf "\n*** Warning: not creating PDF docs; install lyx to rectify this\n"
 
 .lyx.ps:
-       @$(LYX2PS) $< || printf "\n*** Warning: not creating PostScript docs; install lyx to rectify this\n"
+       @echo $(LYX2PS) $< && $(LYX2PS) $< || printf "\n*** Warning: not creating PostScript docs; install lyx to rectify this\n"
 
 .lyx.tex:
-       @$(LYX2TEX) $< || printf "\n*** Warning: not creating LaTeX docs; install lyx to rectify this\n"
+       @echo $(LYX2TEX) $< && $(LYX2TEX) $< || printf "\n*** Warning: not creating LaTeX docs; install lyx to rectify this\n"
 
 .lyx.txt:
-       @$(LYX2TXT) $< || printf "\n*** Warning: not creating text docs; install lyx to rectify this\n"
+       @echo $(LYX2TXT) $< && $(LYX2TXT) $< || printf "\n*** Warning: not creating text docs; install lyx to rectify this\n"
 
 .lyx.html:
-       @$(LYX2HTML) $< || printf "\n*** Warning: not creating HTML docs; install lyx to rectify this\n"
+       @echo $(LYX2HTML) $< && $(LYX2HTML) $< || printf "\n*** Warning: not creating HTML docs; install lyx to rectify this\n"
 
-lustre.pdf lustre.txt lustre.html: $(IMAGES) lustre-HOWTO.lyx
+.tex.dvi:
+       $(LATEX) $<
+
+.dvi.ps:
+       $(DVIPS) $< -o $@
+
+.ps.pdf:
+       $(PS2PDF) $< $@
+
+lustre.tex lustre.pdf lustre.txt lustre.html: $(IMAGES) lustre-HOWTO.lyx
 .fig.eps:
        -fig2dev -L eps $< > $@
 
@@ -59,17 +74,26 @@ syncweb: lustre.pdf
 
 # Build a changebar document from the files in doc.old and this directory.
 chbar: lustre-chbar.pdf
-lustre-chbar.pdf: lyxchbar.sh chbar.sh lustre.bib
-lustre-chbar.pdf: $(addprefix doc.old/,$(LYXFILES)) $(LYXFILES)
-       rm -rf doc.chbar
-       mkdir doc.chbar
-       for f in $(LYXFILES); do \
-         $(SHELL) $(srcdir)/lyxchbar.sh doc.old/$$f $$f > doc.chbar/$$f; \
-       done
-       (cd doc.chbar && ln -s ../lustre.bib lustre.bib)
-       (cd doc.chbar && make -f ../Makefile top_srcdir=../.. top_builddir=../.. srcdir=.. VPATH=.. lustre.pdf)
-       cp -p doc.chbar/lustre.pdf lustre-chbar.pdf
-       #rm -rf doc.chbar
+
+lustre-chbar.tex: chbar.sh postbar doc.old/lustre-full.tex lustre-full.tex
+       $(SHELL) $(srcdir)/chbar.sh doc.old/lustre-full.tex lustre-full.tex | $(srcdir)/postbar > $@
+
+lustre-full.tex: lustre.tex
+       $(TEXEXPAND) -texinputs=. -texinputs=$(srcdir) -output=$@ $<
+
+doc.old/lustre.tex: doc.old/lustre-HOWTO.lyx
+doc.old/lustre-full.tex: doc.old/lustre.tex
+       cd doc.old && $(TEXEXPAND) -texinputs=. -output=lustre-full.tex lustre.tex
+
+# Check out the old directory if it doesn't exist.
+doc.old/lustre.lin doc.old/lustre-HOWTO.lin:
+       @if test "X$(OLD)" = X; then \
+         echo "You must populate doc.old or specify a CVS tag like OLD=v0_5_1"; \
+         exit 1; \
+       fi
+       rm -rf doc.old
+       mkdir doc.old
+       cvs checkout -r $(OLD) -d doc.old lustre/doc
 
 dist-hook:
        rm -rf $(distdir)/figs/CVS
index 8a16d0d..7825241 100755 (executable)
-#! /bin/sh
+#!/bin/sh
 #      Gadget to take two LaTeX files and produce a third which
 #      has changebars highlighting the difference between them.
 #
-# Version 1.1
+# Version 1.2
 # Author:
 #      Don Ward, Careful Computing (don@careful.co.uk)
 # v1.0 April 1989
 # v1.1  Feb 93 Amended to use changebar.sty (v3.0) and dvips
-#
-# Useage:
-#      chbar file1 file2 [output]
-#              (default output is stdout)
-#      chbar old
-#              (new file on stdin, output on stdout)
-#
-# Method:
-# 1    Use diff to get an ed script to go from file1 to file2.
-# 2    Breathe on it a bit (with sed) to insert changebar commands.
-# 3    Apply modified ed script to produce (nearly) the output.
-# 4    Use awk to insert the changebars option into the \documentstyle
-#      and to handle changebar commands inside verbatim environments.
-# 5     Remove changebars before \begin{document} with sed
-if test $# -eq 0
-then cat <<\xEOF
-Useage:
-       chbars old new [output]
-       chbars old
-xEOF
-exit 0
+# v1.2  Aug 95  Added support for LaTeX209/LaTeX2e
+#              Added RCS support to retrive old files
+
+CMD=`basename $0`
+
+SED=sed
+RM="rm -f"
+DIFF=diff
+ED=ed
+AWK=awk
+GREP=grep
+MV=mv
+CAT=cat
+MKDIR=mkdir
+CO="co"
+
+TMPDIR=${TMP-/tmp}/$CMD.$$
+trap 'test $DEBUG = NO && rm -rf $TMPDIR' 0 1 2 3 6 7 13 15
+mkdir $TMPDIR || { echo "cannot create directory \`$TMPDIR'." >&2; exit 1; }
+TMPFILE=${TMPDIR}/$CMD.$$
+SED_CMD_FILE=$TMPFILE.sed
+
+usage()
+{
+$CAT << _END_
+Usage:
+  $CMD [-hgG] [-d dir] old new [output]
+       default output is stdout
+
+  $CMD [-hgG] [-d dir] old
+       new file on stdin, output on stdout
+
+  $CMD [-hgG] -d dir -r rev files
+       old file retrieved using RCS
+
+  Gadget to take two LaTeX files and produce a third which
+  has changebars highlighting the difference between them.
+  Changebars are inserted for differences after '\begin{document}'.
+
+  Feature: \`new' can not be named \`-'.
+
+  Options are:
+  -d dir : Write the output to file  \`dir/new', if \`new' is given or
+          to file \`dir/old'.
+          If \`dir' does not exist, it is created.
+          If \`output' is given, it is discarded.
+
+  -r rev : If the LaTeX \`files' are kept under control of the
+          Revision Control System RCS, the old files of
+          the revision \`rev' can be retrived.
+          \`rev' is specified using the RCS conventions.
+          This option must be used together with the \`-d dir' option.
+          \`files' must be a nonempty list of files.
+
+  -h    : Print this info text.
+  -g    : Print some debugging info.
+  -G    : Even more debug info.
+
+  Version 1.2: August 3. 1995
+_END_
+exit 1
+}
+
+# parse options and arguments
+DEBUG="NO"
+DIR=
+REV=
+# process options
+while getopts d:r:gGh i $*
+do
+  case $i in
+       d ) DIR=$OPTARG;;
+       r ) REV=$OPTARG;;
+       g ) DEBUG="YES" ;;
+       G ) set -x; DEBUG="YES";;
+       h | \
+        * ) usage ;;
+  esac
+done
+
+shift `expr $OPTIND - 1`
+
+case $# in
+  1 ) OLD=$1; NEW="-"; OUT=""   ;;
+  2 ) OLD=$1; NEW=$2;  OUT=""   ;;
+  3 ) OLD=$1; NEW=$2;  OUT="$3" ;;
+  * ) usage ;;
+esac
+
+# check correct options
+if [ ! -z "$DIR" ]
+then
+  [ -d $DIR ] || $MKDIR $DIR
 fi
-#      Strictly speaking, should check that $TMP doesn't exist already.
-TMP=/tmp/chb-$$
-export TMP
-OLD=$1
-if test $# -eq 1
-then   NEW="-";        # arg is old file, take new from stdin
-else   NEW=$2 ; 
-fi  
-#
-#      sed commands to edit ed commands to edit old file
-cat <<\xEOF > $TMP
+
+if [ ! -z "$REV" ]
+then
+  [ -z "$DIR" ] && usage
+  FILES=$*
+else
+  FILES=$NEW
+fi
+
+# do the work
+for NEW in $FILES
+do
+  if [ ! -z "$DIR" ]
+  then
+    if [ $NEW = "-" ]
+    then
+      OUT=$DIR/$OLD
+    else
+      OUT=$DIR/$NEW
+    fi
+  fi
+  if [ ! -z "$REV" ]
+  then
+    OLD=${TMPFILE}.old
+    $CO -p"$REV" -q $NEW > $OLD
+  fi
+
+  [ $DEBUG = "YES" ] && echo "OLD=\`$OLD' NEW=\`$NEW' OUT=\`$OUT'"
+
+  # gather some info about the file
+  # Since we have for sure only the name of the OLD file, ...
+  $GREP "^\\\\begin{document}" $OLD > /dev/null
+  if [ $? -eq 0 ]
+  then
+    [ $DEBUG = "YES" ] && echo "contains a \\begin{document}"
+    HAS_BEGIN_DOC="YES"
+  else
+    [ $DEBUG = "YES" ] && echo "contains no \\begin{document}"
+    HAS_BEGIN_DOC="NO"
+  fi
+
+  # Method to do the work:
+  # 1  Use diff to get an ed script to go from file1 to file2.
+  # 2  Breath on it a bit (with sed) to insert changebar commands.
+  # 3  Apply modified ed script to produce (nearly) the output.
+  # 4  Use awk to insert the changebars option into the \documentstyle
+  #    and to handle changebar commands inside verbatim environments.
+  # 5     Remove changebars before \begin{document} with sed
+
+  #    SED commands to edit ED commands to edit old file
+  $CAT > $SED_CMD_FILE <<\_END_
 /^\.$/i\
 \\cbend{}%
 /^[0-9][0-9]*[ac]$/a\
@@ -54,52 +166,78 @@ i\
 i\
 \\cbdelete{}%\
 .
-xEOF
-diff -b -e $OLD $NEW | ( sed -f $TMP ; echo w ${TMP}1 ; echo q ) | ed - $OLD
-#      awk commands to insert Changebars style and to protect
-#      changebar commands in verbatim environments
-#       and to tell what driver is in use
-cat <<\xEOF >$TMP
-/^\\documentstyle/{
-  if (index($0, "changebar") == 0 ) {
-    opts = index($0, "[")
-    if (opts > 0)
-       printf "%schangebar,%s",substr($0,1,opts),substr($0,opts+1)
-    else
+_END_
+
+  # note DIFF accepts `-' as stdin
+  $DIFF -b -e $OLD $NEW | \
+       ( $SED -f $SED_CMD_FILE ; echo w ${TMPFILE}.1 ; echo q ) | \
+       $ED - $OLD
+
+  #    AWK commands to insert Changebars style and to protect
+  #    changebar commands in verbatim environments
+  #       and to tell what driver is in use; we assume the `dvips' driver
+
+  $AWK '
+  BEGIN {kind=""; # we saw now \documentXXX[]{}
+  }
+  /^\\documentstyle/{
+    kind = "209";
+    if (index($0, "changebar") == 0 ) {
+      opts = index($0, "[")
+      if (opts > 0)
+       printf "%schangebar,%s\n",substr($0,1,opts),substr($0,opts+1)
+      else
        printf "\\documentstyle[changebar]%s\n", substr($0,15)
+      next
+    }
+  }
+  /^\\documentclass/{
+    kind = "2e";
+    printf "%s\n", $0
+    printf "\\usepackage[dvips]{changebar}\n"
     next
   }
-}
-/\\begin{document}/ {print "%\\driver{dvips}"}
-/\\begin{verbatim}/{++nesting}
-/\\end{verbatim}/{--nesting}
-/\\cbstart{}%|\\cbend{}%|\cbdelete{}%/ {
-  if ( nesting > 0) {
-#      changebar command in a verbatim environment: Temporarily exit,
-#      do the changebar command and reenter.
-#
-#      The obvious ( printf "\\end{verbatim}%s\\begin{verbatim} , $0 )
-#      leaves too much vertical space around the changed line(s).
-#      The following magic seeems to work
-#
+  /\\begin{document}/ {if (kind == "209" ) {print "\\driver{dvips}"}}
+  /\\begin{verbatim}/{++nesting}
+  /\\end{verbatim}/{--nesting}
+  /\\cbstart{}%|\\cbend{}%|\cbdelete{}%/ {
+    if ( nesting > 0) {
+  #    changebar command in a verbatim environment: Temporarily exit,
+  #    do the changebar command and reenter.
+  #
+  #    The obvious ( printf "\\end{verbatim}%s\\begin{verbatim} , $0 )
+  #    leaves too much vertical space around the changed line(s).
+  #    The following magic seeems to work
+  #
        print  "\\end{verbatim}\\nointerlineskip"
        print  "\\vskip -\\ht\\strutbox\\vskip -\\ht\\strutbox"
        printf "\\vbox to 0pt{\\vskip \\ht\\strutbox%s\\vss}\n", $0
        print  "\\begin{verbatim}"
        next
        }
-}
-{ print $0 }
-xEOF
-awk -f $TMP ${TMP}1 >${TMP}2
-#    sed commands to clean up unwanted changebars
-#    (those before \begin{document})
-# cat <<xEOF >$TMP
-# 1,/\\begin{document}/s/\\\\cb[sed][tne][adl][^{}]*{}%$/%/
-# xEOF
-# if test $# -le 2 || test $3 = '-'
-# then  sed -f $TMP ${TMP}2
-# else  sed -f $TMP ${TMP}2 >$3
-# fi
-#rm $TMP ${TMP}[0-9]
-cat ${TMP}2
+  }
+  { print $0 }
+  '  ${TMPFILE}.1 > ${TMPFILE}.2
+
+  # if a \begin{document} is contained in the file,
+  # remove the changebar commands before them
+
+  if [ $HAS_BEGIN_DOC = "YES" ]
+  then
+    SED_CMD="1,/\\\\begin{document}/s/\(\\\\cb[sed][tne][adl][^{}]*{}%\)$/%%\1/"
+    $SED "$SED_CMD" ${TMPFILE}.2 > ${TMPFILE}.3
+  else
+    $CAT ${TMPFILE}.2 > ${TMPFILE}.3
+  fi
+  if [ -z "$OUT" ]
+  then
+    $CAT ${TMPFILE}.3
+ else
+    $MV ${TMPFILE}.3 $OUT
+  fi
+
+done
+
+[ $DEBUG =  "NO" ] && $RM ${TMPFILE}.*
+
+###############################################################
diff --git a/lustre/doc/postbar b/lustre/doc/postbar
new file mode 100755 (executable)
index 0000000..349d41c
--- /dev/null
@@ -0,0 +1,151 @@
+#! /usr/bin/perl
+# postbar - Massage chbar.sh output into valid LaTeX
+# Copyright (C) 2002  Cluster File Systems, Inc.
+# Gord Eagle <gord@clusterfs.com>, 2002-08-10
+
+my $progname = $0;
+$progname =~ s|^.*/||;
+my $CHANGE_ENVIRONMENT = '\\\\(begin|end)\\{([^\\}]+)\\}';
+my (@envname, @envdepth, @envbuf);
+my $phony_preamble = 0;
+my $cbdepth = 0;
+my $cbfound = 0;
+
+# Tell whether an environment cannot have arbitrary changebars.
+sub fragile_environment
+{
+    my ($env) = @_;
+    return $env ne 'document';
+}
+
+
+# Tell whether we can hava arbitrary stuff.
+sub toplevel
+{
+    my ($env) = @_;
+    return $env eq 'document';
+}
+
+
+sub out
+{
+    my (@msg) = @_;
+    if ($#envbuf < 0 || toplevel($envname[0])) {
+       print @msg;
+    } else {
+       $envbuf[0] .= join('', @msg);
+    }
+}
+
+
+# Leave an environment.
+sub end_environment
+{
+    my ($env) = @_;
+
+    #out("%$progname end $env\n");
+    if ($envname[0] ne $env) {
+       die "Expecting \\end{$envname[0]} but got \\end{$env}\n";
+    }
+
+    if ($cbfound) {
+       # Did we find a changebar?
+       $cbfound = !toplevel($envname[1]);
+       if (!$cbfound) {
+           # We found one, and the parent environment is the top level.
+           if ($cbdepth == $envdepth[0]) {
+               # There was no change in depth, so mark the environment.
+               $envbuf[0] = "\\cbstart{}%$progname\n" . $envbuf[0];
+               out("\\cbend{}%$progname\n");
+           } elsif ($envdepth[0] > $cbdepth) {
+               # There were more ends in the environment, so append them.
+               for (my $i = 0; $i < $envdepth[0] - $cbdepth; $i ++) {
+                   out("\\cbend{}%$progname\n");
+               }
+           } else {
+               # There were more starts, so prepend them.
+               my $starts;
+               for (my $i = 0; $i < $cbdepth - $envdepth[0]; $i ++) {
+                   $starts .= "\\cbstart{}%$progname\n";
+               }
+               $envbuf[0] = $starts . $envbuf[0];
+           }
+       }
+    }
+
+    # Drop the environment from the list.
+    shift(@envname);
+    shift(@envdepth);
+    out(shift(@envbuf));
+}
+
+
+while ($_ = <STDIN>) {
+    chomp;
+    my $env;
+    if (!/\\begin.*\\end/ && /$CHANGE_ENVIRONMENT/o) {
+       $env = $2;
+       if ($1 eq 'begin') {
+           # Enter the new environment.
+           unshift(@envname, $env);
+           unshift(@envdepth, $cbdepth);
+           unshift(@envbuf, '');
+           #out("%$progname depth=$cbdepth, $#envname ($env)\n");
+       } elsif (!$phony_preamble) {
+           out("$_\n");
+           end_environment($env);
+           next;
+       }
+    }  
+
+    if ($#envname >= 0 && /^\\documentclass/) {
+       $phony_preamble = 1;
+    }
+
+    if ($phony_preamble) {
+       # Comment out and ignore the redundant preambles.
+       out("%$progname $_\n");
+       $phony_preamble = 0 if ($env eq 'document');
+       next;
+    } elsif ($#envname >= 0) {
+       # Track the current changebar depth.
+       if (/^\\cbstart/) {
+           $cbdepth ++;
+           if (!toplevel($envname[0])) {
+               $cbfound = 1;
+               out("%$progname $_\n");
+               next;
+           }
+       } elsif (/^\\cbend/) {
+           if ($cbdepth == 0) {
+               die "$progname: Too many \\cbend{}s\n";
+           }
+           $cbdepth --;
+           if (!toplevel($envname[0])) {
+               $cbfound = 1;
+               out("%$progname $_\n");
+               next;
+           }
+       } elsif (/^\\cbdelete/ && fragile_environment($envname[0])) {
+           # What to do with delete bars?
+           out("%$progname $_\n");
+           next;
+       }
+       out("$_\n");
+    } else {
+       out("$_\n");
+       # Add the options to the usepackage.
+       if (/^\\usepackage.*\{changebar\}$/) {
+           # Prevent PostScript dictionary overflow errors.
+           out("\\def\\cb\@maxpoint{15}\n");
+
+           # Show the bars.
+           out("\\outerbarstrue\n");
+       }
+    }
+
+    if (defined($env)) {
+    }
+}
+
+exit(0);