DIRECTORY Atom USING [EmptyAtom], Basics USING [BITXOR, LowHalf], PGSupport USING [FormatHashIndex, formatHashSize, LooksHashIndex, looksHashSize, noLooks, PGF, PGFBody, PropHashIndex, propHashSize], PrincOps USING [zXOR], TextLooks USING [Looks, LooksBytes, noLooks], TiogaFile USING [FileId, fileIdSize, FormatIndex, IntBytes, LengthByte, LooksIndex, numFormats, numLooks, numProps, PropIndex, ThirdByte, trailerLengthSize]; PGSupportImpl: CEDAR MONITOR IMPORTS Atom, Basics EXPORTS PGSupport = BEGIN OPEN PGSupport; Looks: TYPE ~ TextLooks.Looks; noLooks: Looks ~ TextLooks.noLooks; PropIndex: TYPE ~ TiogaFile.PropIndex; FormatIndex: TYPE ~ TiogaFile.FormatIndex; LooksIndex: TYPE ~ TiogaFile.LooksIndex; CreatePGF: PUBLIC PROC RETURNS [pgf: PGF] = { pgf _ AllocPGF[]; pgf.looksTable[0] _ TextLooks.noLooks; pgf.looksNext _ 1; -- reserve 0 for noLooks FOR i:LooksHashIndex IN LooksHashIndex DO pgf.looksHashKeys[i].looks _ TextLooks.noLooks; ENDLOOP; pgf.formatTable[0] _ NIL; FOR i:FormatHashIndex IN FormatHashIndex DO pgf.formatHashKeys[i].formatName _ NIL; ENDLOOP; pgf.formatNext _ 1; -- reserve 0 for null formatname pgf.propNext _ 1; --reserve 0 for NIL FOR i:PropHashIndex IN PropHashIndex DO pgf.propHashKeys[i].propname _ NIL; ENDLOOP; [] _ EnterProp[$Prefix, pgf]; -- preload system atoms [] _ EnterProp[$Postfix, pgf]; }; pgf1, pgf2, pgf3: PGF _ NIL; AllocPGF: ENTRY PROC RETURNS [pgf: PGF] = { ENABLE UNWIND => NULL; IF pgf3 # NIL THEN { pgf _ pgf3; pgf3 _ NIL } ELSE IF pgf2 # NIL THEN { pgf _ pgf2; pgf2 _ NIL } ELSE IF pgf1 # NIL THEN { pgf _ pgf1; pgf1 _ NIL } ELSE pgf _ NEW[PGFBody] }; FreePGF: PUBLIC ENTRY PROC [pgf: PGF] = { ENABLE UNWIND => NULL; IF pgf3 = pgf OR pgf2 = pgf OR pgf1 = pgf THEN ERROR; IF pgf3 = NIL THEN pgf3 _ pgf ELSE IF pgf2 = NIL THEN pgf2 _ pgf ELSE IF pgf1 = NIL THEN pgf1 _ pgf }; BadIndex: PUBLIC ERROR = CODE; RetrieveFormatName: PUBLIC PROC [index: FormatIndex, pgf: PGF] RETURNS [formatName: ATOM] = { IF index >= pgf.formatNext THEN ERROR BadIndex; RETURN [pgf.formatTable[index]] }; RetrieveLooks: PUBLIC PROC [index: LooksIndex, pgf: PGF] RETURNS [looks: Looks] = { IF index >= pgf.looksNext THEN ERROR BadIndex; RETURN [pgf.looksTable[index]] }; RetrieveProp: PUBLIC PROC [index: PropIndex, pgf: PGF] RETURNS [propname: ATOM] = { IF index >= pgf.propNext THEN ERROR BadIndex; RETURN [pgf.propTable[index]] }; Munch: PROC [key: ATOM] RETURNS [CARDINAL] = TRUSTED MACHINE CODE { PrincOps.zXOR; }; true: BOOL[TRUE..TRUE] ~ (SIZE[ATOM]-SIZE[CARDINAL] = 1); EnterFormatName: PUBLIC PROC [formatName: ATOM, pgf: PGF] RETURNS [ok: BOOL, index: TiogaFile.FormatIndex] = { next: NAT _ pgf.formatNext; initloc, loc: NAT; IF formatName = NIL OR formatName = Atom.EmptyAtom[] THEN RETURN [TRUE, 0]; -- reserved loc _ initloc _ Munch[formatName] MOD formatHashSize; DO SELECT pgf.formatHashKeys[loc].formatName FROM formatName => RETURN [TRUE, pgf.formatHashVals[loc].index]; NIL => EXIT; -- this is an unused entry ENDCASE; SELECT (loc _ loc+1) FROM formatHashSize => IF (loc _ 0)=initloc THEN ERROR; initloc => ERROR; -- should never have full table ENDCASE; ENDLOOP; IF next < TiogaFile.numFormats THEN -- room left in table BEGIN pgf.formatTable[next] _ formatName; pgf.formatNext _ next+1; pgf.formatHashKeys[loc].formatName _ formatName; pgf.formatHashVals[loc].index _ LOOPHOLE[next]; END; RETURN [FALSE, 0] }; -- index irrelevant in this case EnterLooks: PUBLIC PROC [looks: TextLooks.Looks, pgf: PGF] RETURNS [ok: BOOL, index: TiogaFile.LooksIndex] = { next: NAT _ pgf.looksNext; initloc, loc: NAT; IF looks = TextLooks.noLooks THEN RETURN [TRUE, 0]; -- reserved loc _ initloc _ LOOPHOLE[ Basics.BITXOR[ LOOPHOLE[looks, TextLooks.LooksBytes].byte0, Basics.BITXOR[LOOPHOLE[looks, TextLooks.LooksBytes].byte1, LOOPHOLE[looks, TextLooks.LooksBytes].byte2]],NAT] MOD looksHashSize; DO SELECT pgf.looksHashKeys[loc].looks FROM looks => RETURN [TRUE, pgf.looksHashVals[loc].index]; TextLooks.noLooks => EXIT; -- this is an unused entry ENDCASE; SELECT (loc _ loc+1) FROM looksHashSize => IF (loc _ 0)=initloc THEN ERROR; initloc => ERROR; -- should never have full table ENDCASE; ENDLOOP; IF next < TiogaFile.numLooks THEN -- room left in table BEGIN pgf.looksTable[next] _ looks; pgf.looksNext _ next+1; pgf.looksHashKeys[loc].looks _ looks; pgf.looksHashVals[loc].index _ LOOPHOLE[next]; END; RETURN [FALSE, 0] }; -- index irrelevant in this case EnterProp: PUBLIC PROC [propname: ATOM, pgf: PGF] RETURNS [ok: BOOL, index: TiogaFile.PropIndex] = { next: NAT _ pgf.propNext; initloc, loc: NAT; IF propname = NIL THEN RETURN [TRUE, 0]; -- reserved loc _ initloc _ (LOOPHOLE[Basics.LowHalf[LOOPHOLE[propname]],NAT] / 16) MOD propHashSize; DO SELECT pgf.propHashKeys[loc].propname FROM propname => RETURN [TRUE, pgf.propHashVals[loc].index]; NIL => EXIT; -- this is an unused entry ENDCASE; SELECT (loc _ loc+1) FROM propHashSize => IF (loc _ 0)=initloc THEN ERROR; initloc => ERROR; -- should never have full table ENDCASE; ENDLOOP; IF next < TiogaFile.numProps THEN -- room left in table BEGIN pgf.propTable[next] _ propname; pgf.propNext _ next+1; pgf.propHashKeys[loc].propname _ propname; pgf.propHashVals[loc].index _ LOOPHOLE[next]; END; RETURN [FALSE, 0] }; -- index irrelevant in this case PutLength: PUBLIC PROC [put: PROC [CHAR], len: INT] = { first, second, fourth: TiogaFile.LengthByte; third: TiogaFile.ThirdByte; intBytes: TiogaFile.IntBytes _ LOOPHOLE[len]; IF intBytes.fourth#0 THEN { fourth.data _ intBytes.fourth; first.others _ second.others _ third.others _ TRUE }; IF intBytes.thirdTop#0 OR intBytes.thirdBottom#0 THEN { third.dataTop _ intBytes.thirdTop; third.dataBottom _ intBytes.thirdBottom; first.others _ second.others _ TRUE; }; IF intBytes.second#0 THEN { second.data _ intBytes.second; first.others _ TRUE; }; first.data _ intBytes.first; put[LOOPHOLE[first]]; IF first.others THEN { put[LOOPHOLE[second]]; IF second.others THEN { put[LOOPHOLE[third]]; IF third.others THEN { put[LOOPHOLE[fourth]]; }; }; }; }; GetLength: PUBLIC PROC [get: PROC RETURNS [CHAR]] RETURNS [INT] ~ { first, second, fourth: TiogaFile.LengthByte; third: TiogaFile.ThirdByte; intBytes: TiogaFile.IntBytes _ []; first _ LOOPHOLE[get[]]; intBytes.first _ first.data; IF NOT first.others THEN RETURN [LOOPHOLE[intBytes]]; second _ LOOPHOLE[get[]]; intBytes.second _ second.data; IF NOT second.others THEN RETURN [LOOPHOLE[intBytes]]; third _ LOOPHOLE[get[]]; intBytes.thirdBottom _ third.dataBottom; intBytes.thirdTop _ third.dataTop; IF NOT third.others THEN RETURN [LOOPHOLE[intBytes]]; fourth _ LOOPHOLE[get[]]; intBytes.fourth _ fourth.data; RETURN [LOOPHOLE[intBytes]]; }; fileIdSize: INT ~ TiogaFile.fileIdSize; FileIdIndex: TYPE ~ [0..TiogaFile.fileIdSize); PutFileId: PUBLIC PROC [put: PROC [CHAR], id: TiogaFile.FileId] ~ { FOR i: FileIdIndex IN FileIdIndex DO put[id[i]] ENDLOOP; }; GetFileId: PUBLIC PROC [get: PROC RETURNS [CHAR]] RETURNS [id: TiogaFile.FileId] ~ { FOR i: FileIdIndex IN FileIdIndex DO id[i] _ get[] ENDLOOP; }; lenSize: INT ~ TiogaFile.trailerLengthSize; LenIndex: TYPE ~ [0..lenSize); LenBytes: TYPE ~ PACKED ARRAY LenIndex OF CHAR; PutTrailerLength: PUBLIC PROC [put: PROC [CHAR], len: INT] ~ { FOR i: LenIndex IN LenIndex DO put[LOOPHOLE[len, LenBytes][i]] ENDLOOP; }; GetTrailerLength: PUBLIC PROC [get: PROC RETURNS [CHAR]] RETURNS [len: INT] ~ { FOR i: LenIndex IN LenIndex DO LOOPHOLE[len, LenBytes][i] _ get[] ENDLOOP; }; END. „PGSupportImpl.mesa Copyright c 1985, 1986 by Xerox Corporation. All rights reserved. Written by Bill Paxton, January 1981 Paxton. October 18, 1982 11:28 am Russ Atkinson, July 25, 1983 2:37 pm Michael Plass, March 29, 1985 2:06:49 pm PST format Rick Beach, March 28, 1985 9:43:10 am PST Doug Wyatt, September 22, 1986 1:24:39 pm PDT -- PGF is the file-level structure for put/get Κ Α˜codešœ™Kšœ Οmœ7™BKšœ$™$Kšœ"™"K™$K™3K™)K™-—K˜šΟk ˜ Kšœžœ ˜Kšœžœžœ ˜Kšœ žœKžœ(˜…Kšœ žœ˜Kšœ žœ˜-Kšœ žœŽ˜—K˜KšΠbl œžœž˜Kšžœ ˜Kšžœ ˜Kšœžœžœ ˜K˜Kšœžœ˜Kšœ#˜#K˜Kšœ žœ˜&Kšœ žœ˜*Kšœ žœ˜(K˜K˜K˜Kšœ.™.K˜š Οn œžœžœžœžœ˜-Kšœ˜K˜&KšœΟc˜+šžœžœž˜)Kšœ0žœ˜8—Kšœžœ˜šžœžœž˜+Kšœ#žœžœ˜0—Kšœ‘ ˜4Kšœ‘˜%šžœžœž˜'Kšœžœžœ˜,—Kšœ‘˜5K˜K˜K˜—Kšœžœžœ˜K˜š  œžœžœžœžœ˜+Kšžœžœžœ˜Kšžœžœžœžœ˜-Kš žœžœžœžœžœ˜2Kš žœžœžœžœžœ˜2Kšžœžœ ˜K˜—š  œžœžœžœžœ˜)Kšžœžœžœ˜Kš žœ žœ žœ žœžœ˜5Kšžœžœžœ ˜Kšžœžœžœžœ ˜"Kšžœžœžœžœ˜%K˜—šœ žœžœžœ˜K˜—š  œžœžœžœžœžœ˜Yš œžœžœžœ žœ˜VK˜——š   œžœžœžœžœ˜OKš œžœžœžœ žœ˜TK˜—š   œžœžœžœžœ žœ˜OKš œžœžœžœ žœ˜RK˜—š œžœžœžœžœžœžœžœ˜CKšœ˜Kšœ˜—šœžœžœžœžœžœžœžœ˜9K˜—š œžœžœ žœžœžœžœ#˜nKšœžœ˜Kšœžœ˜Kš žœžœžœžœžœžœ‘ ˜WKšœ"žœ˜5šžœžœ$ž˜1Kšœžœžœ!˜;Kšžœžœ‘˜'Kšžœ˜šžœž˜Kšœžœžœžœ˜2Kšœ žœ‘˜1Kšžœ˜—Kšžœ˜—šžœžœ‘˜9Kšž˜K˜#K˜K˜0Kšœ žœ˜/Kšžœ˜—Kšžœžœ‘ ˜5K˜—š   œžœžœžœžœžœ"˜nKšœžœ˜Kšœžœ˜Kš žœžœžœžœ‘ ˜?šœžœ˜šœžœ˜šžœ$˜,šœžœžœ$˜:Kšžœ&žœ˜2———Kšžœ˜—šžœžœž˜+Kšœ žœžœ ˜5Kšœžœ‘˜5Kšžœ˜šžœž˜Kšœžœžœžœ˜1Kšœ žœ‘˜1Kšžœ˜—Kšžœ˜—šžœžœ‘˜7Kšž˜K˜K˜K˜%Kšœžœ˜.Kšžœ˜—Kšžœžœ‘ ˜5K˜—š  œžœžœ žœžœžœžœ!˜dKšœžœ˜Kšœžœ˜Kš žœ žœžœžœžœ‘ ˜4Kš œžœžœ žœžœ˜Yšžœžœ ž˜-Kšœ žœžœ˜7Kšžœžœ‘˜'Kšžœ˜šžœž˜Kšœžœžœžœ˜0Kšœ žœ‘˜1Kšžœ˜—Kšžœ˜—šžœžœ‘˜7Kšž˜K˜K˜K˜*Kšœžœ˜-Kšžœ˜—Kšžœžœ‘ ˜5K˜—K˜š   œžœžœžœžœžœ˜7K˜,K˜Kšœžœ˜-šžœžœ˜K˜Kšœ.žœ˜3K˜—šžœžœžœ˜7K˜"K˜(Kšœžœ˜$K˜—šžœžœ˜Kšœ˜Kšœžœ˜K˜—K˜Kšœžœ ˜šžœžœ˜Kšœžœ ˜šžœžœ˜Kšœžœ ˜šžœžœ˜Kšœžœ ˜Kšœ˜—Kšœ˜—Kšœ˜—K˜K˜—š  œžœžœžœžœžœžœžœ˜CK˜,K˜Kšœ"˜"Kšœžœ˜K˜Kš žœžœžœžœžœ ˜5Kšœ žœ˜K˜Kš žœžœžœžœžœ ˜6Kšœžœ˜K˜(K˜"Kš žœžœžœžœžœ ˜5Kšœ žœ˜K˜Kšžœžœ ˜K˜K˜—Kšœ žœ˜'šœ žœ˜.K˜—š   œžœžœžœžœ˜CKšžœžœ žœ žœ˜8K˜K˜—š  œžœžœžœžœžœžœ˜TKšžœžœ žœžœ˜;K˜K˜—Kšœ žœ˜+Kšœ žœ˜š œ žœžœžœ žœžœ˜/K˜—š  œžœžœžœžœžœ˜>Kš žœ žœ žœžœžœ˜GK˜K˜—š œžœžœžœžœžœžœžœ˜OKš žœ žœ žœžœžœ˜JK˜K˜—K˜Kšžœ˜—…—)]