Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/util/envcfg.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/util/envcfg.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 433 - (view) (download)

1 : blume 354 (*
2 :     * Mechanism for shell-environment configurable parameters.
3 :     *
4 :     * Copyright (c) 1999 by Lucent Technologies, Bell Laboratories.
5 :     *
6 :     * author: Matthias Blume (blume@cs.princeton.edu)
7 :     *)
8 :     signature ENVCONFIG = sig
9 :    
10 : blume 433 val new :
11 :     (string -> 'a option) ->
12 :     string * 'a ->
13 :     { get: unit -> 'a, set: 'a -> unit }
14 : blume 354
15 :     val init : unit -> unit
16 :     end
17 :    
18 :     structure EnvConfig :> ENVCONFIG = struct
19 :    
20 :     fun cfg cvt reg session0 fallback = let
21 :     val session = "CM_" ^ session0
22 :     val default = session ^ "_DEFAULT"
23 :     val getEnv = Option.join o (Option.map cvt) o OS.Process.getEnv
24 :     val r = ref (getOpt (getEnv default, fallback))
25 : blume 433 fun get () = !r
26 :     fun set new = r := new
27 :     val reg = fn () => (reg ();
28 :     case getEnv session of
29 :     NONE => ()
30 :     | SOME x => set x)
31 : blume 354 in
32 : blume 433 ({ get = get, set = set }, reg)
33 : blume 354 end
34 :    
35 :     val chain = ref (fn () => ())
36 :    
37 :     fun new cvt (session0, fallback) = let
38 : blume 433 val (getset, newChain) = cfg cvt (!chain) session0 fallback
39 : blume 354 in
40 :     chain := newChain;
41 : blume 433 getset
42 : blume 354 end
43 :    
44 :     fun init () = !chain ()
45 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0