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/paths/fileid.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/paths/fileid.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 735 - (view) (download)

1 : blume 666 (*
2 :     * Abstract file IDs.
3 :     * - IDs for files regardless whether they exist or not.
4 :     * - For existing files equivalent to OS.FileSys.file_id.
5 :     *
6 :     * Copyright (c) 2000 by Lucent Technologies, Bell Laboratories
7 :     *
8 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
9 :     *)
10 :     signature FILEID = sig
11 :    
12 :     type id
13 :     type ord_key = id (* to be able to match ORD_KEY *)
14 :    
15 :     val compare : id * id -> order
16 :    
17 :     val fileId : string -> id
18 :     end
19 :    
20 :     structure FileId :> FILEID = struct
21 :    
22 :     structure F = OS.FileSys
23 :     structure P = OS.Path
24 :    
25 :     datatype id =
26 :     PRESENT of F.file_id
27 :     | ABSENT of string
28 :    
29 :     type ord_key = id
30 :    
31 :     fun compare (PRESENT fid, PRESENT fid') = F.compare (fid, fid')
32 :     | compare (ABSENT _, PRESENT _) = LESS
33 :     | compare (PRESENT _, ABSENT _) = GREATER
34 :     | compare (ABSENT s, ABSENT s') = String.compare (s, s')
35 :    
36 :     fun fileId f = let
37 : blume 735 (* To maximize our chances of recognizing equivalent path names to
38 : blume 666 * non-existing files, we use F.fullPath to expand the largest
39 :     * possible prefix of the path. *)
40 :     fun expandPath f = let
41 :     fun loop { dir, file } = P.concat (F.fullPath dir, file)
42 :     handle _ => let
43 :     val { dir = dir', file = file' } = P.splitDirFile dir
44 :     in
45 :     loop { dir = dir', file = P.concat (file', file) }
46 :     end
47 :     in
48 :     (* An initial call to splitDirFile is ok because we already know
49 :     * that the complete path does not refer to an existing file. *)
50 :     loop (P.splitDirFile f)
51 :     end
52 :     in
53 :     PRESENT (F.fileId f) handle _ => ABSENT (expandPath f)
54 :     end
55 :     end

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