(* Outputting the help signature database in ASCII, LaTeX and HTML format *)
fun printASCIIBase(sigfile, outfile) =
let fun prtseq (pr, sep) [] = ""
| prtseq (pr, sep) [x] = pr x
| prtseq (pr, sep) (x::xs) = pr x ^ sep ^ prtseq(pr, sep) xs
open Database
val db = readbase sigfile
val os = TextIO.openOut outfile
fun out s = TextIO.output(os, s)
fun prentry comp, str, line =
let fun mkitem kind id =
concat[kind, " ", id, " (", str, " ", Int.toString line, ")"]
in
case comp of
Str => "structure " ^ str
| Exc id => mkitem "exception" id
| Typ id => mkitem "type" id
| Val id => mkitem "value" id
| Con id => mkitem "constructor" id
end
fun prtree Empty = ()
| prtree (Node(key, entries, t1, t2)) =
(prtree t1;
out (prtseq (prentry, ", ") entries);
out "";
prtree t2)
in prtree db; TextIO.closeOut os end
fun printLatexBase(sigfile, outfile) =
let open Database
val db = readbase sigfile
val os = TextIO.openOut outfile
fun out s = TextIO.output(os, s)
fun tt s = "
verb#" ^ s ^ "#"
(* Insert extra vertical space when meeting a new initial letter *)
val lastc1 = ref #" "
fun separator k1 =
let val c1 = Char.toLower k1
in
if Char.isAlpha c1 andalso c1 <> !lastc1 then
(lastc1 := c1;
out "
")
else ()
end
fun nextstr last [] = out ")"
| nextstr last ((e1 as comp, str, ...) :: erest) =
if comp = last then
(out ", "; out (tt str); nextstr last erest)
else
(out ")"; newitem e1 erest)
and newitem (e1 as comp, str, ...) erest =
let val key = Database.getname e1
in
(separator (String.sub(key, 0));
out "
item[] "; out (tt key); out " (";
out (case comp of
Str => "structure"
| Val id => "value; " ^ tt str
| Typ id => "type; " ^ tt str
| Exc id => "exception; " ^ tt str
| Con id => "constructor; " ^ tt str);
nextstr comp erest)
end
fun prentries [] = ()
| prentries (e1 :: erest) = newitem e1 erest
fun prtree Empty = ()
| prtree (Node(key, entries, t1, t2)) =
(prtree t1;
prentries entries;
prtree t2)
in
out "
begindescription
small";
prtree db;
out "
enddescription";
TextIO.closeOut os
end