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

SCM Repository

[smlnj] View of /sml/trunk/src/cm/paths/pathconfig.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 369 - (download) (annotate)
Sun Jul 4 12:55:20 1999 UTC (21 years, 1 month ago) by blume
File size: 1702 byte(s)
bfc_fetch_xxx bogosity eliminated; more fleshing out of CM
(*
 * Configurable path anchors for new CM.
 *
 * (C) 1999 Lucent Technologies, Bell Laboratories
 *
 * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
 *)

signature PATHCONFIG = sig

    type mode

    val new : unit -> mode
    val set : mode * string * string -> unit
    val cancel : mode * string -> unit
    val reset : mode -> unit

    val configAnchor : mode -> string -> (unit -> string) option

    val processSpecFile : mode * string -> unit
end

(*
 * The names of config anchors must be names of actual files.
 * Function configAnchor will map the name of the anchor to
 * the directory that contains the corresponding file.
 *)
structure PathConfig :> PATHCONFIG = struct

    type mode = string StringMap.map ref

    fun set (m, a, s) = m := (Era.newEra (); StringMap.insert (!m, a, s))
    fun reset m = m := (Era.newEra (); StringMap.empty)
    fun cancel (m, a) =
	(Era.newEra ();
	 (m := #1 (StringMap.remove (!m, a)))
	 handle LibBase.NotFound => ())

    fun new () = ref StringMap.empty

    fun configAnchor m s =
	case StringMap.find (!m, s) of
	    NONE => NONE
	  | SOME _ => SOME (fn () => valOf (StringMap.find (!m, s)))

    fun processSpecFile (m, f) = let
	fun work s = let
	    fun loop () = let
		val line = TextIO.inputLine s
	    in
		if line = "" then ()
		else case String.tokens Char.isSpace line of
		    [a, d] => (set (m, a, d); loop ())
		  | ["-"] => (reset m; loop ())
		  | [a] => (cancel (m, a); loop ())
		  | _ => (Say.say [f, ": malformed line (ignored)\n"]; loop ())
	    end
	in
	    loop ()
	end
    in
	SafeIO.perform { openIt = fn () => TextIO.openIn f,
			 closeIt = TextIO.closeIn,
			 work = work,
			 cleanup = fn () => () }
    end
end

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