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 354 - (download) (annotate)
Fri Jun 25 08:36:12 1999 UTC (21 years ago) by blume
File size: 1016 byte(s)
a host of changes related mostly to pathname handling
(*
 * 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 generic (maker, pmaker, p) =
	    maker p
	    handle exn => let
		val { dir, ... } = P.splitDirFile p
	    in
		if dir = "" orelse fileExists dir then raise exn
		else (pmaker dir; maker p)
	    end
	fun makedirs dir = generic (F.mkDir, makedirs, dir)
	fun advertisemakedirs dir =
	    (Say.vsay ["[creating directory ", dir, " ...]\n"];
	     makedirs dir)
    in
	generic (fileopener, advertisemakedirs, p)
    end

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

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