Initial revision
[hcoop/zz_old/domtool.git] / src / util.sig
1 (*
2 Domtool (http://hcoop.sf.net/)
3 Copyright (C) 2004 Adam Chlipala
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *)
19
20 (* Utility functions *)
21
22 signature UTIL =
23 sig
24 val impLoop : (unit -> 'a) -> ('a -> bool) -> ('a * 'b -> 'b) -> 'b -> unit
25 (* (impLoop next stop body init) repeatedly executes next until stop returns
26 * true on the result. Running state is kept in the style of foldl, with
27 * the state for the next iteration being determiend by calling body with
28 * the most recent next return and the current state.
29 *)
30
31 val ioLoop : (unit -> string) -> (string * 'b -> 'b) -> 'b -> unit
32 (* impLoop specialized to work with TextIO.inputLine, where a return of ""
33 * indicates end-of-file.
34 *)
35 val ioOptLoop : (unit -> string option) -> (string * 'b -> 'b) -> 'b -> unit
36 (* Like ioLoop, but with NONE as sentinel value. *)
37
38 val isIdent : char -> bool
39 (* Is the character a valid part of an identifier? (lowercase letter or
40 * digit?
41 *)
42
43 val validHost : string -> bool
44 (* Valid Internet hostname with no periods? *)
45 val validDomain : string -> bool
46 (* Valid domain name? *)
47 val validUser : string -> bool
48 (* Valid UNIX username? *)
49 val validEmail : string -> bool
50 (* Valid e-mail address? *)
51 val isTmp : string -> bool
52 (* Is the name of a temporary file generated by an editor? *)
53 val validIp : string -> bool
54 (* Is a valid IPv4 address? *)
55
56 val trimLast : string -> string
57 (* Remove the last character from a string *)
58
59 val toDir : string -> string
60 (* Translates a domain name into a fileystem path *)
61
62 val checkPath : StringSet.set * string -> bool
63 (* Given a set of valid path bases and a path, is it allowable? *)
64 val resolveAddr : string StringMap.map * string -> string
65 (* Determine the value of an address field that may include variables.
66 * Check that the final result is a validIp. *)
67 val resolveDomain : string StringMap.map * string -> string
68 (* Determine the value of a domain field that may include variables.
69 * Check that the final result is a validDomain. *)
70 end