1(* Outputting the help signature database in ASCII, LaTeX and HTML format *) 2structure Printbase = struct 3 4fun printASCIIBase(sigfile, outfile) = 5 let fun prtseq (pr, sep) [] = "" 6 | prtseq (pr, sep) [x] = pr x 7 | prtseq (pr, sep) (x::xs) = pr x ^ sep ^ prtseq(pr, sep) xs 8 9 open Database 10 val db = readbase sigfile 11 val os = TextIO.openOut outfile 12 fun out s = TextIO.output(os, s) 13 fun prentry {comp, file, line} = 14 let fun mkitem0 id = 15 concat[id, " (", file, " ", Int.toString line, ")"] 16 fun mkitem1 kind id = 17 concat[kind, " ", id, " (", file, " ", Int.toString line, ")"] 18 in 19 case comp of 20 Str => "structure " ^ file 21 | Exc id => mkitem1 "exception" id 22 | Typ id => mkitem1 "type" id 23 | Val id => mkitem1 "value" id 24 | Con id => mkitem1 "constructor" id 25 | Term (id, NONE) => mkitem0 id 26 | Term (id, SOME kind) => mkitem1 kind id 27 end 28 fun prtree Empty = () 29 | prtree (Node(key, entries, t1, t2)) = 30 (prtree t1; 31 out (prtseq (prentry, ", ") entries); 32 out "\n"; 33 prtree t2) 34 in prtree db; TextIO.closeOut os end 35 36fun printLatexBase(sigfile, outfile) = 37 let open Database 38 val db = readbase sigfile 39 val os = TextIO.openOut outfile 40 fun out s = TextIO.output(os, s) 41 fun tt s = "\\verb\"" ^ s ^ "\"" 42 43 (* Insert extra vertical space when meeting a new initial letter *) 44 val lastc1 = ref #" " 45 fun separator k1 = 46 let val c1 = Char.toLower k1 47 in 48 if Char.isAlpha c1 andalso c1 <> !lastc1 then 49 (lastc1 := c1; 50 out "\\\\[2ex]\n\n") 51 else () 52 end 53 fun nextstr last [] = out ")\n" 54 | nextstr last ((e1 as {comp, file, ...}) :: erest) = 55 if comp = last then 56 (out ", "; out (tt file); nextstr last erest) 57 else 58 (out ")\n"; newitem e1 erest) 59 and newitem (e1 as {comp, file, ...}) erest = 60 let val key = Database.getname e1 61 in 62 (separator (String.sub(key, 0)); 63 out "\\item[] "; out (tt key); out " ("; 64 out (case comp of 65 Str => "structure" 66 | Val id => "value; " ^ tt file 67 | Typ id => "type; " ^ tt file 68 | Exc id => "exception; " ^ tt file 69 | Con id => "constructor; " ^ tt file 70 | Term (id, NONE) => "" 71 | Term (id, SOME kind) => kind ^ "; "); 72 nextstr comp erest) 73 end 74 fun prentries [] = () 75 | prentries (e1 :: erest) = newitem e1 erest 76 fun prtree Empty = () 77 | prtree (Node(key, entries, t1, t2)) = 78 (prtree t1; 79 prentries entries; 80 prtree t2) 81 in 82 out "\\begin{description}\\small\n"; 83 prtree db; 84 out "\\end{description}\n"; 85 TextIO.closeOut os 86 end 87end 88