texvc.ml 1.4 KB

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