-- TiogaExecCommands.mesa
-- Last changed by Paxton, October 26, 1982 10:12 am
Last Edited by: Maxwell, January 14, 1983 8:46 am
DIRECTORY
CIFS,
Directory,
TextNode,
TEditMesaOps,
GetTree,
PutGet,
File,
Rope,
InterFile,
IO,
List,
TEditDocument,
TEditOps,
TEditSelection,
TEditProfile USING [GetToken],
TEditInput,
UserExec;
TiogaExecCommands: CEDAR PROGRAM
IMPORTS CIFS, Directory, GetTree, IO, InterFile, List, PutGet, Rope, TEditMesaOps, TEditInput, TEditOps, TEditProfile, TEditSelection, TextNode, UserExec = {
TiogaMesaLooks: UserExec.CommandProc = {
DoTiogaMesa[exec, event, FALSE, TRUE] };
TiogaMesa: UserExec.CommandProc = {
DoTiogaMesa[exec, event, TRUE, TRUE] };
ReadIndent: UserExec.CommandProc = {
DoTiogaMesa[exec, event, TRUE, FALSE] };
Get: PROC [name: Rope.ROPE, exec: UserExec.ExecHandle, tree: BOOLFALSE]
RETURNS [root: TextNode.Ref, filename: Rope.ROPE] = {
out: IO.STREAM;
failed: BOOLFALSE;
filename ← name; {
ENABLE CIFS.Error => {
IF ~failed AND Rope.Find[filename,"."] = -1 THEN { -- add .mesa extension
filename ← Rope.Concat[filename,".mesa"];
failed ← TRUE;
RETRY };
out ← UserExec.GetStreams[exec].out;
IO.PutRope[out, filename];
IO.PutRope[out, " 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 [exec: UserExec.ExecHandle, event: UserExec.HistoryEvent, tree, mesaLooks: BOOLEAN] = {
Writer: DoWriteProc = {
IF mesaLooks THEN [] ← TEditMesaOps.SetSpanMesaLooks[
TextNode.MakeNodeSpan[root,TextNode.LastWithin[root]],NIL];
[] ← PutGet.ToFile[filename, root] };
tabIndent ← 8;
Dudley[Writer, exec, event, tree] };
ReadTiogaTipTables: UserExec.CommandProc = {
TEditInput.ReadTipTables[] };
WriteMesaPlain: UserExec.CommandProc = {
Writer: DoWriteProc = { PutGet.WriteMesaFilePlain[filename, root] };
Dudley[Writer, exec, event] };
WritePlain: UserExec.CommandProc = {
Writer: DoWriteProc = { PutGet.WriteFilePlain[filename, root] };
Dudley[Writer, exec, event] };
WriteInterFile: UserExec.CommandProc = {
Writer: DoWriteProc = { [] ← InterFile.ToFile[filename, root] };
Dudley[Writer, exec, event] };
DoWriteProc: TYPE = PROC [filename: Rope.ROPE, root: TextNode.Ref];
Dudley: PROC [writer: DoWriteProc, exec: UserExec.ExecHandle, event: UserExec.HistoryEvent, tree: BOOLEANFALSE] = {
offset: INT ← 0;
out: IO.STREAM ← UserExec.GetStreams[exec].out;
DO-- process each file in command line
root: TextNode.Ref;
filename: Rope.ROPE;
dollarFile: REF READONLY TEXT;
dollarCap: File.Capability ← File.nullCapability;
[filename,offset] ← TEditProfile.GetToken[event.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, exec, tree];
IF root=NIL THEN LOOP;
IO.PutChar[out, '.];
dollarFile ← Rope.ToRefText[Rope.Cat[filename, "$"]];
TRUSTED {dollarCap ← Directory.LookupUnlimited[fileName: LOOPHOLE[dollarFile]
! Directory.Error => CONTINUE];
IF dollarCap#File.nullCapability THEN
Directory.RemoveFile[LOOPHOLE[dollarFile], dollarCap];
Directory.Rename[LOOPHOLE[Rope.ToRefText[filename]], LOOPHOLE[dollarFile]
! Directory.Error => CONTINUE]};
writer[filename, root];
TEditInput.FreeTree[root];
ENDLOOP;
IO.PutRope[out, " Done."] };
DoTiogaOps: UserExec.CommandProc = { OPEN IO;
pSel: TEditDocument.Selection ← TEditOps.GetSelData[];
rope: Rope.ROPE ← event.commandLine;
h: Handle ← CreateInputStreamFromRope[rope];
item: REF ANY;
list: LIST OF REF ANY;
WHILE (item ← GetRefAny[h ! EndOfStream => { item ← NIL; CONTINUE}]) # NIL DO
list ← List.Nconc1[list, item];
ENDLOOP;
TEditSelection.LockSel[primary, "DoTiogaOps"];
IF pSel.viewer # NIL THEN TEditInput.Interpret[pSel.viewer, list];
TEditSelection.UnlockSel[primary] };
UserExec.RegisterCommand["TiogaMesa", TiogaMesa, "Convert Mesa files to Tioga tree format.
Number in line gives spaces/tab -- must be in [1..9]; default is 8"];
UserExec.RegisterCommand["ReadTiogaTipTables", ReadTiogaTipTables, "Have Tioga read its TIP tables again."];
UserExec.RegisterCommand["ReadIndent", ReadIndent, "Convert to tree structure based on indenting."];
UserExec.RegisterCommand["WritePlain", WritePlain, "Convert Tioga file to unformatted file."];
UserExec.RegisterCommand["WriteMesaPlain", WriteMesaPlain, "Convert Tioga file to unformatted file.\n\tRestores dashes before comments if necessary."];
UserExec.RegisterCommand["WriteInterFile", WriteInterFile, "Convert Tioga file to pseudo InterScript format."];
UserExec.RegisterCommand["DoTiogaOps", DoTiogaOps, "Like EditTool Do Operations command."];
}.