MaintainLatestImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, May 3, 1991 0:34 am PDT
DIRECTORY PFS, PFSNames, Rope, Process, ViewerEvents, ViewerClasses, MessageWindow;
MaintainLatestImpl: CEDAR MONITOR
IMPORTS PFS, PFSNames, Rope, Process, ViewerEvents, MessageWindow
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
PATH: TYPE ~ PFSNames.PATH;
Component: TYPE ~ PFSNames.Component;
Monitored State
copier: PROCESS ¬ NIL;
queueHead: LIST OF ROPE ¬ LIST[NIL];
last: LIST OF ROPE ¬ queueHead;
Entry Procs
Enqueue: ENTRY PROC [filename: ROPE] ~ {
last ¬ last.rest ¬ LIST[filename];
IF copier = NIL THEN Process.Detach[copier ¬ FORK Copier];
};
Dequeue: ENTRY PROC RETURNS [filename: ROPE ¬ NIL] ~ {
first: LIST OF ROPE ¬ queueHead.rest;
IF first = NIL THEN {
copier ¬ NIL;
RETURN [NIL];
};
queueHead.rest ¬ NIL;
queueHead ¬ first;
filename ¬ first.first;
first.first ¬ NIL;
IF filename = NIL THEN filename ¬ "";
};
Died: ENTRY PROC ~ {
copier ¬ NIL;
IF queueHead.rest # NIL THEN Process.Detach[copier ¬ FORK Copier];
};
Background Process
latest: PFS.PATH ~ PFS.PathFromRope["/Latest/foo"];
maxFileSize: INT ¬ 111111;
ShortName: PROC [name: PATH] RETURNS [shortName: Component] ~ {
shortName ¬ PFSNames.ShortName[name];
shortName.version ¬ [none];
};
Copier: PROC ~ {
ENABLE UNCAUGHT => { Died[]; REJECT };
FOR filename: ROPE ¬ Dequeue[], Dequeue[] UNTIL filename = NIL DO
MessageWindow.Append["Save Event for ", TRUE];
MessageWindow.Append[filename, FALSE];
MessageWindow.Append[" ... ", FALSE];
BEGIN ENABLE PFS.Error => {MessageWindow.Append[error.explanation, FALSE]; CONTINUE};
path: PFS.PATH ~ PFS.PathFromRope[filename];
dest: PFS.PATH ¬ PFSNames.ReplaceShortName[latest, ShortName[path]];
size: INT ~ PFS.FileInfo[path].bytes;
IF size <= maxFileSize THEN {
MessageWindow.Append[Rope.Cat[PFS.RopeFromPath[dest], " := ", PFS.RopeFromPath[path]], TRUE];
PFS.Copy[from: path, to: dest, confirmProc: NIL];
MessageWindow.Clear[];
};
END;
ENDLOOP;
};
Event Registration
disabled: BOOL ¬ FALSE;
Disable: PROC RETURNS [INT¬1] ~ {disabled ¬ TRUE};
AddEvent: ViewerEvents.EventProc = {
filename: ROPE ¬ viewer.file;
IF NOT (disabled OR filename.Size=0 OR Rope.Match[".*", filename] OR Rope.Match["*~", filename]) THEN {
Enqueue[filename];
};
};
regProc: REF ¬ ViewerEvents.RegisterEventProc[proc: AddEvent, filter: $Text, event: save, before: FALSE];
END.
PcrCmd eval [ MaintainLatestImpl.Disable ]