home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume32
/
gaps
/
part01
/
get
< prev
next >
Wrap
Text File
|
1992-09-20
|
2KB
|
63 lines
#!/bin/sh
# GAPS version 4.0
# get and put system - by Nadav Har'El
# get: extract file from history
VERSION=0
INPUT=
OUTPUT=
FILEFLG=
USAGE="Usage: get [-<number version> or -v<named version>] [-o outfile] file"
while test "$1" != ""
do
case "$1" in
-o) OUTPUT=$2; shift ;;
-[0-9]|-[0-9][0-9]|-[0-9][0-9][0-9]) VERSION=$1 ;; # 1-999 versions
-v*) VERSION=$1;;
-*) echo "get: unknown argument $i" 1>&2; exit 1 ;;
*.H) case "$FILEFLG" in
y) echo "$USAGE" 1>&2
exit 1;;
esac
FILEFLG=y
case "$OUTPUT" in
"") OUTPUT=`expr "$1" : '\(.*\)\.H'`
esac
INPUT=$1;;
*) case "$FILEFLG" in
y) echo "$USAGE" 1>&2
exit 1;;
esac
FILEFLG=y
case "$OUTPUT" in
"") OUTPUT=$1
esac
INPUT=$1.H
esac
shift
done
case $FILEFLG in
"") echo "$USAGE" 1>&2
exit 1;;
esac
test -r $INPUT -a -f $INPUT ||
{ echo "Get: Cannot open $INPUT for input" 1>&2; exit 1; }
test -w $OUTPUT -a ! -d $OUTPUT -o ! -f $OUTPUT -a ! -d $OUTPUT -a \
! -c $OUTPUT -a ! -b $OUTPUT ||
{ echo "Get: Cannot open $OUTPUT for writing" 1>&2; exit 1; }
case $VERSION in
-v*) VERSION=`ver "\`expr \"$VERSION\" : '^-v\(.*\)'\`" $INPUT` || exit 1;;
esac
trap 'rm -f /tmp/get.[ab]$$;exit 1' 1 2 3 15
# split into current version and editing command
sed <$INPUT '/^@@\^/q' >/tmp/get.a$$
sed <$INPUT -n '/^@@\^/,$w /tmp/get.b'$$
# preform the edits
awk </tmp/get.b$$ '
/^@@\^/ { count++ }
!/^@@\^/ && count > 0 && count <= - '$VERSION'
END { print "$d"; print "w", "'$OUTPUT'" }
' | ed - /tmp/get.a$$
rm -f /tmp/get.[ab]$$