text, formatting, archiveName, tiogaFile, msgSetName, leftArrow, name, msgId, arg, uniquifier, date: ROPE;
{
parse arguments
arg ¬ IO.GetTokenRope[cmdin, IO.IDProc ! IO.Error, IO.EndOfStream => { GOTO formatfailure;}].token;
WHILE Rope.Fetch[arg,0] = '-
DO
These are flags
flags: ROPE ¬ arg;
l: INT ¬ Rope.Length[flags];
pos: INT;
CedarProcess.CheckAbort[];
Eliminate negative items
WHILE (pos ¬ Rope.SkipTo[flags, 0, "~"]) < l
DO
flags ¬ Rope.Replace[flags, pos, 2, NIL];
ENDLOOP;
Search for positive items
IF Rope.SkipTo[flags, 0, "a"] < l THEN accessType ¬ append;
IF Rope.SkipTo[flags, 0, "x"] < l THEN DoCheckOnly ¬ TRUE;
IF Rope.SkipTo[flags, 0, "p"] < l THEN PeanutFormat ¬ TRUE;
IF Rope.SkipTo[flags, 0, "v"] < l THEN Verbose ¬ TRUE;
arg ¬ IO.GetTokenRope[cmdin, IO.IDProc ! IO.Error, IO.EndOfStream => { GOTO formatfailure;}].token;
ENDLOOP;
archiveName ¬ arg;
leftArrow ¬ IO.GetTokenRope[cmdin, IO.IDProc ! IO.Error, IO.EndOfStream => { GOTO formatfailure;}].token;
IF NOT Rope.Equal[leftArrow, "←"] THEN GOTO formatfailure;
tiogaFile ¬ IO.GetTokenRope[cmdin, IO.IDProc ! IO.Error, IO.EndOfStream => { GOTO formatfailure;}].token;
msgSetName ¬ IO.GetTokenRope[cmdin, IO.IDProc ! IO.Error, IO.EndOfStream => { GOTO formatfailure;}].token;
Open files
IF DoCheckOnly
THEN {
outstream ¬ IO.noWhereStream;
}
ELSE {
outstream ¬
PFS.StreamOpen[
PFS.PathFromRope[archiveName], accessType !
PFS.Error =>
IF error.group = user THEN {IO.PutF1[cmd.out, "%g\n", IO.rope[error.explanation]]; name ¬ archiveName; GOTO iofailure;}];
};
startnode ¬ TiogaExtraOps.GetFile[tiogaFile ! PFS.Error, IO.Error, IO.EndOfStream => { name ¬ tiogaFile; GOTO iofailure;}];
skip the root for peanut format so we get the top level nodes individually
IF PeanutFormat THEN startnode ¬ TextNode.Forward[startnode].nx;
Startnode now points to the root node, or the first peanut mail message. Process this and subsequent items at the same level
count ¬ 0;
WHILE startnode #
NIL
DO
CedarProcess.CheckAbort[];
uniquifier ¬ IO.PutR[IO.rope[tiogaFile], IO.int[count]];
msgId ¬ BuildMsgId[uniquifier];
[text, formatting] ¬ TiogaToWalnut.GetContentsOfNodeAndChildren[startnode];
TiogaToWalnut.ContentsToArchive[text, formatting, msgSetName, msgId, outstream];
startnode ¬ TextNode.ForwardClipped[startnode, 1, 1].nx;
count ¬ count + 1;
IF Verbose
AND (count
MOD 10) = 0
THEN
{
IF (count
MOD 100) = 0
THEN IO.Put1[cmd.out, IO.int[count]]
ELSE IO.Put1[cmd.out, IO.rope["~"]];
};
ENDLOOP;
TiogaExtraOps.FreeTree[r];
IO.Close[outstream];
IF Verbose THEN IO.PutF[cmd.out, "Finished %g msgs in %g.\n", IO.int[count], IO.rope[tiogaFile]];
EXITS
iofailure => IO.PutF1[cmd.err, "Could not open file named '%g'.\n", IO.rope[name]];
formatfailure => IO.PutF1[cmd.err, "%g\n", IO.rope[Explanation]];
}