-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfu
executable file
·93 lines (86 loc) · 1.43 KB
/
fu
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
set -e
if test $# -lt 1; then
echo "usage: $0 [-c comment] file" 1>&2
exit 1
fi
COMMENTS=""
if test $# -gt 1; then
while test $# -gt 1; do
case "$1" in
-c)
COMMENTS="$2"
shift
shift
;;
*)
echo "$0: unknown option $1" 1>&2
exit 1
esac
done
fi
if test \( ! -r "$1" \) -o \( ! -f "$1" \); then
echo "$0: $1 not a readable file" 1>&2
exit 1
fi
if test ! -s "$1"; then
echo "$0: $1 empty" 1>&2
exit 1
fi
if test ! -d H; then
mkdir H || (echo "$0: cannot mkdir H" 1>&2; exit 1)
fi
HF="H/H.$1"
if test ! -s "$HF"; then
echo "a" >>"$HF"
cat "$1" >>"$HF"
cat >>"$HF" <<EOF
.
C 1,{{END}}
`date`
init
EOF
: + 2 because of the 'a' and '.' commands
LEN=`wc -l "$1" | awk '{print $1 + 2}'`
ed - "$HF" <<EOF
/^C 1,{{END}}$/s/{{END}}/$LEN/
w
q
EOF
else
OLDLEN=`sed '/^C /q' "$HF"|wc -l|awk '{print $1}'`
fr -o tmpold "$1"
STATUS=0
{ diff -e tmpold "$1" > tmpnew; STATUS=$?; } || :
if test $STATUS -eq 0; then
echo "$0: no differences" 1>&2
rm -f tmpold tmpnew
exit 1
elif test $STATUS -eq 2; then
rm -f tmpold tmpnew
exit 1
fi
if sed -n '1p' tmpnew|grep '^Binary'; then
echo "$0: $1 is a binary file" 1>&2
rm -f tmpold tmpnew
exit 1
fi
rm tmpold
NEWLEN=`wc -l tmpnew|awk "{print \\$1 + $OLDLEN - 1}"`
if test -z "$COMMENTS"; then
echo "comments? (EOF to end) "
COMMENTS=`cat`
fi
ed - "$HF" <<EOF
${OLDLEN}-1r tmpnew
\$a
C $OLDLEN,$NEWLEN
`date`
$COMMENTS
.
w
q
EOF
rm tmpnew
fi
exit 0