## os-path.pkg
# Win32 implementation of the winix__premicrothread::path package.
local
package string = StringImp
in
package winix_path = winix_path_g (
package {
package W32G = win32_general
package c = char
package s = string
package ss = substring
exception PATH
enum arc_kind = Null
| Parent | Current | Arc of String
fun ilkify "" = Null
| ilkify "." = Current
| ilkify ".." = Parent
| ilkify a = Arc a
parent_arc = ".."
current_arc = "."
volSepChar = ':'
arcSepChar = W32G::arcSepChar
arcSep = s::str arcSepChar
fun volPresent disk_volume =
(string::size disk_volume >= 2) and
(c::is_alpha (s::sub (disk_volume, 0)) and (s::sub (disk_volume, 1) = volSepChar))
fun volume_is_valid (_, disk_volume) =
(ss::is_empty disk_volume) or volPresent (ss::string disk_volume)
emptySS = ss::from_string ""
fun splitPath (disk_volume, s) =
if (ss::size s >= 1) and (ss::sub (s, 0) == arcSepChar) then
(TRUE, disk_volume, ss::drop_first 1 s)
else (FALSE, disk_volume, s)
fun splitVolPath "" = (FALSE, emptySS, emptySS)
| splitVolPath s =
if volPresent s then splitPath (ss::split_at (ss::from_string s, 2))
else splitPath (emptySS, ss::from_string s)
fun joinVolPath arg =
let fun checkVolume disk_volume = if (volPresent disk_volume) then disk_volume else raise exception Path
fun aux (TRUE, "", "") = arcSep
| aux (TRUE, "", s) = arcSep$s
| aux (TRUE, disk_volume, "") = (checkVolume disk_volume)$arcSep
| aux (TRUE, disk_volume, s) = (checkVolume disk_volume)$arcSep$s
| aux (FALSE, "", s) = s
| aux (FALSE, disk_volume, "") = checkVolume disk_volume
| aux (FALSE, disk_volume, s) = (checkVolume disk_volume)$s
in aux arg
end
fun sameVol (v1, v2) =
# DiskVolume names are case-insensitive
v1 = v2 or
string::map char::to_lower v1 = string::map char::to_lower v2
});
end
## COPYRIGHT (c) 1996 Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.