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 354 - (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 :     fun generic (maker, pmaker, p) =
21 :     maker p
22 :     handle exn => let
23 :     val { dir, ... } = P.splitDirFile p
24 :     in
25 :     if dir = "" orelse fileExists dir then raise exn
26 :     else (pmaker dir; maker p)
27 :     end
28 :     fun makedirs dir = generic (F.mkDir, makedirs, dir)
29 :     fun advertisemakedirs dir =
30 :     (Say.vsay ["[creating directory ", dir, " ...]\n"];
31 :     makedirs dir)
32 :     in
33 :     generic (fileopener, advertisemakedirs, p)
34 :     end
35 :    
36 :     val openTextOut = openOut TextIO.openOut
37 :     val openBinOut = openOut BinIO.openOut
38 :     end

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