Added direction to ResourceLoaderContext hashing (prevents cache mangling), dropped...
[lhc/web/wiklou.git] / math / texvc.ml
1 exception LexerException of string
2 let lexer_token_safe lexbuf =
3 try Lexer.token lexbuf
4 with Failure s -> raise (LexerException s)
5
6 let render tmppath finalpath tree backcolor =
7 let outtex = Util.mapjoin Texutil.render_tex tree in
8 let md5 = Digest.to_hex (Digest.string outtex) in
9 begin
10 let mathml = Mathml.render tree
11 and html = Html.render tree
12 in print_string (match (html,!Html.conservativeness,mathml) with
13 None,_,None -> "+" ^ md5
14 | Some h,Html.CONSERVATIVE,None -> "c" ^ md5 ^ h
15 | Some h,Html.MODERATE,None -> "m" ^ md5 ^ h
16 | Some h,Html.LIBERAL,None -> "l" ^ md5 ^ h
17 | Some h,Html.CONSERVATIVE,Some m -> "C" ^ md5 ^ h ^ "\000" ^ m
18 | Some h,Html.MODERATE,Some m -> "M" ^ md5 ^ h ^ "\000" ^ m
19 | Some h,Html.LIBERAL,Some m -> "L" ^ md5 ^ h ^ "\000" ^ m
20 | None,_,Some m -> "X" ^ md5 ^ m
21 );
22 Render.render tmppath finalpath outtex md5 backcolor
23 end
24 let _ =
25 Texutil.set_encoding (try Sys.argv.(4) with _ -> "UTF-8");
26 try render Sys.argv.(1) Sys.argv.(2) (Parser.tex_expr lexer_token_safe (Lexing.from_string Sys.argv.(3))) (try Sys.argv.(5) with _ -> "rgb 1.0 1.0 1.0")
27 with Parsing.Parse_error -> print_string "S"
28 | LexerException _ -> print_string "E"
29 | Texutil.Illegal_tex_function s -> print_string ("F" ^ s)
30 | Util.FileAlreadyExists -> print_string "-"
31 | Invalid_argument _ -> print_string "-"
32 | Failure _ -> print_string "-"
33 | Render.ExternalCommandFailure s -> ()
34 | _ -> print_string "-"