ScanLog.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by: Willie-Sue, April 8, 1985 4:26:29 pm PST
DIRECTORY
IO,
RefTab USING [EachPairAction, Ref, Val, Create, Fetch, Store, Pairs],
Rope USING [ROPE],
ViewerClasses USING [Viewer],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [FindViewer, OpenIcon],
WalnutStream USING [Open, PeekEntry];
ScanLog: CEDAR PROGRAM
IMPORTS
IO, RefTab, ViewerIO, ViewerOps, WalnutStream
= BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
out: STREAMNIL;
Xyz: TYPE = REF ValueObject;
ValueObject: TYPE = RECORD[num, bytes: INT ← 0];
DebugStream: PROC RETURNS [IO.STREAM] = {
v: ViewerClasses.Viewer ← ViewerOps.FindViewer["NewWalnut ScanLog"];
out: IO.STREAM ← ViewerIO.CreateViewerStreams["NewWalnut ScanLog", v].out;
IF v#NIL THEN IF v.iconic THEN ViewerOps.OpenIcon[v];
RETURN[out];
};
Scan: PROC[logFile: ROPE] = {
ident: ATOM;
at, length: INT;
strm: STREAM;
table: RefTab.Ref ← RefTab.Create[];
found: BOOL;
val: RefTab.Val;
count: INT ← 0;
ForPrinting: RefTab.EachPairAction = {
ident: ATOMNARROW[key];
this: Xyz ← NARROW[val];
out.PutF["Ident: %g, num: %g, bytes: %g\n",
IO.atom[ident], IO.int[this.num], IO.int[this.bytes] ];
RETURN[FALSE];  -- don't quit
};
out ← DebugStream[];
strm ← WalnutStream.Open[name: logFile, readOnly: TRUE];
out.PutF["\n Scanning the logfile: %g\n\n(0)", IO.rope[logFile]];
strm.SetIndex[at ← 0];
DO
this: Xyz;
[ident, , length] ← WalnutStream.PeekEntry[strm];
IF ident = NIL THEN EXIT;
strm.SetIndex[at ← at + length];
[found, val] ← RefTab.Fetch[table, ident];
IF found THEN {
this ← NARROW[val];
this.num ← this.num + 1;
this.bytes ← this.bytes + length;
}
ELSE this ← NEW[ValueObject ← [1, length]];
[] ← RefTab.Store[table, ident, this];
IF (count ← count + 1) MOD 10 = 0 THEN {
IF count MOD 100 = 0 THEN out.PutF["(%g)", IO.int[count]]
ELSE out.PutChar['~];
};
ENDLOOP;
out.PutF["\n\n\t\tThe log contained the following %g entries:\n", IO.int[count]];
[] ← RefTab.Pairs[table, ForPrinting];
strm.Close[];
};
END.