<> <> <> <> 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; }; }. <> <> <> <> < VoiceUtils>> <> <> <> <> <<>> <<>>