| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Printf |
| 12 |
open Common |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
let banner () = |
| 20 |
eprintf "This is coqdoc version %s\n" Coq_config.version; |
| 21 |
flush stderr |
| 22 |
|
| 23 |
let target_full_name f = |
| 24 |
match !prefs.targetlang with |
| 25 |
| HTML -> f ^ ".html" |
| 26 |
| Raw -> f ^ ".txt" |
| 27 |
| _ -> f ^ ".tex" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
let gen_one_file l = |
| 37 |
let file = function |
| 38 |
| Vernac_file (f,m) -> |
| 39 |
let sub = if !prefs.lib_subtitles then Cpretty.detect_subtitle f m else None in |
| 40 |
Output.set_module m sub; |
| 41 |
Cpretty.coq_file f m |
| 42 |
| Latex_file _ -> () |
| 43 |
in |
| 44 |
if (!prefs.header_trailer) then Output.header (); |
| 45 |
if !prefs.toc then Output.make_toc (); |
| 46 |
List.iter file l; |
| 47 |
if !prefs.index then Output.make_index(); |
| 48 |
if (!prefs.header_trailer) then Output.trailer () |
| 49 |
|
| 50 |
let gen_mult_files l = |
| 51 |
let file = function |
| 52 |
| Vernac_file (f,m) -> |
| 53 |
let sub = if !prefs.lib_subtitles then Cpretty.detect_subtitle f m else None in |
| 54 |
let hf = target_full_name m in |
| 55 |
Output.set_module m sub; |
| 56 |
open_out_file hf; |
| 57 |
if (!prefs.header_trailer) then Output.header (); |
| 58 |
Cpretty.coq_file f m; |
| 59 |
if (!prefs.header_trailer) then Output.trailer (); |
| 60 |
close_out_file() |
| 61 |
| Latex_file _ -> () |
| 62 |
in |
| 63 |
List.iter file l; |
| 64 |
if (!prefs.index && !prefs.targetlang=HTML) then begin |
| 65 |
if (!prefs.multi_index) then Output.make_multi_index (); |
| 66 |
open_out_file (!prefs.index_name^".html"); |
| 67 |
page_title := (if !prefs.title <> "" then !prefs.title else "Index"); |
| 68 |
if (!prefs.header_trailer) then Output.header (); |
| 69 |
Output.make_index (); |
| 70 |
if (!prefs.header_trailer) then Output.trailer (); |
| 71 |
close_out_file() |
| 72 |
end; |
| 73 |
if (!prefs.toc && !prefs.targetlang=HTML) then begin |
| 74 |
open_out_file "toc.html"; |
| 75 |
page_title := (if !prefs.title <> "" then !prefs.title else "Table of contents"); |
| 76 |
if (!prefs.header_trailer) then Output.header (); |
| 77 |
if !prefs.title <> "" then printf "<h1>%s</h1>\n" !prefs.title; |
| 78 |
Output.make_toc (); |
| 79 |
if (!prefs.header_trailer) then Output.trailer (); |
| 80 |
close_out_file() |
| 81 |
end |
| 82 |
|
| 83 |
|
| 84 |
let read_glob_file vfile f = |
| 85 |
try Glob_file.read_glob vfile f |
| 86 |
with Sys_error s -> eprintf "Warning: %s (links will not be available)\n" s |
| 87 |
|
| 88 |
let read_glob_file_of = function |
| 89 |
| Vernac_file (f,_) -> |
| 90 |
read_glob_file (Some f) (Filename.chop_extension f ^ ".glob") |
| 91 |
| Latex_file _ -> () |
| 92 |
|
| 93 |
let index_module = function |
| 94 |
| Vernac_file (f,m) -> |
| 95 |
Index.add_module m |
| 96 |
| Latex_file _ -> () |
| 97 |
|
| 98 |
module E = Boot.Env |
| 99 |
|
| 100 |
let copy_style_file file = |
| 101 |
|
| 102 |
let env = E.init_with ~coqlib:!prefs.coqlib in |
| 103 |
let coqdoc = E.tool env "coqdoc" in |
| 104 |
let sty_file = E.Path.relative coqdoc file in |
| 105 |
if not (E.Path.exists sty_file) then |
| 106 |
begin |
| 107 |
let sty_file = E.Path.to_string sty_file in |
| 108 |
eprintf "coqdoc: cannot find coqdoc style file: %s\n" sty_file; |
| 109 |
exit 1 |
| 110 |
end; |
| 111 |
let sty_file_s = E.Path.to_string sty_file in |
| 112 |
let dst = coqdoc_out file in |
| 113 |
FileUtil.copy sty_file_s dst |
| 114 |
|
| 115 |
let produce_document l = |
| 116 |
if !prefs.targetlang=HTML then copy_style_file "coqdoc.css"; |
| 117 |
if !prefs.targetlang=LaTeX then copy_style_file "coqdoc.sty"; |
| 118 |
(match !prefs.glob_source with |
| 119 |
| NoGlob -> () |
| 120 |
| DotGlob -> List.iter read_glob_file_of l |
| 121 |
| GlobFile f -> read_glob_file None f); |
| 122 |
List.iter index_module l; |
| 123 |
match !prefs.out_to with |
| 124 |
| StdOut -> |
| 125 |
Common.out_channel := stdout; |
| 126 |
gen_one_file l |
| 127 |
| File f -> |
| 128 |
open_out_file f; |
| 129 |
gen_one_file l; |
| 130 |
close_out_file() |
| 131 |
| MultFiles -> |
| 132 |
gen_mult_files l |
| 133 |
|
| 134 |
let produce_output fl = |
| 135 |
if List.length !prefs.compile_targets = 0 then |
| 136 |
produce_document fl |
| 137 |
else |
| 138 |
let otypes = !prefs.compile_targets in |
| 139 |
LatexCompiler.compile ~otypes ~produce_document fl |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
let main ~prog args = |
| 145 |
CmdArgs.parse_args ~prog args; |
| 146 |
let files = List.rev !prefs.files in |
| 147 |
Index.init_coqlib_library (); |
| 148 |
if not !prefs.quiet then banner (); |
| 149 |
if files <> [] then produce_output files |