DIRECTORY Atom USING [PropList], Commander USING [GetProperty, Handle], FS USING [ExpandName], IO USING [atom, Put, PutF, rope], LoganBerry USING [Close, EnumerateEntries, Error, Open, WriteEntry], PrincOps USING [], ProcessProps USING [GetPropList], RefID USING [nullID], Rope USING [Concat, ROPE], ThNet USING [WPListing, WPState, WPStateBody], UserProfile USING [Token], VoiceUtils USING [Problem, WhereToReport] ; WPBTreeImpl: CEDAR PROGRAM IMPORTS Commander, FS, IO, LoganBerry, ProcessProps, Rope, UserProfile, VoiceUtils EXPORTS ThNet = { OPEN IO; ROPE: TYPE = Rope.ROPE; WPListing: TYPE = ThNet.WPListing; WPState: TYPE = ThNet.WPState; InitWhitePagesDatabase: PUBLIC PROC[ fileName: ROPE, howToComplain: VoiceUtils.WhereToReport_$System] RETURNS[wpState: WPState_NIL] = { IF fileName=NIL THEN fileName _ UserProfile.Token[key: "ThrushWPFileName", default: "WhitePages.df"]; wpState _ NEW[ThNet.WPStateBody _ [ dbName: FS.ExpandName[fileName].fullFName, howToComplain: howToComplain]]; []_OpenWhitePagesDatabase[wpState]; }; OpenWhitePagesDatabase: PROC[ wpState: WPState] RETURNS [ok: BOOL_FALSE] = { ENABLE LoganBerry.Error => { VoiceUtils.Problem[IF ec=$DBNotAvailable THEN "Trouble opening white pages" ELSE "Trouble opening white pages", wpState.howToComplain]; CONTINUE }; --  IF wpState=NIL THEN RETURN[FALSE]; wpState.db _ LoganBerry.Open[dbName: wpState.dbName]; RETURN[TRUE]; }; CloseWhitePagesDatabase: PUBLIC PROC[ wpState: WPState, howToComplain: VoiceUtils.WhereToReport_$System] RETURNS [ok: BOOL_TRUE] = { IF wpState.db#RefID.nullID THEN LoganBerry.Close[db: wpState.db]; wpState.db _ RefID.nullID; }; WhitePagesLookup: PUBLIC PROC[ wpState: WPState, name: ROPE, feep: BOOL_FALSE ] RETURNS [ listing: WPListing_NIL ] = { FindOne: PROC[entry: WPListing] RETURNS [continue: BOOLEAN_FALSE] = { IF feep AND listing#NIL THEN { listing _ NIL; RETURN; }; -- must be unique! listing _ entry; RETURN[feep]; }; IF ~OpenWhitePagesDatabase[wpState] THEN RETURN; -- Open is cheap! []_LoganBerry.EnumerateEntries[db: wpState.db, key: IF feep THEN $fnm ELSE $rname, start: name, end: name.Concat["\377"], proc: FindOne]; }; WhitePagesEntry: PUBLIC PROC[ wpState: WPState, name: ROPE_NIL, key: ATOM_$OfficeNumber, feep: BOOL_FALSE, listing: WPListing _ NIL] RETURNS [fullRName: ROPE_NIL, entry: ROPE_NIL, newListing: WPListing_NIL] = { IF listing = NIL THEN listing _ WhitePagesLookup[wpState, name, feep]; newListing _ listing; IF newListing = NIL THEN RETURN; fullRName _ Fetch[newListing, $rname]; IF key#NIL THEN entry _ Fetch[newListing, key]; }; WhitePagesEnter: PUBLIC PROC[wpState: WPState, listing: WPListing] = { IF ~OpenWhitePagesDatabase[wpState] THEN RETURN; LoganBerry.WriteEntry[db: wpState.db, entry: listing, replace: TRUE]; }; WhitePagesPrint: PUBLIC PROC[wpState: WPState, listing: WPListing] = { p: Atom.PropList = ProcessProps.GetPropList[]; h: Commander.Handle; IF p=NIL THEN RETURN; h _ NARROW[Commander.GetProperty[$CommanderHandle, p]]; FOR lst: WPListing _ listing, lst.rest WHILE lst#NIL DO h.out.PutF["%g: %g\n", atom[lst.first.type], rope[lst.first.value]]; IF lst.first.type=$Rname AND h.out#h.err THEN h.err.Put[rope[lst.first.value], rope["\n"]]; ENDLOOP; }; Fetch: PROC[listing: WPListing, key: ATOM] RETURNS [value: ROPE_NIL] = { FOR lst: WPListing _ listing, lst.rest WHILE lst#NIL DO IF lst.first.type = key THEN RETURN[lst.first.value]; ENDLOOP; }; }. ΎWPBTreeImpl.mesa Copyright c 1985, 1986 by Xerox Corporation. All rights reserved. Last Edited by: Swinehart, February 23, 1987 7:44:53 am PST White pages databases can be browsed using the LoganBerryBrowser. Representation primitives Top-level State ThNet Procedures Returns first listing for which name is a substring, case unimportant, of the listing Swinehart, May 16, 1985 9:16:38 am PDT Cedar 6.0 changes to: DIRECTORY, WPBTreeImpl, WhitePagesFill Swinehart, October 28, 1985 12:05:20 pm PST Log => VoiceUtils changes to: DIRECTORY, WPBTreeImpl, InitWhitePagesDatabase, OpenWhitePagesDatabase, CloseWhitePagesDatabase, GetLinkValues, WhitePagesFill Swinehart, November 7, 1986 5:20:40 pm PST Use LoganBerry instead of specialized BTree stuff. changes to: WPBTreeImpl, WPState, InitWhitePagesDatabase, OpenWhitePagesDatabase, WhitePagesLookup, FindOne, WhitePagesEntry, Fetch, WhitePagesEnter, WhitePagesPrint, WPFn, WhitePagesDo, }, DIRECTORY Κϋ– "Cedar" style˜šœ™Jšœ Οmœ7™BJ™;J™A—J˜šΟk ˜ Jšœžœ ˜Jšœ žœ˜&Jšžœžœ˜Jšžœžœ˜!Jšœ žœ4˜DJšœ žœ˜Jšœ žœ˜!Jšœžœ ˜Jšœžœ žœ˜Jšœžœ#˜.Jšœ žœ ˜Jšœ žœ˜)J˜—code2šΟn œžœž˜Icodešžœ žœžœ9˜RLšžœ ˜Lšžœžœ˜Kšžœžœžœ˜—head™™Kšœ žœ˜"Jšœ žœ˜——šœ™J˜šŸœžœžœ˜$Jšœ žœ2˜@Jšžœžœ˜!šžœ žœž˜J˜P—šœ žœ˜#Jšœžœ@˜J—Jšœ#˜#J˜—J˜šŸœžœ˜Jšœ˜Jšžœžœžœ˜šžœ˜Jš œžœžœžœ8žœΠct˜™—Jš žœ žœžœžœžœ˜"K˜5Jšžœžœ˜ J˜J˜—šŸœžœžœ˜%JšœB˜BJšžœžœžœ˜Jšžœžœ"˜AJ˜J˜J˜—šŸœžœžœ˜Jšœžœžœžœ˜0Jšžœžœ˜&J™Uš Ÿœžœžœ žœžœ˜EJš žœžœ žœžœ žœžœΟc˜KJ˜Jšžœ˜ J˜—Jšžœ"žœžœ‘˜Bšœ4žœžœžœ˜RJšœ6˜6—J˜—J˜šŸœžœžœ˜Jš œžœžœžœžœžœ˜LJšœžœ˜Jš žœ žœžœ žœžœžœ˜MJšžœ žœžœ2˜GJ˜Jšžœžœžœžœ˜ J˜&Jšžœžœžœ ˜/J˜—J˜šŸœžœžœ*˜FJšžœ"žœžœ˜0Jšœ?žœ˜EJ˜J˜—šŸœžœžœ*˜FJ˜.J˜Jšžœžœžœžœ˜Jšœžœ-˜7šžœ$žœžœž˜7J˜DJšžœžœ žœ.˜[Jšžœ˜—J˜J˜—š Ÿœžœžœžœ žœžœ˜Hšžœ$žœžœž˜7Jšžœžœžœ˜5Jšžœ˜—J˜—Kšžœ˜—™&L™ Lšœ Οr&™2—™+L™Lšœ ’~™Š—™*L™2Lšœ ’»™Η—L™L™—…— R