TermProgsImpl.Mesa
Last Edited by: Spreitzer, May 5, 1985 2:13:01 pm PDT
DIRECTORY Basics, CharDisplays, Commander, CommandTool, DisplayControllers, FS, IO, RedBlackTree, Rope, TermProgs;
TermProgsImpl: CEDAR PROGRAM
IMPORTS CommandTool, FS, IO, RedBlackTree, Rope
EXPORTS TermProgs
= {OPEN TermProgs;
TermData: TYPE = REF TermDataRep;
TermDataRep: TYPE = RECORD [
termName, bcdBase, bcdDir: ROPENIL,
term: Term ← NIL];
terms: RedBlackTree.Table;
GetTerm: PUBLIC PROC [name: ROPE, cmd: Commander.Handle] RETURNS [term: Term] = {
td: TermData ← NARROW[terms.Lookup[name]];
IF td = NIL THEN RETURN [NIL];
IF td.term # NIL THEN RETURN [td.term];
[] ← CommandTool.DoCommand[
commandLine: IO.PutFR[
"Push %g\nRun %g\nPop",
IO.rope[td.bcdDir],
IO.rope[td.bcdBase]],
parent: cmd];
td ← NARROW[terms.Lookup[name]];
term ← IF td # NIL THEN td.term ELSE NIL;
};
RegTerm: PUBLIC PROC [name: ROPE, term: Term] = {
td: TermData ← NARROW[terms.Lookup[name]];
IF td = NIL THEN {
td ← NEW [TermDataRep ← [termName: name]];
terms.Insert[td, name]};
td.term ← term;
};
EnumerateTerms: PUBLIC PROC [consume: PROC [name: ROPE, term: Term]] = {
PerTermData: PROC [item: REF ANY] RETURNS [stop: BOOL] = {
td: TermData ← NARROW[item];
consume[td.termName, td.term];
stop ← FALSE};
terms.EnumerateIncreasing[PerTermData];
};
CompareTermDatas: PROC [k, data: REF ANY] RETURNS [c: Basics.Comparison] = {
r1: ROPENARROW[k];
r2: ROPE ← GetTermKey[data];
c ← r1.Compare[r2, FALSE]};
GetTermKey: PROC [data: REF ANY] RETURNS [key: ROPE] =
{td: TermData ← NARROW[data]; key ← td.termName};
Start: PROC = {
ConsumeTerms: PROC [fullFName: ROPE] RETURNS [continue: BOOL] = {
termsFName, bcdDir: ROPE;
cp: FS.ComponentPositions;
fromTerms: IO.STREAMNIL;
continue ← TRUE;
[termsFName, cp] ← FS.ExpandName[fullFName];
IF termsFName.Substr[cp.server.start, cp.server.length].Length[] > 0 THEN ERROR;
IF termsFName.Substr[cp.dir.start, cp.dir.length].Length[] > 0 THEN ERROR;
bcdDir ← Rope.Cat[
"[]<>",
termsFName.Substr[cp.subDirs.start, cp.subDirs.length]
];
fromTerms ← FS.StreamOpen[termsFName];
FOR i: INT ← fromTerms.SkipWhitespace[], fromTerms.SkipWhitespace[] WHILE NOT fromTerms.EndOf[] DO
termName: ROPE ← fromTerms.GetRopeLiteral[];
td: TermData ← NEW [TermDataRep ← [
termName: termName,
bcdBase: termsFName.Substr[cp.base.start, cp.base.length],
bcdDir: bcdDir
]];
terms.Insert[td, termName];
ENDLOOP;
fromTerms.Close[];
};
terms ← RedBlackTree.Create[GetTermKey, CompareTermDatas];
FS.EnumerateForNames["Em*.terms!H", ConsumeTerms];
};
Start[];
}.