#!/bin/csh -f
#
# Add TITLE= info to HTML pages that have just ALT=.
#
# Brent Chivers 2005/Nov/13
#
# Don't copy empty ALT="" to TITLE="". BDC 2006/Mar/03
# set verbose # see commands before variable substitution
# set echo # see commands after variable substitution
unset histchars # get other users' history characters out of the way
unalias * # get other users' .cshrc stuff out of the way
# $0:t construction doesn't work!
set cmd_name = $0
set cmd_name = $cmd_name:t # the name of this command
foreach file ( $* ) # try to copy ALT= info on all lines without TITLE=
sed -e '/[Tt][Ii][Tt][Ll][Ee]=/\!s/\([Aa][Ll][Tt]\)\(="[^"][^"]*"\)/\1\2 TITLE\2/' -e '/[Tt][Ii][Tt][Ll][Ee]=/\!s/\([Aa][Ll][Tt]\)\(='"'"'[^'"'"'][^'"'"']*'"'"'\)/\1\2 TITLE\2/' -e '/[Tt][Ii][Tt][Ll][Ee]=/\!s/\([Aa][Ll][Tt]\)\(=`[^`][^`]*`\)/\1\2 TITLE\2/' < $file > /tmp/$cmd_name.$$
/usr/bin/cmp -s $file /tmp/$cmd_name.$$ # test for changes (`cmp` test in the next "if" statement didn't work)
if ( $status ) then # files are different
echo "Added TITLE= tags to ${file}:" # show changed lines
/usr/bin/diff $file /tmp/$cmd_name.$$ | grep '^> ' | sed 's/^> / /'
/usr/bin/touch -r $file /tmp/$cmd_name.$$ # save file's original timestamp
/bin/cat /tmp/$cmd_name.$$ > $file # overwrite original file (cp may break links)
/usr/bin/touch -r /tmp/$cmd_name.$$ $file # restore file's original timestamp
# else
# echo "No TITLE= added to $file."
endif
/bin/rm /tmp/$cmd_name.$$
end