# make-book-ps: shell script, built from toc.htm, to make PostScript MH book
#
# Ugly hack.  For Jerry Peek's use.  If you have suggestions, I'd be
# glad to get them.
#
# Tabstops in this script set at 4

## Note for Debian users:
##
##  Run this script like so:
##   sh make-postscript-mh-book
## 
##  I have removed the first line to invoke the shell:
##  #!/bin/sh
##  because Debian packaging policy discourages having executable scripts
##  outside of the PATH or of /usr/doc/PACKAGE/examples/.  That's why the
##  scripts is not executable and that you must invoke it with `sh' first.
## 
##  This file was adapted by Peter Galbraith <psg@debian.org> from 
##  Jerry Peek's script downloaded from
##   ftp://ftp.gw.com/pub/people/jpeek/mh/book-ps/make-book-ps
##  The changes are to adjust to where the files are installed,
##  and that they have been renamed to .html and compressed on Debian.

if ! command -v html2ps >/dev/null 2>&1; then
    echo "Could not find command html2ps."
    echo "Please install the Debian package html2ps and try again."
    exit 0                 
fi

# Overall setup
source=/usr/share/doc/mh-book/html			# HTML files
# Debian has /usr/doc mapped to http://localhost/doc
httpsource=http://localhost/doc/mh-book/html    # HTML GIF files
psfiles=/tmp/mh-book-ps				# Where PostScript files go
#baseurl="http://www.ics.uci.edu/~mh/book"	# For URLs at ends of pages
baseurl="http://localhost/doc/mh-book/html"	# For URLs at ends of pages

install -d $psfiles

front="index.html
roadmap.html
overall/whaboo.html
whatsnew.html
updates.html
copying.html
structur.html
browhelp.html
servers.html
to-do.html
xmh/tocs/xmh.html
exmh/tocs/exmh.html"

ch00="overall/ch-p.html
overall/whymh.html
overall/whyboo.html
overall/whaboo.html
overall/neitthed.html
overall/whanotbo.html
overall/thefor.html
overall/reqfocom.html
overall/ack.html"

ch01="overall/ch-i.html
overall/whaema.html
overall/howwor.html
overall/intomim.html
overall/addema.html
overall/pro.html
overall/whamh.html
overall/obtxmh.html"

ch02="overall/ch-kpotu.html
overall/anand.html
overall/mhbindir.html
overall/mhlibdir.html
overall/sysmai.html
overall/audir.html
overall/spexmh.html
overall/speexmh.html
overall/lin.html
overall/caucha.html"

ch03="overall/ch-itm.html
overall/abe.html
overall/ovofmime.html
overall/mulmes.html
overall/moabmi.html"

ch04="overall/ch-su.html
overall/getrea.html
overall/setup.html
overall/onmanpag.html"

ch05="mh/ch-ttm.html
mh/getsta.html
mh/sensen.html
mh/reapre.html
mh/reprep.html
mh/comopt.html
mh/forfor.html
mh/faswsprs.html
mh/clermm.html
mh/usimim.html
mh/theswi.html
mh/othfea.html"

ch06="mh/ch-rymwm.html
mh/shomes.html
mh/remime.html
mh/limimepa.html
mh/morsca.html
mh/chemsg.html
mh/othinc.html
mh/usmwp.html
mh/pnmiba.html"

ch07="mh/ch-smwm.html
mh/senove.html
mh/wiabnab.html
mh/chaedi.html
mh/mh.html
mh/hea.html
mh/wormes.html
mh/cosemime.html
mh/thecom.html
mh/reprep-2.html
mh/forfor-2.html
mh/disdis.html
mh/sencom.html"

ch08="mh/ch-faomw.html
mh/fol.html
mh/thplofmh.html
mh/finpic.html
mh/gepiadse.html
mh/prehpick.html
mh/morseq.html
mh/stormess.html
mh/sorsor.html
mh/rem.html
mh/remrmf.html
mh/annann.html
mh/usilin.html
mh/burdig.html
mh/pamiafwp.html
mh/rfl_man.html
mh/mhsoamfm.html"

ch09="mh/ch-mmwyw.html
mh/runcom.html
mh/mhanthsh.html
mh/angen.html
mh/confmhn.html
mh/inchsu.html
mh/chanam.html
mh/setacc.html
mh/defmai.html
mh/shafol.html
mh/drafil.html
mh/drafil-o.html
mh/pccewca.html
mh/autmes.html
mh/qufoac.html"

ch10="mh/ch-nvomc.html
mh/whacom.html
mh/makcom.html
mh/wcvaaof.html
mh/verrep.html
mh/mmbwm.html
mh/vermes.html
mh/verfor.html
mh/edmeshm.html
mh/smmpws.html
mh/verpro.html
mh/verpus.html
mh/versca.html
mh/vercha.html
mh/verpic.html"

