Directory.dcl 4.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
definition module Directory

// version 1.1.1

from StdFile		import class FileSystem
from StdOverloaded	import class toInt (..), class == (..)
from StdLibMisc		import :: Date, :: Time
//from BigInt			import :: BigInt

// shorthands: PI="platform independent", PD="platform dependent"

getDirectoryContents :: !Path !*env -> (!(!DirError, [DirEntry]), !*env)  | FileSystem env

	/*	error codes: NoDirError, DoesntExist, BadName, NoPermission, OtherErro
		The returned list is only valid, if the error code is NoDirError */

isHidden :: !DirEntry -> Bool

	/*	unix: whether the filename's first character is '.'
		windows/mac: the win(mac)IsHidden flag from the pd_fileInfo field */
	
getFileInfo :: !Path !*env -> (!(!DirError, FileInfo), !*env)  | FileSystem env

	/*	get information about a given file/directory.
		error codes: NoDirError, DoesntExist, BadName, NoPermission, OtherDirError
		The returned FileInfo is only valid, if the error code is NoDirError */

28 29
getFileName			::	!Path !*env	-> (!(!DirError, String), !*env)	| FileSystem env

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
createDirectory :: !Path !*env -> (!DirError, !*env)  | FileSystem env

	/*	error codes: NoDirError, DoesntExist, BadName, NotEnoughSpace, AlreadyExists, NoPermission,
					 OtherDirError */

fmove :: !MoveMode !Path !Path !*env -> (!DirError, !*env)  | FileSystem env

	/*	(fmove mode src dest) moves a file or directory src to another location dst. dst also contains
		the possibly new name of the moved object. Iff (dst already exists and dst is not a directory
		and	mode is OverwriteFile) then dst will be replaced by src.
		error codes: NoDirError, DoesntExist, BadName, NotEnoughSpace, AlreadyExists, NoPermission,
					 MoveIntoOffspring, MoveAcrossDisks, OtherDirError */

fremove :: !Path !*env -> (!DirError, !*env)  | FileSystem env

	/*	removes files and empty directories.
		error codes: NoDirError, DoesntExist, BadName, NoPermission, NotYetRemovable, OtherDirError */

getCurrentDirectory :: !*env -> (!Path, !*env)           | FileSystem env

setCurrentDirectory :: !Path !*env -> (!DirError, !*env) | FileSystem env

	/*	error codes: NoDirError, DoesntExist, BadName, NoPermission, OtherDirError */

getDiskNames :: !*env -> ([DiskName], !*env)             | FileSystem env

pd_StringToPath :: !String !*env -> (!(!Bool, Path), !*env) | FileSystem env

	/*	converts a platform dependent string representation of a path into a Path which
		is only valid, if the returned Bool is True */ 
	
pathToPD_String :: !Path !*env -> (!String,  !*env)      | FileSystem env

	// converts a Path into a platform dependent string representation of a path

encodeUnixModeBits	::	!UnixModeBitsField -> UnixAccessRights
instance == DirError

::	Path
	=	RelativePath [PathStep]
	|	AbsolutePath DiskName [PathStep]

::	PathStep	= PathUp | PathDown String
::	DiskName	:== String
	/*	on UNI//Name is ignored, on DOS/Windows/MacOS the ":" is omitted,
		Windows network paths are specified as an AbsolutePath whose DiskName begins with two
		backslashes (\\) */
	
::	DirError = NoDirError | DoesntExist | BadName | NotEnoughSpace | AlreadyExists | NoPermission
				| MoveIntoOffspring | MoveAcrossDisks | NotYetRemovable | OtherDirError

	/* NotYetRemovable: a file can't be removed because it has not been closed yet or
						a directory can't be removed because it is not empty */

::	DirEntry
	=	{	fileName		::	!String
		,	fileInfo		::	!FileInfo
		}

::	FileInfo
	=	{	pi_fileInfo		::	!PI_FileInfo
		,	pd_fileInfo		::	!PD_FileInfo
		}

::	PI_FileInfo								//	platform independent information
	=	{	fileSize		::	!(!Int, !Int)			// MdM
		,	lastModified	::	!DateTime
		,	isDirectory		::	!Bool
		,	isReadOnly		::	!Bool
		}

::	PD_FileInfo	:== PlatformDependent UnixFileInfo WindowsFileInfo MacFileInfo
											//	platform dependent information

::	PlatformDependent unix windows mac
	=	Unix	unix
	|	Windows	windows
	|	Mac		mac

::	UnixFileInfo
	= 	{	unixModeBitsField	::	!UnixModeBitsField
		,	unixOwnerUserId		::	Int
		,	unixOwnerGroupId	::	Int
		,	unixLastAccessTime	::	!DateTime
		}
		
::	UnixModeBitsField	:==	Int

::	UnixAccessRights
	=	{	ownerRight			::	UnixRight
		,	groupRight			::	UnixRight
		,	othersRight			::	UnixRight
		}

::	UnixRight
	=	{	mayRead				::	!Bool
		,	mayWrite			::	!Bool
		,	mayExecute			::	!Bool
		}
		
::	WindowsFileInfo
	=	{	winCreationTime		::	!DateTime
		,	winLastAccessTime	::	!DateTime
		,	winDOSName			::	!String
		,	winIsHidden			::	!Bool
		,	winIsArchiveFile	::	!Bool
		,	winIsSystemFile		::	!Bool
		}

::	MacFileInfo
	=	{	macCreationTime		::	!DateTime
		,	macBackupTime		::	!DateTime
		,	macIsHidden			::	!Bool
		,	macFDFlags			::	!Int	//	finder information from FInfo/DInfo record
		,	macFurtherInfo		::	!ForFile MacFurtherInfo
		}

::	MacFurtherInfo	:==	(!MacCreator, !MacFileType)

::	MacCreator	:==	String		//	always four characters
::	MacFileType	:==	String		//	always four characters

::	MoveMode	= OverwriteFile | DontOverwrite
::	DateTime	:==	(!Date, !Time)

::	ForFile x
	=	File x
	|	Directory