X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Fmatita%2Fcontribs%2Flambdadelta%2Fbin%2Froles%2FwebLWS.ml;fp=matita%2Fmatita%2Fcontribs%2Flambdadelta%2Fbin%2Froles%2FwebLWS.ml;h=89dbfb5d2747cd316633b1c9e54e4fbf0e5cc310;hb=cfccf434a57e10848d74d06674af4ec9cef0f0ca;hp=0000000000000000000000000000000000000000;hpb=7666f9dddfcaca5671dd25d3cd2095481968c7bf;p=helm.git diff --git a/matita/matita/contribs/lambdadelta/bin/roles/webLWS.ml b/matita/matita/contribs/lambdadelta/bin/roles/webLWS.ml new file mode 100644 index 000000000..89dbfb5d2 --- /dev/null +++ b/matita/matita/contribs/lambdadelta/bin/roles/webLWS.ml @@ -0,0 +1,88 @@ +(* + ||M|| This file is part of HELM, an Hypertextual, Electronic + ||A|| Library of Mathematics, developed at the Computer Science + ||T|| Department, University of Bologna, Italy. + ||I|| + ||T|| HELM is free software; you can redistribute it and/or + ||A|| modify it under the terms of the GNU General Public License + \ / version 2 or (at your option) any later version. + \ / This software is distributed as is, NO WARRANTY. + V_______________________________________________________________ *) + +module KL = List +module KP = Printf +module KR = Random +module KT = String + +type request = (string * string) list * string + +(* internals *) + +let opt_map = function + | opt, "" -> opt + | opt, arg -> KP.sprintf "%s=%s" opt arg + +let get_random () = + KP.sprintf "%08X" (KR.bits ()) + +(* interface *) + +let open_out enc len = + KP.printf "%s %u\n" enc len + +let close_out () = + KP.printf "\x04" + +let loop_in context handler eot st = + let read () = KT.trim (read_line ()) in + let rec aux st = + let opt = read () in + let arg = read () in + match opt with + | "control-stop" -> st + | "control-random" -> aux st + | "control-context" -> aux (context st) + | "control-eot" -> aux (eot st) + | _ -> + let st = handler opt arg st in + aux st + in + aux st + +let string_of_request cx (opts, fi) = + let str = + if opts = [] then "" else + let opts = ("control-random", get_random ()) :: opts in + let str = KT.concat "&" (KL.map opt_map opts) in + KP.sprintf "/%s?%s" cx str + in + KP.sprintf "%s#%s" str fi + +let control_input form = + KP.printf "" + form "control-random" (get_random ()) + +let open_out_html author description title css icon = + open_out "application/xhtml+xml" 0; + KP.printf "\n"; + KP.printf "\n"; + KP.printf "\n"; + KP.printf "\n"; + KP.printf " \n"; + KP.printf " \n"; + KP.printf " \n"; + KP.printf " \n"; + KP.printf " \n"; + KP.printf " \n"; + KP.printf " \n" author; + KP.printf " \n" description; + KP.printf " %s" title; + KP.printf " \n" css; + KP.printf " \n" icon; + KP.printf "\n"; + KP.printf "\n" + +let close_out_html () = + KP.printf "\n"; + KP.printf "\n"; + close_out ()