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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
(***********************************************************************)
(* *)
(* HEVEA *)
(* *)
(* Luc Maranget, projet PARA, INRIA Rocquencourt *)
(* *)
(* Copyright 1998 Institut National de Recherche en Informatique et *)
(* Automatique. Distributed only by permission. *)
(* *)
(***********************************************************************)
type input = File of string | Prog of string
let files = ref []
let add_input s = files := File s :: !files
and add_program s = files := Prog s :: !files
(* use this to create your warnings if you wish to *)
let frenchwarning = ref false
type destination = Html | Text | Info
let mathml = ref false
(*to activate advanced entities*)
let moreentities = ref false
(* NO NEED AFTER BABEL SUPPORT *)
(*let language = ref English*)
type symbol_mode = SText | Symbol | Entity
let symbol_mode = ref Entity
and pedantic = ref false
and destination = ref Html
and fixpoint = ref false
and optimize = ref false
let default_width = 72
and default_small_length = 1024
let width = ref default_width
and except = ref []
and path = ref []
and outname = ref ""
and small_length = ref default_small_length
let check_displayverb n =
if n > 1 then
Misc.displayverb := true
let () =
let usage =
"Usage: hevea [OPTION...] [HVA-FILE...|LATEX-FILE...]\n\
\n\
Consult all HVA-FILEs and LATEX-FILEs; designate last LATEX-FILE\n\
as main-input file and translate it to HTML. If no file is given\n\
or the last file is not a LATEX-FILE work in filter mode: read\n\
LaTeX-source from standard input and write to standard output.\n\
\n\
Options `-info' or `-text' switch the output format to GNU Info\n\
or plain text.\n\
\n\
Options:"
and spec =
["-I", Arg.String (fun s -> path := s :: !path),
"DIR prepend directory DIR to search path";
"-e", Arg.String (fun s -> except := s :: !except),
"FILE exclude FILE from being processed";
"-fix", Arg.Set fixpoint,
" iterate Hevea until reaching a fixpoint";
"-info", Arg.Unit (fun () -> symbol_mode := SText; destination := Info),
" output GNU Info file(s)";
"-text", Arg.Unit (fun () -> symbol_mode := SText; destination := Text),
" output plain text";
"-o", Arg.Set_string outname,
"FILE redirect Hevea output to FILE";
"-s", Arg.Set Misc.silent,
" suppress warnings";
"-w", Arg.String (fun s -> width := int_of_string s),
(Printf.sprintf "WIDTH set the output WIDTH (default: %i) for text or Info output" default_width);
"-O", Arg.Set optimize,
" call Esponja to optimize the HTML output of Hevea";
"-exec", Arg.String add_program,
"PROG execute external program PROG, then read its result";
"-entities", Arg.Unit (fun () -> symbol_mode := Entity),
" render symbols by using entities (default)";
"-francais", Arg.Set frenchwarning,
" French mode (deprecated)";
"-noiso", Arg.Unit (fun () -> Misc.warning "-noiso is deprecated, by default hevea output is ASCII"),
" deprecated, does nothing";
"-mathml", Arg.Set mathml,
" generate MathML output for equations; VERY EXPERIMENTAL";
"-moreentities", Arg.Set moreentities,
" enable the output of some rare entities";
"-pedantic", Arg.Set pedantic,
" be pedantic in interpreting HTML 4.0 transitional";
"-textsymbols", Arg.Unit (fun () -> symbol_mode := SText),
" render symbols by English text";
"-dv", Arg.Set Misc.displayverb,
" add borders to some block-level elements";
"-rsz", Arg.Set_int small_length,
(Printf.sprintf "SIZE set SIZE (default: %i) of leaves in rope implementation" default_small_length);
"-v", Arg.Unit (fun () -> incr Misc.readverb; check_displayverb !Misc.readverb),
" verbose flag; repeat to increase verbosity";
"-version",
Arg.Unit
(fun () ->
print_endline ("hevea " ^ Version.version);
print_endline ("library directory: " ^ Mylib.static_libdir);
exit 0),
" output version information, library directory and exit"]
in
Arg.parse (Arg.align spec) add_input usage
let warning s =
if not !Misc.silent || !Misc.verbose > 0 then
begin
Location.print_pos ();
prerr_string "Warning: ";
prerr_endline s
end
(* For correcting strange user (-exec prog en dernier) *)
let rec ffirst = function
| [] -> None, []
| Prog _ as arg :: rem ->
let file, rest = ffirst rem in
file, arg :: rest
| File _ as arg :: rem ->
Some arg, rem
;;
files :=
match ffirst !files with
| None, rem -> rem
| Some arg, rem -> arg :: rem
let base_in, name_in, styles =
match !files with
| File x :: rest ->
if Filename.check_suffix x ".hva" then
"", "", !files
else
let base_file = Filename.basename x in
begin
try
let base =
if Filename.check_suffix base_file ".tex" then
Filename.chop_extension base_file
else
base_file in
base,x,rest
with Invalid_argument _ -> base_file, x, rest
end
| [] | Prog _ :: _ -> "", "", !files
let filter = match base_in with "" -> true | _ -> false
;;
if filter then
begin
if !fixpoint then
Misc.warning ("No fixpoint in filter mode");
fixpoint := false
end
let base_out =
match !outname with
| "" ->
begin
match base_in with
| "" -> ""
| _ -> Filename.basename base_in
end
| name ->
let suff =
match !destination with
| Html -> ".html"
| Text -> ".txt"
| Info -> ".info"
in
if Filename.check_suffix name suff then
Filename.chop_suffix name suff
else
try Filename.chop_extension name
with Invalid_argument _ -> name
let name_out =
match !outname with
| "" ->
begin
match base_in with
| "" -> ""
| x ->
begin
match !destination with
| Html ->x ^ ".html"
| Text ->x ^ ".txt"
| Info ->x ^ ".info"
end
end
| x -> x
let () =
if !frenchwarning then
warning "-francais option is deprecated, use babel instead"
|