Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/cm/paths/abspath.sml
ViewVC logotype

Diff of /sml/trunk/src/cm/paths/abspath.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 330, Sat Jun 12 07:45:52 1999 UTC revision 340, Fri Jun 18 05:32:46 1999 UTC
# Line 26  Line 26 
26      val native : { context: context, spec: string } -> t      val native : { context: context, spec: string } -> t
27      val standard : PathConfig.mode -> { context: context, spec: string } -> t      val standard : PathConfig.mode -> { context: context, spec: string } -> t
28    
29      val pickle : (string -> unit) -> t -> string list      val pickle : (bool -> unit) -> t * t -> string list
30      val unpickle : PathConfig.mode -> string list * context -> t option      val unpickle : PathConfig.mode -> string list * t -> t option
31    
32      val joinDirFile : { dir: t, file: string } -> t      val joinDirFile : { dir: t, file: string } -> t
33      val splitDirFile : t -> { dir: t, file: string }      val splitDirFile : t -> { dir: t, file: string }
# Line 49  Line 49 
49    
50      structure P = OS.Path      structure P = OS.Path
51      structure F = OS.FileSys      structure F = OS.FileSys
52        val impossible = GenericVC.ErrorMsg.impossible
53    
54      (* unique file id that can handle absent files *)      (* unique file id that can handle absent files *)
55      datatype id =      datatype id =
# Line 236  Line 237 
237          end          end
238    
239          (* make a pickle-string *)          (* make a pickle-string *)
240          fun pickle warn_nonanchor (PATH { context, spec, ... }) = let          fun pickle warn (path, gdir) = let
241              fun p_c (CONFIG_ANCHOR { config_name = n, ... }) = [n, "a"]              val warned = ref false
242                | p_c _ = (warn_nonanchor spec; ["c"])              fun warn_once abs =
243                    if !warned then () else (warned := true; warn abs)
244                fun check_abs spec =
245                    if OS.Path.isAbsolute spec then warn_once true else ()
246                fun p_p (p as PATH { context, spec, ... }) =
247                    if compare (p, gdir) = EQUAL then (warn_once false; ["r"])
248                    else (check_abs spec; spec :: p_c context)
249                and p_c (CONFIG_ANCHOR { config_name = n, ... }) = [n, "a"]
250                  | p_c (RELATIVE p) = p_p p
251                  | p_c _ = impossible "AbsPath.pickle"
252          in          in
253              spec :: p_c context              p_p path
254          end          end
255    
256          fun unpickle mode (l, context) = let          fun unpickle mode (l, gdir) = let
257              exception Format              exception Format
258              fun u_p (h :: t) =              fun u_p ["r"] = gdir
259                  | u_p (h :: t) =
260                  PATH { context = u_c t, spec = h, cache = ref NONE }                  PATH { context = u_c t, spec = h, cache = ref NONE }
261                | u_p [] = raise Format                | u_p [] = raise Format
262              and u_c ["c"] = context              and u_c [n, "a"] =
               | u_c [n, "a"] =  
263                  (case PathConfig.configAnchor mode n of                  (case PathConfig.configAnchor mode n of
264                       NONE => raise Format                       NONE => raise Format
265                     | SOME fetch => CONFIG_ANCHOR { fetch = fetch,                     | SOME fetch => CONFIG_ANCHOR { fetch = fetch,
266                                                     cache = ref NONE,                                                     cache = ref NONE,
267                                                     config_name = n })                                                     config_name = n })
268                | u_c _ = raise Format                | u_c l = RELATIVE (u_p l)
269          in          in
270              SOME (u_p l) handle Format => NONE              SOME (u_p l) handle Format => NONE
271          end          end
# Line 263  Line 273 
273          (* . and .. are not permitted as file parameter *)          (* . and .. are not permitted as file parameter *)
274          fun joinDirFile { dir = PATH { context, spec, ... }, file } =          fun joinDirFile { dir = PATH { context, spec, ... }, file } =
275              if file = P.currentArc orelse file = P.parentArc then              if file = P.currentArc orelse file = P.parentArc then
276                  raise Fail "AbsPath.joinDirFile: . or .."                  impossible "AbsPath.joinDirFile: . or .."
277              else fresh (context, P.joinDirFile { dir = spec, file = file })              else fresh (context, P.joinDirFile { dir = spec, file = file })
278    
279          (* splitDirFile never walks past a context.          (* splitDirFile never walks past a context.
280           * Moreover, it is an error to split something that ends in "..". *)           * Moreover, it is an error to split something that ends in "..". *)
281          fun splitDirFile (PATH { context, spec, ... }) = let          fun splitDirFile (PATH { context, spec, ... }) = let
282              fun loop "" =              fun loop "" =
283                  raise Fail "AbsPath.splitDirFile: tried to split a context"                  impossible "AbsPath.splitDirFile: tried to split a context"
284                | loop spec = let                | loop spec = let
285                      val { dir, file } = P.splitDirFile spec                      val { dir, file } = P.splitDirFile spec
286                  in                  in
287                      if file = P.currentArc then loop dir                      if file = P.currentArc then loop dir
288                      else if file = P.parentArc then                      else if file = P.parentArc then
289                          raise Fail "AbsPath.splitDirFile: <path>/.."                          impossible "AbsPath.splitDirFile: <path>/.."
290                      else (dir, file)                      else (dir, file)
291                  end                  end
292              val (dir, file) = loop spec              val (dir, file) = loop spec

Legend:
Removed from v.330  
changed lines
  Added in v.340

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