#!/bin/sh

# gmdoc2html utility utility.imdoc > utility.html

# <!-- ---------------------------------------------------------------- -->
# <!-- Options.xml: "options" subsection of convert, composite, et al.  -->
# <!-- ---------------------------------------------------------------- -->
# <!-- Markup tags in this document are                                 -->
# <!--   imdoc (Identifies file as ImageMagick document source file)    -->
# <!--   sect name=section_name (section); remainder of line is title   -->
# <!--   opt  (option)                                                  -->
# <!--   abs  (abstract)                                                -->
# <!--   p    (regular print paragraph, not OK to nest)                 -->
# <!--   pp   (small print paragraph, not OK to nest)                   -->
# <!--   pre  (== HTML pre, not allowed in dd, p, pp or sp)             -->
# <!--   tab  (== simple HTML table)                                    -->
# <!--   |    (tab char, separates table cells)                         -->
# <!--   sp   (subparagraph, must be inside p or pp, OK to nest         -->
# <!--   ul   (== HTML ul)                                              -->
# <!--   li   (== HTML li)                                              -->
# <!--   dl   (== HTML dl)                                              -->
# <!--   dt   (== HTML dt, dt without a dd is OK)                       -->
# <!--   dd   (== HTML dd, dd without a dt is OK)                       -->
# <!--   br   (== HTML br)                                              -->
# <!--   i    (== HTML em)                                              -->
# <!--   s    (== HTML strong)                                          -->
# <!--   tt   (== HTML tt)                                              -->
# <!--   bq   (== HTML blockquote)                                      -->
# <!--   o    ("dd" list item with ball)                                -->
# <!--   back (write "back to contents" link)                           -->
# <!--   utils apps=name ... (which apps the enclosed lines pertain to) -->
# <!--   format type=name ... (html, man, tex, ...)                     -->
# <!--   !--  (== HTML !--) comment                                     -->
# <!--                                                                  -->
# <!--   All tags must close with </...> form of tag, e.g. <pp>..</pp>  -->
# <!-- ---------------------------------------------------------------- -->

