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/util/autodir.sml
ViewVC logotype

View of /sml/trunk/src/cm/util/autodir.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 376 - (download) (annotate)
Wed Jul 7 04:25:11 1999 UTC (23 years ago) by blume
File size: 1050 byte(s)
fixed AutoDir (handling of ..)
 * Opening files for output while automagically creating any
 * necessary directories.
 * Copyright (c) 1999 by Lucent Technologies, Bell Laboratories
 * Author: Matthias Blume (blume@cs.princeton.edu)
structure AutoDir :> sig
    val openBinOut : string -> BinIO.outstream
    val openTextOut : string -> TextIO.outstream
end = struct

    structure P = OS.Path
    structure F = OS.FileSys

    fun fileExists n = F.access (n, []) handle _ => false

    fun openOut fileopener p = let
	fun mkDir d = if fileExists d then () else F.mkDir d
	fun generic (maker, pmaker, p) =
	    maker p
	    handle exn => let
		val dir = P.dir p
		if dir = "" orelse fileExists dir then raise exn
		else (pmaker dir; maker p)
	fun makedirs dir = generic (mkDir, makedirs, dir)
	fun advertisemakedirs dir =
	    (Say.vsay ["[creating directory ", dir, " ...]\n"];
	     makedirs dir)
	generic (fileopener, advertisemakedirs, p)

    val openTextOut = openOut TextIO.openOut
    val openBinOut = openOut BinIO.openOut

ViewVC Help
Powered by ViewVC 1.0.0