Cover V02, I04
Article
Figure 1
Listing 1
Listing 2
Listing 3
Listing 4

jul93.tar


Listing 1: fss.sh--Compares two du_files

#!/bin/sh
# fss.sh:
# compares two du-files and reports with:
#
#       '>' filesize increased
#       '<' filesize decreased
#       '=' filesize not changed
#       '+' new file
#       '-' file removed
#

PROG=`basename $0`

usage(){
echo $PROG: $* >&2
echo Usage: $PROG '-[<>=+-]'  -o ofile -n nfile >&2
exit 1
}

# PARSE OPTIONS
# it was not very clever to use <> and - as flags.
# the user must take care of < and >, but we must take
# care of -: getopt doesn't like -, so we convert it to a D

NARG=
for arg in $*           # - can be in any arg.
do
case "$arg" in
-*-*)
NARG="$NARG "`echo ' ' $arg |
sed -e 's/-/D/g' -e 's/D/-/'`
;;
*)     NARG="$NARG $arg"
;;
esac
done                    # NARG is the new commandline

set -- `getopt  '><=+Do:n:' $NARG`

EQ=N LT=N GT=N RM=N NW=N
DONE=0
OLD=
NEW=

for i in $*
do
case $i in
'->') GT=Y ; shift ;;
'-<') LT=Y ; shift ;;
'-=') EQ=Y ; shift ;;
'-D') RM=Y ; shift ;;
'-+') NW=Y ; shift ;;
'-o') OLD=$2; shift 2 ;;
'-n') NEW=$2; shift 2 ;;
'--') DONE=1; shift ;;
*)    if test $DONE -eq 1
then
usage unexpected argument: $i
fi

;;
esac
done

if test ! -f "$OLD" -o ! -f "$NEW"
then
usage -o or -n: not a file or not set
fi

if test $EQ$LT$GT$NW$RM = NNNNN
then
EQ=Y LT=Y GT=Y RM=Y NW=Y
fi

# Parsing done, write both files to awk into 2 assoc arrays
# In awk's END section the comparison is done

( cat  $OLD
echo ======
cat  $NEW
) | awk '

BEGIN { f2=0 }

$0 == "======" { f2=1; next }

{ if (f2 == 0)
f1a[$2] = $1
else
f2a[$2] = $1
}
END {
for( f1f in f1a) {

du1 = f1a[f1f]
du2 = f2a[f1f]

if (du2 == "" && "'$RM'" == "Y")
# removed
printf "-\t%d\t%d\t%d\t%s\n" , du1, 0, 0, f1f
else if (du1 == du2 && "'$EQ'" == "Y")
# equal
printf "=\t%d\t%d\t%d\t%s\n" , du1, du2, 1, f1f
else if (du1 > du2 && "'$LT'" == "Y")
# shrunk
printf "<\t%d\t%d\t%d\t%s\n" , du1, du2, du1/du2,
f1f
else if (du1 < du2 && "'$GT'" == "Y")
# grown
printf ">\t%d\t%d\t%d\t%s\n" , du1, du2, du2/du1,
f1f
}
# new
for( f2f in f2a) {
du1 = f1a[f2f]
du2 = f2a[f2f]
if (du1 == "" && "'$NW'" == "Y")
printf "+\t%d\t%d\t%d\t%s\n" , 0, du2, du2, f2f
}
}'