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𡤌+('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 <destFile> <sourceFile> augments log entries in source file"];
}.
Swinehart, November 8, 1986 3:02:55 pm PST
Derived from old WPFill stuff, but only vaguely. Adds feep name, first name, reg name entries to log so that indices can be created for them. Would prefer to be able to specify these keys computationally. Maybe we should be programming in Lisp., FeepAttr, RegAttr, FirstAttr, FeepName, DIRECTORY