InterscriptImpl.mesa
Last Edited by: Mitchell, February 7, 1983 3:46 pm
DIRECTORY
Rope,
Interscript,
FileIO USING [Open, OpenFailed],
Process,
SafeStorage,
IO;
InterscriptImpl: CEDAR PROGRAM
IMPORTS Interscript, IO, SafeStorage, FileIO, Rope, Process
= BEGIN OPEN Interscript;
ROPE: TYPE ~ Rope.ROPE;
MainLoop: PROCEDURE = {
ask user for name of script (e.g., foo.is83, extension for "interscript-83", is assumed)
ask if user would like to see script printed, e.g., fully expanded, or just shown span boundaries.
open stream for the file
initialize binding table, scanner; call parser
if error from parsing, restart parsing when user confirms (so he can fix an error and then plow on).
error, fileName: ROPE;
bindTbl: BTHandle;
vin, vout: IO.STREAM;
scriptZone: ZONE ← SafeStorage.NewZone[sr: quantized];
script: IO.STREAM;
[in: vin, out: vout] ← IO.CreateViewerStreams[name: "Interscript"];
BEGIN ENABLE IO.Error => GO TO quit;
DO
vout.Put[IO.rope["Type the name of the file to be internalized (extension .is83 is assumed): "]];
fileName ← GetFileName[in: vin, dfltExt: "is83"];
script ← FileIO.Open[fileName: fileName !
FileIO.OpenFailed => {vout.Put[IO.rope["\nCouldn't open the file named "], IO.rope[fileName], IO.rope["\n"]]; LOOP}];
EXIT;
ENDLOOP;
DO
vout.Put[IO.rope["Internalizing "], IO.rope[fileName], IO.rope[": "]];
error ← Internalize[stream: script, z: scriptZone];
IF error = NIL THEN {vout.Put[IO.rope["No errors\n"]]; EXIT}
ELSE vout.Put[IO.rope[error], IO.rope["\n"]];
ENDLOOP;
EXITS
quit => RETURN;
END;
};
GetFileName: PROC [in: IO.STREAM, dfltExt: ROPENIL] RETURNS [name: ROPE] = {
reads a file name from the in stream. If no .extension is given, the dfltExt, if any, is assumed and is appended to the file name from the stream.
point: INT;
name ← in.GetRope[];
IF (point ← name.Index[s2: "."]) >= name.Length[] THEN name ← name.Cat[".", dfltExt];
};
TRUSTED {Process.Detach[FORK MainLoop[]]};
END.
Change Log
Created by Mitchell, February 7, 1983 10:41 am.