Fix initialization SQL
[hcoop/zz_old/portal.git] / util.sml
CommitLineData
8d347a33 1structure Util :> UTIL =
2struct
3
51520441 4datatype 'a flat_element =
5 BEGIN
6 | END
7 | ITEM of 'a
8type 'a flat_tree = 'a flat_element list
9
8d347a33 10fun printInt n =
11 Web.print (if n < 0 then
12 "-" ^ Int.toString (~n)
13 else
14 Int.toString n)
15
16fun printReal n =
17 Web.print (if n < 0.0 then
18 "-" ^ Real.fmt (StringCvt.FIX (SOME 2)) (~n)
19 else
20 Real.fmt (StringCvt.FIX (SOME 2)) n)
21
22fun id x = x
23
24fun makeSet f items =
25 case items of
26 [] => "()"
27 | [usr] => "(" ^ f usr ^ ")"
28 | usr::rest => foldl (fn (usr, s) => s ^ ", " ^ f usr) ("(" ^ f usr) rest ^ ")"
29
f1ea3762 30fun neg (r : real) = ~r
31
ff2b7604 32fun isIdent ch = Char.isLower ch orelse Char.isDigit ch
33
34fun validHost s =
35 size s > 0 andalso size s < 20 andalso List.all isIdent (String.explode s)
36
37fun validDomain s =
38 size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s)
39
78304862 40fun validUser s =
41 size s > 0 andalso size s < 50 andalso List.all
42 (fn ch => isIdent ch orelse ch = #"." orelse ch = #"_" orelse ch = #"-" orelse ch = #"+")
43 (String.explode s)
44
45fun validEmailUser s =
46 size s > 0 andalso size s < 50 andalso List.all
47 (fn ch => Char.isAlphaNum ch orelse ch = #"." orelse ch = #"_" orelse ch = #"-" orelse ch = #"+")
48 (String.explode s)
49
50fun validEmail s =
51 (case String.fields (fn ch => ch = #"@") s of
52 [user, host] => validEmailUser user andalso validDomain host
53 | _ => false)
54
ff2b7604 55fun whoisUrl dom = String.concat ["http://reports.internic.net/cgi/whois?whois_nic=", dom, "&type=domain"]
56
78304862 57val rnd = ref (Random.rand (0, 0))
58
59fun init () = rnd := Random.rand (SysWord.toInt (Posix.Process.pidToWord (Posix.ProcEnv.getpid ())),
60 SysWord.toInt (Posix.Process.pidToWord (Posix.ProcEnv.getpid ())))
61
62fun randomPassword () = Int.toString (Int.abs (Random.randInt (!rnd)))
63
8d347a33 64end