BlackCherryToWalnutImpl.mesa
Copyright Ó 1989, 1990, 1992 by Xerox Corporation. All rights reserved.
Willie-Sue, February 9, 1990 12:33:08 pm PST
Doug Terry, January 19, 1990 4:56:06 pm PST
Willie-s, April 27, 1992 2:41 pm PDT
DIRECTORY
BlackCherry,
IO,
Process,
RefText USING [page],
Rope,
ViewerClasses USING [Viewer],
ViewerIO,
ViewerOps USING [FindViewer, OpenIcon],
ViewerTools USING [EnableUserEdits, GetSelectedViewer, InhibitUserEdits],
WalnutDefs USING [Error],
WalnutOps USING [EndNewMail, RecordNewMailInfo, StartNewMail],
WalnutRegistry,
WalnutWindowPrivate USING [WalnutHandle, WalnutHandleRec],
WalnutWindow USING [GetHandleForMail, GetHandleList, GetNewMail, QueueCall, OutCome],
WalnutWindowSidedoor USING [GetHandleForViewer, IsHandleActive];
BlackCherryToWalnutImpl:
CEDAR
MONITOR
IMPORTS
BlackCherry, IO, Process, ViewerIO, ViewerOps, ViewerTools,
WalnutDefs, WalnutOps, WalnutRegistry, WalnutWindow, WalnutWindowSidedoor
EXPORTS WalnutWindow
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Copied Types
Viewer: TYPE ~ ViewerClasses.Viewer;
Types
MsgHandle: TYPE ~ BlackCherry.MsgHandle;
MsgSetInfo: TYPE ~ BlackCherry.MsgSetInfo;
WalnutHandle: TYPE = WalnutWindowPrivate.WalnutHandle;
WalnutHandleRec: PUBLIC TYPE = WalnutWindowPrivate.WalnutHandleRec;
Various
copyBuffer: REF TEXT ¬ NEW[TEXT[RefText.page]];
noXferRope: ROPE = "\n*** Walnut must be running to do %g\n";
XFerToWalnutProc:
ENTRY BlackCherry.OpsProc ~ {
PROC[msI: MsgSetInfo]
ENABLE UNWIND => NULL;
out: STREAM ¬ TSStream["XFerToWalnut"];
wH: WalnutHandle;
deleteAll: BOOL ¬ FALSE;
WHILE WalnutRegistry.CurrentWalnutState[] = initializing
DO
Process.PauseMsec[100]; ENDLOOP;
IF WalnutRegistry.CurrentWalnutState[] = unknown
THEN
{ out.PutF1[noXferRope, [rope["XFerToWalnut"]] ]; UndoInhibit[out]; RETURN };
wH ¬ WalnutWindow.GetHandleForMail[];
IF wH =
NIL
THEN {
out.PutRope["No mail version of Walnut running, XFerToWalnut not done\n"];
UndoInhibit[out];
RETURN
};
deleteAll ¬ DoXFer[msI, wH, out];
UndoInhibit[out];
IF deleteAll THEN BlackCherry.NewFile[msI];
};
XFerToSelectedProc:
ENTRY BlackCherry.OpsProc ~ {
ENABLE UNWIND => NULL;
wH: WalnutHandle;
v: Viewer = ViewerTools.GetSelectedViewer[];
msg: ROPE = "No appropriate Walnut found - Xfer not done\n";
out: STREAM ¬ TSStream["XFerToWalnut"];
deleteAll: BOOL ¬ FALSE;
WHILE WalnutRegistry.CurrentWalnutState[] = initializing
DO
Process.PauseMsec[100]; ENDLOOP;
IF WalnutRegistry.CurrentWalnutState[] = unknown
THEN
{ out.PutF1[noXferRope, [rope["XferToSelectedWalnut"]] ]; UndoInhibit[out]; RETURN };
IF v # NIL THEN wH ¬ WalnutWindowSidedoor.GetHandleForViewer[v];
IF wH =
NIL
THEN {
FOR whL:
LIST
OF WalnutHandle ¬ WalnutWindow.GetHandleList[],
whL.rest
UNTIL whL =
NIL
DO
IF WalnutWindowSidedoor.IsHandleActive[whL.first]
THEN {
IF wH = NIL THEN { wH ¬ whL.first; LOOP };
out.PutRope[msg];
UndoInhibit[out];
RETURN
};
ENDLOOP;
IF wH =
NIL
THEN {
out.PutRope[msg];
UndoInhibit[out];
RETURN
};
};
deleteAll ¬ DoXFer[msI, wH, out];
UndoInhibit[out];
IF deleteAll THEN BlackCherry.NewFile[msI];
};
Transfer msgs to database
DoXFer:
INTERNAL
PROC[msI: MsgSetInfo, wH: WalnutHandle, out:
STREAM]
RETURNS[deleteAll:
BOOL ¬
FALSE] = {
BEGIN ENABLE WalnutDefs.Error =>
GOTO couldnt;
out: STREAM ¬ TSStream["XFerToWalnut"];
num: INT ¬ 0;
outcome: WalnutWindow.OutCome ¬ notRunning;
XferMail:
PROC[wH: WalnutHandle]
RETURNS[reset:
BOOL ¬
FALSE] = {
mailStrm: STREAM ¬ WalnutOps.StartNewMail[wH.opsH];
IF mailStrm =
NIL
THEN {
out.PutRope["\n*** Could not get Walnut's NewMailStream - quitting ***\n"];
RETURN
};
out.PutRope["\n*** Starting XferToWalnut\n"];
mailStrm.SetIndex[mailStrm.GetLength[]]; -- at end
FOR msgH: MsgHandle ¬ msI.first, msgH.next
UNTIL msgH =
NIL
DO
IF msgH.deleted THEN LOOP;
msI.fileData.readStream.SetIndex[msgH.entryStart];
CopyBytes[to: mailStrm, from: msI.fileData.readStream, num: msgH.entryLen];
num ¬ num + 1;
ENDLOOP;
mailStrm.Flush[];
WalnutOps.RecordNewMailInfo[wH.opsH, mailStrm.GetLength[], "BlackWalnut", num];
WalnutOps.EndNewMail[wH.opsH];
out.PutF1[" %g messages appended to Walnut's NewMailLog\n", [integer[num]] ];
deleteAll ¬ ( num # 0 );
RETURN[num # 0];
};
SELECT WalnutWindow.QueueCall[wH, XferMail]
FROM
ok => { IF num # 0 THEN WalnutWindow.GetNewMail[wH] };
notRunning => out.PutF1[noXferRope, [rope["XferToWalnut"]] ];
flushed =>
out.PutRope["\n*** XferToWalnut operation was not done - try again ***\n"];
ENDCASE => NULL;
EXITS couldnt => out.PutRope["\n*** WalnutDefs.Error\n" ];
END;
};
CopyBytes:
PROC[to, from:
STREAM, num:
INT] = {
bytes: INT ¬ num;
WHILE bytes >= 512
DO
[] ¬ from.GetBlock[copyBuffer, 0, 512];
to.PutBlock[copyBuffer];
bytes ¬ bytes - 512;
ENDLOOP;
IF bytes # 0
THEN {
[] ¬ from.GetBlock[copyBuffer, 0, bytes];
to.PutBlock[copyBuffer];
};
};
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];
};
UndoInhibit:
PROC[out:
STREAM] = {
v: Viewer = ViewerIO.GetViewerFromStream[out];
ViewerTools.EnableUserEdits[v];
};
BlackCherry.AddOpsProc["XFerToWalnut", XFerToWalnutProc, $writeNeeded];
BlackCherry.AddOpsProc["XFerToSelectedWalnut", XFerToSelectedProc, $writeNeeded];
END.