OpenWhitePagesDatabase:
SAFE
PROC[
wpState: WPState, howToComplain: Log.WhereToReport←$System]
RETURNS [ok: BOOL←FALSE] = TRUSTED {
ENABLE BTree.Error => {
Log.Problem["Trouble opening BTree", howToComplain]; CONTINUE };
treeName: ROPE←wpState.treeRootName.Concat[".Tree"];
feepTreeName: ROPE←wpState.treeRootName.Concat[".FTree"];
logFileName: ROPE ← wpState.logFileName;
treeFile, feepFile: FS.OpenFile;
logStream: IO.STREAM;
init: BOOL;
IF wpState=NIL THEN RETURN[FALSE];
IF wpState.wpOpen THEN RETURN;
wpState.wpTree ← BTreeSimple.New[];
wpState.wpFeepTree ← BTreeSimple.New[];
{
ENABLE
FS.Error =>
IF error.group = user
THEN {
Log.Problem[error.explanation, howToComplain]; treeFile←FS.nullOpenFile; CONTINUE; };
sbp: FS.StreamBufferParms = [FS.defaultStreamBufferParms.vmPagesPerBuffer, 4];
SELECT wpState.accessOptions
FROM
$read => {
treeFile←FS.Open[name: treeName];
feepFile←FS.Open[name: feepTreeName];
logStream ← FS.StreamOpen[fileName: logFileName, streamBufferParms: sbp];
};
$create => {
treeFile←FS.Create[name: treeName, keep: 2, setKeep: TRUE, pages: 100];
feepFile←FS.Create[name: feepTreeName, keep: 2, setKeep: TRUE, pages: 100];
logStream ←
FS.StreamOpen[fileName: logFileName, accessOptions: $write, streamBufferParms: sbp];
};
$write => {
treeFile←FS.OpenOrCreate[name: treeName, keep: 2, pages: 100];
feepFile←FS.OpenOrCreate[name: feepTreeName, keep: 2, pages: 100];
logStream ←
FS.StreamOpen[fileName: logFileName, accessOptions: $write, streamBufferParms: sbp];
};
ENDCASE => Log.Problem["Don't request $append option for BTree", howToComplain];
};
IF treeFile=NIL OR logStream = NIL OR feepFile=NIL THEN RETURN[FALSE];
wpState.wpFile ← treeFile;
wpState.wpFeepFile ← feepFile;
wpState.logStream ← logStream;
init ← wpState.accessOptions = $create OR logStream.GetLength = 0;
BTreeSimple.Open[tree: wpState.wpTree, file: wpState.wpFile, initialize: init];
BTreeSimple.Open[tree: wpState.wpFeepTree, file: wpState.wpFeepFile, initialize: init];
IF wpState.accessOptions = $create THEN wpState.accessOptions ← $write;
ok ← wpState.wpOpen ← TRUE;
};