StyleList.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Matt Kaplan, July 22, 1985 1:07:26 pm PDT
MKaplan, September 12, 1985 3:01:38 pm PDT
Given a root directory, collects list of styles used by files beneath root, counts number of files of each style, and produces list of files with mesa style. List of mesa files is placed in MesaStyleFiles.log, and style counts in StyleList.log.
DIRECTORY
Atom USING [GetPropFromList],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Parse],
FileNames USING [ResolveRelativePath],
IO USING [int, PutF, rope, STREAM, Flush],
FS USING [StreamOpen, OpenFileFromStream, Close, EnumerateForNames, NameProc, ExpandName, ComponentPositions, Error],
TiogaAccess USING [FromFile, GetExternalProp, GetNodeProps, Reader, DoneWith],
SymTab USING [Create, EachPairAction, Fetch, Pairs, Ref, Store, Val],
Rope USING [ROPE, Substr, Equal, Find];
StyleList: CEDAR PROGRAM
IMPORTS Commander, CommandTool, FileNames, FS, IO, TiogaAccess, Atom, SymTab, Rope
= BEGIN
StyleListProc: Commander.CommandProc ~ {
PROC [cmd: Handle] RETURNS [result: REFNIL, msg: Rope.ROPENIL];
argv: CommandTool.ArgumentVector;
reader: TiogaAccess.Reader;
styleTable: SymTab.Ref;
styleName: Rope.ROPE;
Entry: TYPE ~ REF EntryRep;
EntryRep: TYPE ~ RECORD[
entry: INT
];
nTimes: Entry;
argNum: INT ← 0;
val: SymTab.Val;
styleLogStream: IO.STREAMFS.StreamOpen["StyleList.log", $create];
fileLogStream: IO.STREAMFS.StreamOpen["MesaStyleFiles.log", $create];
styleProperty: ATOM ← $Prefix;
pattern: Rope.ROPE;
currentDirectory: Rope.ROPE;
PrintStyleStats: PROC ~ {
IO.PutF[styleLogStream, "Style Counts for %g\n\n", IO.rope[pattern]];
[] ← SymTab.Pairs[styleTable, PrintTableEntry];
};
PrintTableEntry: SymTab.EachPairAction = {
[key: SymTab.Key, val: SymTab.Val] RETURNS [quit: BOOL]
e: Entry ← NARROW[val];
IO.PutF[styleLogStream, " %g:\t%g\n", IO.rope[key], IO.int[e.entry]];
RETURN [FALSE];
};
ProcessFile: FS.NameProc = {
[fullFName: ROPE] RETURNS [continue: BOOL]
positions: FS.ComponentPositions;
noDir: BOOL;
fullFName ← FileNames.ResolveRelativePath[fullFName];
[fullFName, positions, noDir] ← FS.ExpandName[fullFName];
IF Rope.Equal[Rope.Substr[fullFName, positions.ext.start, positions.ext.length], "bcd", FALSE]
OR Rope.Equal[Rope.Substr[fullFName, positions.ext.start, positions.ext.length], "press", FALSE]
THEN RETURN[TRUE];
reader ← TiogaAccess.FromFile[fullFName
! FS.Error => GO TO Error];
styleName ← TiogaAccess.GetExternalProp[
styleProperty,
Atom.GetPropFromList[TiogaAccess.GetNodeProps[reader], styleProperty]
];
IF Rope.Find[s1:styleName, s2:"mesa", case:FALSE] # -1 THEN LogMesaFile[fullFName, positions];
val ← SymTab.Fetch[styleTable, styleName].val;
IF (nTimes ← NARROW[val]) # NIL
THEN nTimes.entry ← nTimes.entry+1
ELSE {
nTimes ← NEW[EntryRep];
nTimes.entry ← 1;
};
[] ← SymTab.Store[styleTable, styleName, nTimes];
TiogaAccess.DoneWith[reader];
continue ← TRUE;
EXITS
Error => continue ← TRUE;
};
LogMesaFile: PROC [name: Rope.ROPE, positions: FS.ComponentPositions] ~ {
dir: Rope.ROPE ← Rope.Substr[name, positions.server.start-1, positions.base.start-positions.server.start+1];
IF NOT Rope.Equal[currentDirectory, dir] THEN {
currentDirectory ← dir;
IO.PutF[fileLogStream, "\nDirectory %g:\n", IO.rope[currentDirectory]];
};
IO.PutF[fileLogStream, " %g\n", IO.rope[Rope.Substr[name, positions.base.start, positions.base.length+positions.ext.length+positions.ver.length+2]]];
};
argv ← CommandTool.Parse[cmd -- Exception handler should go here --];
IF argv.argc < 2 THEN GOTO Usage;
styleTable ← SymTab.Create[case: FALSE];
pattern ← argv[1];
pattern ← FileNames.ResolveRelativePath[pattern];
pattern ← FS.ExpandName[pattern].fullFName;
IO.PutF[fileLogStream, "Mesa style files in %g\n\n", IO.rope[pattern]];
[] ← FS.EnumerateForNames[pattern, ProcessFile];
PrintStyleStats;
styleLogStream.Flush;
FS.Close[FS.OpenFileFromStream[styleLogStream]];
fileLogStream.Flush;
FS.Close[FS.OpenFileFromStream[fileLogStream]];
EXITS
Usage => RETURN [$Failure, "Usage: StyleList list-of-patterns\n"];
};
Commander.Register["StyleList", StyleListProc, "Collect style distribution info."];
END.