#!/bin/sh usage() { echo usage: $0 templatefile contentfile 1>&2 exit 1 } now=`date` template=$1 if [ "$template" = "" ] ; then usage fi content=$2 if [ "$content" = "" ] ; then usage fi (cat "$template"; cat "$content" ) | awk -vnow="$now" ' BEGIN { istemplate = 1 iscontent = 0 isleft = 0 isbottom = 0 ntemplate = 0 ncontent = 0 npage = 0 imagedir="" aprev = "" anext = "" awidth = 0 aheight = 0 supportdir = "" sstitle = "Slideshow" homepage = "/" indexpage = "../" } /^<\/[Hh][Tt][Mm][Ll]>$/ { istemplate = 0 template[ntemplate++] = $0 iscontent = 1 next } istemplate { template[ntemplate++] = $0 next } iscontent && /^IMAGEDIR[ ]+/ { imagedir = $2 next } iscontent && /^SUPPORTDIR[ ]+/ { supportdir = $2 "/" next } iscontent && /^PAGE-HOME[ ]+/ { homepage = $2 next } iscontent && /^PAGE-INDEX[ ]+/ { indexpage = $2 next } iscontent && /^TITLE[ ]+/ { sstitle = "" for(i = 2; i <= NF; i++) sstitle = sstitle " " $i next } iscontent && /^ARROW[ ]+/ { if(NF != 5) { print "content: bad arrow specification" exit 1 } aprev = $2 anext = $3 awidth = "width=\"" $4 "\"" aheight = "height=\"" $5 "\"" next } iscontent && /^[^ ]/ { npage++ ltext[npage] = "" btext[npage] = "" imagew[npage] = "" imageh[npage] = "" isleft = 0 isbottom = 0 if(imagedir != "") image[npage] = imagedir "/" $1 else image[npage] = $1 if(NF > 1) { if(NF != 3) { "bad image specification (bad args)" exit 1 } imagew[npage] = "width=\"" $2 "\"" imageh[npage] = "height=\"" $3 "\"" } next } iscontent && /^[ ]+TEXT-LEFT[ ]*$/ { isleft = 1 isbottom = 0 next } iscontent && /^[ ]+TEXT-BOTTOM[ ]*$/ { isleft = 0 isbottom = 1 next } isleft { ltext[npage] = ltext[npage] $0 "\n" next } isbottom { btext[npage] = btext[npage] $0 "\n" next } { next } END { for(page = 1; page <= npage; page++) { out = page ".html" for(i = 0; i < ntemplate; i++) { line = template[i] if(match(line, "THUMB-PREV-LINK")) { if(page == 1) link = npage ".html" else link = page - 1 ".html" sub(/THUMB-PREV-LINK/, link, line) } if(match(line, "THUMB-PREV-IMAGE")) { if(page == 1) img = image[npage] else img = image[page-1] sub(/.*\//, "&th-", img) sub(/THUMB-PREV-IMAGE/, img, line) } if(match(line, "THUMB-NEXT-LINK")) { if(page == npage) link = "1.html" else link = page + 1 ".html" sub(/THUMB-NEXT-LINK/, link, line) } if(match(line, "THUMB-NEXT-IMAGE")) { if(page == npage) img = image[1] else img = image[page+1] sub(/.*\//, "&th-", img) sub(/THUMB-NEXT-IMAGE/, img, line) } if(match(line, "PAGE-PREV")) { if(page == 1) pp = npage else pp = page - 1 sub(/PAGE-PREV/, pp ".html", line) } if(match(line, "PAGE-NEXT")) { if(page == npage) np = 1 else np = page + 1 sub(/PAGE-NEXT/, np ".html", line) } if(match(line, "SLIDESHOW-TITLE")) sub(/SLIDESHOW-TITLE/, sstitle, line) if(match(line, "SUPPORTDIR")) sub(/SUPPORTDIR/, supportdir, line) if(match(line, "ARROW-PREV")) sub(/ARROW-PREV/, supportdir aprev, line) if(match(line, "ARROW-NEXT")) sub(/ARROW-NEXT/, supportdir anext, line) if(match(line, "ARROW-WIDTH")) sub(/ARROW-WIDTH/, awidth, line) if(match(line, "ARROW-HEIGHT")) sub(/ARROW-HEIGHT/, aheight, line) if(match(line, "IMAGE-NAME")) sub(/IMAGE-NAME/, image[page], line) if(match(line, "IMAGE-WIDTH")) sub(/IMAGE-WIDTH/, imagew[page], line) if(match(line, "IMAGE-HEIGHT")) sub(/IMAGE-HEIGHT/, imageh[page], line) if(match(line, "TEXT-LEFT")) sub(/TEXT-LEFT/, ltext[page], line) if(match(line, "TEXT-BOTTOM")) sub(/TEXT-BOTTOM/, btext[page], line) if(match(line, "CREATION-TIME")) sub(/CREATION-TIME/, "Created: " now, line) if(match(line, "PAGE-HOME")) sub(/PAGE-HOME/, homepage, line) if(match(line, "PAGE-INDEX")) sub(/PAGE-INDEX/, indexpage, line) if(match(line, "SLIDESHOW-LINKS")) { line = "" for(link = 1; link <= npage; link++) { if(link == page) line = line "" link "" else line = line "" link "" if(link < npage) line = line ", \n" } } print line > out } } } '