#!/bin/sh
#
# Copyright (c) 1993 InterSoft Co.  All Rights Reserved
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF InterSoft Co.
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#
# $Id: verslog.sh,v 1.4 1996/07/29 20:25:36 hernan Exp $
#
# Usage: verslog [-h|-?|-v version] files
#
# Version for the CVS Concurrent Version System.
#
DELTA=""
KEEP=""
VERSION=""
USAGE="Usage: `basename $0` [-h|-?|-v version] files"
RET=0
SAVEPWD=`pwd`
TMPFILE="/tmp/__verslog.$$"

while getopts h?v: OPT
do
	case $OPT in
	h|\?)
		echo $USAGE 1>&2
		exit 1
		;;
	v)
		if [ $OPTARG = "last" ]
		then
			VERSION=-r
		else
			VERSION=-r$OPTARG
		fi
		;;
	esac
done

shift `expr $OPTIND - 1`

if [ $# -eq 0 ]
then
	echo $USAGE 1>&2
	exit 1
fi

for i
do
	DIR=`dirname $i`
	FILE=`basename $i`
	cd $SAVEPWD
	cd $DIR
	if [ $? -ne 0 ]
	then
		RET=1
		continue
	fi

	if [ \! -r "CVS/Repository" ]
	then
		RET=4
		continue
	fi
	cvs log $VERSION $FILE 2>$TMPFILE | awk '
		$1 == "revision" {
			revision = $2
		}
		$1 == "date:" {
			date = substr($2, 9, 2) "/" substr($2, 6, 2) "/" substr($2, 3, 2)
			time = substr($3, 1, length($3)-1)
			author = substr($5, 1, length($5)-1)
			firstLine = 1
			next
		}
		$1 == "branches:" {
			next
		}
		firstLine == 1 {
			printf("%s\t%s\t%s\t%s\t%s\n", revision, date, time, author, $0)
			firstLine = 0
		}'
	if [ $? -ne 0 ]
	then
		RET=3
		cat 1>&2 $TMPFILE
		rm -f $TMPFILE
		continue
	fi
	rm -f $TMPFILE
done
exit $RET
