Commit 1401a028 authored by sof's avatar sof
Browse files

[project @ 1997-03-14 05:22:26 by sof]

OGI changes through 130397
parent d8f5fc44
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
module Array ( module Array (
module Ix, -- export all of Ix module Ix, -- export all of Ix
Array, -- Array type abstractly Array, -- Array type is abstract
array, listArray, (!), bounds, indices, elems, assocs, array, listArray, (!), bounds, indices, elems, assocs,
accumArray, (//), accum, amap, ixmap accumArray, (//), accum, ixmap
) where ) where
import Ix import Ix
...@@ -73,6 +73,9 @@ ixmap b f a = array b [(i, a ! f i) | i <- range b] ...@@ -73,6 +73,9 @@ ixmap b f a = array b [(i, a ! f i) | i <- range b]
%********************************************************* %*********************************************************
\begin{code} \begin{code}
instance Ix a => Functor (Array a) where
map = amap
instance (Ix a, Eq b) => Eq (Array a b) where instance (Ix a, Eq b) => Eq (Array a b) where
a == a' = assocs a == assocs a' a == a' = assocs a == assocs a'
a /= a' = assocs a /= assocs a' a /= a' = assocs a /= assocs a'
......
...@@ -7,15 +7,44 @@ ...@@ -7,15 +7,44 @@
\begin{code} \begin{code}
{-# OPTIONS -fno-implicit-prelude #-} {-# OPTIONS -fno-implicit-prelude #-}
module Char ( module Char
isAscii, isControl, isPrint, isSpace, isUpper, isLower, (
isAlpha, isDigit, isOctDigit, isHexDigit, isAlphanum, toUpper, toLower isAscii, isLatin1, isControl,
) where isPrint, isSpace, isUpper,
isLower, isAlpha, isDigit,
isOctDigit, isHexDigit, isAlphanum, -- :: Char -> Bool
toUpper, toLower, -- :: Char -> Char
digitToInt, -- :: Char -> Int
intToDigit, -- :: Int -> Char
ord, -- :: Char -> Int
chr, -- :: Int -> Char
readLitChar, -- :: ReadS Char
showLitChar -- :: Char -> ShowS
) where
import PrelBase import PrelBase
\end{code} import PrelRead (readLitChar)
import IOBase (error)
\end{code}
\begin{code}
--Digitconversionoperations
digitToInt :: Char -> Int
digitToInt c
| isDigit c = fromEnum c - fromEnum '0'
| c >= 'a' && c <= 'f' = fromEnum c - fromEnum 'a' + 10
| c >= 'A' && c <= 'F' = fromEnum c - fromEnum 'A' + 10
| otherwise = error "Char.digitToInt: not a digit" -- sigh
intToDigit :: Int -> Char
intToDigit i
| i >= 0 && i <= 9 = toEnum (fromEnum '0' + i)
| i >= 10 && i <= 15 = toEnum (fromEnum 'a' + i -10)
| otherwise = error "Char.intToDigit: not a digit" -- ....
\end{code}
% %
% (c) The AQUA Project, Glasgow University, 1994-1996 % (c) The AQUA Project, Glasgow University, 1994-1997
% %
\section[Complex]{Module @Complex@} \section[Complex]{Module @Complex@}
......
% %
% (c) The AQUA Project, Glasgow University, 1994-1996 % (c) The AQUA Project, Glasgow University, 1994-1997
% %
\section[Directory]{Module @Directory@} \section[Directory]{Module @Directory@}
...@@ -19,9 +19,15 @@ are relative to the current directory. ...@@ -19,9 +19,15 @@ are relative to the current directory.
\begin{code} \begin{code}
module Directory ( module Directory (
-- Permissions(Permissions),
createDirectory, removeDirectory, removeFile, createDirectory, removeDirectory, removeFile,
renameDirectory, renameFile, getDirectoryContents, renameDirectory, renameFile, getDirectoryContents,
getCurrentDirectory, setCurrentDirectory getCurrentDirectory, setCurrentDirectory
{-
,doesFileExist, doesDirectoryExist,
getPermissions, setPermissions,
getModificationTime
-}
) where ) where
import Prelude import Prelude
...@@ -51,39 +57,57 @@ setCurrentDirectory :: FilePath -> IO () ...@@ -51,39 +57,57 @@ setCurrentDirectory :: FilePath -> IO ()
%********************************************************* %*********************************************************
%* * %* *
\subsection{Signatures} \subsection{Permissions}
%* * %* *
%********************************************************* %*********************************************************
$createDirectory dir$ creates a new directory The @Permissions@ type is used to record whether certain operations are permissible on a
{\em dir} which is initially empty, or as near to empty as the file/directory:
operating system allows.
\begin{code}
data Permissions
= Permissions {
readable, writeable,
executable, searchable :: Bool
} deriving (Eq, Ord, Read, Show)
\end{code}
%*********************************************************
%* *
\subsection{Implementation}
%* *
%*********************************************************
@createDirectory dir@ creates a new directory {\em dir} which is
initially empty, or as near to empty as the operating system
allows.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $AlreadyExists$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation.
@[EROFS, EACCES]@
\item @isAlreadyExistsError@ / @AlreadyExists@
The operand refers to a directory that already exists. The operand refers to a directory that already exists.
[$EEXIST$] @ [EEXIST]@
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @ [EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
The operand is not a valid directory name. The operand is not a valid directory name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @NoSuchThing@
There is no path to the directory. There is no path to the directory.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @ResourceExhausted@
The process has insufficient privileges to perform the operation.
[$EROFS$, $EACCES$]
\item $ResourceExhausted$
Insufficient resources (virtual memory, process file descriptors, Insufficient resources (virtual memory, process file descriptors,
physical disk space, etc.) are available to perform the operation. physical disk space, etc.) are available to perform the operation.
[$EDQUOT$, $ENOSPC$, $ENOMEM$, @[EDQUOT, ENOSPC, ENOMEM, EMLINK]@
$EMLINK$] \item @InappropriateType@
\item $InappropriateType$
The path refers to an existing non-directory object. The path refers to an existing non-directory object.
[$EEXIST$] @[EEXIST]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -95,7 +119,7 @@ createDirectory path = ...@@ -95,7 +119,7 @@ createDirectory path =
constructErrorAndFail "createDirectory" constructErrorAndFail "createDirectory"
\end{code} \end{code}
$removeDirectory dir$ removes an existing directory {\em dir}. The @removeDirectory dir@ removes an existing directory {\em dir}. The
implementation may specify additional constraints which must be implementation may specify additional constraints which must be
satisfied before a directory can be removed (e.g. the directory has to satisfied before a directory can be removed (e.g. the directory has to
be empty, or may not be in use by other processes). It is not legal be empty, or may not be in use by other processes). It is not legal
...@@ -106,27 +130,27 @@ directory). ...@@ -106,27 +130,27 @@ directory).
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] [@EIO@]
\item $InvalidArgument$ \item @InvalidArgument@
The operand is not a valid directory name. The operand is not a valid directory name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExist@ / @NoSuchThing@
The directory does not exist. The directory does not exist.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EROFS$, $EACCES$, $EPERM$] @[EROFS, EACCES, EPERM]@
\item $UnsatisfiedConstraints$ \item @UnsatisfiedConstraints@
Implementation-dependent constraints are not satisfied. Implementation-dependent constraints are not satisfied.
[$EBUSY$, $ENOTEMPTY$, $EEXIST$] @[EBUSY, ENOTEMPTY, EEXIST]@
\item $UnsupportedOperation$ \item @UnsupportedOperation@
The implementation does not support removal in this situation. The implementation does not support removal in this situation.
[$EINVAL$] @[EINVAL]@
\item $InappropriateType$ \item @InappropriateType@
The operand refers to an existing non-directory object. The operand refers to an existing non-directory object.
[$ENOTDIR$] @[ENOTDIR]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -138,7 +162,7 @@ removeDirectory path = ...@@ -138,7 +162,7 @@ removeDirectory path =
constructErrorAndFail "removeDirectory" constructErrorAndFail "removeDirectory"
\end{code} \end{code}
$removeFile file$ removes the directory entry for an existing file @removeFile file@ removes the directory entry for an existing file
{\em file}, where {\em file} is not itself a directory. The {\em file}, where {\em file} is not itself a directory. The
implementation may specify additional constraints which must be implementation may specify additional constraints which must be
satisfied before a file can be removed (e.g. the file may not be in satisfied before a file can be removed (e.g. the file may not be in
...@@ -146,24 +170,24 @@ use by other processes). ...@@ -146,24 +170,24 @@ use by other processes).
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
The operand is not a valid file name. The operand is not a valid file name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExist@ / @NoSuchThing@
The file does not exist. The file does not exist.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EROFS$, $EACCES$, $EPERM$] @[EROFS, EACCES, EPERM]@
\item $UnsatisfiedConstraints$ \item @UnsatisfiedConstraints@
Implementation-dependent constraints are not satisfied. Implementation-dependent constraints are not satisfied.
[$EBUSY$] @[EBUSY]@
\item $InappropriateType$ \item @InappropriateType@
The operand refers to an existing directory. The operand refers to an existing directory.
[$EPERM$, $EINVAL$] @[EPERM, EINVAL]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -175,7 +199,7 @@ removeFile path = ...@@ -175,7 +199,7 @@ removeFile path =
constructErrorAndFail "removeFile" constructErrorAndFail "removeFile"
\end{code} \end{code}
$renameDirectory old$ {\em new} changes the name of an existing @renameDirectory old@ {\em new} changes the name of an existing
directory from {\em old} to {\em new}. If the {\em new} directory directory from {\em old} to {\em new}. If the {\em new} directory
already exists, it is atomically replaced by the {\em old} directory. already exists, it is atomically replaced by the {\em old} directory.
If the {\em new} directory is neither the {\em old} directory nor an If the {\em new} directory is neither the {\em old} directory nor an
...@@ -187,31 +211,30 @@ must be documented. ...@@ -187,31 +211,30 @@ must be documented.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
Either operand is not a valid directory name. Either operand is not a valid directory name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExistError@ / @NoSuchThing@
The original directory does not exist, or there is no path to the target. The original directory does not exist, or there is no path to the target.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EROFS$, $EACCES$, $EPERM$] @[EROFS, EACCES, EPERM]@
\item $ResourceExhausted$ \item @ResourceExhausted@
Insufficient resources are available to perform the operation. Insufficient resources are available to perform the operation.
[$EDQUOT$, $ENOSPC$, $ENOMEM$, @[EDQUOT, ENOSPC, ENOMEM, EMLINK]@
$EMLINK$] \item @UnsatisfiedConstraints@
\item $UnsatisfiedConstraints$
Implementation-dependent constraints are not satisfied. Implementation-dependent constraints are not satisfied.
[$EBUSY$, $ENOTEMPTY$, $EEXIST$] @[EBUSY, ENOTEMPTY, EEXIST]@
\item $UnsupportedOperation$ \item @UnsupportedOperation@
The implementation does not support renaming in this situation. The implementation does not support renaming in this situation.
[$EINVAL$, $EXDEV$] @[EINVAL, EXDEV]@
\item $InappropriateType$ \item @InappropriateType@
Either path refers to an existing non-directory object. Either path refers to an existing non-directory object.
[$ENOTDIR$, $EISDIR$] @[ENOTDIR, EISDIR]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -223,7 +246,7 @@ renameDirectory opath npath = ...@@ -223,7 +246,7 @@ renameDirectory opath npath =
constructErrorAndFail "renameDirectory" constructErrorAndFail "renameDirectory"
\end{code} \end{code}
$renameFile old$ {\em new} changes the name of an existing file system @renameFile old@ {\em new} changes the name of an existing file system
object from {\em old} to {\em new}. If the {\em new} object already object from {\em old} to {\em new}. If the {\em new} object already
exists, it is atomically replaced by the {\em old} object. Neither exists, it is atomically replaced by the {\em old} object. Neither
path may refer to an existing directory. A conformant implementation path may refer to an existing directory. A conformant implementation
...@@ -233,32 +256,30 @@ documented. ...@@ -233,32 +256,30 @@ documented.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
Either operand is not a valid file name. Either operand is not a valid file name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExistError@ / @NoSuchThing@
The original file does not exist, or there is no path to the target. The original file does not exist, or there is no path to the target.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EROFS$, $EACCES$, $EPERM$] @[EROFS, EACCES, EPERM]@
\item $ResourceExhausted$ \item @ResourceExhausted@
Insufficient resources are available to perform the operation. Insufficient resources are available to perform the operation.
[$EDQUOT$, $ENOSPC$, $ENOMEM$, @[EDQUOT, ENOSPC, ENOMEM, EMLINK]@
$EMLINK$] \item @UnsatisfiedConstraints@
\item $UnsatisfiedConstraints$
Implementation-dependent constraints are not satisfied. Implementation-dependent constraints are not satisfied.
[$EBUSY$] @[EBUSY]@
\item $UnsupportedOperation$ \item @UnsupportedOperation@
The implementation does not support renaming in this situation. The implementation does not support renaming in this situation.
[$EXDEV$] @[EXDEV]@
\item $InappropriateType$ \item @InappropriateType@
Either path refers to an existing directory. Either path refers to an existing directory.
[$ENOTDIR$, $EISDIR$, $EINVAL$, @[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]@
$EEXIST$, $ENOTEMPTY$]
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -270,29 +291,29 @@ renameFile opath npath = ...@@ -270,29 +291,29 @@ renameFile opath npath =
constructErrorAndFail "renameFile" constructErrorAndFail "renameFile"
\end{code} \end{code}
$getDirectoryContents dir$ returns a list of @getDirectoryContents dir@ returns a list of {\em all} entries
<i>all</i> entries in {\em dir}. in {\em dir}.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
The operand is not a valid directory name. The operand is not a valid directory name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExistError@ / @NoSuchThing@
The directory does not exist. The directory does not exist.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EACCES$] @[EACCES]@
\item $ResourceExhausted$ \item @ResourceExhausted@
Insufficient resources are available to perform the operation. Insufficient resources are available to perform the operation.
[$EMFILE$, $ENFILE$] @[EMFILE, ENFILE]@
\item $InappropriateType$ \item @InappropriateType@
The path refers to an existing non-directory object. The path refers to an existing non-directory object.
[$ENOTDIR$] @[ENOTDIR]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -319,23 +340,23 @@ getDirectoryContents path = ...@@ -319,23 +340,23 @@ getDirectoryContents path =
\end{code} \end{code}
If the operating system has a notion of current directories, If the operating system has a notion of current directories,
$getCurrentDirectory$ returns an absolute path to the @getCurrentDirectory@ returns an absolute path to the
current directory of the calling process. current directory of the calling process.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $NoSuchThing$ \item @isDoesNotExistError@ / @NoSuchThing@
There is no path referring to the current directory. There is no path referring to the current directory.
[$EPERM$, $ENOENT$, $ESTALE$...] @[EPERM, ENOENT, ESTALE...]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EACCES$] @[EACCES]@
\item $ResourceExhausted$ \item @ResourceExhausted@
Insufficient resources are available to perform the operation. Insufficient resources are available to perform the operation.
\item $UnsupportedOperation$ \item @UnsupportedOperation@
The operating system has no notion of current directory. The operating system has no notion of current directory.
\end{itemize} \end{itemize}
...@@ -352,29 +373,29 @@ getCurrentDirectory = ...@@ -352,29 +373,29 @@ getCurrentDirectory =
\end{code} \end{code}
If the operating system has a notion of current directories, If the operating system has a notion of current directories,
$setCurrentDirectory dir$ changes the current @setCurrentDirectory dir@ changes the current
directory of the calling process to {\em dir}. directory of the calling process to {\em dir}.
The operation may fail with: The operation may fail with:
\begin{itemize} \begin{itemize}
\item $HardwareFault$ \item @HardwareFault@
A physical I/O error has occurred. A physical I/O error has occurred.
[$EIO$] @[EIO]@
\item $InvalidArgument$ \item @InvalidArgument@
The operand is not a valid directory name. The operand is not a valid directory name.
[$ENAMETOOLONG$, $ELOOP$] @[ENAMETOOLONG, ELOOP]@
\item $NoSuchThing$ \item @isDoesNotExistError@ / @NoSuchThing@
The directory does not exist. The directory does not exist.
[$ENOENT$, $ENOTDIR$] @[ENOENT, ENOTDIR]@
\item $PermissionDenied$ \item @isPermissionError@ / @PermissionDenied@
The process has insufficient privileges to perform the operation. The process has insufficient privileges to perform the operation.
[$EACCES$] @[EACCES]@
\item $UnsupportedOperation$ \item @UnsupportedOperation@
The operating system has no notion of current directory, or the The operating system has no notion of current directory, or the
current directory cannot be dynamically changed. current directory cannot be dynamically changed.
\item $InappropriateType$ \item @InappropriateType@
The path refers to an existing non-directory object. The path refers to an existing non-directory object.
[$ENOTDIR$] @[ENOTDIR]@
\end{itemize} \end{itemize}
\begin{code} \begin{code}
...@@ -387,3 +408,38 @@ setCurrentDirectory path = ...@@ -387,3 +408,38 @@ setCurrentDirectory path =
\end{code} \end{code}
\begin{code}
{-
doesFileExist :: FilePath -> IO Bool