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/paths/pathconfig.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/paths/pathconfig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

1 : blume 267 (*
2 :     * Configurable path anchors for new CM.
3 :     *
4 :     * (C) 1999 Lucent Technologies, Bell Laboratories
5 :     *
6 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7 :     *)
8 :    
9 : blume 265 signature PATHCONFIG = sig
10 : blume 321
11 : blume 318 type mode
12 :    
13 : blume 361 val new : unit -> mode
14 :     val set : mode * string * string -> unit
15 : blume 368 val cancel : mode * string -> unit
16 :     val reset : mode -> unit
17 : blume 318
18 :     val configAnchor : mode -> string -> (unit -> string) option
19 : blume 361
20 :     val processSpecFile : mode * string -> unit
21 : blume 265 end
22 :    
23 : blume 309 (*
24 :     * The names of config anchors must be names of actual files.
25 :     * Function configAnchor will map the name of the anchor to
26 :     * the directory that contains the corresponding file.
27 :     *)
28 : blume 265 structure PathConfig :> PATHCONFIG = struct
29 : blume 318
30 : blume 361 type mode = string StringMap.map ref
31 : blume 318
32 : blume 405 fun set0 mkAbsolute (m, a, s) = let
33 :     val s' =
34 :     if OS.Path.isAbsolute s then s
35 :     else mkAbsolute s
36 :     in
37 :     m := (Era.newEra (); StringMap.insert (!m, a, s'))
38 :     end
39 :     fun set x = let
40 :     fun mkAbsolute rel =
41 :     OS.Path.mkAbsolute { path = rel,
42 :     relativeTo = OS.FileSys.getDir () }
43 :     in
44 :     set0 mkAbsolute x
45 :     end
46 : blume 369 fun reset m = m := (Era.newEra (); StringMap.empty)
47 :     fun cancel (m, a) =
48 :     (Era.newEra ();
49 :     (m := #1 (StringMap.remove (!m, a)))
50 :     handle LibBase.NotFound => ())
51 : blume 321
52 : blume 368 fun new () = ref StringMap.empty
53 : blume 321
54 : blume 377 fun configAnchor m s = let
55 :     fun look () = StringMap.find (!m, s)
56 :     fun get () =
57 :     case look () of
58 :     SOME v => v
59 :     (* Return a bogus value here that will later cause a failure
60 :     * when actually opening a file. We don't want to fail here
61 :     * because the anchor may come back to life later. *)
62 :     | NONE => concat ["$$undefined<", s, ">"]
63 :     in
64 :     case look () of
65 : blume 361 NONE => NONE
66 : blume 377 | SOME _ => SOME get
67 :     end
68 : blume 361
69 :     fun processSpecFile (m, f) = let
70 : blume 405 val full_f_dir = OS.Path.dir (OS.FileSys.fullPath f)
71 :     fun set x = let
72 :     fun mkAbsolute rel =
73 :     OS.Path.mkAbsolute { path = rel, relativeTo = full_f_dir }
74 :     in
75 :     set0 mkAbsolute x
76 :     end
77 : blume 361 fun work s = let
78 :     fun loop () = let
79 :     val line = TextIO.inputLine s
80 :     in
81 :     if line = "" then ()
82 :     else case String.tokens Char.isSpace line of
83 : blume 368 [a, d] => (set (m, a, d); loop ())
84 :     | ["-"] => (reset m; loop ())
85 :     | [a] => (cancel (m, a); loop ())
86 : blume 406 | [] => loop () (* ignore empty lines *)
87 : blume 368 | _ => (Say.say [f, ": malformed line (ignored)\n"]; loop ())
88 : blume 361 end
89 :     in
90 :     loop ()
91 :     end
92 : blume 360 in
93 : blume 361 SafeIO.perform { openIt = fn () => TextIO.openIn f,
94 :     closeIt = TextIO.closeIn,
95 :     work = work,
96 : blume 459 cleanup = fn _ => () }
97 : blume 360 end
98 : blume 265 end

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