#! /bin/csh -f ###################################################################### # This script inserts a string (typically, the date) between # a pair of special comment tags in one or more .html files. # # For example, the html code might look like this: # # Last revised Fri Apr 1 1888 # # This script could be used to edit that line to look something like this: # # Last revised Mon Jan 1 2003 # # # In general, given the tag "XXX", this script looks for pairs of html comments # like this: # and # # set me=$0:t goto start Usage: echo "Usage: ${me} TAG string thisfile.html [thatfile.html /foo/whatnot/theotherfile.html ...]" echo " " echo "TAG Identifies the special comment tag pair that mark where the" echo " stamp goes. For example, if you specify 'TAG' as 'REV_DATE'," echo " the script looks for this pair of tags:" echo " <\!--_REV_DATE_START_--> and <\!--_REV_DATE_END_-->" echo " (Note that the script assumes that the actual tags are prefixed by '_'" echo " and suffixed by _START_ or _END_). The script expects this pair of" echo " tags to be inline; don't put newlines between them in your html" echo " code." echo " " echo "string is an arbitary character string. Be sure to double-quote it" echo " as necessary (e.g., if it contains spaces)." echo exit # # 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. # # jtb 050101: allowed .rss files, in addition to .html # jtb 050106: allowed .css files, in addition to .html # jtb 050313: added better error handling; generalized it beyond just date stamps ###################################################################### start: if (${#argv} < 3) then goto Usage endif set theTag=$1 set theTagString="$2" # the string may have spaces in it, so always quote it set theStartTag="<\!--_${theTag}_START_-->" set theEndTag="<\!--_${theTag}_END_-->" set tmpFile=/tmp/${me}.tmp shift; shift; # loop through all the files in the argument list foreach x ($*) set shortName=`basename $x` grep -q $theStartTag $x >& /dev/null # see if the file contains the tag set grepStat = $status if ($grepStat == 0) then # it contains the start tag, so let's continue... if (-e $x && ( $x:e == html || $x:e == rss || $x:e == css) ) then sed -e "s/$theStartTag\(.*\)$theEndTag/$theStartTag$theTagString$theEndTag/" $x > $tmpFile #diff $x $tmpFile > /dev/null # compare the two files #if ($status != 0) then # if the stamping changed the file mv $tmpFile $x # then save the changes chmod a+r $x echo " ${me}: ${x}: $theTag = $theTagString" #else #echo " ${me}: ${shortName}: file not changed." # rm $tmpFile #endif else echo " ${me}: ${x}: Can't stamp this type of file." endif else if ($grepStat == 1) then echo " ${me}: ${x}: skipped (no '$theTag' tag)" else echo " ${me}: ${x}: can't find file." endif end exit