#!/bin/bash

# this file takes the graphic.mapping.txt file and turns it into a series of link
# reference munges in the html files

# it's ugly, I know!

cp graphic.mapping.txt graphic.mapping.sh

# These are the ones that come off the DVD
# We're not doing alt tags yet. This needs to be added to the mapping files.
# Note that the img tag has no close as this is html 4.0 strict
perl -pi -e 's#^([0-9][0-9])\.([0-9][0-9][0-9][0-9]) : ([0-9]+)\.png.*$#perl -pi -e FOOsBAREmbedded Graphic \1.\2BAR\<a href="img/tif/\3.tif"\>\<img src="img/\3.png" alt="Embedded Graphic"\>\</a\>BARFOO gov.ca.oal.title\1.html#' graphic.mapping.sh


# these are graphics we couldn't match in the official distribution
# they were retrieved off the web site or off of paper copies and saved
perl -pi -e 's#^([0-9][0-9])\.([0-9][0-9][0-9][0-9]) : SAVE : ([0-9.]+.png.).*$#perl -pi -e FOOsBAREmbedded Graphic \1.\2BAR<img src="\3" alt="Embedded Graphic">BARFOO gov.ca.oal.title\1.html#' graphic.mapping.sh

perl -pi -e "s#FOO#'#g" graphic.mapping.sh
perl -pi -e "s/BAR/#/g" graphic.mapping.sh

# remove any lines that don't have a match
perl -pi -e 's#^[^p].*$##' graphic.mapping.sh

chmod +x graphic.mapping.sh
