MaintainFilesList.mesa
Paxton, August 31, 1982 4:16 pm
McGregor, September 10, 1982 2:21 pm
Maxwell, January 6, 1983 12:19 pm
Russ Atkinson, September 26, 1983 6:03 pm
Doug Wyatt, January 13, 1984 4:02 pm
DIRECTORY
Booting USING [RegisterProcs, RollbackProc],
FS USING [Error, StreamOpen],
IO USING [Close, GetChar, GetLength, PutRope, STREAM],
MessageWindow USING [Append],
Process USING [Detach],
Rope USING [Concat, Equal, Fetch, Find, FromProc, ROPE, Size, Substr],
UserCredentials USING [Get],
ViewerEvents USING [EventProc, RegisterEventProc, UnRegisterEventProc];
MaintainFilesList: CEDAR MONITOR
IMPORTS Booting, FS, IO, Process, Rope, MessageWindow, UserCredentials, ViewerEvents
= {
STREAM: TYPE = IO.STREAM;
regProc: REF;
filesList: Rope.ROPE;
userName: Rope.ROPE = UserName[];
fileName: Rope.ROPE = Rope.Concat[userName, ".List"];
UserName: PROC RETURNS [name: Rope.ROPE] = {
dot: INT;
name ← UserCredentials.Get[].name;
dot ← Rope.Find[name, "."];
IF dot > 0 THEN name ← Rope.Substr[name, 0, dot];
};
Add: ViewerEvents.EventProc = TRUSTED { Process.Detach[FORK AddToFilesList[viewer.file]] };
AddToFilesList: ENTRY PROC [name: Rope.ROPE] = {
ENABLE UNWIND => NULL;
s: STREAMNIL;
AlreadyThere: PROC RETURNS [BOOL] = {
pos: INT ← 0;
len: INT = Rope.Size[name];
fileLen: INT = Rope.Size[filesList];
blank: CHAR = ' ;
WHILE (pos ← Rope.Find[filesList, name, pos, FALSE]) # -1 DO -- look for adjacent blanks
IF (pos>0 AND Rope.Fetch[filesList, pos-1] # blank) OR
(pos+len < fileLen AND Rope.Fetch[filesList, pos+len] # blank)
THEN { pos ← pos+len; LOOP };
RETURN [TRUE];
ENDLOOP;
RETURN [FALSE] };
IF Rope.Size[name]=0 THEN RETURN;
IF Rope.Equal[name, fileName, FALSE] THEN {
record hand change to file holding list
GetFilesList[];
RETURN;
};
IF AlreadyThere[] THEN RETURN;
MessageWindow.Append["Adding ", TRUE];
MessageWindow.Append[name];
MessageWindow.Append[" to "];
MessageWindow.Append[fileName];
filesList ← Rope.Concat[filesList, Rope.Concat[" ", name]];
s ← FS.StreamOpen[fileName, $create];
IO.PutRope[s, filesList];
IO.Close[s];
};
AfterRollback: Booting.RollbackProc = {
--update cached copy--
GetFilesList[];
};
GetFilesList: PROC = {
s: IO.STREAM = FS.StreamOpen[fileName, $read ! FS.Error => GO TO Quit];
len: INT = IO.GetLength[s];
readChar: SAFE PROC RETURNS [CHAR] = { RETURN [IO.GetChar[s]] };
filesList ← Rope.FromProc[len, readChar];
IO.Close[s];
EXITS Quit => filesList ← NIL;
};
UnReg: ENTRY PROC = {
ENABLE UNWIND => NULL;
IF regProc # NIL THEN ViewerEvents.UnRegisterEventProc[regProc, save];
regProc ← NIL;
filesList ← NIL };
Reg: ENTRY PROC = {
ENABLE UNWIND => NULL;
IF regProc # NIL THEN ViewerEvents.UnRegisterEventProc[regProc, save];
regProc ← ViewerEvents.RegisterEventProc[Add, save];
GetFilesList[] };
Reg[];
Booting.RegisterProcs[r: AfterRollback];
}...