cat <<!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=us-ascii">
	<title>GraphicsMagick GM Utility</title>
	<style type=text/css>
	<!--
		@page { size: 8.5in 11in }
		TD P { color: #000000; font-family: "Verdana", "Arial", "Helvetica", sans-serif; font-size: 12pt }
		P { color: #000000; font-family: "Verdana", "Arial", "Helvetica", sans-serif; font-size: 12pt }
		A:link { color: #00B04F }
		A:visited { color: #007B37 }
	-->
	</style>

</head>
<body LANG="en-US" TEXT="#000000" LINK="#00B04F" VLINK="#007B37" BGCOLOR="#ffffff">
<a name="top"></a>
<table border=0 cellpadding=10 cellspacing=0 style="margin-top:-17px" width="100%"><tr><td>
!!

${SED}  "
     /<!--/d
     /<include file=/d

     /<imdoc>/d
     /<\/imdoc>/d

     s/<title>.*<\/title>//

     s/<utils/!utils!/
     /!utils!/s/>/+!!/
     s/<.utils>/+!utils!/

     s/<sect/!sect!/
     /!sect!/s/>/+!!/
     s/<\/sect>/+!sect!/

     s/<back>/!back!/
     s/<home>/!home!/
     s/<bq>/!bq!/
     s/<\/bq>/+!bq!/
     s/<lopt>/!lopt!/
     s/<dopt>/!dopt!/
     s/<opt>/!opt!/
     s/<\/opt>/+!opt!/
     s/<abs>/!abs!/
     s/<\/abs>/+!abs!/
     s/<p>/!p!/
     s/<\/p>//
     s/<pp>/!pp!/
     s/<\/pp>/+!pp!/
     s/<sp>/!sp!/
     s/<\/sp>/+!sp!/
     s/<br>/!br!/
     s/<\/br>/+!br!/

     s/<ul>/!ul!/
     s/<\/ul>/+!ul!/
     s/<li>/!li!/
     s/<\/li>//
     s/<dl>/!dl!/
     s/<\/dl>/+!dl!/
     s/<dt>/!dt!/
     s/<\/dt>/+!dt!/
     s/<dd>/!dd!/
     s/<\/dd>/+!dd!/
     s/<o>/!o!/
     s/< >/ /

     s/<i>/!em!/g
     s/<\/i>/+!em!/g
     s/<tt>/!tt!/g
     s/<\/tt>/+!tt!/g
     s/<s>/!strong!/g
     s/<\/s>/+!strong!/g
     s/<pre>/!pre!/
     s/<\/pre>/+!pre!/
     s/<tab>/!tab!/
     s/<\/tab>/+!tab!/
     s/<|>/!|!/g
     s/<a href=\([^>]*\)>/!a href=\1+!!/
     s/<\/a>/+!a!/

     s/\&/\&amp;/g
     s/</\&lt;/g
     s/>/\&gt;/g

     s/+!!/>/
     s/+!sect!/<\/sect>/
     s/!sect!/<sect/
     s/+!utils!/<\/utils>/
     s/!utils!/<utils/
     s/+!opt!/<\/opt>/
     s/!opt!/<opt>/
     s/!lopt!/<lopt>/
     s/!dopt!/<dopt>/
     s/!back!/<back>/
     s/!home!/<home>/
     s/+!abs!/<\/abs>/
     s/!abs!/<abs>/
     s/+!bq!/<\/blockquote>/
     s/!bq!/<blockquote>/

     s/+!dl!/<\/dl>/
     s/!dl!/<dl>/
     s/+!dt!/<\/dt>/
     s/!dt!/<dt>/
     s/+!dd!/<\/dd>/
     s/!dd!/<dd>/
     s/+!ul!/<\/ul>/
     s/!ul!/<ul>/
     s/!li!/<li>/

     s/!p!/<p>/
     s/+!pp!/<\/pp>/
     s/!pp!/<pp>/
     s/+!sp!/<\/sp>/
     s/!sp!/<sp>/
     s/+!br!/<\/br>/
     s/!br!/<br>/
     s/+!em!/<\/em>/g
     s/!em!/<em>/g
     s/+!tt!/<\/tt>/g
     s/!tt!/<tt>/g
     s/+!strong!/<\/strong>/g
     s/!strong!/<strong>/g
     s/+!pre!/<\/pre>/
     s/!pre!/<pre>/
     s/+!tab!/<\/tab>/
     s/!tab!/<tab>/
     s/!|!/<|>/g
     s/+!a!/<\/a>/
     s/!a href=/<a href=/
     s/ *!o!/<dd>!o!/
     s/!o!/<img SRC=\"images\/ball.png\" ALT=\"*\">/
     s/^ *$/<br>\&nbsp;<br>/

     s/<tab>/<tab> cellspacing=\"0\" cellpadding=\"2\">/
     s/<tab>/<table border=\"0\"/
     s/<\/tab>/<\/table>/
     /<|>/s/^/<tr><td>/
     /<|>/s/$/<\/td><\/tr>/
     s/<|>/<\/td><td>/g

     /<sect /i\\
<table BORDER=0 WIDTH=\"100%\"> \\
<tr> \\
<td ALIGN=LEFT bgcolor=\"#FFFFFF\"><img \\
SRC=\"images/right_triangle.png\" \\ ALT=\">\" BORDER=0 \\
height=14 width=15><b><font face=\"Helvetica, Arial\"><font \\
color=\"#00B04F\"><font size=\"+1\">

     t dummy
   : dummy
     s/<sect /<a /
     t sect
     b notsect

   : sect
     s/>/><\/a>/
     a\\
</font></font></font></b></td></tr></table>\\
<table width=\"94%\" border=\"0\" cellspacing=\"0\" cellpadding=\"8\">\\
<tr><td width=\"3%\"><br></td><td>

   : notsect

     /<\/sect>/i\\
</td></tr></table>

     /<\/sect>/d

     /<back>/i\\
     <p>\\
<i><a href=\"\#top\">Back to Contents</a></i> \\
&nbsp;</p>
     /<back>/d

     /<home>/i\\
<HR>\\
\\
[<a href=\"index.html\">Home</a>] [<a href=\"utilities.html\">Utilities Index</a>]\\
<BR>\\
<p align=center <a href=\"Copyright.html\">Copyright &#169; GraphicsMagick Group 2002 - 2018</a></p></td>\\
</tr></table>\\
</body></html>
     /<home>/d

     /opt>.* .*</s/ / <i>/
     /opt>.* .*</s/<\/opt/<\/i><\/opt/
     /<lopt>/s/>\\([^ <]*\\)/>\<a href=\"GraphicsMagick.html#details\1\">\\1<\/a>/
     /<dopt>/s/>\\([^ <]*\\)/>\<a name=\"details\\1\"><\/a>\\1/
     s/<lopt>/<opt>/
     s/<dopt>/<opt>/
     /opt>/s/\([{}]\)/<\/i>\1<i>/g
     /<opt>/i\\
<table BORDER=0 WIDTH=\"94%\">\\
<tr>\\
<td width=\"3%\"><br></td> \\
<td ALIGN=LEFT BGCOLOR=\"#FFFFFF\">\\
<img SRC=\"images/right_triangle_option.png\"\\
ALT=\">\" BORDER=0 height=14\\
width=15><b><font face=\"Helvetica, Arial\"\\
><font color=\"#00B04F\"><font size=\"+1\">

     /^<opt>$/d
     /<\/opt>/a\\
</font></font></font></b></td></tr></table>
     /^<.opt>$/d
     s/<.opt>//
     s/<opt>/    /

     /<utils.*>/d
     /<\/utils>/d

     s/<abs>/<table width=\"90%\" border=\"0\" cellspacing=\"0\" \
             cellpadding=\"8\"> \
             <tr><td width=\"6%\"><br><\/td><td>/g
     s/<\/abs>/<\/td><\/tr><\/table>/g

     s/<pp>/<table width=\"90%\" border=\"0\" cellspacing=\"0\" \
            cellpadding=\"8\"> \
            <tr><td width=\"6%\"><br><\/td><td><font size=\"-1\">/g
     s/<\/pp>/<\/font><\/td><\/tr><\/table>/g

     s/<sp>/<\/font><table width=\"84%\" border=\"0\" cellspacing=\"0\" \
            cellpadding=\"8\"> \
            <tr><td width=\"12%\"><br><\/td><td><font size=\"-1\">/g
     s/<\/sp>/<\/font><\/td><\/tr><\/table><font>/g


     " $2
