file: WeaveExternalsImpl.mesa
Edited by Lyle Ramshaw: October 27, 1983 5:24 pm
Last changed by Pavel on September 11, 1984 5:00:10 pm PDT
implements those procedures called by Weave as externals.
DIRECTORY
FS USING [StreamOpen],
IO USING [BreakProc, Error, GetIndex, GetTokenRope, RIS, STREAM],
PascalBasic,
PascalWizardFiles,
Rope USING [Cat, Concat, FromChar],
WeaveProcs,
WeaveVars;
WeaveExternalsImpl: PROGRAM IMPORTS
PascalBasic, FS, IO, PascalWizardFiles, Rope EXPORTS WeaveProcs =
BEGIN OPEN PascalBasic, PascalWizardFiles, WeaveProcs, WeaveVars;
TtyRewrite: PUBLIC PROC [F: PascalTextFilePtr] =
BEGIN
PascalOpenTextFileTTYOutput[F];
END;
FileReset: PUBLIC PROC [F: PascalTextFilePtr, Ext: Alfa] =
BEGIN
inStream: IO.STREAM;
IF F.baseFile = NIL THEN-- In case we actually want to rewind this already-open file
{
inStream ← FS.StreamOpen[Rope.Cat[FileNameRoot[], ".", RopeFromAlfa[Ext]]];
PascalOpenTextFileWithStream[F, inStream];
};
PascalTextRESET[F];
END;
FileRewrite: PUBLIC PROC [F: PascalTextFilePtr, Ext: Alfa] =
BEGIN
outStream: IO.STREAM;
outStream ← FS.StreamOpen[Rope.Cat[FileNameRoot[], ".", RopeFromAlfa[Ext]], $create];
PascalOpenTextFileWithStream[F, outStream];
PascalTextREWRITE[F];
END;
FileClose: PUBLIC PROC [F: PascalTextFilePtr] =
BEGIN
PascalCloseTextFile[F];
END;
FileGetPos: PUBLIC PROC [F: PascalTextFilePtr] RETURNS [FileGetPosResult: PascalInteger] =
BEGIN
FileGetPosResult ← 0; -- in case of error below
FileGetPosResult ← F.baseFile.str.GetIndex[ ! IO.Error =>
IF ec = NotImplementedForThisStream THEN CONTINUE];
END;
fileNameRootBreak: PRIVATE IO.BreakProc = CHECKED
BEGIN
RETURN[SELECT char FROM
IN ['0..'9], IN ['A..'Z], IN ['a..'z], '-, '+, '# => other,
ENDCASE => sepr];
END;
FileNameRoot: PROC RETURNS [ROPE] =
BEGIN
RETURN[IO.RIS[commandLineTail].GetTokenRope[breakProc: fileNameRootBreak].token];
END;
RopeFromAlfa: PROC [a: Alfa] RETURNS [r: ROPE] =
BEGIN
r ← NIL;
FOR i:AlfaIndex IN AlfaIndex DO
IF a[i] = ' THEN EXIT;
r ← Rope.Concat[r, Rope.FromChar[a[i]]];
ENDLOOP;
END;
END.