Whamcloud - gitweb
Changebar support for lustre.pdf. Check out the old doc directory into doc/doc.old...
[fs/lustre-release.git] / lustre / doc / chbar.sh
1 #! /bin/sh
2 #       Gadget to take two LaTeX files and produce a third which
3 #       has changebars highlighting the difference between them.
4 #
5 # Version 1.1
6 # Author:
7 #       Don Ward, Careful Computing (don@careful.co.uk)
8 # v1.0  April 1989
9 # v1.1  Feb 93  Amended to use changebar.sty (v3.0) and dvips
10 #
11 # Useage:
12 #       chbar file1 file2 [output]
13 #               (default output is stdout)
14 #       chbar old
15 #               (new file on stdin, output on stdout)
16 #
17 # Method:
18 # 1     Use diff to get an ed script to go from file1 to file2.
19 # 2     Breathe on it a bit (with sed) to insert changebar commands.
20 # 3     Apply modified ed script to produce (nearly) the output.
21 # 4     Use awk to insert the changebars option into the \documentstyle
22 #       and to handle changebar commands inside verbatim environments.
23 # 5     Remove changebars before \begin{document} with sed
24 if test $# -eq 0
25 then cat <<\xEOF
26 Useage:
27         chbars old new [output]
28         chbars old
29 xEOF
30 exit 0
31 fi
32 #       Strictly speaking, should check that $TMP doesn't exist already.
33 TMP=/tmp/chb-$$
34 export TMP
35 OLD=$1
36 if test $# -eq 1
37 then   NEW="-";         # arg is old file, take new from stdin
38 else   NEW=$2 ; 
39 fi  
40 #
41 #       sed commands to edit ed commands to edit old file
42 cat <<\xEOF > $TMP
43 /^\.$/i\
44 \\cbend{}%
45 /^[0-9][0-9]*[ac]$/a\
46 \\cbstart{}%
47 /^[0-9][0-9]*,[0-9][0-9]*[ac]$/a\
48 \\cbstart{}%
49 /^[0-9][0-9]*d$/a\
50 i\
51 \\cbdelete{}%\
52 .
53 /^[0-9][0-9]*,[0-9][0-9]*d$/a\
54 i\
55 \\cbdelete{}%\
56 .
57 xEOF
58 diff -b -e $OLD $NEW | ( sed -f $TMP ; echo w ${TMP}1 ; echo q ) | ed - $OLD
59 #       awk commands to insert Changebars style and to protect
60 #       changebar commands in verbatim environments
61 #       and to tell what driver is in use
62 cat <<\xEOF >$TMP
63 /^\\documentstyle/{
64   if (index($0, "changebar") == 0 ) {
65     opts = index($0, "[")
66     if (opts > 0)
67         printf "%schangebar,%s",substr($0,1,opts),substr($0,opts+1)
68     else
69         printf "\\documentstyle[changebar]%s\n", substr($0,15)
70     next
71   }
72 }
73 /\\begin{document}/ {print "%\\driver{dvips}"}
74 /\\begin{verbatim}/{++nesting}
75 /\\end{verbatim}/{--nesting}
76 /\\cbstart{}%|\\cbend{}%|\cbdelete{}%/ {
77   if ( nesting > 0) {
78 #       changebar command in a verbatim environment: Temporarily exit,
79 #       do the changebar command and reenter.
80 #
81 #       The obvious ( printf "\\end{verbatim}%s\\begin{verbatim} , $0 )
82 #       leaves too much vertical space around the changed line(s).
83 #       The following magic seeems to work
84 #
85         print  "\\end{verbatim}\\nointerlineskip"
86         print  "\\vskip -\\ht\\strutbox\\vskip -\\ht\\strutbox"
87         printf "\\vbox to 0pt{\\vskip \\ht\\strutbox%s\\vss}\n", $0
88         print  "\\begin{verbatim}"
89         next
90         }
91 }
92 { print $0 }
93 xEOF
94 awk -f $TMP ${TMP}1 >${TMP}2
95 #    sed commands to clean up unwanted changebars
96 #    (those before \begin{document})
97 # cat <<xEOF >$TMP
98 # 1,/\\begin{document}/s/\\\\cb[sed][tne][adl][^{}]*{}%$/%/
99 # xEOF
100 # if test $# -le 2 || test $3 = '-'
101 # then  sed -f $TMP ${TMP}2
102 # else  sed -f $TMP ${TMP}2 >$3
103 # fi
104 #rm $TMP ${TMP}[0-9]
105 cat ${TMP}2