#!/usr/bin/csh

#MAIN program for texdiff. 
#texdiff highlights modified text in a latex file 
#
#Input: two latex files to compare (new and old version)
#Style Options: -d: "delim style" (e.g. embrace modified text between [ ])
#                   This is the default option if no style option is given.
#               -p: "paint style" (e.g. boldface)
#               -m: "margin style" (uses margin notes to mark the modifed text)
#diff option:   -b: sequences of one or more blanks (space, tab) are 
#                   considered identical.
#SEE readme file for details

#define path
#setenv tdpath ~italiano/texdiff
setenv tdpath $HACKS/texdiff

#determine options, set $bopt (diff option) and $script (style option)

setenv bopt ''
switch ( $1 )
case  -p: 
    setenv script paint ;  breaksw
case -m: 
    setenv script margin ; breaksw
case -b:
    setenv bopt -b  #falls through to next case (i.e. will perfrom delim)
default: 
    setenv script delim ; echo default 
endsw

if ( $#argv > 3 ) then

switch ( $2 )
case  -p: 
    setenv script paint ;  breaksw
case -m: 
    setenv script margin ; breaksw
case -b:
    setenv bopt -b ; breaksw   #as a second option -w assumes a previous option
                            #existed to define $script so the break is mandatory
default: #nothing done!! The first flag already defined the script.
endsw

endif
#echo $script'.ed diff' $bopt

#determine new and old files from the input

@ n1 = $#argv - 1
setenv old $argv[$#argv]
setenv new $argv[$n1]
echo New version: $new.tex Old version: $old.tex
echo Style: $script

#run programs: $bopt contains option for diff (-b or nothing)
#$script contains name of ed script which defines the highlighting style.

diff -c99999 $bopt $new.tex $old.tex | sed -f $tdpath/linediff.sed > $new.diff 
ed - $new.diff < $tdpath/blockdiff.ed
ed - $new.diff < $tdpath/$script.ed > $new.diff.tex

echo 'texdiff done' 
exit
