structure Web :> WEB =
struct
- val params : string StringMap.map ref = ref StringMap.empty
+ fun for f (r1, r2) =
+ if r1 < r2 then
+ let
+ fun loop i =
+ if i > r2 then
+ ()
+ else
+ (f i;
+ loop (i+1))
+ in
+ loop r1
+ end
+ else
+ let
+ fun loop i =
+ if i < r2 then
+ ()
+ else
+ (f i;
+ loop (i-1))
+ in
+ loop r1
+ end
- val paramStack : string StringMap.map list ref = ref []
+ val params : string list StringMap.map ref = ref StringMap.empty
+
+ val paramStack : string list StringMap.map list ref = ref []
fun setParam (n, v) = params := StringMap.insert (!params, n, v)
+ fun setSingleParam (n, v) = setParam (n, [v])
fun getParam v =
(case StringMap.find (!params, v) of
NONE => ""
- | SOME s => s)
+ | SOME [] => ""
+ | SOME (s::_) => s)
+
+ fun getMultiParam v =
+ (case StringMap.find (!params, v) of
+ NONE => []
+ | SOME l => l)
fun pushParams nvs =
(paramStack := (!params) :: (!paramStack);
fun output () =
(TextIO.print "Status: 200\nContent-type: text/html\n\n";
TextIO.print (String.concat (List.rev (!text))))
+
+ val getCgi = OS.Process.getEnv
+
+ fun html s =
+ let
+ fun xch #"<" = "<"
+ | xch #">" = ">"
+ | xch #"&" = "&"
+ | xch #"\"" = """
+ | xch ch = str ch
+ in
+ foldr op^ "" (map xch (String.explode s))
+ end
+
+ fun htmlNl s =
+ let
+ fun xch #"<" = "<"
+ | xch #">" = ">"
+ | xch #"&" = "&"
+ | xch #"\"" = """
+ | xch #"\n" = "<br />"
+ | xch ch = str ch
+ in
+ foldr op^ "" (map xch (String.explode s))
+ end
+
+ exception Format of string
+
+ fun stoiOpt s = Int.fromString s
+ fun stoi s =
+ (case Int.fromString s of
+ NONE => raise Format s
+ | SOME i => i)
+
+ fun storOpt s = Real.fromString s
+ fun stor s =
+ (case Real.fromString s of
+ NONE => raise Format s
+ | SOME r => r)
+
+ fun summary () =
+ StringMap.foldli (fn (n, vs, s) => foldl (fn (v, s) => s ^ " VALUE: " ^ v) (s ^ " NAME: " ^ n) vs)
+ "" (!params)
end
\ No newline at end of file