ch11="mh/ch-mf.html
mh/hl.html
mh/mhstr.html"

ch12="mh/ch-pnma.html
mh/homwotb.html
mh/thmafid.html
mh/ruyomfi.html
mh/exmbcom.html
mh/nmenorc.html
mh/stmifrc.html
mh/redmerc.html
mh/samimfr.html
mh/altmhpr.html
mh/putitat.html
mh/debugti.html"

ch13="mh/ch-itupw.html
mh/wripro.html
mh/wrioth.html
mh/tesfil.html
mh/comsub.html
mh/usista.html
mh/hanarg.html
mh/finnam.html
mh/wgiafw1l.html
mh/atset.html
mh/maimhm.html
mh/thecom-2.html
mh/getmenu.html
mh/getpro.html
mh/getenv.html
mh/chaenv.html
mh/wriedi.html
mh/usiinf.html
mh/watpro.html
mh/proref.html"

ch14="xmh/ch-ttx.html
xmh/getsta-2.html
xmh/runxmh.html
xmh/whawin.html
xmh/sendmai.html
xmh/getmai.html
xmh/repmai.html
xmh/chaare.html
xmh/seapic.html
xmh/formes.html
xmh/remmes.html
xmh/leaxmh.html
xmh/morxmh.html"

ch15="xmh/ch-ux.html
xmh/senmai.html
xmh/scrbar.html
xmh/edixmh.html
xmh/reamai.html
xmh/primai.html
xmh/orgfol.html
xmh/intseq.html
xmh/usipic.html
xmh/modseq.html
xmh/thewin.html"

ch16="xmh/ch-cx.html
xmh/comopt-2.html
xmh/comliop.html
xmh/resfun.html
xmh/resacc.html
xmh/concus.html
xmh/usihea.html
xmh/chafor.html
xmh/chacom.html
xmh/snoxmh.html"

ch17="mh-e/mh-e_1.html
mh-e/mh-e_2.html
mh-e/mh-e_3.html
mh-e/mh-e_4.html
mh-e/mh-e_5.html
mh-e/mh-e_6.html
mh-e/mh-e_7.html
mh-e/mh-e_8.html
mh-e/mh-e_9.html"

ch18="mh-e/mh-e_10.html
mh-e/mh-e_11.html
mh-e/mh-e_12.html
mh-e/mh-e_15.html
mh-e/mh-e_16.html
mh-e/mh-e_17.html
mh-e/mh-e_18.html
mh-e/mh-e_19.html
mh-e/mh-e_20.html
mh-e/mh-e_21.html
mh-e/mh-e_22.html
mh-e/mh-e_28.html
mh-e/mh-e_34.html
mh-e/mh-e_35.html
mh-e/mh-e_36.html
mh-e/mh-e_37.html
mh-e/mh-e_38.html
mh-e/mh-e_39.html
mh-e/mh-e_40.html
mh-e/mh-e_41.html
mh-e/mh-e_42.html
mh-e/mh-e_43.html
mh-e/mh-e_44.html
mh-e/mh-e_45.html"

ch19="mh-e/mh-e_46.html
mh-e/mh-e_47.html
mh-e/mh-e_48.html
mh-e/mh-e_49.html
mh-e/mh-e_50.html
mh-e/mh-e_51.html
mh-e/mh-e_52.html
mh-e/mh-e_53.html
mh-e/mh-e_54.html
mh-e/mh-e_55.html
mh-e/mh-e_56.html
mh-e/mh-e_59.html
mh-e/mh-e_61.html
mh-e/mh-e_62.html
mh-e/mh-e_63.html
mh-e/mh-e_64.html
mh-e/mh-e_65.html
mh-e/mh-e_67.html
mh-e/mh-e_68.html
mh-e/mh-e_69.html
mh-e/mh-e_70.html
mh-e/mh-e_71.html
mh-e/mh-e_72.html
mh-e/mh-e_73.html
mh-e/mh-e_74.html
mh-e/mh-e_75.html
mh-e/mh-e_76.html
mh-e/mh-e_77.html
mh-e/mh-e_78.html
mh-e/mh-e_79.html
mh-e/mh-e_80.html
mh-e/mh-e_81.html
mh-e/mh-e_82.html
mh-e/mh-e_83.html
mh-e/mh-e_84.html"

ch20="exmh/ch-ie.html
exmh/getsta-4.html
exmh/runexm.html
exmh/thexmdi.html
exmh/senmai-5.html
exmh/anacap.html
exmh/genema.html
exmh/remime-2.html
exmh/repmai-2.html
exmh/selmes.html
exmh/formes-2.html
exmh/delmes.html
exmh/prefer.html
exmh/leaexm.html
exmh/moabex.html"

