BlackCherryFromWalnut.mesa
Copyright Ó 1990, 1992, 1993 by Xerox Corporation. All rights reserved.
Willie-Sue, July 9, 1990 11:32:30 am PDT
Doug Terry, August 29, 1990 10:57:09 am PDT
Willie-s, July 20, 1993 4:47 pm PDT
DIRECTORY
BasicTime USING [Now],
BlackCherrySidedoor,
Commander,
CommanderOps USING [NextArgument],
FS USING [ExpandName],
IO,
Rope,
ViewerClasses USING [Viewer],
ViewerIO,
ViewerOps,
ViewerTools,
WalnutDefs USING [Error],
WalnutOps,
WalnutWindowPrivate USING [WalnutHandle, WalnutHandleRec],
WalnutWindow USING [GetHandleForRootFile, GetHandleList, GetRootFileForHandle, QueueCall, OutCome, ReportFormat, ReportRope, StartUp],
WalnutWindowSidedoor USING [IsHandleActive, GetSelectedMsgSetNames];
BlackCherryFromWalnut: CEDAR MONITOR
IMPORTS
BasicTime,
BlackCherrySidedoor,
Commander, CommanderOps, FS, IO, Rope, ViewerIO, ViewerOps, ViewerTools,
WalnutDefs, WalnutOps, WalnutWindow, WalnutWindowSidedoor
EXPORTS WalnutWindow
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Types
WalnutHandle: TYPE = WalnutWindowPrivate.WalnutHandle;
WalnutHandleRec: PUBLIC TYPE = WalnutWindowPrivate.WalnutHandleRec;
Transfer msgs to database
BCFromWalnut: Commander.CommandProc = {
out: STREAM ¬ cmd.out;
wH: WalnutHandle;
rootFile: ROPE ¬ CommanderOps.NextArgument[cmd];
IF rootFile = NIL THEN {
wH ¬ WalnutWindow.GetHandleList[].first;
IF wH = NIL THEN {
out.PutF1["\n***Couldn't get handle for any rootFile %g - quitting\n",
[rope[rootFile]] ];
RETURN;
};
rootFile ¬ WalnutWindow.GetRootFileForHandle[wH];
}
ELSE {
wH ¬ WalnutWindow.GetHandleForRootFile[rootFile];
IF wH = NIL THEN {
out.PutF1["\n***Couldn't get handle for rootFile %g - quitting\n",
[rope[rootFile]] ];
RETURN;
};
};
IF NOT WalnutWindowSidedoor.IsHandleActive[wH] THEN {
out.PutF1["\n***Starting Walnut for rootFile %g\n", [rope[rootFile]] ];
wH ¬ WalnutWindow.StartUp[rootFile, FALSE];
IF wH = NIL THEN {
out.PutRope["\n***Couldn't start Walnut - quitting\n"];
RETURN
};
};
WalnutWindow.ReportFormat[wH, "\n*** Starting BlackCherryFromWalnut at %g\n", [time[BasicTime.Now[]]] ];
WalnutWindow.ReportFormat[wH, "\t Using rootFile %g\n\n", [rope[rootFile]] ];
BEGIN ENABLE WalnutDefs.Error => GOTO couldnt;
outcome: WalnutWindow.OutCome ¬ notRunning;
WriteBCLog: PROC[wH: WalnutHandle] RETURNS[reset: BOOL ¬ FALSE] = {
msgSetNames: LIST OF ROPE ¬ WalnutWindowSidedoor.GetSelectedMsgSetNames[wH];
msgList: LIST OF ROPE;
counter: INT;
MsgsToBCLog: BlackCherrySidedoor.MsgFromRopesProc = {
tc: ViewerTools.TiogaContents;
IF msgList = NIL THEN RETURN[NIL, NIL, NIL, FALSE];
tc ¬ WalnutOps.GetMsg[wH.opsH, msgID ¬ msgList.first].contents;
IF ( counter ¬ counter + 1 ) MOD 10 = 0
THEN WalnutWindow.ReportFormat[wH, "(%g) ", [integer[counter]] ]
ELSE WalnutWindow.ReportRope[wH, "."];
msgList ¬ msgList.rest;
text ¬ tc.contents;
formatting ¬ tc.formatting;
unRead ¬ NOT WalnutOps.GetDisplayProps[wH.opsH, msgID].hasBeenRead;
};
IF msgSetNames = NIL THEN msgSetNames ¬ WalnutOps.MsgSetNames[wH.opsH].mL;
FOR mL: LIST OF ROPE ¬ msgSetNames, mL.rest UNTIL mL = NIL DO
msgSet: ROPE ~ mL.first;
ok: BOOL ¬ FALSE;
num: INT ¬ WalnutOps.SizeOfMsgSet[wH.opsH, msgSet].messages;
fileName: ROPE ¬ FS.ExpandName[Rope.Concat[msgSet, ".mailLog"]].fullFName;
IF num = 0 THEN {
WalnutWindow.ReportFormat[wH, "MsgSet %g is empty - skipping\n", [rope[msgSet]] ];
LOOP;
};
WalnutWindow.ReportFormat[wH, "Starting msgSet %g (%g msgs), on file %g\n", [rope[msgSet]], [integer[num]], [rope[fileName]] ];
msgList ¬ WalnutOps.MsgsInSetEnumeration[wH.opsH, msgSet].mL;
counter ¬ 0;
ok ¬ BlackCherrySidedoor.CreateBCMailLogFromRopes[fileName, MsgsToBCLog];
IF ok THEN WalnutWindow.ReportFormat[wH, "\n\tDone with %g\n\n", [rope[msgSet]] ]
ELSE WalnutWindow.ReportFormat[wH, "Problems accessing msgSet %g ***\n\n", [rope[msgSet]] ];
ENDLOOP;
};
SELECT WalnutWindow.QueueCall[wH, WriteBCLog] FROM
ok => WalnutWindow.ReportFormat[wH, "\nDone with BlackCherryFromWalnut at %g\n", [time[BasicTime.Now[]]] ];
notRunning => out.PutRope["\n*** Walnut is not running so can't do BlackCherryFromWalnut\n" ];
flushed => out.PutRope["\n*** BlackCherryFromWalnut operation was not done - try again ***\n"];
ENDCASE => NULL;
EXITS couldnt => out.PutRope["\n*** WalnutDefs.Error\n" ];
END;
};
TSStream: PROC[name: ROPE] RETURNS [out: STREAM] = {
v: ViewerClasses.Viewer ¬ ViewerOps.FindViewer[name];
out ¬ ViewerIO.CreateViewerStreams[name, v, NIL, FALSE].out;
IF v = NIL THEN v ¬ ViewerIO.GetViewerFromStream[out];
IF v#NIL THEN IF v.iconic THEN ViewerOps.OpenIcon[v];
ViewerTools.InhibitUserEdits[v];
};
docRope: ROPE ~ "Usage: BlackCherryFromWalnut [-d root-file-name] ";
Commander.Register["BlackCherryFromWalnut", BCFromWalnut, docRope];
END.