<<-- TiogaExecCommands.mesa>> <<-- Last changed by Paxton, October 26, 1982 10:12 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: BOOL _ FALSE] RETURNS [root: TextNode.Ref, filename: Rope.ROPE] = { out: IO.STREAM; failed: BOOL _ FALSE; 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: BOOLEAN _ FALSE] = { 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."]; }.