TiogaExecCommands.mesa
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
DIRECTORY
FS USING [Error],
Commander,
TextNode,
TEditMesaOps,
GetTree,
PutGet,
ProcessExtras USING [CheckForAbort],
Rope,
InterFile,
IO USING [EndOfStream, GetRefAny, PutRope, RIS, STREAM],
List,
TEditDocument,
TEditOps,
TEditSelection,
TEditProfile USING [GetToken],
TEditInput;
TiogaExecCommands: CEDAR PROGRAM
IMPORTS
FS, Commander, GetTree, IO, InterFile, List, ProcessExtras, PutGet, Rope, TEditMesaOps, TEditInput, TEditOps, TEditProfile, TEditSelection, TextNode
= {
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: BOOLFALSE]
RETURNS [root: TextNode.Ref, filename: Rope.ROPE] = {
failed: BOOLFALSE;
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[filename];
log.PutRope[" not found.\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: BOOLFALSE] = {
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.STREAMIO.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."];
}.