aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/FNAME.ht
blob: 60f652e76ce5133b8f41e99240cacdd08a20d784 (plain)
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
28
29
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
% 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}
%