File: WhiteboardLoad.mesa
Copyright (C) 1984 by Xerox Corporation. All rights reserved.
For loading of whiteboard databases. (Companion to WhiteboardDump.mesa.)
Last edited by: Jennifer Widom, August 24, 1984 11:02:17 pm PDT
Last edited by: Donahue, August 7, 1985 8:49:19 am PDT
Last Edited by: Winkler, December 17, 1984 6:32:29 pm PST
DIRECTORY
Atom,
BasicTime USING[Now],
Commander USING [CommandProc, Register],
FS USING [StreamOpen],
IO,
Rope,
ViewerTools,
WhiteboardDB,
WhiteboardDBPrivate;
WhiteboardLoad: CEDAR PROGRAM
IMPORTS
Atom, BasicTime, Commander, FS, IO, Rope, WhiteboardDBPrivate, WhiteboardDB =
BEGIN OPEN WhiteboardDBPrivate, IO, Rope;
DoLoad: Commander.CommandProc =
BEGIN
ENABLE WhiteboardDB.WBError => {
SELECT reason FROM
$ServerDown => {msg ← "Load Failed -- server unavailable; retry later"; CONTINUE};
$TransactionAbort => {msg ← "Load Failed -- transaction aborted; retry later"; CONTINUE};
$ReadOnly => {msg ← "Load Failed -- database is readonly"; CONTINUE};
ENDCASE => REJECT };
h: IO.STREAM = IO.RIS[cmd.commandLine];
[] ← h.SkipWhitespace[];
IF h.EndOf THEN [] ← WhiteboardDB.Load["Whiteboard.dump"]
ELSE [] ← WhiteboardDB.Load[h.GetLineRope[]];
END;
LoadFromFile: PUBLIC PROC[dumpFile: ROPE] =
BEGIN
in: STREAM;
in ← FS.StreamOpen[dumpFile];
IF in = NIL THEN RETURN;
LoadWBs[in];
WhiteboardDBPrivate.MarkTransaction[];
END;
LoadWBs: PROC[in: STREAM] =
BEGIN
WHILE LoadWB[in] DO ENDLOOP;
END;
LoadWB: PROC[in: STREAM] RETURNS [success: BOOLEAN] =
BEGIN
wb: Whiteboard;
children: ChildSet;
wbName: ROPE;
[] ← in.GetTokenRope[ ! IO.EndOfStream => GOTO Done];
read keyword "WHITEBOARD"
wbName ← in.GetTokenRope[].token;
wb ← DeclareWhiteboard[name: wbName];
make sure all children are destroyed
children ← Children[wb];
FOR child: WBItem ← NextChild[children], NextChild[children] UNTIL child = NIL DO
Destroy[child]
ENDLOOP;
SetVersion[wb, 0];
SetCreateDate[wb, BasicTime.Now[]];
WHILE LoadWBItem[in, wb] DO ENDLOOP;
RETURN[TRUE];
EXITS Done => { RETURN[FALSE] };
END;
LoadWBItem: PROC[in: STREAM, wb: Whiteboard] RETURNS [BOOLEAN] =
BEGIN
key: ROPE;
key ← in.GetTokenRope[].token; -- read keyword
IF Rope.Equal[key,"NOTE"] THEN LoadNote[in, wb]
ELSE IF Rope.Equal[key, "ICON"] THEN LoadIcon[in, wb]
ELSE IF Rope.Equal[key, "END"] THEN RETURN[FALSE];
RETURN[TRUE];
END;
LoadNote: PROC[in: STREAM, wb: Whiteboard] =
BEGIN
contentsRope, formatRope: ROPE;
x, y, w, h: INTEGER;
[] ← in.SkipWhitespace[];
[x, y, w, h] ← ReadCoords[in];
contentsRope ← in.GetRopeLiteral[];
formatRope ← in.GetRopeLiteral[];
[] ← NewNote[wb, x, y, w, h, NEW[ViewerTools.TiogaContentsRec ← [contentsRope, formatRope]]]
END;
LoadIcon: PROC[in: STREAM, wb: Whiteboard] =
BEGIN
iconNameRope, iconLabelRope, iconTypeRope, iconIconRope, iconArgumentRope: ROPE;
x, y: INTEGER;
x ← in.GetInt[];
y ← in.GetInt[];
iconNameRope ← in.GetRopeLiteral[];
iconLabelRope ← in.GetRopeLiteral[];
iconTypeRope ← in.GetRopeLiteral[];
iconIconRope ← in.GetRopeLiteral[];
iconArgumentRope ← in.GetRopeLiteral[];
[] ← NewIcon[wb, x, y, iconNameRope, iconLabelRope, iconIconRope, iconArgumentRope, Atom.MakeAtom[iconTypeRope]]
END;
ReadCoords: PROC[in: STREAM] RETURNS [x, y, w, h: INTEGER] =
BEGIN
x ← in.GetInt[];
y ← in.GetInt[];
w ← in.GetInt[];
h ← in.GetInt[];
END;
Commander.Register[key: "WBLoad", proc: DoLoad,
doc: "\nLoads named file into current whiteboard segment\n (File defaults to Whiteboard.dump)"]
END...