#!/bin/csh -f # editcaptions # ------------------------------------------------------------------------- # Shell script to create and edit caption files for a picture album # ------------------------------------------------------------------------- # Revision History: # $Log$ # ------------------------------------------------------------------------- # Collect command line options set option_string_makethumbs_remote = "" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options]" echo "Options:" echo " -h = Show this help text" echo " --help = Show this help text" echo " -r = Make the thumbnails remotely on server mbp4" echo " --remote = Make the thumbnails remotely on server mbp4" exit 1 else if ("$1" == "-r" || "$1" == "--remote") then shift set option_string_makethumbs_remote = "--remote" else if ("-" == "`echo $1:q | cut -c 1`") then echo "Error: Invalid option: $1:q" $0 --help exit 1 else # Not a recognized option. Assume it's the first argument break endif end # No arguments defined, so allow none if ($#argv > 0) then $0 -h exit 1 endif if (`find . -name "*.[Jj][Pp][Gg]" -print` != "") then @ created_file_counter = 0 @ deleted_file_counter = 0 # Create TXT file for each JPG, so we can load them all into the editor # at the same time. foreach image_file (*.[jJ][pP][gG] *.[gG][iI][fF] *.[pP][nN][gG]) set txt_file = "${image_file:r}.txt" # Note: Don't touch it if already exists. Changing the timestamp # causes it to be unnecessarily re-published to the server. if (! -e $txt_file:q) then @ created_file_counter++ echo "Creating empty file: $txt_file" touch $txt_file:q endif end # Optional other album and slideshow files too foreach htm_file (prependToIndex.htm appendToIndex.htm) if (! -e $htm_file:q) then @ created_file_counter++ echo "Creating empty file: $htm_file" touch $htm_file:q endif end # Edit all the TXT and HTM files, except for index.htm since that # is typically generated and should not be edited manually, waiting # till the editor exits. # Note: Double quotes outside the backticks cause the list of filenames, # generated by find, to be quoted so that embedded whitespace and # special chars are tolerated. The ew command then operates on # each filename, not each word of each filename. ew "`find . -maxdepth 1 \ -not -iname index.htm \ \( -iname \*.htm -or -iname \*.txt \)`" # Delete any that are still empty foreach file (*.txt *.htm) if (-z $file:q) then @ deleted_file_counter++ echo -n "Deleting empty file: " rm -v $file:q endif end @ net_new_file_counter = $created_file_counter - $deleted_file_counter if ($created_file_counter != 0 || $deleted_file_counter != 0 ) then echo "Created empty files: " $created_file_counter echo "Deleted empty files: " $deleted_file_counter echo "New non-empty files: " $net_new_file_counter endif if ("$1" != "-q") then # Pass along command line arge/options like -l makealbum -q ${option_string_makethumbs_remote} $*:q slideshow open $*:q endif endif