DecomposerRegistryImpl.mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) April 10, 1992 6:30 pm PDT
Michael Plass, March 3, 1992 1:10 pm PST
DIRECTORY BasicTime, Rope, DecomposerRegistry;
DecomposerRegistryImpl: CEDAR MONITOR
EXPORTS DecomposerRegistry
= BEGIN OPEN DecomposerRegistry;
RegistryList: TYPE = LIST OF DecomposerData;
registry: RegistryList ← NIL;
Register: PUBLIC ENTRY PROC [data: DecomposerData] = {
Registers a decomposer under data.key. Any previous registration for the given key is lost.
Some anticipated keys are:
$IP Interpress
$PS PostScript
$PCL HP PCL
IF data # NIL THEN {
FOR each: RegistryList ← registry, each.rest WHILE each # NIL DO
first: DecomposerData = each.first;
IF first.key = data.key THEN {each.first ← data; RETURN};
ENDLOOP;
registry ← CONS[data, registry];
};
};
UnRegister: PUBLIC ENTRY PROC [data: DecomposerData] = {
Removes the registration (if any) for the given data.
IF data # NIL THEN {
lag: RegistryList ← NIL;
FOR each: RegistryList ← registry, each.rest WHILE each # NIL DO
first: DecomposerData = each.first;
IF each.first = data THEN {
IF lag = NIL THEN registry ← each.rest ELSE lag.rest ← each.rest;
RETURN;
};
lag ← each;
ENDLOOP;
};
};
Lookup: PUBLIC ENTRY PROC [key: ATOM] RETURNS [DecomposerData] = {
Looks up a registered decomposer under a given key. NIL is returned when there is no registration.
FOR each: RegistryList ← registry, each.rest WHILE each # NIL DO
first: DecomposerData = each.first;
IF first.key = key THEN RETURN [first];
ENDLOOP;
RETURN [NIL];
};
Enumerate: PUBLIC ENTRY PROC RETURNS [LIST OF DecomposerData] = {
Returns a list of the current registered decomposers. The order is not important. No element in the list is NIL.
head: RegistryList ← NIL;
tail: RegistryList ← NIL;
FOR each: RegistryList ← registry, each.rest WHILE each # NIL DO
new: RegistryList ← LIST[each.first];
IF tail = NIL THEN head ← new ELSE tail.rest ← new;
tail ← new;
ENDLOOP;
RETURN [head];
};
MakeBoolVal: PUBLIC PROC [b: BOOL] RETURNS [Value] = {
RETURN [NEW[ValueRep.boolean ← [boolean[b]]]];
};
MakeCardVal: PUBLIC PROC [c: CARD32] RETURNS [Value] = {
RETURN [NEW[ValueRep.cardinal ← [cardinal[c]]]];
};
MakeIntVal: PUBLIC PROC [i: INT32] RETURNS [Value] = {
RETURN [NEW[ValueRep.integer ← [integer[i]]]];
};
MakeTimeVal: PUBLIC PROC [gmt: BasicTime.GMT] RETURNS [Value] = {
RETURN [NEW[ValueRep.time ← [time[gmt]]]];
};
MakeTextVal: PUBLIC PROC [rope: Rope.ROPE] RETURNS [Value] = {
RETURN [NEW[ValueRep.text ← [text[rope]]]];
};
MakeSeqVal1: PUBLIC PROC [val: Value] RETURNS [Value] = {
seq: ValueSeq = NEW[ValueSeqRep[1]];
seq[0] ← val;
RETURN [NEW[ValueRep.sequence ← [sequence[seq]]]];
};
MakeSeqVal2: PUBLIC PROC [val1, val2: Value] RETURNS [Value] = {
seq: ValueSeq = NEW[ValueSeqRep[2]];
seq[0] ← val1;
seq[1] ← val2;
RETURN [NEW[ValueRep.sequence ← [sequence[seq]]]];
};
MakeSeqValList: PUBLIC PROC [list: LIST OF Value] RETURNS [Value] = {
seq: ValueSeq ← NIL;
n: NAT ← 0;
FOR each: LIST OF Value ← list, each.rest WHILE each # NIL DO
n ← n + 1;
ENDLOOP;
seq ← NEW[ValueSeqRep[n]];
n ← 0;
FOR each: LIST OF Value ← list, each.rest WHILE each # NIL DO
seq[n] ← each.first;
n ← n + 1;
ENDLOOP;
RETURN [NEW[ValueRep.sequence ← [sequence[seq]]]];
};
END.