#!/bin/ksh

# This script exists to "unfreeze" sccs revisions of files recorded
# by the "frz" utility.
# The idea is that you take a snapshot of all your controlled files with
# "frz", and then at a later point, you can go back to those revisions
# with "unfrz"

if [[ "$1" = "" ]] ; then
	print "unfrz v2.0.1"
	print " http://www.bolthole.com/solaris/"
	print "Usage: "
	print "  unfrz file.frz"
	print ""
	print Need the name of a frz generated file
	print ASSUMES frz file was generated IN CURRENT DIRECTORY
	print We will then get those SCCS revisions mentioned in the file
	print 'and get them (readonly) to your current directory'
	exit
fi


# $1==filename
# $2==revision of file
unfrz(){
	sccs get -s -r$2 $1
}

parsefrzline(){
	topdir=$PWD

	lastdir=""
	read line
	while [[ $? -eq 0 ]] ; do
		set $line
		filename=${1%:}
		dir=${filename%/*}
		file=${filename##*/}
		if [[ "$dir" = "$file" ]] ; then
			# no directory, just file present
			dir=.
		fi

		revision="$2"
	
		#print DEBUG: dir is $dir, file is $file
		if [[ "$dir" != "$lastdir" ]] ; then
			case $dir in
				/*)
					cd $dir
				;;
				*)
					cd $topdir/$dir
				;;
			esac
			print working on directory $dir
			lastdir="$dir"
		fi
		#print Getting $filename r$revision
		unfrz $file $revision

		read line
	done
}

egrep -v '^#' $1 | parsefrzline
