DeleteArchived:
CEDAR
PROGRAM
IMPORTS Commander, CommandExtras, CommandTool, IO, ProcessExtras, Rope, ViewerOps, ViewerTools
={
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewerClasses.Viewer;
STREAM: TYPE = IO.STREAM;
Date: TYPE = BasicTime.Unpacked;
Barf: ERROR = CODE;
ListFromAck:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- = {
List:
PROC [fileName:
ROPE, date: Date, primaryVolume, backupVolume:
ROPE] = {
cmd.out.PutRope[fileName];
cmd.out.PutRope["\n"];
};
cls: STREAM ← IO.RIS[cmd.commandLine];
viewerName: ROPE ← NIL;
v: Viewer;
vContents: ROPE;
fromV: STREAM;
viewerName ← cls.GetRopeLiteral[!IO.EndOfStream, IO.Error => CONTINUE];
IF viewerName = NIL THEN RETURN [$Failure, "Usage: ListFromAck \"viewerName\""];
v ← ViewerOps.FindViewer[viewerName];
IF v = NIL THEN RETURN [$Failure, IO.PutFR["viewer named %g not found", IO.refAny[viewerName]]];
vContents ← ViewerTools.GetContents[v];
fromV ← IO.RIS[vContents];
EnumAck[from: fromV, to: List !Barf,
IO.EndOfStream,
IO.Error => {
result ← $Failure;
msg ← IO.PutFR["syntax error before [%g]", IO.card[fromV.GetIndex[]]];
CONTINUE;
}];
};
DeleteFromAck:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- = {
subFailures: NAT ← 0;
Delete:
PROC [fileName:
ROPE, date: Date, primaryVolume, backupVolume:
ROPE] = {
deleteCmd: ROPE ← IO.PutFR["Delete %g", IO.rope[fileName]];
deleteResult: REF ANY;
ProcessExtras.CheckForAbort[];
deleteResult ← CommandTool.DoCommand[commandLine: deleteCmd, parent: cmd];
IF deleteResult = $Failure THEN subFailures ← subFailures + 1;
};
AddMsg:
PROC [more:
ROPE] = {
IF msg # NIL THEN msg ← msg.Cat["; "];
msg ← msg.Cat[more]};
cls: STREAM ← IO.RIS[cmd.commandLine];
viewerName: ROPE ← NIL;
v: Viewer;
vContents: ROPE;
fromV: STREAM;
viewerName ← cls.GetRopeLiteral[!IO.EndOfStream, IO.Error => CONTINUE];
IF viewerName = NIL THEN RETURN [$Failure, "Usage: DeleteFromAck \"viewerName\""];
v ← ViewerOps.FindViewer[viewerName];
IF v = NIL THEN RETURN [$Failure, IO.PutFR["viewer named %g not found", IO.refAny[viewerName]]];
vContents ← ViewerTools.GetContents[v];
fromV ← IO.RIS[vContents];
EnumAck[from: fromV, to: Delete !Barf,
IO.EndOfStream,
IO.Error => {
result ← $Failure;
AddMsg[IO.PutFR["syntax error before [%g]", IO.card[fromV.GetIndex[]]]];
CONTINUE;
}];
IF subFailures > 0
THEN {
result ← $Failure;
AddMsg[IO.PutFR["%g delete(s) failed", IO.card[subFailures]]];
};
};
MakeChatStuffFromAck:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- = {
misses: NAT ← 0;
Delete:
PROC [fileName:
ROPE, date: Date, primaryVolume, backupVolume:
ROPE] = {
IF prefix.Equal[fileName.Substr[len: prefixLength]]
THEN {
remainder: ROPE ← fileName.Substr[start: prefixLength, len: fileName.Length[] - prefixLength];
cmd.out.PutF["Delete %g\n\n", IO.rope[remainder]];
}
ELSE misses ← misses + 1;
};
AddMsg:
PROC [more:
ROPE] = {
IF msg # NIL THEN msg ← msg.Cat["; "];
msg ← msg.Cat[more]};
cls: STREAM ← IO.RIS[cmd.commandLine];
prefix: ROPE ← NIL;
prefixLength: INT;
viewerName: ROPE ← NIL;
v: Viewer;
vContents: ROPE;
fromV: STREAM;
prefix ← cls.GetTokenRope[MyBreak !IO.EndOfStream, IO.Error => CONTINUE].token;
IF prefix = NIL THEN RETURN [$Failure, "Usage: MakeChatStuffFromAck directory \"viewerName\""];
prefixLength ← prefix.Length[];
viewerName ← cls.GetRopeLiteral[!IO.EndOfStream, IO.Error => CONTINUE];
IF viewerName = NIL THEN RETURN [$Failure, "Usage: MakeChatStuffFromAck directory \"viewerName\""];
v ← ViewerOps.FindViewer[viewerName];
IF v = NIL THEN RETURN [$Failure, IO.PutFR["viewer named %g not found", IO.refAny[viewerName]]];
vContents ← ViewerTools.GetContents[v];
fromV ← IO.RIS[vContents];
EnumAck[from: fromV, to: Delete !Barf,
IO.EndOfStream,
IO.Error => {
result ← $Failure;
AddMsg[IO.PutFR["syntax error before [%g]", IO.card[fromV.GetIndex[]]]];
CONTINUE;
}];
IF misses > 0
THEN {
cmd.out.PutF["%g files weren't in %g\n", IO.card[misses], IO.rope[prefix]];
};
};
MyBreak:
PROC [char:
CHAR]
RETURNS [cc:
IO.CharClass]
--IO.BreakProc-- = {
cc ← IF char IN ['\000 .. ' ] THEN sepr ELSE other;
};
EnumAck:
PROC [from:
STREAM, to:
PROC [fileName:
ROPE, date: Date, primaryVolume, backupVolume:
ROPE]] = {
Skip:
PROC [toke:
ROPE] = {
got: ROPE ← from.GetTokenRope[MyBreak].token;
IF NOT got.Equal[toke] THEN ERROR Barf;
};
InsistEOL:
PROC = {
c: CHAR ← from.GetChar[];
IF c # '\n THEN ERROR Barf;
};
heading: BOOL ← TRUE;
DO
keyword: ROPE;
[] ← from.SkipWhitespace[];
IF from.EndOf[] THEN EXIT;
keyword ← from.GetTokenRope[MyBreak].token;
IF keyword.Equal["Archived:"] THEN heading ← FALSE ELSE IF NOT heading THEN ERROR Barf;
IF heading
THEN {
IF keyword.Length[] = 0 THEN ERROR Barf;
IF keyword.Fetch[keyword.Length[]-1] # ': THEN ERROR Barf;
[] ← from.GetLineRope[];
}
ELSE {
fileName, pv, bv: ROPE;
date: Date;
fileName ← from.GetTokenRope[MyBreak].token;
Skip["of"];
date ← from.GetUnpackedTime[];
Skip["on"];
pv ← from.GetTokenRope[MyBreak].token;
Skip["or"];
bv ← from.GetTokenRope[MyBreak].token;
InsistEOL[];
to[fileName: fileName, date: date, primaryVolume: pv, backupVolume: bv];
};
ENDLOOP;
heading ← heading;
};
Start:
PROC = {
Commander.Register[key: "ListFromAck", proc: ListFromAck, doc: "List the files in an Archivist Request Acknowledgement"];
CommandExtras.MakeUninterpreted[Commander.Lookup[CommandTool.CurrentWorkingDirectory[].Cat["ListFromAck"]]];
Commander.Register[key: "DeleteFromAck", proc: DeleteFromAck, doc: "Delete the files in an Archivist Request Acknowledgement"];
CommandExtras.MakeUninterpreted[Commander.Lookup[CommandTool.CurrentWorkingDirectory[].Cat["DeleteFromAck"]]];
Commander.Register[key: "MakeChatStuffFromAck", proc: MakeChatStuffFromAck, doc: "Write IFS Chat commands to delete the files in an Archivist Request Acknowledgement"];
CommandExtras.MakeUninterpreted[Commander.Lookup[CommandTool.CurrentWorkingDirectory[].Cat["MakeChatStuffFromAck"]]];
};
Start[];
}.