-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathhtmlwdiff
More file actions
executable file
·92 lines (85 loc) · 2.59 KB
/
htmlwdiff
File metadata and controls
executable file
·92 lines (85 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# htmlwdiff
# Requires: wdiff from ftp://ftp.gnu.org/gnu/wdiff/
# mktemp (in the FreeBSD base system so I don't know where to
# get it if you don't have it)
#
# Henrik's functions
# ----------------------------------------------------------------------
# Utility to find an executable
# ----------------------------------------------------------------------
lookfor() {
default="$1"; shift
for b in "$@"; do
found=`type -p "$b" 2>/dev/null`
if [ -n "$found" ]; then
if [ -x "$found" ]; then
echo "$found"
return
fi
fi
done
echo "$default"
}
AWK=`lookfor gawk gawk nawk awk`
#-----------------------------------------------------------------------
#mktemp
#-----------------------------------------------------------------------
mktemp() {
TMPFILE=$1.$$
echo $TMPFILE
}
# ----------------------------------------------------------------------
# Strip headers and footers, end-of-line whitespace and \r (CR)
# ----------------------------------------------------------------------
strip() {
$AWK '
{ gsub(/\r/, ""); }
{ gsub(/[ \t]+$/, ""); }
/\[?[Pp]age [0-9ivx]+\]?[ \t]*$/{
next;
}
/^[ \t]*\f/ { newpage=1; next; }
/^ *Internet.Draft.+[0-9]+ *$/ { newpage=1; next; }
/^ *INTERNET.DRAFT.+[0-9]+ *$/ { newpage=1; next; }
/^RFC.+[0-9]+$/ { newpage=1; next; }
/^draft-[-a-z0-9_.]+.*[0-9][0-9][0-9][0-9]$/ { newpage=1; next; }
/^[^ \t]/ { sentence=1; }
/[^ \t]/ {
if (newpage) {
if (sentence) {
outline++; print "";
}
} else {
if (haveblank) {
outline++; print "";
}
}
haveblank=0;
sentence=0;
newpage=0;
}
/[.:][ \t]*$/ { sentence=1; }
/^[ \t]*$/ { haveblank=1; next; }
{ outline++; print; }
' $1
}
# ----------------------------------------------------------------------
# Bill's code starts here
# ----------------------------------------------------------------------
a1=`mktemp htmlwdiff1`
a2=`mktemp htmlwdiff2`
strip $1 | sed -e 's/&/&/g' -e 's/</\</g' -e 's/>/\>/g' > $a1
strip $2 | sed -e 's/&/&/g' -e 's/</\</g' -e 's/>/\>/g' > $a2
# This was originally meant to create a portion of a page that
# should be wrapped; however, it seems more common to just use it
# to create a page, so create html wrapper. With luck, you can remove
# the wrapper with "grep -v 'html>'".
echo "<html><head><title>wdiff $1 $2</title></head><body>"
echo "<pre>"
wdiff -w "<strike><font color='red'>" -x "</font></strike>" -y "<strong><font color='green'>" -z "</font></strong>" $a1 $a2
echo "</pre>"
echo "</body></html>"
rm -f $a1
rm -f $a2