#!/bin/sh

# Shell script to remove clearcase Edit History text from source files.

dir=.	# PLEASE UPDATE THIS LINE
dirlist=`ls $dir`

for file in $dirlist
do
	echo "Examining file $file"
	matches=`sed -n "/Edit History:/p" $dir/$file | wc -l`

	# Update the file only if one Edit History exists.
	if [ "$matches" -eq 1 ]
	then

		firstline=`grep -n "Edit History:" $dir/$file | cut -d: -f1`
		lastline=`grep -n "End ClearCase Header" $dir/$file | cut -d: -f1`
		if [ -n "$firstline" -a -n "$lastline" -a `expr $lastline - $firstline` -gt 2 ]
		then
			# We want to keep the actual Edit History line, so increment
			# firstline by one. We also want to keep the End ClearCase
			# line and the blank line preceeding it, so decrement lastline
			# by two.
			firstline=`expr $firstline + 1`
			lastline=`expr $lastline - 2`

			sed ${firstline},${lastline}d $dir/$file > tempfile$$
			/usr/bin/mv $dir/$file .save/$file
			/usr/bin/mv tempfile$$ $dir/$file
		fi
	fi
done

