TiogaExecCommands.mesa
Copyright (C) 1982, 1983, 1984, 1985, Xerox Corporation. All rights reserved.
Paxton, October 26, 1982 10:12 am
Maxwell, January 14, 1983 8:46 am
Plass, April 20, 1983 9:26 am
Russ Atkinson, September 29, 1983 11:17 am
Doug Wyatt, January 2, 1985 2:44:52 pm PST
DIRECTORY
Commander USING [CommandProc, Handle, Register],
FS USING [Error],
GetTree USING [ReadIndent],
InterFile USING [ToFile],
IO USING [EndOfStream, GetRefAny, PutRope, RIS, STREAM],
List USING [Nconc1],
ProcessExtras USING [CheckForAbort],
PutGet USING [FromFile, ToFile, WriteFilePlain, WriteMesaFilePlain],
Rope USING [Concat, Fetch, Find, ROPE, Size],
TEditDocument USING [Selection],
TEditInput USING [FreeTree, Interpret, ReadTipTables],
TEditMesaOps USING [SetSpanMesaLooks],
TEditOps USING [GetSelData],
TEditProfile USING [GetToken],
TEditSelection USING [LockSel, UnlockSel],
TextNode USING [LastWithin, MakeNodeSpan, Ref];
TiogaExecCommands: CEDAR PROGRAM
IMPORTS FS, Commander, GetTree, IO, InterFile, List, ProcessExtras, PutGet, Rope, TEditMesaOps, TEditInput, TEditOps, TEditProfile, TEditSelection, TextNode
= BEGIN
TiogaMesaLooks: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
DoTiogaMesa[cmd, FALSE, TRUE];
};
TiogaMesa: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
DoTiogaMesa[cmd, TRUE, TRUE];
};
ReadIndent: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
DoTiogaMesa[cmd, TRUE, FALSE];
};
Get:
PROC [name: Rope.
ROPE, log:
IO.
STREAM, tree:
BOOL ←
FALSE]
RETURNS [root: TextNode.Ref, filename: Rope.ROPE] = {
failed: BOOL ← FALSE;
filename ← name;
{
ENABLE
FS.Error => {
IF ~failed
AND Rope.Find[filename,"."] = -1
THEN {
-- add .mesa extension
filename ← Rope.Concat[filename,".mesa"];
failed ← TRUE;
RETRY };
log.PutRope[error.explanation];
log.PutRope["\n"];
GOTO Quit };
root ← IF tree THEN GetTree.ReadIndent[filename, tabIndent] ELSE PutGet.FromFile[filename];
};
EXITS Quit => RETURN [NIL, NIL]
};
tabIndent: NAT ← 8;
DoTiogaMesa:
PROC [cmd: Commander.Handle, tree, mesaLooks:
BOOL] = {
Writer: DoWriteProc = {
IF mesaLooks
THEN [] ← TEditMesaOps.SetSpanMesaLooks[
TextNode.MakeNodeSpan[root,TextNode.LastWithin[root]],NIL];
[] ← PutGet.ToFile[filename, root] };
tabIndent ← 8;
Dudley[Writer, cmd, tree];
};
ReadTiogaTipTables: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
TEditInput.ReadTipTables[];
};
WriteMesaPlain: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
Writer: DoWriteProc = { PutGet.WriteMesaFilePlain[filename, root] };
Dudley[Writer, cmd];
};
WritePlain: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
Writer: DoWriteProc = { PutGet.WriteFilePlain[filename, root] };
Dudley[Writer, cmd];
};
WriteInterFile: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
Writer: DoWriteProc = { [] ← InterFile.ToFile[filename, root] };
Dudley[Writer, cmd];
};
DoWriteProc: TYPE = PROC [filename: Rope.ROPE, root: TextNode.Ref];
Dudley:
PROC [writer: DoWriteProc, cmd: Commander.Handle, tree:
BOOL ←
FALSE] = {
offset: INT ← 0;
out: IO.STREAM ← cmd.out;
DO
process each file in command line
root: TextNode.Ref;
filename: Rope.ROPE;
[filename,offset] ← TEditProfile.GetToken[cmd.commandLine, offset];
IF Rope.Size[filename]=0 THEN EXIT;
IF Rope.Size[filename]=1
AND Rope.Fetch[filename,0]
IN ['1..'9]
THEN {
tabIndent ← LOOPHOLE[Rope.Fetch[filename,0]-'1];
LOOP
};
[root, filename] ← Get[filename, out, tree];
IF root=NIL THEN LOOP;
IO.PutRope[out, " "];
IO.PutRope[out, filename];
IO.PutRope[out, " "];
ProcessExtras.CheckForAbort[];
writer[filename, root];
TEditInput.FreeTree[root];
IO.PutRope[out, "\n"];
ENDLOOP;
};
DoTiogaOps: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
pSel: TEditDocument.Selection ← TEditOps.GetSelData[];
rope: Rope.ROPE ← cmd.commandLine;
h: IO.STREAM ← IO.RIS[rope];
item: REF ANY;
list: LIST OF REF ANY;
DO
item ← IO.GetRefAny[h ! IO.EndOfStream => { item ← NIL; CONTINUE}];
IF item = NIL THEN EXIT;
list ← List.Nconc1[list, item];
ENDLOOP;
TEditSelection.LockSel[primary, "DoTiogaOps"];
-- IF pSel.viewer # NIL THEN -- TEditInput.Interpret[pSel.viewer, list];
TEditSelection.UnlockSel[primary];
};
Commander.Register["TiogaMesa", TiogaMesa, "Convert Mesa files to Tioga tree format.
Number in line gives spaces/tab -- must be in [1..9]; default is 8"];
Commander.Register["ReadTiogaTipTables", ReadTiogaTipTables, "Have Tioga read its TIP tables again."];
Commander.Register["ReadIndent", ReadIndent, "Convert to tree structure based on indenting."];
Commander.Register["WritePlain", WritePlain, "Convert Tioga file to unformatted file."];
Commander.Register["WriteMesaPlain", WriteMesaPlain, "Convert Tioga file to unformatted file.\n\tRestores dashes before comments if necessary."];
Commander.Register["WriteInterFile", WriteInterFile, "Convert Tioga file to pseudo InterScript format."];
Commander.Register["DoTiogaOps", DoTiogaOps, "Like EditTool Do Operations command."];
END.