10 |
|
|
11 |
type mode |
type mode |
12 |
|
|
13 |
val hardwire : (string * string) list -> mode |
val new : unit -> mode |
14 |
val envcfg : (string * string EnvConfig.getterSetter) list -> mode |
val set : mode * string * string -> unit |
|
val bootcfg : string -> mode |
|
15 |
|
|
16 |
val configAnchor : mode -> string -> (unit -> string) option |
val configAnchor : mode -> string -> (unit -> string) option |
17 |
|
|
18 |
|
val processSpecFile : mode * string -> unit |
19 |
end |
end |
20 |
|
|
21 |
(* |
(* |
25 |
*) |
*) |
26 |
structure PathConfig :> PATHCONFIG = struct |
structure PathConfig :> PATHCONFIG = struct |
27 |
|
|
28 |
type mode = string -> (unit -> string) option |
type mode = string StringMap.map ref |
29 |
|
|
30 |
|
fun set (m, a, s) = m := StringMap.insert (!m, a, s) |
31 |
|
|
32 |
|
fun new () = ref (StringMap.empty) |
33 |
|
|
34 |
fun hardwire [] (a: string) = NONE |
fun configAnchor m s = |
35 |
| hardwire ((a', v) :: t) a = |
case StringMap.find (!m, s) of |
36 |
if a = a' then SOME (fn () => v) else hardwire t a |
NONE => NONE |
37 |
|
| SOME _ => SOME (fn () => valOf (StringMap.find (!m, s))) |
38 |
fun envcfg [] (a: string) = NONE |
|
39 |
| envcfg ((a', gs) :: t) a = |
fun processSpecFile (m, f) = let |
40 |
if a = a' then SOME (fn () => EnvConfig.getSet gs NONE) |
fun work s = let |
41 |
else envcfg t a |
fun loop () = let |
42 |
|
val line = TextIO.inputLine s |
|
fun bootcfg bootdir a = let |
|
|
fun isDir x = OS.FileSys.isDir x handle _ => false |
|
|
val d = OS.Path.concat (bootdir, a) |
|
43 |
in |
in |
44 |
if isDir d then SOME (fn () => d) else NONE |
if line = "" then () |
45 |
|
else case String.tokens Char.isSpace line of |
46 |
|
[a, d] => (set (m, a, d); |
47 |
|
Say.vsay ["PathConfig: ", a, " -> ", d, "\n"]; |
48 |
|
loop ()) |
49 |
|
| _ => (Say.say [f, ": malformed line (ignored)\n"]; |
50 |
|
loop ()) |
51 |
|
end |
52 |
|
in |
53 |
|
loop () |
54 |
|
end |
55 |
|
in |
56 |
|
SafeIO.perform { openIt = fn () => TextIO.openIn f, |
57 |
|
closeIt = TextIO.closeIn, |
58 |
|
work = work, |
59 |
|
cleanup = fn () => () } |
60 |
end |
end |
|
|
|
|
fun configAnchor m s = m s |
|
61 |
end |
end |