DIRECTORY Atom, Buttons, Pausers, ViewerClasses, ViewRec, FileIO, IO, MessageWindow, OrderedSymbolTableRef, Rope, Rosemary, RoseHelp; RoseHelpImpl: CEDAR PROGRAM IMPORTS Atom, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, FIO: FileIO, IO, ViewRec, Rosemary EXPORTS RoseHelp = BEGIN OPEN Rosemary; NoHelpForAnything: PUBLIC ERROR = CODE; LORA: TYPE = LIST OF REF ANY; Viewer: TYPE = ViewerClasses.Viewer; Name: TYPE = LIST OF ROPE; StartData: TYPE = REF StartDataRep; StartDataRep: TYPE = RECORD [ instanceName: ROPE, class: CellClass, initData: REF ANY _ NIL]; InitData: TYPE = REF InitDataRep; InitDataRep: TYPE = RECORD [ name: ROPE, ioTemplate: REF ANY]; ExpandQuery: TYPE = REF ExpandQueryRep; ExpandQueryRep: TYPE = RECORD [ instanceName, className: ROPE _ NIL, whatToDo: Rosemary.ExpandDecision _ Nested]; qp: Pausers.Pauser _ NIL; eq: ExpandQuery _ NEW [ExpandQueryRep _ []]; ask: PUBLIC Rosemary.ExpandDeciderClosure _ NEW [Rosemary.ExpandDeciderClosureRep _ [ Decide: Ask, otherData: NIL]]; decisionProp: ATOM _ Atom.Gensym[]; GiveItAnything: PUBLIC PROC [topInstanceName, instanceName, className: ROPE, initData: REF ANY _ NIL, decider: ExpandDeciderClosure] RETURNS [topCell: Cell] = BEGIN sd: StartData _ NEW [StartDataRep _ [ instanceName: instanceName, class: NIL, initData: initData]]; sd.class _ NARROW[cellClasses.Lookup[className]]; IF sd.class = NIL THEN ERROR Error[IO.PutFR["No such class (%g)", IO.rope[className]]]; topCell _ CreateTopCell[instanceName: topInstanceName, className: "GiveItAnything", initData: sd, decider: decider]; END; ExpandAnything: ExpandProc = BEGIN sd: StartData _ NARROW[initData]; usersCell: Cell; usersInterface: ROPE _ NIL; FOR index: CARDINAL IN [0 .. sd.class.ports.length) DO name: ROPE _ sd.class.ports[index].name; step: ROPE _ name.Cat[": ", name]; [] _ CreateNode[within: thisCell, name: name, type: sd.class.ports[index].type]; usersInterface _ IF usersInterface = NIL THEN step ELSE usersInterface.Cat[", ", step]; ENDLOOP; usersCell _ CreateCell[within: thisCell, instanceName: sd.instanceName, className: sd.class.name, interfaceNodes: usersInterface, initData: sd.initData]; END; LookupClass: PROC [name: ROPE] RETURNS [CellClass] = {RETURN [NARROW[cellClasses.Lookup[name]]]}; DecideFromFile: PUBLIC PROC [fileName: ROPE] RETURNS [dff: Rosemary.ExpandDeciderClosure] = BEGIN file: IO.STREAM _ NIL; top: LORA; file _ FIO.Open[fileName: fileName]; top _ LIST[NIL, NIL, IO.GetRefAny[file]]; file.Close[]; dff _ NEW [Rosemary.ExpandDeciderClosureRep _ [Decide: DecideByName, otherData: top]]; END; DecideByName: Rosemary.ExpandDecider = BEGIN Yelp: PROC [problem: ROPE] RETURNS [Rosemary.ExpandDecision] = TRUSTED BEGIN qerv.DisplayMessage[problem]; RETURN [Ask[cell, NIL]]; END; decisionsByName: LORA _ NARROW[otherData]; name: Name _ GetName[cell]; descr: LORA _ GetDescr[name, decisionsByName]; decAt: ATOM; asAny: REF ANY; IF descr = NIL THEN RETURN [Yelp["no decision given"]]; IF descr.rest = NIL THEN BEGIN IF Possible[cell, Leaf] THEN RETURN [Leaf]; RETURN [Yelp["cant make it a Leaf"]]; END; IF NOT ISTYPE[descr.rest.first, ATOM] THEN RETURN [Yelp["decision not an Atom"]]; IF (asAny _ Atom.GetProp[atom: (decAt _ NARROW[descr.rest.first]), prop: decisionProp]) = NIL THEN RETURN [Yelp["atom not a decision"]]; IF (IF asAny = NIL THEN TRUE ELSE NOT ISTYPE[asAny, ExpandDecisionRef]) THEN RETURN [Yelp["atom not a decision"]]; RETURN [NARROW[asAny, ExpandDecisionRef]^]; END; ExpandDecisionRef: TYPE = REF Rosemary.ExpandDecision; GetName: PROC [cell: Cell] RETURNS [name: Name] = BEGIN name _ NIL; WHILE cell # NIL DO name _ CONS[cell.name, name]; cell _ cell.parent; ENDLOOP; END; GetDescr: PROC [name: Name, dbn: LORA] RETURNS [LORA] = BEGIN Matches: PROC [name: ROPE, asAny: REF ANY] RETURNS [BOOLEAN] = BEGIN dbn: LORA; s2: ROPE; IF NOT ISTYPE[asAny, LORA] THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [FALSE]; END; dbn _ NARROW[asAny]; IF (IF dbn = NIL THEN TRUE ELSE (IF dbn.first = NIL THEN TRUE ELSE (NOT ISTYPE[dbn.first, ROPE] AND NOT ISTYPE[dbn.first, ATOM]))) THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [FALSE]; END; s2 _ WITH dbn.first SELECT FROM r: ROPE => r, a: ATOM => Atom.GetPName[a], ENDCASE => ERROR; RETURN [Rope.Equal[s1: name, s2: s2, case: FALSE]]; END; WHILE name # NIL DO tail: LORA; IF (IF dbn = NIL THEN TRUE ELSE dbn.rest = NIL) THEN TRUSTED BEGIN MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE]; RETURN [NIL]; END; FOR tail _ dbn.rest.rest, tail.rest WHILE tail # NIL DO IF Matches[name.first, tail.first] THEN EXIT; ENDLOOP; IF tail = NIL THEN TRUSTED BEGIN MessageWindow.Append[message: "No decsion", clearFirst: TRUE]; RETURN [NIL]; END; name _ name.rest; dbn _ NARROW[tail.first]; ENDLOOP; RETURN [dbn]; END; MakeQueryPauser: ViewRec.OtherStuffProc = BEGIN v: Viewer; [qp, v] _ Pausers.CreatePauser[enabledName: "Answer Query", disabledName: "", viewerInit: [parent: in, border: FALSE], paint: FALSE]; RETURN [LIST[v]]; END; Ask: Rosemary.ExpandDecider = BEGIN first: BOOLEAN _ TRUE; eq.instanceName _ cell.name; eq.className _ cell.class.name; WHILE first OR NOT Possible[cell, eq.whatToDo] DO qp.Pause[]; first _ FALSE ENDLOOP; RETURN [eq.whatToDo]; END; qerv: ViewRec.RecordViewer; Setup: PROC = BEGIN RegisterCellClass[className: "GiveItAnything", expandProc: ExpandAnything, ioCreator: NIL, evalProc: NIL, ports: NEW [PortsRep[0]]]; TRUSTED BEGIN qerv _ ViewRec.ViewRef[ agg: eq, otherStuff: MakeQueryPauser, viewerInit: [iconic: FALSE, column: right, name: "ExpandQuery"]]; END; Atom.PutProp[atom: $N, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Nested]]; Atom.PutProp[atom: $I, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Inline]]; Atom.PutProp[atom: $L, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Leaf]]; END; Setup[]; END. vRoseHelpImpl.Mesa Last Edited by: Spreitzer, July 8, 1983 3:33 pm Last Edited by: Barth, June 9, 1983 11:23 am Κχ˜J™J™/JšΟk,™,Icode˜š ˜ Kšœ8œA˜{—K˜šΠbx œœ˜Kšœ<œ œ˜eKšœ ˜—K˜Kšœœ ˜K˜Kšœœœœ˜'K˜Kš œœœœœœ˜K˜Kšœœ˜$K˜Kš œœœœœ˜K˜Kšœ œœ˜#šœœœ˜Kšœœ˜K˜Kšœ œœœ˜—K˜Kšœ œœ ˜!šœ œœ˜Kšœœ˜ Kšœ œœ˜—K˜Kšœ œœ˜'šœœœ˜Kšœœœ˜$Kšœ,˜,—K˜K˜Kšœœ˜Kšœœ˜,šœœ!œ&˜UKšœœ˜—K˜Kšœœ˜#K˜šΟnœœœ,œ œœœ!œ˜žKš˜šœœ˜%Kšœ=˜=—Kšœ œ ˜1Kš œ œœœœœ˜WKšœt˜tKšœ˜—K˜šŸœ˜Kš˜Kšœœ ˜!K˜Kšœœœ˜šœœœ˜6Kšœœ˜(Kšœœ˜"K˜PKš œœœœœ ˜WKšœ˜—Kšœ™˜™Kšœ˜—K˜šŸ œœœœ˜4Kšœœœ˜,—K˜š Ÿœœœ œœ'˜[Kš˜Kšœœœœ˜Kšœœ˜ Kšœœ˜$Kš œœœœœ˜)K˜ KšœœM˜VKšœ˜—K˜šŸ œ˜&Kš˜š Ÿœœ œœ˜FKš˜K˜Kšœ œ˜Kšœ˜—Kšœœœ ˜*K˜Kšœœ#˜.Kšœœ˜ Kšœœœ˜Kšœ œœœ˜7šœœ˜Kš˜Kšœœœ˜+Kšœ˜%Kšœ˜—Kš œœœœœœ ˜QKš œ&œ,œœœ˜ˆKšœœ œœœœœœœœ˜rKšœœ˜+Kšœ˜—K˜Kšœœœ˜6K˜šŸœœœ˜1Kš˜Kšœœ˜ šœœ˜Kšœœ˜K˜Kšœ˜—Kšœ˜—K˜š Ÿœœœœœ˜7Kš˜šŸœœœ œœœœ˜>Kš˜Kšœœ˜ Kšœœ˜ š œœœœœ˜'Kš˜KšœCœ˜IKšœœ˜Kšœ˜—Kšœœ˜š'œœœœœœœ œœœœœœ œœœœ œœ˜Kš˜KšœCœ˜IKšœœ˜Kšœ˜—šœœ œ˜Kšœœ˜ Kšœœ˜Kšœœ˜—Kšœ%œ˜3Kšœ˜—šœœ˜Kšœœ˜ šœœœœœœ œœ˜Kšœœ˜ Kšœ˜—K˜Kšœœ ˜Kšœ˜—Kšœ˜ Kšœ˜—K˜šŸœ˜)Kš˜K˜ Kšœoœ œ˜…Kšœœ˜Kšœ˜—K˜šŸœ˜Kš˜Kšœœœ˜K˜K˜Kš œœœœœœ˜TKšœ˜Kšœ˜—K˜K˜K˜šŸœœ˜ Kš˜˜.K˜Kšœ œ˜Kšœ œ˜Kšœœ˜—K˜šœ˜ ˜Kšœ˜K˜Kšœœ'˜A—Kšœ˜—K˜KšœX˜XKšœX˜XKšœV˜VKšœ˜—K˜K˜K˜Kšœ˜—…—< ©