TFtoPLExternalsImpl:
PROGRAM
IMPORTS FS, IO, PascalBasic, PascalWizardFiles, Rope
EXPORTS TFtoPLExternals =
BEGIN OPEN PascalBasic, PascalWizardFiles, TFtoPLPrivate;
TtyRewrite:
PUBLIC
PROC [
F: PascalTextFilePtr] =
BEGIN
PascalOpenTextFileTTYOutput[F];
END;
ByteFileReset:
PUBLIC PROC [
F:
LONG
POINTER
TO ByteFile, Ext: Alfa] =
BEGIN
inStream: IO.STREAM;
so: FS.StreamOptions ← FS.defaultStreamOptions;
so[tiogaRead] ← FALSE;
inStream ← FS.StreamOpen[fileName: Rope.Cat[FileNameRoot[], ".", RopeFromAlfa[Ext]], streamOptions: so];
PascalOpenFileWithStream[@(F^.baseFile), inStream];
PascalRESET[file: @(F^.baseFile), length: 1, element: @(F^.element)];
END;
FileReset:
PROC [
F: PascalTextFilePtr, Ext: Alfa] =
BEGIN
inStream: IO.STREAM;
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;
ByteFileClose:
PUBLIC
PROC [
F:
LONG
POINTER
TO ByteFile] =
BEGIN
PascalCloseFile[@(F^.baseFile)];
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.