<> <> <> DIRECTORY Commander USING [CommandProc, Handle, Register], CommandTool USING [NextArgument], FS USING [StreamOpen], IO USING [Close, GetChar, STREAM], LoganBerryBackdoor USING [MarkUpdateComplete, ReadLogEntry, WriteLogEntry], LoganBerry USING [Attribute, Entry], Rope USING [Cat, Fetch, Flatten, Length, MakeRope, ROPE, SkipOver, SkipTo, Substr], VoiceUtils USING [Problem, Rname, RnameToRspec, RspecToSortName]; WPFillImpl: CEDAR PROGRAM IMPORTS Commander, CommandTool, FS, IO, LoganBerryBackdoor, Rope, VoiceUtils = { ROPE: TYPE = Rope.ROPE; WhitePagesFill: SAFE PROC[cmd: Commander.Handle] = { s, t: IO.STREAM; listing: LoganBerry.Entry_NIL; lNew: LoganBerry.Entry_NIL; destFile: ROPE _ CommandTool.NextArgument[cmd]; sourceFile: ROPE _ CommandTool.NextArgument[cmd]; IF sourceFile=NIL OR destFile=NIL THEN { VoiceUtils.Problem["Source or Dest file not specified", $System]; RETURN; }; s _ FS.StreamOpen[sourceFile]; t _ FS.StreamOpen[destFile, $create]; DO rName: ROPE; listing _ LoganBerryBackdoor.ReadLogEntry[s, -1]; IF listing = NIL THEN EXIT; [] _ s.GetChar[]; rName _ Fetch[listing, $rname]; lNew_LIST[FeepAttr[rName], RegAttr[rName], FirstAttr[Fetch[listing, $name]]]; IF listing=NIL THEN listing _ lNew ELSE FOR lst: LoganBerry.Entry _ listing, lst.rest WHILE lst#NIL DO IF lst.rest=NIL THEN { lst.rest _ lNew; EXIT; }; ENDLOOP; []_LoganBerryBackdoor.WriteLogEntry[t, listing, TRUE]; ENDLOOP; s.Close[]; LoganBerryBackdoor.MarkUpdateComplete[t]; t.Close[]; }; FeepAttr: PROC[rName: ROPE] RETURNS[LoganBerry.Attribute] = { RETURN[[$fnm, FeepName[rName]]]; }; RegAttr: PROC[rName: ROPE] RETURNS[LoganBerry.Attribute] = { RETURN[[$rgnm, VoiceUtils.RspecToSortName[VoiceUtils.RnameToRspec[rName]]]]; }; FirstAttr: PROC[name: ROPE] RETURNS[LoganBerry.Attribute] = { commaIndex: INT _ Rope.SkipTo[name, 0, ","]; firstIndex: INT _ Rope.SkipOver[name, commaIndex+1, " "]; IF commaIndex#firstIndex THEN name _ Rope.Cat[name.Substr[firstIndex], " ", name.Substr[0, commaIndex]]; RETURN[[$fstnm, name]]; }; Fetch: PROC[listing: LoganBerry.Entry, key: ATOM] RETURNS [value: ROPE_NIL] = { FOR lst: LoganBerry.Entry _ listing, lst.rest WHILE lst#NIL DO IF lst.first.type = key THEN RETURN[lst.first.value]; ENDLOOP; }; FeepName: PUBLIC PROC[rName: ROPE] RETURNS[feepName: ROPE] = { FeepFetch: PROC[data: REF, index: INT] RETURNS [c: CHAR] = { c_NARROW[data, ROPE].Fetch[index]; IF c IN ['A..'Z] THEN c_c+('a-'A); IF c NOT IN ['a..'z] THEN c_'z+1; RETURN[FeepMap[c]]; }; feepName _ Rope.MakeRope[base: rName, size: rName.Length[], fetch: FeepFetch]; feepName _ Rope.Flatten[feepName]; }; FeepMap: PACKED ARRAY CHAR['a..'z+1] OF CHAR = [ '2, '2, '2, '3, '3, '3, '4, '4, '4, '5, '5, '5, '6, '6, '6, '7, '7, '7, '7, '8, '8, '8, '9, '9, '9, '9, '1 ]; FillCmd: Commander.CommandProc = TRUSTED { WhitePagesFill[cmd]; }; Commander.Register["WPFill", FillCmd, "WPFill augments log entries in source file"]; }. <> <> <<>> <<>> <<>> <<>>