open Netcgi;; open Netcgi_types;; open Netcgi_env;; open Netchannels;; let cgi = new Netcgi.std_activation () let out = cgi # output # output_string let math = cgi # argument_value ~default:"" "math" let tmppath = "/home/taw/public_html/wiki/tmp/" let finalpath = "/home/taw/public_html/wiki/math/" let finalurl = "http://wroclaw.taw.pl.eu.org/~taw/wiki/math/" ;; let h_header = "\n"^ "texvc"^ "
"^ "
" let h_footer = "\n" let render tmppath finalpath tree = let outtex = Texutil.mapjoin Texutil.print tree in let md5 = Digest.to_hex (Digest.string outtex) in begin out "

TeX

"; out outtex; (* <, & and > should be protected *) (try out ("

HTML

" ^ (Texutil.html_render tree)) with _ -> out "

HTML could not be rendered

"); try Render.render tmppath finalpath outtex md5; out ("

Image:

") with Util.FileAlreadyExists -> out ("

Image:

") | Failure s -> out ("

Other failure: " ^ s ^ "

") | Render.ExternalCommandFailure "latex" -> out "

latex failed

" | Render.ExternalCommandFailure "dvips" -> out "

dvips failed

" | _ -> out "

Other failure

" end ;; cgi#set_header ();; out h_header;; out math;; out h_middle;; exception LexerException of string let lexer_token_safe lexbuf = try Lexer.token lexbuf with Failure s -> raise (LexerException s) ;; if math = "" then () else try render tmppath finalpath (Parser.tex_expr lexer_token_safe (Lexing.from_string math)) with Parsing.Parse_error -> out "

Parse error

" | LexerException s -> out "

Lexing failure

" | Texutil.Illegal_tex_function s -> out ("

Illegal TeX function: " ^ s ^ "

") | Failure s -> out ("

Other failure: " ^ s ^ "

") | _ -> out "

Other failure

" ;; out h_footer