#! /bin/csh -f
######################################################################
# This csh script applies a "time stamp" to one or more .html files.
#
# A "time stamp" is formed in an html file by inserting today's date
# between the revision date tags in the html code. Typically, the html
# code might look like this:
#
#	This page was last revised <!--_REV_DATE_START_--><!--_REV_DATE_END_-->.
#
# This script would edit that line to look something like this:
#
#	This page was last revised <!--_REV_DATE_START_-->Mon Jan 1 1999 <!--_REV_DATE_END_-->
#
# Usage:
#	
#	% htmlstamp [-t START_TAG END_TAG] thisfile.html [thatfile.html /foo/whatnot/theotherfile.html ...]
#
# START_TAG and END_TAG are the strings *in the HTML comments* that indicate
# where the time stamp goes. 
# The default tags are "_REV_DATE_START_" and "_REV_DATE_END_" (as in the 
# example above).
# Any files in the argument list that don't exist or don't end in
# .html are ignored.
#
######################################################################

# set the format for the date stamp (see 'man date' for details about
# the date format options).
set theDate=`date '+%a %e %B %Y'`

# These are the revision date tags to look for in the html code
# (Be sure to escape the '!')
set defaultStartTag="<\!--_REV_DATE_START_-->"
set defaultEndTag="<\!--_REV_DATE_END_-->"

set theStartTag=$defaultStartTag
set theEndTag=$defaultEndTag

#this is a kludgey arg-parser -- it only allows "-t " in the 1st arg position
#jtb 001223
if (${#argv} >= 1) then
	if ("$1" == "-t") then 
		if (${#argv} < 4) then
			goto Usage
		else
			set theStartTag="<\!--$2-->"
			set theEndTag="<\!--$3-->"
			# Now dump the first 3 args; they're not files
			shift; shift; shift 
		endif
	endif
else
	goto Usage
endif

# Double-check that there isn't a stray -t flag anywhere else
foreach x ($*)
	if ("$x" == "-t") then
		goto Usage
	endif
end


# loop through all the files in the argument list
foreach x ($*)
	echo -n "\t" Time-stamping `basename $x`:
	if (-e $x && $x:e == html) then
		# It used to be  ".../$theStartTag $theDate $theEndTag /...",
                # but that introduced an annoying space in some files, 
		# so I got rid of the spaces. -- jtb 12/26/98
		sed -e "s/$theStartTag\(.*\)$theEndTag/$theStartTag$theDate$theEndTag/" $x > $x.tmp
		mv $x.tmp $x
		chmod a+r $x
		echo  " " $theDate
	else
		echo ${0}: Can\'t find file \'$x\' or not an .html file\!
	endif
end

exit

Usage:
	echo Usage: htmlstamp \[-t START_TAG END_TAG\] thisfile.html \[thatfile.html /foo/whatnot/theotherfile.html ...\]


