#!/bin/tcsh -f
# Create *.comment files for Lazygal from feh's *.txt files
#
# Put comments inside
tags.
# Tag additional lines with
.
# Change "|" in .txt files to line breaks in .comment files.
#
# Brent Chivers 2012/Aug/26
#
# Don't include "^tags:" lines in the comment file. 2015/Sep/13
#
# Using separate .tags files for tags. 2015/Nov/29
# If there is a matching .tags file, add links
# to this photo in the tag-album directories.
# Fixing tag links. 2015/Dec/06
# Fixing tag links again. 2016/Feb/25
# Changing BASE to new domain. 2016/Jul/22
# Use the tags: from the .txt file, not the .tags file. 2016/Sep/05
# Changing $BASE again.
# If this script is newer than the .comment file, redo. 2016/Sep/07
#
# Don't include lines that begin with "#" in the comment 2017/Oct/08
# file. This allows comments that won't be on the web site.
##! /bin/tcsh -fb # for setuid/setgid scripts (tsk)
# 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
## set nonomatch # don't require wildcard matches
#set BASE = "file://$HOME/webpages/bdchivers"
#set BASE = "http://bchivers.name"
#set BASE = "/bdchivers"
set BASE = ""
foreach TXT ( $* )
set COMMENT = "$TXT:r.comment"
if ( -e $COMMENT ) then # COMMENT file exists
set UPDATE = `/usr/bin/find $TXT -newer $COMMENT`
if ( "$UPDATE" == "" ) then # if TXT is not new, was script updated?
set UPDATE = `/usr/bin/find $0 -newer $COMMENT`
endif
if ( "$UPDATE" == "" ) then
continue # TXT and script are not newer than COMMENT, skip
endif
echo "updating $COMMENT file"
else # COMMENT file does not exist
echo "creating new $COMMENT file"
endif
/usr/bin/tr '|' '\012' < $TXT | /usr/bin/awk ' \
NR == 1 { printf ("%s", $0) } \
/^#/ { next} \
/^tags:/ { next} \
NR > 1 { printf ("\n
%s", $0) } \
END { printf ("\n") }' > $COMMENT
# set TAGS = "$TXT:r.tags"
set TAGS = `/bin/grep '^tags:' $TXT | /usr/bin/cut -d: -f2- | /usr/bin/tr ',' ' ' | /usr/bin/fmt -1 | /usr/bin/tr -d ' ' | /usr/bin/sort | /usr/bin/uniq`
if ( "$TAGS" != "" ) then # photo has TAGS
echo -n "Galleries: " >> $COMMENT
# set DATE_TIME = "$TXT:t:r"
# set DATE_PATH = `echo $DATE_TIME | /usr/bin/cut -d- -f1 | /usr/bin/tr '.' '/'`
set DATE_PATH = `echo $TXT:t:r | /usr/bin/cut -d- -f1 | /usr/bin/tr '.' '/'`
# echo ''$DATE_PATH'' >> $COMMENT
echo ''$DATE_PATH'' >> $COMMENT
# /usr/bin/fmt -1 $TAGS | /usr/bin/sort -f | /bin/sed 's+.*+
&+' >> $COMMENT
echo $TAGS | /usr/bin/fmt -1 | /bin/sed 's+.*+
&+' >> $COMMENT
echo "" >> $COMMENT
endif
end