From 183851b06bd6c52f3cae5375f433da720d410447 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 11 Oct 2006 18:12:39 +0000 Subject: MediaWiki 1.7.1 wiederhergestellt --- math/texvc_cgi.ml | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 math/texvc_cgi.ml (limited to 'math/texvc_cgi.ml') diff --git a/math/texvc_cgi.ml b/math/texvc_cgi.ml new file mode 100644 index 00000000..2e6079fe --- /dev/null +++ b/math/texvc_cgi.ml @@ -0,0 +1,62 @@ +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 -- cgit v1.2.3-54-g00ecf