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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 376 - (view) (download)

1 : blume 354 (*
2 :     * Opening files for output while automagically creating any
3 :     * necessary directories.
4 :     *
5 :     * Copyright (c) 1999 by Lucent Technologies, Bell Laboratories
6 :     *
7 :     * Author: Matthias Blume (blume@cs.princeton.edu)
8 :     *)
9 :     structure AutoDir :> sig
10 :     val openBinOut : string -> BinIO.outstream
11 :     val openTextOut : string -> TextIO.outstream
12 :     end = struct
13 :    
14 :     structure P = OS.Path
15 :     structure F = OS.FileSys
16 :    
17 :     fun fileExists n = F.access (n, []) handle _ => false
18 :    
19 :     fun openOut fileopener p = let
20 : blume 376 fun mkDir d = if fileExists d then () else F.mkDir d
21 : blume 354 fun generic (maker, pmaker, p) =
22 :     maker p
23 :     handle exn => let
24 : blume 376 val dir = P.dir p
25 : blume 354 in
26 :     if dir = "" orelse fileExists dir then raise exn
27 :     else (pmaker dir; maker p)
28 :     end
29 : blume 376 fun makedirs dir = generic (mkDir, makedirs, dir)
30 : blume 354 fun advertisemakedirs dir =
31 :     (Say.vsay ["[creating directory ", dir, " ...]\n"];
32 :     makedirs dir)
33 :     in
34 :     generic (fileopener, advertisemakedirs, p)
35 :     end
36 :    
37 :     val openTextOut = openOut TextIO.openOut
38 :     val openBinOut = openOut BinIO.openOut
39 :     end

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