file: PascalWizardFiles.mesa
last modified by Ramshaw, October 10, 1983 5:34 pm
written by McCreight, November 17, 1980 3:13 PM
a thin layer of Pascal files on top of IO.STREAM
DIRECTORY
IO USING [STREAM],
PascalBasic;
PascalWizardFiles: CEDAR DEFINITIONS =
BEGIN OPEN PascalBasic;
T Y P E S
PascalFile: TYPE = LONG POINTER TO MesaFile ← NIL;
PascalFilePtr: TYPE = LONG POINTER TO PascalFile; -- for passing files as VAR parameters
MesaFile: TYPE = RECORD [
str: IO.STREAMNIL,
eof: BOOLEANFALSE,
openFileLink: MesaFilePtr ← NIL];
MesaFilePtr: TYPE = REF MesaFile;
PascalTextFile: TYPE = RECORD [
baseFile: PascalFile,
eoln: BOOLEANTRUE, -- TRUE if element is a blank representing CR
element: PascalChar ← ' -- last character read
];
PascalTextFilePtr: TYPE = LONG POINTER TO PascalTextFile; -- for passing by VAR
Text: TYPE = PascalTextFile;
P R O C E D U R E S Called by PasMesa
Text File Operations:
PascalTextBREAK: PROCEDURE [file: PascalTextFilePtr];
PascalTextGET: PROCEDURE [file: PascalTextFilePtr];
PascalTextElement: PROCEDURE [file: PascalTextFilePtr] RETURNS [PascalChar];
PascalTextPUT: PROCEDURE [file: PascalTextFilePtr];
PascalTextRESET: PROCEDURE [file: PascalTextFilePtr];
PascalTextREWRITE: PROCEDURE [file: PascalTextFilePtr];
PascalTextPAGE: PROCEDURE [file: PascalTextFilePtr];
PascalTextEOF: PROCEDURE [file: PascalTextFilePtr] RETURNS [BOOLEAN];
PascalTextEOLN: PROCEDURE [file: PascalTextFilePtr] RETURNS [BOOLEAN];
Binary File Operations:
The "length" argument is in units of bytes rather than words, but the only odd
value that will ever arise is 1. The Pascal program generates these arguments
by utilizing a little-known feature of the SIZE operator in Mesa: if you say
SIZE[T, 2], you get back the size in words of a packed array of 2 T's.
PascalBREAK: PROCEDURE [
file: PascalFilePtr, length: CARDINAL,
element: LONG POINTER];
PascalGET: UNSAFE PROCEDURE [
file: PascalFilePtr, length: CARDINAL,
element: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --];
PascalPUT: PROCEDURE [
file: PascalFilePtr, length: CARDINAL,
element: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --];
PascalRESET: UNSAFE PROCEDURE [
file: PascalFilePtr, length: CARDINAL,
element: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --];
PascalREWRITE: PROCEDURE [
file: PascalFilePtr, length: CARDINAL ← 0,
element: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --NIL];
The latter two arguments don't mean anything, and are just included since PasMesa
prefers to generate them.
PascalRead, PascalReadLong, PascalWrite, PascalWriteLong: UNSAFE PROCEDURE [
file: PascalFilePtr, length: CARDINAL,
element: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --,
item: LONG POINTER -- TO ARRAY[0..length/2) OF UNSPECIFIED --];
PascalEOF: PROCEDURE [file: PascalFilePtr] RETURNS [BOOLEAN];
formatted IO for text files
PascalReadLn, PascalWriteLn: PROCEDURE [file: PascalTextFilePtr];
reads up to or writes a CR
PascalReadInteger: PROCEDURE [file: PascalTextFilePtr] RETURNS [PascalInteger];
PascalWriteInteger: PROCEDURE [
file: PascalTextFilePtr, item: PascalInteger,
fieldMinLength: PascalInteger ← -1];
PascalReadReal: PROCEDURE [file: PascalTextFilePtr] RETURNS [PascalReal];
PascalWriteReal: PROCEDURE [
file: PascalTextFilePtr, item: PascalReal,
fieldMinLength, fracLength: PascalInteger ← -1];
PascalReadChar: PROCEDURE [file: PascalTextFilePtr] RETURNS [PascalChar];
PascalWriteChar: PROCEDURE [
file: PascalTextFilePtr, item: PascalChar, fieldMinLength: PascalInteger ← -1];
PascalReadBoolean: PROCEDURE [file: PascalTextFilePtr] RETURNS [PascalBoolean];
PascalWriteBoolean: PROCEDURE [
file: PascalTextFilePtr, item: PascalBoolean,
fieldMinLength: PascalInteger ← -1];
PascalReadArrayOfChar, PascalReadLongArrayOfChar: UNSAFE PROCEDURE [
file: PascalTextFilePtr,
item: CharArrayPtr,
arrayBound: PascalInteger];
PascalWriteArrayOfChar, PascalWriteLongArrayOfChar: PROCEDURE [
file: PascalTextFilePtr,
item: CharArrayPtr,
arrayBound: PascalInteger, fieldMinLength: PascalInteger ← -1];
At this point, McCreight included the following ReadString routines, but I don't see
how they could ever arise, nor do I see how to make them safe.
PascalReadString, PascalReadLongString:
PROCEDURE [file: PascalTextFilePtr, item: LONG POINTER TO ??ROPE??];
PascalWriteString, PascalWriteLongString: PROCEDURE [
file: PascalTextFilePtr, item: ROPE, fieldMinLength: PascalInteger ← -1];
P R O C E D U R E S NOT Called by PasMesa
(and hence, intended to be called as external procedures by the Pascal
program, or else from Mesa code that implements such external procedures).
text file operations
PascalOpenTextFileWithStream: UNSAFE PROCEDURE [
file: PascalTextFilePtr,
stream: IO.STREAM];
Allocates a new MesaFile and installs the specified stream
PascalOpenTextFileTTYInput: UNSAFE PROCEDURE [
file: PascalTextFilePtr];
Allocates a new MesaFile and sets up file to read from the terminal (no pre-read)
PascalOpenTextFileTTYOutput: UNSAFE PROCEDURE [
file: PascalTextFilePtr];
Allocates a new MesaFile and sets up file to output to the terminal
PascalCloseTextFile: UNSAFE PROCEDURE [file: PascalTextFilePtr];
Closes the file, and sets the PascalFile to NIL; the MesaFile must
continue to exist however, to avoid collecting non-garbage.
binary file operations
PascalOpenFileWithStream: UNSAFE PROCEDURE [
file: PascalFilePtr,
stream: IO.STREAM];
Allocates a new MesaFile and installs the specified stream
PascalCloseFile: UNSAFE PROCEDURE [file: PascalFilePtr];
Closes the file, and sets the PascalFile to NIL; the MesaFile must
continue to exist however, to avoid collecting non-garbage.
END. -- PascalWizardFiles