1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/bin/bash
# html2texi,v
FILES1="index.html strict.html ptools.html"
FILES2="parsers.html lexers.html fparsers.html bparsers.html grammars.html"
FILES3="printers.html pprintf.html pretty.html"
FILES4="locations.html ml_ast.html ast_transi.html ast_strict.html q_ast.html pcaml.html directives.html syntext.html opretty.html redef.html quot.html revsynt.html scheme.html macros.html pragma.html extfun.html"
FILES5="commands.html library.html sources.html about.html"
FILES="$FILES1 1 $FILES2 2 $FILES3 3 $FILES4 4 $FILES5"
VERSION="$(grep "value version =" ../../main/pcaml.ml | sed -e 's/^[^"]*"\([^"]*\).*$/\1/')"
/bin/echo '\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename camlp5.info'
/bin/echo "@settitle Camlp5 manual $VERSION"
/bin/echo '@c %**end of header'
/bin/echo '
@titlepage
@title Camlp5 manual
@author Daniel de Rauglaudre
@end titlepage'
/bin/echo '
@node Top
@top Camlp5: a preprocessor pretty printer for OCaml'
/bin/echo "@noindent Version $VERSION"
/bin/echo '
@menu'
(
/bin/echo 'sed \'
for i in $FILES; do
if [ "$i" = "1" ]; then
:
elif [ "$i" = "2" ]; then
:
elif [ "$i" = "3" ]; then
:
elif [ "$i" = "4" ]; then
:
elif [ "$i" = "5" ]; then
:
else
N=$(grep '<h1' $i | sed -e 's|<h1[^>]*>||' -e 's|</h1>||')
/bin/echo " -e 's/@pxref{$i}/@pxref{$N}/' \\"
fi
done
/bin/echo
) > tmp
for i in $FILES; do
if [ "$i" = "1" ]; then
/bin/echo
/bin/echo 'Parsing Tools'
/bin/echo
elif [ "$i" = "2" ]; then
/bin/echo
/bin/echo 'Printing Tools'
/bin/echo
elif [ "$i" = "3" ]; then
/bin/echo
/bin/echo 'Language extensions'
/bin/echo
elif [ "$i" = "4" ]; then
/bin/echo
/bin/echo 'Appendix'
/bin/echo
else
N=$(grep '<h1' $i | sed -e 's|<h1[^>]*>||' -e 's|</h1>||')
/bin/echo "* $N::"
fi
done
/bin/echo '
@end menu'
/bin/echo
chapter=chapter
for i in $FILES; do
if [ "$i" = "1" ]; then
:
elif [ "$i" = "2" ]; then
:
elif [ "$i" = "3" ]; then
:
elif [ "$i" = "4" ]; then
:
elif [ "$i" = "5" ]; then
chapter=appendix
else
N=$(grep '<h1' $i | sed -e 's|<h1[^>]*>||' -e 's|</h1>||')
/bin/echo "
@node $N
@$chapter $N"
cat $i |
sed \
-e 's|^\(.*\)<ul>|\n\1<ul>|' \
-e 's|^\(.*\)<dl>|\n\1<dl>|' |
sed \
-e '{:b; /^$/N; s/^\n$//; tb}' |
sed \
-e 's|</p>|\n</p>|' \
-e 's|\([^ ]\)</li>|\1\n</li>|g' \
-e 's|\([^ ]\)</dd>|\1\n</dd>|g' \
-e '/<pre[^>]*>/,/<\/pre>/s/ /~~/g' |
sed \
-e '/<p>/,/<\/p>/s/^ *//' \
-e '/<li>/,/^ <\/li>/s/^ *//' \
-e '/<dd>/,/<\/dd>/s/^ *//' \
-e '/<div[^>]*>/,/<\/div>/s/^ *//' \
-e '/<pre[^>]*>/,/<\/pre>/s/~~/ /g' |
sed \
-e '{/<table[^>]*>$/N; :b; /<tr>$/N; s/\n *//; tb; /<\/tr>$/N; s/\n *//; tb; /<\/th>$/N; s/\n *//; tb; /<\/td>$/N; s/\n *//; tb; /<thead>$/N; s/\n *//; tb; /<\/thead>$/N; s/\n *//; tb; /<tbody>$/N; s/\n *//; tb; /<\/tbody>$/N; s/\n *//; tb}' \
-e 's|@|@@|g' \
-e 's|{|@{|g' -e 's|}|@}|g' \
-e "s|''|@w{'}@w{'}|g" |
sed \
-e '{s|<a href=\"\([^.]*\.html\)[^>]*>|(@pxref{\1}) |; tb; bc; :b; h; s|(@pxref{.*}) ||; :c}' \
-e '{/<\/a>/bd; be; :d; /<\/a/G; x; s/^.*$//; x; s|</a>\(.*\)\n.*\((@pxref{.*})\).*$| \2\1|; s/\n//; :e}' |
sed \
-e '/<div id="tableofcontents">/,/<\/div>/d' \
-e '/<div class="trailer">/,$d' \
-e 's|<div[^>]*>|@noindent |' -e 's|</div>||' \
-e '1,/<h1/d' \
-e 's|<h2>|@section |' -e 's|</h2>||' \
-e 's|<h3>|@subsection |' -e 's|</h3>||' \
-e 's|<h4>|@subsubsection |' -e 's|</h4>||' \
-e 's|<h5>|@noindent @strong{|' -e 's|</h5>|}|' \
-e '/<pre>/,/<\/pre>/s/^ //' \
-e 's|<br/>|@*|g' \
-e 's|^ *<p>|@noindent |' -e '/<\/p>/d' \
-e 's|^ *<ul>|@itemize|' -e 's|^ *</ul>|@end itemize|' \
-e 's|^ *<ol>|@enumerate|' -e 's|^ *</ol>|@end enumerate|' \
-e 's|^ *<li>|@item |' -e '/<\/li>/d' \
-e 's|^ *<dl><dd>|@exampleindent 5\n@quotation |' \
-e 's|^ *</dd></dl>|@end quotation|' \
-e 's|^ *<dl[^>]*>|@exampleindent 5\n@table @asis|' \
-e 's|^ *</dl>|@end table|' \
-e 's|^ *<dt>|@item |' -e 's|</dt>||' \
-e 's|^ *<dd>||' -e '/<\/dd>/d' \
-e 's|<b>|@strong{|g' -e 's|</b>|}|g' \
-e 's|<em>|@emph{|g' -e 's|</em>|}|g' \
-e 's|<tt[^>]*>||g' -e 's|</tt>||g' \
-e 's|<code>||g' -e 's|</code>||g' \
-e 's|<span [^>]*>|@emph{|g' -e 's|</span>|}|g' \
-e 's|</a>||g' \
-e 's|<a [^>]*>||g' \
-e 's|<pre>|@exampleindent 5\n@example|' -e 's|</pre>|@end example|' \
-e 's|<pre [^>]*>|@exampleindent 0\n@example|' \
-e 's|<table border="1">|@multitable @columnfractions .35 .35 .23\n|' \
-e 's|<table[^>]*>|\n@multitable @columnfractions .50 .50\n|' \
-e 's|</table>|@end multitable|' \
-e 's|<tr><th[^>]*>|@item |g' -e 's|</th><th[^>]*>| @tab |g' \
-e 's|</th></tr>|\n@item\n|g' \
-e 's|<tr><td>|@item |g' -e 's|</td><td[^>]*>| @tab |g' \
-e 's|</td></tr>|\n|g' \
-e 's/</</g' -e 's/>/>/g' -e 's/ / /g' -e 's/&/\&/g' \
-e "s|<version/>|$VERSION|" \
-e '/<licence\/>/r ../../LICENSE' -e '/<licence\/>/d'
fi
done |
sh ./tmp
/bin/echo '
@bye'
|