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, May 1, 1985 11:14:19 am PDT
Last Edited by: Winkler, December 17, 1984 6:32:29 pm PST
DIRECTORY
Atom,
Commander USING [CommandProc, Register],
DB USING[MarkTransaction, GetSegmentInfo],
FS USING [StreamOpen],
IO,
Rope,
ViewerTools,
WhiteboardDB,
WhiteboardDBPrivate;
WhiteboardLoad: CEDAR PROGRAM
IMPORTS
Atom, Commander, DB, 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];
DB.MarkTransaction[DB.GetSegmentInfo[$Whiteboard].trans];
END;
LoadWBs: PROC[in: STREAM] =
BEGIN
[] ← in.SkipWhitespace[ ! EndOfStream => GOTO Return];
WHILE LoadWB[in] DO
[] ← in.SkipWhitespace[ ! EndOfStream => GOTO Return];
ENDLOOP;
EXITS Return => {};
END;
LoadWB: PROC[in: STREAM] RETURNS [BOOLEAN] =
BEGIN
wb: Whiteboard;
children: ChildSet;
wbName: ROPE;
[] ← in.GetChar[ ! EndOfStream => GOTO Done ]; -- read leading "("
[] ← in.GetTokenRope[breakProc: IDProc ! EndOfStream => GOTO Done ];
read keyword "WHITEBOARD"
[] ← in.SkipWhitespace[];
wbName ← in.GetTokenRope[breakProc: IDProc].token;
[] ← in.SkipWhitespace[];
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];
WHILE LoadWBItem[in, wb] DO
[] ← in.SkipWhitespace[];
ENDLOOP;
RETURN[TRUE];
EXITS Done => { RETURN[FALSE] };
END;
LoadWBItem: PROC[in: STREAM, wb: Whiteboard] RETURNS [BOOLEAN] =
BEGIN
key: ROPE;
IF in.EndOf THEN RETURN[FALSE]; -- no more WB Items
IF in.GetChar[] = ') THEN RETURN[FALSE]; -- no more WB Items
key ← in.GetTokenRope[breakProc: IDProc].token; -- read keyword
[] ← in.SkipWhitespace[];
IF Rope.Equal[key,"NOTE"] THEN LoadNote[in, wb]
ELSE IF Rope.Equal[key, "ICON"] THEN LoadIcon[in, wb];
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[];
[] ← in.SkipWhitespace[];
[] ← in.GetChar[]; --read trailing ")"
[] ← 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;
[] ← in.SkipWhitespace[];
x ← in.GetInt[];
[] ← in.SkipWhitespace[];
y ← in.GetInt[];
[] ← in.SkipWhitespace[];
iconNameRope ← in.GetTokenRope[breakProc: IconBreakProc].token;
[] ← in.GetChar[]; --read dividing "|"
iconLabelRope ← in.GetTokenRope[breakProc: IconBreakProc].token;
IF Rope.Equal[iconLabelRope, "-"] THEN iconLabelRope ← NIL;
[] ← in.GetChar[]; --read dividing "|"
iconTypeRope ← in.GetTokenRope[breakProc: IconBreakProc].token;
[] ← in.GetChar[]; --read dividing "|"
iconIconRope ← in.GetTokenRope[breakProc: IconBreakProc].token;
IF Rope.Equal[iconIconRope, "-"] THEN iconIconRope ← NIL;
[] ← in.GetChar[]; --read dividing "|"
iconArgumentRope ← in.GetTokenRope[breakProc: IconBreakProc].token;
IF Rope.Equal[iconArgumentRope, "-"] THEN iconArgumentRope ← NIL;
[] ← in.GetChar[]; --read trailing ")"
[] ← NewIcon[wb, x, y, iconNameRope, iconLabelRope, iconIconRope, iconArgumentRope, Atom.MakeAtom[iconTypeRope]]
END;
IconBreakProc: BreakProc =
BEGIN
IF (char = '|) OR (char = NUL) OR (char = ')) THEN RETURN[CharClass[break]]
ELSE RETURN[CharClass[other]];
END;
FormatBreakProc: BreakProc =
BEGIN
IF char = '| THEN RETURN[CharClass[break]] ELSE RETURN[CharClass[other]];
END;
ReadCoords: PROC[in: STREAM] RETURNS [x, y, w, h: INTEGER] =
BEGIN
x ← in.GetInt[];
[] ← in.SkipWhitespace[];
y ← in.GetInt[];
[] ← in.SkipWhitespace[];
w ← in.GetInt[];
[] ← in.SkipWhitespace[];
h ← in.GetInt[];
[] ← in.SkipWhitespace[];
END;
ReadRope: PROC[in: STREAM, length: INTEGER] RETURNS [r: ROPE] =
BEGIN
r ← NIL;
THROUGH [1..length] DO r ← r.Cat[FromChar[in.GetChar[]]] ENDLOOP;
END;
Commander.Register[key: "WBLoad", proc: DoLoad,
doc: "\nLoads named file into current whiteboard segment\n (File defaults to Whiteboard.dump)"]
END...