#!/bin/sh
#	Place an entire directory under rcs control.
#
#	rcsify <dirname>	Where <dirname> is the pathname of the
#				directory to place under rcs control.
#
#	WARNING: This only checks in the RCS subdirectory to see if the source
#		 file is already under rcs.  If the rcs file is not in that
#		 directory and a file in the working directory has one of the
#		 suffixes below, the header information will be erroneously
#		 duplicated in a source file which has been under rcs before.
#		 Since the header information is a comment, the duplication
#		 should cause no trouble, but it is ugly.
#
# If an rcs file exists in the RCS sub-directory for an individual file,
# nothing is done to that file.  Otherwise *ALL* files, with any of the
# suffixes below, are:
# 1) Modified to contain the rcs header information inside a legal comment
#    for the type of source file.
# 2) Checked in to the RCS directory with the description: "Initial checkin
#    using RCS."
# 3) NOT locked.  The ci -u option is used to check in the files and check
#    them back out again without a lock.
#
# The affected suffixes are listed below.  Any action taken for the particular
# type of file in addition to the list above are specified below:
#
#	Suffix	Type		Actions
#       ------  ------------    ----------------------------------
#     .q, .c	C source	A static character string containing some of
#				the rcs header information is added.
#	  .h	Header files
#	  .y	Yacc files
#	  .f	Fortran files
#	  .s	Assembly files
#   .csh, .sh	Shell scripts	The "header" information is appended to the
#				bottom of the file, instead of the top.  Also,
#				a line containing "exit" is placed before
#				the comment.
#	[mM]akefile		These are input to "make". They all have one of
#				two specific filenames: makefile or Makefile
#	.SCR,.MEN,.FST		These are BLOX date files, comment character
#				is a "!".
#

cd $1
echo "################# rcsifying $1 #################"

# Do C source files.
for i in *.[cq]
do
	if [ $i != '*.[cq]' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat - $i.before_rcs > $i <<EOF
/*
 *	\$Source\$
 *	\$Header\$
 */

#ifndef lint
static char *rcsid_`echo $i | sed 's/\./_/g' | sed 's/-/_/g'` = "\$Header\$";
#endif	lint

EOF

	                if [ ! -d RCS ]
        	        then
				mkdir RCS
			fi

			rm -f $i.before_rcs
			rcs -i -c" * " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi
	fi
done

# Do Assembly, Yacc and Header files.
for i in *.[syh]
do
	if [ $i != '*.[syh]' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat - $i.before_rcs > $i <<EOF
/*
 *	\$Source\$
 *	\$Header\$
 */

EOF

	                if [ ! -d RCS ]
	                then
				mkdir RCS
			fi

			rm -f $i.before_rcs
			rcs -i -c" * " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi
	fi
done

# Do Fortran source files.
for i in *.f
do
	if [ $i != '*.f' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat - $i.before_rcs > $i <<EOF
c
c 	\$Source\$
c	\$Header\$
c

EOF
	                if [ ! -d RCS ]
	                then
				mkdir RCS
			fi

			rm -f $i.before_rcs
			rcs -i -c"c " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi
	fi
done

# DO Makefiles
for i in [Mm]akefile
do
	if [ $i != '[Mm]akefile' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat - $i.before_rcs > $i <<EOF
#
# 	\$Source\$
#	\$Header\$
#

EOF
	                if [ ! -d RCS ]
	                then
				mkdir RCS
			fi

			rm -f $i.before_rcs

			rcs -i -c"# " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi	
	fi
done

# Do Shell scripts. (both types)
for i in *.sh *.csh
do
	if [ $i != '*.sh' -a $i != '*.csh' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat $i.before_rcs - > $i <<EOF
exit
#
# 	\$Source\$
#	\$Header\$
#
EOF
	                if [ ! -d RCS ]
	                then
				mkdir RCS
			fi

			rm -f $i.before_rcs
			rcs -i -c"# " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi
	fi
done

# Do BLOX data files.
for i in *.SCR *.MEN *.FST
do
	if [ $i != '*.SCR' -a $i != '*.MEN' -a $i != '*.FST' ]
	then
		if [ -f $i -a ! -f RCS/$i,v ]
		then
			echo $i
			mv -f $i $i.before_rcs
			cat - $i.before_rcs > $i <<EOF
!
! 	\$Source\$
!	\$Header\$
!
EOF
	                if [ ! -d RCS ]
	                then
				mkdir RCS
			fi

			rm -f $i.before_rcs
			rcs -i -c"! " $i <<EOF
Initial checkin using RCS.
.
EOF
			ci -u $i
		fi
	fi
done
exit
#
# 	$Source: /source/4.3/usr.athena/RCS/rcsify.sh,v $
#	$Header: rcsify.sh,v 1.2 86/01/20 13:10:38 wesommer Exp $
