1 structure Util
:> UTIL
=
4 datatype 'a flat_element
=
8 type 'a flat_tree
= 'a flat_element list
11 Web
.print (if n
< 0 then
12 "-" ^
Int.toString (~n
)
17 Web
.print (if n
< 0.0 then
18 "-" ^
Real.fmt (StringCvt.FIX (SOME
2)) (~n
)
20 Real.fmt (StringCvt.FIX (SOME
2)) n
)
27 |
[usr
] => "(" ^ f usr ^
")"
28 | usr
::rest
=> foldl (fn (usr
, s
) => s ^
", " ^ f usr
) ("(" ^ f usr
) rest ^
")"
30 fun neg (r
: real) = ~r
31 fun add (r1
: real, r2
) = r1
+ r2
33 fun isIdent ch
= Char.isLower ch
orelse Char.isDigit ch
36 size s
> 0 andalso size s
< 20 andalso List.all
isIdent (String.explode s
)
39 size s
> 0 andalso size s
< 100 andalso List.all
validHost (String.fields (fn ch
=> ch
= #
".") s
)
42 size s
> 0 andalso size s
< 50 andalso List.all
43 (fn ch
=> isIdent ch
orelse ch
= #
"." orelse ch
= #
"_" orelse ch
= #
"-" orelse ch
= #
"+")
46 fun validEmailUser s
=
47 size s
> 0 andalso size s
< 50 andalso List.all
48 (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"_" orelse ch
= #
"-" orelse ch
= #
"+")
52 (case String.fields (fn ch
=> ch
= #
"@") s
of
53 [user
, host
] => validEmailUser user
andalso validDomain host
56 fun whoisUrl dom
= String.concat
["http://reports.internic.net/cgi/whois?whois_nic=", dom
, "&type=domain"]
58 val rnd
= ref (Random
.rand (0, 0))
60 fun init () = rnd
:= Random
.rand (SysWord
.toInt (Posix
.Process
.pidToWord (Posix
.ProcEnv
.getpid ())),
61 SysWord
.toInt (Posix
.Process
.pidToWord (Posix
.ProcEnv
.getpid ())))
63 fun randomPassword () = Int.toString (Int.abs (Random
.randInt (!rnd
)))