/usr/share/axiom-20170501/src/algebra/FILE.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | )abbrev domain FILE File
++ Author: Stephen M. Watt, Victor Miller
++ Date Created: 1984
++ Date Last Updated: June 4, 1991
++ Description:
++ This domain provides a basic model of files to save arbitrary values.
++ The operations provide sequential access to the contents.
File(S) : SIG == CODE where
S : SetCategory
SIG ==> FileCategory(FileName, S) with
readIfCan_! : % -> Union(S, "failed")
++ readIfCan!(f) returns a value from the file f, if possible.
++ If f is not open for reading, or if f is at the end of file
++ then \spad{"failed"} is the result.
CODE ==> add
FileState ==> SExpression
IOMode ==> String
Rep:=Record(fileName: FileName, _
fileState: FileState, _
fileIOmode: IOMode)
defstream(fn: FileName, mode: IOMode): FileState ==
mode = "input" =>
not readable? fn => error ["File is not readable", fn]
MAKE_-INSTREAM(fn::String)$Lisp
mode = "output" =>
not writable? fn => error ["File is not writable", fn]
MAKE_-OUTSTREAM(fn::String)$Lisp
error ["IO mode must be input or output", mode]
f1 = f2 ==
f1.fileName = f2.fileName
coerce(f: %): OutputForm ==
f.fileName::OutputForm
open fname ==
open(fname, "input")
open(fname, mode) ==
fstream := defstream(fname, mode)
[fname, fstream, mode]
reopen_!(f, mode) ==
fname := f.fileName
f.fileState := defstream(fname, mode)
f.fileIOmode:= mode
f
close_! f ==
SHUT(f.fileState)$Lisp
f.fileIOmode := "closed"
f
name f ==
f.fileName
iomode f ==
f.fileIOmode
read_! f ==
f.fileIOmode ^= "input" =>
error "File not in read state"
x := VMREAD(f.fileState)$Lisp
PLACEP(x)$Lisp =>
error "End of file"
x
readIfCan_! f ==
f.fileIOmode ^= "input" =>
error "File not in read state"
x: S := VMREAD(f.fileState)$Lisp
PLACEP(x)$Lisp => "failed"
x
write_!(f, x) ==
f.fileIOmode ^= "output" =>
error "File not in write state"
z := PRINT_-FULL(x, f.fileState)$Lisp
TERPRI(f.fileState)$Lisp
x
flush f ==
f.fileIOmode ^= "output" => error "File not in write state"
FORCE_-OUTPUT(f.fileState)$Lisp
|