#! /bin/csh -f ###################################################################### # This script applies a formatted time stamp to one or more .html files. # (A generalized version of the old 'htmlstamp' -- R.I.P.) # # A time stamp is formed in an html file by inserting today's date # between a pair of special comment tags in the html code. # For example, the html code might look like this: # # Last revised Fri Apr 1 1888 # # This script would edit that line to look something like this: # # Last revised Mon Jan 1 2003 # # Usage: # # % htmlstamp TAG fmt thisfile.html [thatfile.html /foo/whatnot/theotherfile.html ...] # # 'TAG' is the "name" of the special comment tag pair that indicate # where the time stamp goes. # For example, if you specify 'TAG' as "REV_DATE", this script looks for # this pair of tags: # and # (Note that the script assumes that the actual tags are prefixed by "_" # and suffixed by _START_ or _END_). # The script expects this pair of tags to be inline; don't put newlines # between them in your html code. # # 'fmt' is a date format string (see "man date"). Be sure to double-quote the # string as necessary (e.g., if the string contains spaces). # # Any files in the argument list that either don't exist, don't end in # .html, or don't contain the tags are ignored. Otherwise, the file # is edited in place. # ###################################################################### if (${#argv} < 3) then goto Usage endif set theTag=$1 set theStartTag="<\!--_${theTag}_START_-->" set theEndTag="<\!--_${theTag}_END_-->" # the date format string may have spaces in it, so always quote it set theDateString=`date "$2"` shift; shift; # loop through all the files in the argument list foreach x ($*) grep -q $theStartTag $x # see if the file contains the tag if ($status) then # if it doesn't, then skip it echo "\t" Skipping $x \(\"$theTag\" tag not found\)... else echo -n "\t" Stamping $theTag on `basename $x`: if (-e $x && $x:e == html) then # It used to be ".../$theStartTag $theVersion $theEndTag /...", # but that introduced an annoying space in some files, # so I got rid of the spaces. -- jtb 981226 sed -e "s/$theStartTag\(.*\)$theEndTag/$theStartTag$theDateString$theEndTag/" $x > $x.tmp mv $x.tmp $x chmod a+r $x echo " " $theDateString else echo " " Can\'t find file \'$x\' or not an .html file\! endif endif end exit Usage: echo Usage: htmlstamp TAG fmt thisfile.html \[thatfile.html /foo/whatnot/theotherfile.html ...\]