-- File: DisjointProp.mesa
-- Routines to handle property lists
-- Written by Martin Newell/Dan Fitzpatrick June 1981
-- Last edited (Pilot): 16-Jul-81 14:27:38
DIRECTORY
DisjointAllocDefs: FROM "DisjointAllocDefs" USING [AllocateProp, FreeProp],
DisjointTypes: FROM "DisjointTypes" USING [PropList, PropID],
DisjointPropDefs: FROM "DisjointPropDefs",
Inline: FROM "Inline" USING [LowHalf];
DisjointProp: PROGRAM
IMPORTS DisjointAllocDefs, Inline
EXPORTS DisjointPropDefs =
BEGIN
OPEN DisjointAllocDefs, DisjointTypes, Inline;
AllocPropID: PUBLIC PROCEDURE[] RETURNS[PropID] =
-- Returns a unique PropID each time it is called
BEGIN
MaxPropID ← MaxPropID + 1;
RETURN[MaxPropID];
END;
PutProp: PUBLIC PROCEDURE [list: LONG POINTER TO PropList, id: PropID, data: UNSPECIFIED] =
-- Enters data into list with the specified PropID
-- Any data already in list with the given PropID is overwritten
BEGIN
PutLongProp[list,id,LONG[data]];
END;
PutLongProp: PUBLIC PROCEDURE [list: LONG POINTER TO PropList, id: PropID, data: LONG UNSPECIFIED] =
-- Enters long data into list with the specified PropID
-- Any data already in list with the given PropID is overwritten
BEGIN
prop: PropList ← FindProp[list↑,id];
IF prop # NIL THEN {
prop.data ← data;
}
ELSE {
prop ← FindProp[list↑, 0];
IF prop # NIL THEN {
prop.id ← id;
prop.data ← data;
}
ELSE {
prop ← AllocateProp[];
prop↑ ← [
next: list↑,
id: id,
data: data
];
list↑ ← prop;
}
}
END;
GetProp: PUBLIC PROCEDURE [list: PropList, id: PropID] RETURNS[UNSPECIFIED] =
-- Finds data with specified PropID from list
BEGIN
data: LONG UNSPECIFIED ← GetLongProp[list,id];
IF data = NIL THEN RETURN[NIL]
ELSE RETURN[LowHalf[data]];
END;
GetLongProp: PUBLIC PROCEDURE [list: PropList, id: PropID] RETURNS[LONG UNSPECIFIED] =
-- Finds long data with specified PropID from list
BEGIN
prop: PropList ← FindProp[list,id];
IF prop # NIL THEN RETURN[prop.data]
ELSE RETURN[LONG[NIL]];
END;
RemoveProp: PUBLIC PROCEDURE [list: PropList, id: PropID] =
-- Removes any data from list with the given PropID
BEGIN
prop: PropList ← FindProp[list,id];
IF prop # NIL THEN prop.id ← 0;
END;
FreePropList: PUBLIC PROCEDURE [list: PropList] =
-- Frees all storage used by list
BEGIN
next: PropList;
FOR prop: PropList ← list, next UNTIL prop = NIL DO
next ← prop.next;
FreeProp[prop];
ENDLOOP;
END;
FindProp: PROCEDURE [list: PropList, id: PropID] RETURNS[cell: PropList] =
-- Returns property cell found in list with given PropID
BEGIN
FOR cell ← list, cell.next UNTIL cell = NIL DO
IF cell.id = id THEN RETURN;
ENDLOOP;
END;
MaxPropID: CARDINAL ← 0;
END.