File: RecoverNewMail.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-Sue on August 5, 1985 11:40:46 am PDT
Woosh, August 5, 1985 11:43:23 am PDT
DIRECTORY
Commander USING [CommandProc, Register],
FS USING [StreamOpen],
FSRope USING [StreamFromRope],
IO,
Rope,
WalnutDefs USING [Error],
WalnutOps USING [EndNewMail, RecordNewMailInfo, StartNewMail],
WalnutRoot USING [FlushAndContinue],
WalnutStream USING [CopyBytes];
RecoverNewMail: CEDAR PROGRAM
IMPORTS Commander, FS, FSRope, IO, WalnutDefs, WalnutOps, WalnutRoot, WalnutStream =
BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
server: ROPE ← "Salvador.ms";
********************************************************
RecoverNewMail, copies fName onto newMailLog
SetupRecover: Commander.CommandProc = {
clStream: STREAM ← FSRope.StreamFromRope[cmd.commandLine];
fileName, outcome: ROPE;
num: INT;
fileName ← clStream.GetTokenRope[IO.IDProc ! IO.EndOfStream => CONTINUE].token;
num ← clStream.GetInt[ ! IO.EndOfStream => { num ← 1; CONTINUE}];
outcome ← Recover[fileName, num];
cmd.out.PutRope[outcome];
};
Recover: PUBLIC PROC[fName: ROPE, num: INT ← 1] RETURNS[ROPE] = {
ENABLE WalnutDefs.Error => { WalnutOps.EndNewMail[]; GOTO err};
fStrm: STREAM;
ms: STREAM ← WalnutOps.StartNewMail[];
fLength: INT;
IF ms = NIL THEN RETURN["Can't get new mail stream"];
fStrm ← FS.StreamOpen[fName];
fLength ← fStrm.GetLength[];
ms.SetIndex[ms.GetLength[]];
WalnutStream.CopyBytes[from: fStrm, to: ms, num: fStrm.GetLength[]];
WalnutRoot.FlushAndContinue[ms];
WalnutOps.RecordNewMailInfo[ms.GetLength[], server, num];
WalnutOps.EndNewMail[];
fStrm.Close[];
RETURN[IO.PutFR["Copied %g bytes from %g\n", IO.int[fLength], IO.rope[fName]] ];
EXITS
err => RETURN["WalnutDefs.Error"];
};
Commander.Register["Recover", SetupRecover,
"Recovers a Walnut newMailLog; syntax is \"Recover logFile\""];
END.