<> <> DIRECTORY Commander, List USING [AList, Assoc, PutAssoc], Rope USING [Equal, FromRefText, ROPE], SymTab USING [Create, Delete, EachPairAction, Fetch, Pairs, Ref, Store]; CommanderImpl: CEDAR MONITOR IMPORTS List, Rope, SymTab EXPORTS Commander = BEGIN registry: SymTab.Ref; <> <<>> Register: PUBLIC ENTRY PROC[key: Rope.ROPE, proc: Commander.CommandProc, doc: Rope.ROPE] = { IF proc = NIL THEN [] _ SymTab.Delete[x: registry, key: key] ELSE [] _ SymTab.Store[x: registry, key: key, val: NEW[Commander.ProcCell _ [proc: proc, doc: doc]]]; }; Enumerate: PUBLIC ENTRY PROC[matchProc: PROC[name: Rope.ROPE, proc: Commander.CommandProc, doc: Rope.ROPE] RETURNS[stop: BOOL]] RETURNS [name: Rope.ROPE, proc: Commander.CommandProc, doc: Rope.ROPE] = { EachPairProc: SymTab.EachPairAction = { procCell: REF Commander.ProcCell _ NARROW[val, REF Commander.ProcCell]; name _ key; proc _ procCell.proc; doc _ procCell.doc; RETURN[matchProc[name: key, proc: proc, doc: doc]]; }; IF NOT SymTab.Pairs[x: registry, action: EachPairProc] THEN { name _ NIL; proc _ NIL; doc _ NIL; }; }; Lookup: PUBLIC PROC[key: Rope.ROPE] RETURNS [proc: Commander.CommandProc, doc: Rope.ROPE] = { procRef: REF ANY; found: BOOL; procCell: REF Commander.ProcCell; [found: found, val: procRef] _ SymTab.Fetch[x: registry, key: key]; IF procRef # NIL THEN procCell _ NARROW[procRef, REF Commander.ProcCell] ELSE procCell _ NIL; IF procCell # NIL THEN { proc _ procCell.proc; doc _ procCell.doc; } ELSE { proc _ NIL; doc _ NIL; }; }; <<>> <> <<>> <> <<>> GetProperty: PUBLIC ENTRY PROCEDURE [key: REF ANY, aList: List.AList] RETURNS [val: REF ANY] = { ropeKey: Rope.ROPE; val _ List.Assoc[key: key, aList: aList]; IF val # NIL THEN RETURN; <> WITH key SELECT FROM r: Rope.ROPE => ropeKey _ r; t: REF TEXT => ropeKey _ Rope.FromRefText[t]; ENDCASE; IF ropeKey # NIL THEN { FOR l: List.AList _ aList, l.rest WHILE l # NIL DO WITH l.first.key SELECT FROM r: Rope.ROPE => IF Rope.Equal[s1: ropeKey, s2: r, case: TRUE] THEN RETURN[l.first.val]; t: REF TEXT => IF Rope.Equal[s1: ropeKey, s2: Rope.FromRefText[t], case: TRUE] THEN RETURN[l.first.val]; ENDCASE; ENDLOOP; }; RETURN[NIL]; }; <<>> <> <<>> PutProperty: PUBLIC ENTRY PROCEDURE [key: REF ANY, val: REF ANY, aList: List.AList] RETURNS [List.AList] = { << handle it differently if key is a ROPE and already present on the list>> IF ISTYPE[key, Rope.ROPE] THEN { ropeKey: Rope.ROPE _ NARROW[key]; FOR l: List.AList _ aList, l.rest WHILE l # NIL DO IF ISTYPE[l.first.key, Rope.ROPE] THEN { IF Rope.Equal[s1: ropeKey, s2: NARROW[l.first.key, Rope.ROPE], case: TRUE] THEN { l.first.val _ val; RETURN[aList]; }; }; ENDLOOP; }; RETURN[List.PutAssoc[key: key, val: val, aList: aList]]; }; Init: PROCEDURE = { registry _ SymTab.Create[mod: 59, case: FALSE]; }; <<>> <> Init[]; END. March 28, 1983 12:26 pm, L. Stewart, created