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 Σ 1985, 1986, 1987 by Xerox Corporation. All rights reserved. Last Edited by: Swinehart, April 6, 1987 12:07:31 pm PDT 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šœH™HJ™8J™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