1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (** Configuration repository for HELM applications.
31 * path ::= component ( '.' component )*
32 * component ::= ( alpha | num | '_' )+
33 * # with the only exception that sequences of '_' longer than 1 aren't valid
36 * Suggested usage <application>.<setting>:
37 * e.g. gTopLevel.prooffile, http_getter.port, ...
39 * ++ Configuration file example ++
41 * gTopLevel.prooffile = "/home/zack/prooffile"
42 * http_getter.port = "58080"
44 * ++ Environment variable override ++
46 * each key has an associated environment variable name. At runtime (i.e. when
47 * "get" requests are performed) a variable with this name will be looked for,
48 * if it's defined it will override the value present (or absent) in the
50 * Environment variables are _not_ considered when saving the configuration to
51 * a configuration file (via "save_to" function below) .
53 * Mapping between keys and environment variables is as follows:
54 * - each "." is converted to "__"
55 * E.g.: my.Foo_iSH.Application -> my__Foo_iSH__Application
57 * ++ Variable interpolation ++
59 * Interpolation is supported with the following syntax:
62 * foo.baz = $(foo.bar)/baz
65 (** raised when a looked up key can't be found
66 * @param key looked up key *)
67 exception Key_not_found of string
69 (** raised when a cyclic definitions is found, e.g. after
70 * Helm_registry.set "a" "$b"
71 * Helm_registry.set "b" "$a"
72 * @param msg brief description of the definition cycle *)
73 exception Cyclic_definition of string
75 (** raised when a looked up key doesn't have the required type, parameter is
77 exception Type_error of string
79 (** raised when a malformed key is encountered
80 * @param key malformed key *)
81 exception Malformed_key of string
83 (** raised when an error is encountered while parsing a configuration file
84 * @param fname file name
85 * @param line line number
86 * @param col column number
87 * @param msg error description
89 exception Parse_error of string * int * int * string
91 (** {2 Generic untyped interface}
92 * Using the functions below this module could be used as a repository of
95 (** lookup key in registry with environment variable override *)
96 val get: string -> string
97 val set: key:string -> value:string -> unit
98 val has: string -> bool
100 (** remove a key from the current environment, next get over this key will
101 * raise Key_not_found until the key will be redefined *)
102 val unset: string -> unit
104 (** @param interpolate defaults to true *)
106 ?prefix:string -> ?interpolate:bool ->
107 ('a -> string -> string -> 'a) -> 'a -> 'a
109 (** @param interpolate defaults to true *)
111 ?prefix:string -> ?interpolate:bool ->
112 (string -> string -> unit) -> unit
114 (** @param interpolate defaults to true *)
116 ?prefix:string -> ?interpolate:bool ->
117 unit -> (string * string) list
119 (** @param prefix key representing the section whose contents should be listed
120 * @return section list * key list *)
121 val ls: string -> string list * string list
123 (** {2 Typed interface}
124 * Three basic types are supported: strings, int and strings list. Strings
125 * correspond literally to what is written inside double quotes; int to the
126 * parsing of an integer number from ; strings list to the splitting at blanks
127 * of it (heading and trailing blanks are removed before splitting) *)
129 (** {3 Unmarshallers} *)
131 val string: string -> string
132 val int: string -> int
133 val float: string -> float
134 val bool: string -> bool
135 val pair: (string -> 'a) -> (string -> 'b) -> string -> 'a * 'b
137 (** {3 Typed getters} *)
139 (** like get, with an additional unmarshaller
140 * @param unmarshaller conversion function from string to the desired type.
141 * Use one of the above unmarshallers *)
142 val get_typed: (string -> 'a) -> string -> 'a
144 val get_opt: (string -> 'a) -> string -> 'a option
145 val get_opt_default: (string -> 'a) -> default:'a -> string -> 'a
147 (** never fails with Key_not_found, instead return the empty list *)
148 val get_list: (string -> 'a) -> string -> 'a list
150 (** decode values which are blank separated list of values, of length 2 *)
151 val get_pair: (string -> 'a) -> (string -> 'b) -> string -> 'a * 'b
153 (** {4 Shorthands} *)
155 val get_string: string -> string
156 val get_int: string -> int
157 val get_float: string -> float
158 val get_bool: string -> bool
160 (** {3 Marshallers} *)
162 val of_string: string -> string
163 val of_int: int -> string
164 val of_float: float -> string
165 val of_bool: bool -> string
167 (** {3 Typed setters} *)
169 (** like set, with an additional marshaller
170 * @param marshaller conversion function to string.
171 * Use one of the above marshallers *)
172 val set_typed: ('a -> string) -> key:string -> value:'a -> unit
174 val set_opt: ('a -> string) -> key:string -> value:'a option -> unit
175 val set_list: ('a -> string) -> key:string -> value:'a list -> unit
177 (** {4 Shorthands} *)
179 val set_string: key:string -> value:string -> unit
180 val set_int: key:string -> value:int -> unit
181 val set_float: key:string -> value:float -> unit
182 val set_bool: key:string -> value:bool -> unit
184 (** {2 Persistent configuration} *)
186 (** @param fname file to which save current configuration *)
187 val save_to: string -> unit
189 (** @param fname file from which load new configuration. If it's an absolute
190 * file name "path" argument is ignored.
191 * Otherwise given file name is looked up in each directory member of the
192 * given path. Each matching file is loaded overriding previous settings. If
193 * no path is given a default path composed of just the current working
196 val load_from: ?path:string list -> string -> unit
198 (** removes all keys *)
199 val clear: unit -> unit