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 366 - (download) (annotate)
Fri Jul 2 14:13:29 1999 UTC (21 years, 5 months ago) by blume
File size: 1393 byte(s)
handling of cwd corrected
(*
 * 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 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 := StringMap.insert (!m, a, s)

    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 ())
		  | _ => (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