ch21="exmh/ch-ue.html
exmh/mouaro.html
exmh/keycom.html
exmh/thexmd-2.html
exmh/foldis.html
exmh/folcac.html
exmh/tabcon.html
exmh/mesdis.html
exmh/manmes.html
exmh/senmai-6.html
exmh/maiali.html
exmh/thbuied.html
exmh/maiform.html
exmh/mimfor.html
exmh/faces.html
exmh/usaned.html
exmh/filmai.html
exmh/tips.html
exmh/tksexa.html
exmh/morinf.html"

ch22="exmh/ch-ce.html
exmh/prefer-2.html
exmh/presec.html
exmh/bindui.html
exmh/mhprof.html
exmh/xresou.html
exmh/wiclhi.html
exmh/resbut.html
exmh/resmen.html
exmh/butgro.html
exmh/colres.html
exmh/colhea.html
exmh/gepore.html
exmh/icopos.html
exmh/fodire.html
exmh/mimres.html
exmh/proexm.html
exmh/codorg.html"

appa="mh/ap-wcygf.html
mh/mhbbo.html
mh/morabo.html"

appb="overall/ap-homxa.html
overall/hiofmh.html
overall/xmh.html
overall/exmh.html
overall/earmhe.html
mh-e/chamhe.html"

appc="overall/ap-rl.html"

appd="mh/ap-efap.html
mh/obtpro.html
overall/faq.html
overall/rfcaid.html
mh/mh-2.html
mh/mhscex.html
overall/metama.html
mh-e/getmhe.html
exmh/exmh-2.html
mh/pritba.html
mh/e-aligre.html
mh/e-append.html
mh/e-autoin.html
mh/e-automh.html
mh/e-distpr.html
mh/tiaooril.html
mh/e-drmm.html
xmh/e-edprof.html
mh/e-execit.html
mh/e-fols.html
mh/e-forwed.html
mh/e-fpick.html
mh/e-mhprof.html
mh/e-mimeca.html
mh/e-mkfona.html
mh/e-mysend.html
mh/e-origin.html
mh/e-pick2m.html
mh/e-pof.html
mh/e-rcvsea.html
mh/e-recomp.html
mh/e-resend.html
mh/e-rfl.html
mh/e-rmmer.html
mh/e-scandr.html
mh/e-showpr.html
mh/e-storep.html
xmh/e-xmhpri.html"

appe="overall/ap-rg.html
mh/mhrg.html
mh/r-ali.html
mh/r-anno.html
mh/r-burst.html
mh/r-comp.html
mh/r-dist.html
mh/r-flist.html
mh/r-folder.html
mh/r-foldrs.html
mh/r-forw.html
mh/r-inc.html
mh/r-mark.html
mh/r-mhbuil.html
mh/r-mhl.html
mh/r-mhlist.html
mh/r-mhmail.html
mh/r-mhn.html
mh/r-mhpara.html
mh/r-mhpath.html
mh/r-mhshow.html
mh/r-mhstor.html
mh/r-msgchk.html
mh/r-msh.html
mh/r-next.html
mh/r-packf.html
mh/r-packmb.html
mh/r-pick.html
mh/r-prev.html
mh/r-prompt.html
mh/r-rcvdis.html
mh/r-rcvpac.html
mh/r-rcvsto.html
mh/r-rcvtty.html
mh/r-refile.html
mh/r-repl.html
mh/r-rmf.html
mh/r-rmm.html
mh/r-scan.html
mh/r-send.html
mh/r-show.html
mh/r-slocal.html
mh/r-sortm.html
mh/r-viamai.html
mh/r-whatno.html
mh/r-whom.html
xmh/xmhrg.html
mh-e/mherg.html
exmh/exmhrg.html
overall/mimerg.html"

