#!/bin/bash
textutil -convert html gov.ca.oal.title01.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 01." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title01.html
textutil -convert html gov.ca.oal.title02.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 02." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title02.html
textutil -convert html gov.ca.oal.title03.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 03." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title03.html
textutil -convert html gov.ca.oal.title04.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 04." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title04.html
textutil -convert html gov.ca.oal.title05.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 05." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title05.html
textutil -convert html gov.ca.oal.title07.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 07." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title07.html
textutil -convert html gov.ca.oal.title08.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 08." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title08.html
textutil -convert html gov.ca.oal.title09.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 09." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title09.html
textutil -convert html gov.ca.oal.title10.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 10." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title10.html
textutil -convert html gov.ca.oal.title11.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 11." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title11.html
textutil -convert html gov.ca.oal.title12.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 12." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title12.html
textutil -convert html gov.ca.oal.title13.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 13." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title13.html
textutil -convert html gov.ca.oal.title14.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 14." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title14.html
textutil -convert html gov.ca.oal.title15.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 15." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title15.html
textutil -convert html gov.ca.oal.title16.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 16." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title16.html
textutil -convert html gov.ca.oal.title17.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 17." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title17.html
textutil -convert html gov.ca.oal.title18.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 18." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title18.html
textutil -convert html gov.ca.oal.title19.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 19." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title19.html
textutil -convert html gov.ca.oal.title20.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 20." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title20.html
textutil -convert html gov.ca.oal.title21.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 21." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title21.html
textutil -convert html gov.ca.oal.title22.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 22." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title22.html
textutil -convert html gov.ca.oal.title23.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 23." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title23.html
textutil -convert html gov.ca.oal.title25.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 25." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title25.html
textutil -convert html gov.ca.oal.title26.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 26." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title26.html
textutil -convert html gov.ca.oal.title27.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 27." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title27.html
textutil -convert html gov.ca.oal.title28.rtf
perl -pi -e 's/>View Graphic/">Embedded Graphic 28." . sprintf("%04d", ++$i) . " "/e' gov.ca.oal.title28.html

# this introduces a couple duplicate IDs, but not very many
perl -pi -e 's#"><b>§([^ ]+)\. #"><a name="\1"></a><b>§\1. #' *.html

# this does the style sheet
# note that the link tag is not closed because this is html 4.0 strict
perl -i -pe 'BEGIN{undef $/;} s#<style.*</style>#<link rel="stylesheet" type="text/css" href="https://law.resource.org/pub/us/ccr/ccs/ccr.css">#smg' gov*.html

# some cleanup
perl -pi -e 's#<title>Barclays Official #<title>#' gov*.html
perl -pi -e 's#name="Author" content="[^"]+"#name="Author" content="State of California"#' gov*html

# There are 61,000 of these empty tags. I don't believe the white space is significant. 
perl -pi -e 's#<p class="p8"><br></p>##' gov*html

# don't forget to change the graphics links by running mk.images.sh then graphic.mapping.sh
