#!/bin/ksh

# This script takes a checkpoint, or "freeze", of the SCCS versions
# of the filenames you give on the command line, and dump it
# to stdout.
#
# It will ignore files that are not under SCCS control, even if you
# explicitly name them.

if [[ "$1" = "" ]] ; then
	print "Frz v2.0: http://www.bolthole.com/solaris/"
	print 'Usage: frz  {[-R] directoryname|file list}'
	print ""
	print "Will dump SCCS 'freeze' info to stdout"
	print "If the -R flag is used with a directory, will recursively decend"
	print "each directory"
	exit
fi

printheader(){
	print '#This file made by the "frz" script'
	print "# directory $PWD: `date`"
}

frzdir() {
	DIR="$1"
	printheader

	(
	cd $DIR
	if [[ "$DIR" = "." ]] ; then
		DIR=""
	else
		DIR=${DIR}/
	fi
	for f in SCCS/s.* ; do
		if [[ "$f" = 'SCCS/s.*' ]] ; then
			print "# Warning: no files SCCS-controlled in $DIR"
			exit
		fi

		shortname=${f#SCCS/s.}
		print "${DIR}${shortname}: \c" ; prt $f |
			nawk '$1 == "D" { print $2; exit}'
	done
	)
	exit
}

if [[ "$1" = "-R" ]] ; then
	shift
	dir="$1"
	if [[ "$dir" = "" ]] ; then
		dir="."
		
	fi
	if [[ ! -d "$dir" ]] ; then
		print ERROR: need to specify a dir with -R option
		exit 1
	fi
	find $dir -name SCCS -prune -o -type d -print | xargs -n 1 $0
	exit
fi

if [[ -d "$1" ]] ; then
	frzdir $1
	exit
fi


######################################################################
# Else, we assume this is about stuff in the CURRENT DIRECTORY

for f in $* ; do
  if [[ -f SCCS/s.$f ]] ; then
	print "$f: \c" ; prt SCCS/s.$f |
	nawk ' $1 == "D" { print $2; exit}'
  fi
done