for chunk in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 20 21 22
do
	eval files="\$ch$chunk"
	(
	cat <<- ENDHDR
	<HTML>
	<HEAD>
	<TITLE>MH &amp; nmh: Printed chapter $chunk</TITLE>
	</HEAD>

	<BODY>
	ENDHDR
	for file in $files
	do
		figurl=$httpsource/`dirname $file` 
		echo "<P><HR><STRONG>URL of section below: $baseurl/$file</STRONG><P>"
		(zcat -f --stdout $source/${file} | sed "
		1,/^<BODY BGCOLOR=\"\#FFFFFF\">/d
		/^<\/BODY>/,\$d
		s@<[Ii][Mm][Gg] .* [Ss][Rr][Cc]=\"@&$figurl/@
		" ) || echo "PROBLEM WITH sed $file IN $chunk ?!?" 1>&2
	done
	cat <<- ENDFTR
	</BODY>
	</HTML>
	ENDFTR
	) |
	html2ps -D -g -n -N ${chunk}01 -u |
	gzip -9  > $psfiles/ch$chunk.ps.gz
done

mhe_date=`date '+%d %h %Y'`
for chunk in 17 18 19
do
	eval files="\$ch$chunk"
	(
	cat <<- ENDHDR
	<HTML>
	<HEAD>
	<TITLE>MH &amp; nmh: Printed chapter $chunk</TITLE>
	</HEAD>

	<BODY>
	ENDHDR
	for file in $files
	do
		figurl=$httpsource/`dirname $file` 
		echo "<P><HR><STRONG>URL of section below: $baseurl/$file<BR>"
		echo "as of $mhe_date.</STRONG><BR>"
		(zcat -f --stdout $source/${file} |sed "
		1,/^<BODY BGCOLOR=\"\#FFFFFF\">/d
		/^<\/BODY>/,\$d
		s@<[Ii][Mm][Gg] .* [Ss][Rr][Cc]=\"@&$figurl/@
		" ) || echo "PROBLEM WITH sed $file IN $chunk ?!?" 1>&2
	done
	cat <<- ENDFTR
	</BODY>
	</HTML>
	ENDFTR
	) |
	html2ps -D -g -n -N ${chunk}01 -u |
	gzip -9  > $psfiles/ch$chunk.ps.gz
done

for pair in "a 23" "b 24" "c 25" "d 26" "e 27"
do
	set x $pair
	eval chunk=app$2 page=$3

	eval files="\$$chunk"
	(
	cat <<- ENDHDR
	<HTML>
	<HEAD>
	<TITLE>MH &amp; nmh: Printed appendix $chunk</TITLE>
	</HEAD>

	<BODY>
	ENDHDR
	for file in $files
	do
		figurl=$httpsource/`dirname $file` 
		echo "<P><HR><STRONG>URL of section below: $baseurl/$file</STRONG><P>"
		(zcat -f --stdout $source/${file} | sed "
		1,/^<BODY BGCOLOR=\"\#FFFFFF\">/d
		/^<\/BODY>/,\$d
		s@<[Ii][Mm][Gg] .* [Ss][Rr][Cc]=\"@&$figurl/@
		" ) || echo "PROBLEM WITH sed $file IN $chunk ?!?" 1>&2
	done
	cat <<- ENDFTR
	</BODY>
	</HTML>
	ENDFTR
	) |
	html2ps -D -g -n -N ${page}01 -u |
	gzip -9  > $psfiles/$chunk.ps.gz
done


(
cat <<- ENDHDR
<HTML>
<HEAD>
<TITLE>MH &amp; nmh: Printed Front-matter and Table of Contents</TITLE>
</HEAD>

<BODY>
ENDHDR
for file in $front toc.html
do
        figurl=$httpsource/`dirname $file` 
	echo "<P><HR><STRONG>URL of section below: $baseurl/$file</STRONG><P>"
	(zcat -f --stdout $source/${file} | sed "
	1,/^<BODY BGCOLOR=\"\#FFFFFF\">/d
	/^<\/BODY>/,\$d
	s@<[Ii][Mm][Gg] .* [Ss][Rr][Cc]=\"@&$figurl/@
	" ) || echo "PROBLEM WITH sed $file IN $chunk ?!?" 1>&2
done
cat <<- ENDFTR
</BODY>
</HTML>
ENDFTR
) |
html2ps -D -g -u |
gzip -9  > $psfiles/front.ps.gz

sed 's/$/<BR>/
1i\
<HTML>\
<HEAD>\
<TITLE>MH &amp; nmh: Index for Printed Version</TITLE>\
</HEAD>\
<BODY>\
<H1>MH &amp; nmh: Index for Printed Version</H1>
$a\
<HR>\'"
<EM>Printed from $baseurl/indx-cgi.html on $mhe_date</EM>"'\
<P>\
This file first appeared in the updated online edition of the book\
<I>MH &amp; nmh: Email for Users &amp; Programmers</I>, by Jerry Peek.\
Copyright &copy; 1997 by Jerry Peek.\
This file is freely-available; you can redistribute it and/or modify\
it under the terms of the GNU General Public License as published by\
the Free Software Foundation.  For more information, see\
<A HREF="../copying.html">the file <I>copying.html</I></A>.\
<P>\
<ADDRESS>\
Suggestions are welcome:\
<A HREF="http://www.jpeek.com/~jpeek/">Jerry Peek</A> <A HREF="mailto:jpeek@jpeek.com">&lt;jpeek@jpeek.com&gt;</A>\
</ADDRESS>\
</BODY>\
</HTML>' $source/indx-cgi.html | html2ps -D -g -n -N 2801 -u | gzip -9 > $psfiles/index.ps.gz

echo Output files created in  $psfiles
