-- TiogaExecCommands.mesa
-- Last changed by Paxton, October 26, 1982 10:12 am
Last Edited by: Maxwell, January 14, 1983 8:46 am
Last Edited by: Plass, April 20, 1983 9:26 am
DIRECTORY
CIFS,
Commander,
Directory,
TextNode,
TEditMesaOps,
GetTree,
PutGet,
File,
Rope,
InterFile,
IO,
List,
TEditDocument,
TEditOps,
TEditSelection,
TEditProfile USING [GetToken],
TEditInput;
TiogaExecCommands: CEDAR PROGRAM
IMPORTS CIFS, Commander, Directory, GetTree, IO, InterFile, List, PutGet, Rope, TEditMesaOps, TEditInput, TEditOps, TEditProfile, TEditSelection, TextNode = {
TiogaMesaLooks: Commander.CommandProc = {
DoTiogaMesa[cmd, FALSE, TRUE] };
TiogaMesa: Commander.CommandProc = {
DoTiogaMesa[cmd, TRUE, TRUE] };
ReadIndent: Commander.CommandProc = {
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
CIFS.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:
BOOLEAN] = {
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 = {
TEditInput.ReadTipTables[] };
WriteMesaPlain: Commander.CommandProc = {
Writer: DoWriteProc = { PutGet.WriteMesaFilePlain[filename, root] };
Dudley[Writer, cmd] };
WritePlain: Commander.CommandProc = {
Writer: DoWriteProc = { PutGet.WriteFilePlain[filename, root] };
Dudley[Writer, cmd] };
WriteInterFile: Commander.CommandProc = {
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:
BOOLEAN ←
FALSE] = {
offset: INT ← 0;
out: IO.STREAM ← cmd.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[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.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: Commander.CommandProc = {
pSel: TEditDocument.Selection ← TEditOps.GetSelData[];
rope: Rope.ROPE ← cmd.commandLine;
h: IO.Handle ← IO.CreateInputStreamFromRope[rope];
item: REF ANY;
list: LIST OF REF ANY;
WHILE (item ←
IO.GetRefAny[h !
IO.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] };
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."];
}.