2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
17 type request = (string * string) list * string
21 let opt_map = function
23 | opt, arg -> KP.sprintf "%s=%s" opt arg
26 KP.sprintf "%08X" (KR.bits ())
30 let open_out enc len =
31 KP.printf "%s %u\n" enc len
36 let loop_in context handler eot st =
37 let read () = KT.trim (read_line ()) in
42 | "control-stop" -> st
43 | "control-random" -> aux st
44 | "control-context" -> aux (context st)
45 | "control-eot" -> aux (eot st)
47 let st = handler opt arg st in
52 let string_of_request cx (opts, fi) =
54 if opts = [] then "" else
55 let opts = ("control-random", get_random ()) :: opts in
56 let str = KT.concat "&" (KL.map opt_map opts) in
57 KP.sprintf "/%s?%s" cx str
59 let fi = if fi = "" then "" else "#" ^ fi in
60 KP.sprintf "%s%s" str fi
62 let control_input form =
63 KP.printf "<input form=\"%s\" type=\"hidden\" name=\"%s\" value=\"%s\"/>"
64 form "control-random" (get_random ())
66 let open_out_html author description title icon css js =
67 open_out "application/xhtml+xml" 0;
68 KP.printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
69 KP.printf "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
70 KP.printf "<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-us\">\n";
72 KP.printf " <meta http-equiv=\"Pragma\" content=\"no-cache\"/>\n";
73 KP.printf " <meta http-equiv=\"Expires\" content=\"-1\"/>\n";
74 KP.printf " <meta http-equiv=\"CACHE-CONTROL\" content=\"NO-CACHE\"/>\n";
75 KP.printf " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n";
76 KP.printf " <meta http-equiv=\"Content-Language\" content=\"en-us\"/>\n";
77 KP.printf " <meta http-equiv=\"Content-Style-Type\" content=\"text/css\"/>\n";
78 KP.printf " <meta http-equiv=\"content-script-type\" content=\"text/javascript\"/>\n";
79 KP.printf " <meta name=\"author\" content=\"%s\"/>\n" author;
80 KP.printf " <meta name=\"description\" content=\"%s\"/>\n" description;
81 KP.printf " <title>%s</title>" title;
82 KP.printf " <link rel=\"shortcut icon\" href=\"%s\"/>\n" icon;
83 KP.printf " <link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n" css;
84 KP.printf "</head>\n";
85 KP.printf "<body lang=\"en-US\">\n";
86 KP.printf "<script type=\"text/javascript\" src=\"%s\"/>\n" js
88 let close_out_html () =
89 KP.printf "</body>\n";
90 KP.printf "</html>\n";