diff options
Diffstat (limited to 'src/hyper/pages/FNAME.ht')
-rw-r--r-- | src/hyper/pages/FNAME.ht | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/hyper/pages/FNAME.ht b/src/hyper/pages/FNAME.ht new file mode 100644 index 00000000..60f652e7 --- /dev/null +++ b/src/hyper/pages/FNAME.ht @@ -0,0 +1,130 @@ +% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. +% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. +\newcommand{\FileNameXmpTitle}{FileName} +\newcommand{\FileNameXmpNumber}{9.25} +% +% ===================================================================== +\begin{page}{FileNameXmpPage}{9.25 FileName} +% ===================================================================== +\beginscroll + +The \spadtype{FileName} domain provides an interface to the computer's +file system. +Functions are provided to manipulate file names and to test properties of +files. + +The simplest way to use file names in the \Language{} interpreter is to +rely on conversion to and from strings. +The syntax of these strings depends on the operating system. +\xtc{ +}{ +\spadpaste{fn: FileName \bound{fndecl}} +} +\xtc{ +On AIX, this is a proper file syntax: +}{ +\spadpaste{fn := "/spad/src/input/fname.input" \free{fndecl}\bound{fn}} +} + +Although it is very convenient to be able to use string notation +for file names in the interpreter, it is desirable to have a portable +way of creating and manipulating file names from within programs. +\xtc{ +A measure of portability is obtained by considering a file name +to consist of three parts: the {\it directory}, the {\it name}, +and the {\it extension}. +}{ +\spadpaste{directory fn \free{fn}} +} +\xtc{ +}{ +\spadpaste{name fn \free{fn}} +} +\xtc{ +}{ +\spadpaste{extension fn \free{fn}} +} +The meaning of these three parts depends on the operating system. +For example, on CMS the file \spad{"SPADPROF INPUT M"} +would have directory \spad{"M"}, name \spad{"SPADPROF"} and +extension \spad{"INPUT"}. + +\xtc{ +It is possible to create a filename from its parts. +}{ +\spadpaste{fn := filename("/u/smwatt/work", "fname", "input") \free{fndecl}\bound{fn1}} +} +\xtc{ +When writing programs, it is helpful to refer to directories via +variables. +}{ +\spadpaste{objdir := "/tmp" \bound{objdir}} +} +\xtc{ +}{ +\spadpaste{fn := filename(objdir, "table", "spad") \free{fndecl,objdir}\bound{fn2}} +} +\xtc{ +If the directory or the extension is given as an empty string, then +a default is used. On AIX, the defaults are the current directory +and no extension. +}{ +\spadpaste{fn := filename("", "letter", "") \free{fndecl}\bound{fn3}} +} + +Three tests provide information about names in the file system. +\xtc{ +The \spadfunFrom{exists?}{FileName} operation tests whether the named file exists. +}{ +\spadpaste{exists? "/etc/passwd"} +} +\xtc{ +The operation \spadfunFrom{readable?}{FileName} tells whether the named file +can be read. If the file does not exist, then it cannot be read. +}{ +\spadpaste{readable? "/etc/passwd"} +} +\xtc{ +}{ +\spadpaste{readable? "/etc/security/passwd"} +} +\xtc{ +}{ +\spadpaste{readable? "/ect/passwd"} +} +\xtc{ +Likewise, the operation \spadfunFrom{writable?}{FileName} tells whether the named file +can be written. +If the file does not exist, the test is determined +by the properties of the directory. +}{ +\spadpaste{writable? "/etc/passwd"} +} +\xtc{ +}{ +\spadpaste{writable? "/dev/null"} +} +\xtc{ +}{ +\spadpaste{writable? "/etc/DoesNotExist"} +} +\xtc{ +}{ +\spadpaste{writable? "/tmp/DoesNotExist"} +} + +The \spadfunFrom{new}{FileName} operation constructs the name of a new +writable file. +The argument sequence is the same as for \spadfunFrom{filename}{FileName}, +except that the name part is actually a prefix for a constructed +unique name. +\xtc{ +The resulting file is in the specified directory +with the given extension, and the same defaults are used. +}{ +\spadpaste{fn := new(objdir, "xxx", "yy") \free{objdir,fndecl}\bound{fn4}} +} +\endscroll +\autobuttons +\end{page} +% |