#!/bin/sh
#	This file is part of the Concurrent Versions System CVS.
#	Written by Erik Baalbergen, Vrije Universiteit, Amsterdam.
#	$Header: RC,v 3.3 89/10/13 12:04:30 dick Exp $

#
#		R e a d   C o n f i g u r a t i o n   h i s t o r y
#
#	Reads the configuration history file, either of the working
#	directory or of a repository.
#		RC -i
#	will display the present configuration identifier.
#
Name=RC; export Name

# CVSBIN, CVSLIB and RCSBIN directories
CVSBIN=/home/top/dick/cvs
CVSLIB=/home/top/dick/cvs
RCSBIN=${RCSBIN-/usr/local/bin}
export CVSBIN CVSLIB RCSBIN

# avoid spurious identifications
PATH=${CVSPATH-/bin:/usr/bin}; export PATH

# get the one possible option
case "$1" in
-i)
	Option=$1
	shift
	;;
-*)
	echo Call is: $Name \[ -i \] \[ repository-name \] >&2
	exit 1
	;;
esac

# determine the name of the repository
Repository=$1
. $CVSLIB/NR.aux

# set up names in Admin
Admin=$Repository/Admin
Cfr=CVS.confrec
RcsCfr=$Admin/$Cfr,v

if	[ -f $RcsCfr ]
then
	case "$Option" in
	'')	# display the whole configuration history
		# get the RCS log
		if	$RCSBIN/rlog $RcsCfr
		then	:
		else
			echo $Name: rlog failed on existing $RcsCfr >&2
			exit 1
		fi |
		# remove all kinds of garbage
		tr '\200-\377' '' |
		# identify revision and date lines
		sed '
			/^-*$/{
				N
				s/\nrevision /\
<REV> /
				N
				s/\ndate: /\
<DATE> /
			}
		' |
		# edit date lines and remove crud
		sed '
			1,/^-*$/d
			/^<DATE>/s/;  author: / /
			/^<DATE>/s/;  .*//
			/^-*$/d
			/^=*$/d
		' |
		# format output
		awk '{
			if ($1 == "<REV>") {
				rev = $2;
			}
			else
			if ($1 == "<DATE>") {
				date = $2; time = $3; author = "(" $4 ")";
			}
			else {
				printf("%s\t%s %s %s\t%s\n", \
					rev, date, time, author, $0);
				rev = ""; date = "        "; time = "        ";
				author = "\t";
			}
		}'
		;;

	-i)	# display present configuration identifier
		if	$RCSBIN/rlog $RcsCfr
		then	:
		else
			echo $Name: rlog failed on existing $RcsCfr >&2
			exit 1
		fi |
		grep '^revision ' |
		sed '
			s/revision //
			s/ *$//
			2,$d
		'
		;;
	esac
else
	echo $Name: no configuration history available for $Repository >&2
	exit 1
fi

exit 0
