ListArchivesImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Tim Diebert: November 7, 1985 5:53:03 pm PST
DIRECTORY
ArchivistBTreePublic USING [OpenBTree, Handle, CloseBTree, EnumerateRecord, FileInfoList],
BasicTime USING [GMT, nullGMT, Unpacked, Unpack, Now],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
FS USING [ComponentPositions, ExpandName, Error],
IO USING [PutRope, PutF, PutFR, int, rope],
Rope USING [Substr, Equal, Length, Fetch, ROPE]
;
ListArchivesImpl: CEDAR PROGRAM
IMPORTS ArchivistBTreePublic, BasicTime, Commander, CommandTool, FS, IO, Rope
= BEGIN
ROPE: TYPE ~ Rope.ROPE;
GMT: TYPE ~ BasicTime.GMT;
ListArchivesCommandProc: Commander.CommandProc = BEGIN
CommandProc: TYPE = PROC [cmd: Handle] RETURNS [result: REFNIL, msg: Rope.ROPENIL];
CommandObject = [in, out, err: STREAM, commandLine, command: ROPE, ...]
h: ArchivistBTreePublic.Handle ← NIL;
BEGIN
ProcessList: PROC [list: ArchivistBTreePublic.FileInfoList] = BEGIN
cp: FS.ComponentPositions;
newDir: ROPE;
DO
IF list = NIL THEN EXIT;
cp ← FS.ExpandName[list.fileName].cp;
newDir ← list.fileName.Substr[0, cp.base.start];
IF NOT lastFileDirStuff.Equal[newDir, FALSE]
THEN cmd.out.PutF["%g\n", IO.rope[newDir]];
lastFileDirStuff ← newDir;
cmd.out.PutF[" %g\t%g %g\n", IO.rope[list.fileName.Substr[cp.base.start]], IO.rope[RFC822Date[list.created]], IO.rope[list.volumes]];
list ← list.next;
ENDLOOP;
END;
pattern, r: ROPENIL;
lastFileDirStuff: ROPENIL;
list: ArchivistBTreePublic.FileInfoList ← NIL;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd: cmd
! CommandTool.Failed => {cmd.out.PutF["%g\n", IO.rope[errorMsg]]; GOTO Failed}];
IF argv.argc <= 1 THEN {cmd.out.PutRope["\n"]; RETURN; };
h ← ArchivistBTreePublic.OpenBTree[cmd.out];
IF h = NIL THEN RETURN;
FOR i: NAT IN [1..argv.argc) DO
arg: ROPE ← argv[i];
IF Rope.Length[arg] = 0 THEN LOOP;
IF Rope.Fetch[arg, 0] = '- THEN {
This argument sets switches for the remaining patterns
-- Since there are not switches -- LOOP;
};
Now the argument is assumed to be a file pattern.
arg ← FS.ExpandName[arg ! FS.Error => GOTO Failed].fullFName;
IO.PutRope[cmd.out, "Enumerating ... "];
list ← ArchivistBTreePublic.EnumerateRecord[h, arg];
IO.PutRope[cmd.out, "Done\n"];
ProcessList[list];
ENDLOOP;
ArchivistBTreePublic.CloseBTree[h];
EXITS Failed => {ArchivistBTreePublic.CloseBTree[h]; RETURN};
END;
END;
RFC822Date: PUBLIC PROC[gmt: BasicTime.GMT← BasicTime.nullGMT] RETURNS[date: ROPE] =
-- generates arpa standard time, dd mmm yy hh:mm:ss zzz
BEGIN OPEN IO;
upt: BasicTime.Unpacked ←
BasicTime.Unpack[IF gmt = BasicTime.nullGMT THEN BasicTime.Now[] ELSE gmt];
zone: ROPE;
month, tyme, year: ROPE;
timeFormat: ROPE = "%02g:%02g:%02g %g"; -- "hh:mm:ss zzz"
dateFormat: ROPE = "%2g %g %g %g";  -- "dd mmm yy timeFormat"
arpaNeg: BOOL← upt.zone > 0;
aZone: INTABS[upt.zone];
zDif: INT← aZone / 60;
zMul: INT← zDif * 60;
IF (zMul = aZone) AND arpaNeg THEN
BEGIN IF upt.dst = yes
THEN
SELECT zDif FROM
0 => zone← "UT";
4 => zone← "EDT";
5 => zone← "CDT";
6 => zone← "MDT";
8 => zone← "PDT";
ENDCASE
ELSE
SELECT zDif FROM
0 => zone← "UT";
5 => zone← "EST";
6 => zone← "CST";
7 => zone← "MST";
8 => zone← "PST";
ENDCASE;
END;
IF zone = NIL THEN BEGIN
mm: INT← aZone - zMul;
zone← PutFR[IF arpaNeg THEN "-%02g%02g" ELSE "+%02g%02g", int[zDif], int[mm]];
END;
SELECT upt.month FROM
January => month← "Jan";
February => month← "Feb";
March => month← "Mar";
April => month← "Apr";
May => month← "May";
June => month← "Jun";
July => month← "Jul";
August => month← "Aug";
September => month← "Sep";
October => month← "Oct";
November => month← "Nov";
December => month← "Dec";
unspecified => ERROR;
ENDCASE => ERROR;
year← Rope.Substr[PutFR[NIL, int[upt.year]], 2];
tyme← PutFR[timeFormat, int[upt.hour], int[upt.minute], int[upt.second], rope[zone]];
date← PutFR[dateFormat, int[upt.day], rope[month], rope[year], rope[tyme]];
END;
Commander.Register[key: "ListArchives", proc: ListArchivesCommandProc, doc: "ListArchives pattern"];
END......