LoganBerryViewerCommandsImpl.mesa
Copyright Ó 1986, 1992 by Xerox Corporation. All rights reserved.
Doug Terry, May 9, 1991 9:16 am PDT
Brian Oki, May 29, 1990 9:43 am PDT
Registers the LoganBerry commands that must be executed in a viewers world. Currently, there is only one: LoganBerryBrowser. The rest of the LoganBerry commands are implemented in LoganBerryCommandsImpl.mesa.
DIRECTORY
BlackBerry USING [PrintEntry, SetCountLimit],
Commander USING [CommandProc, Register],
Convert USING [Error, IntFromRope],
IO USING [atom, BreakProc, EndOfStream, GetTokenRope, IDProc, PutF, TokenProc, RIS, rope, STREAM],
LoganBerry USING [AttributeType, Entry, Error, Open, OpenDB, SchemaInfo, nullDB],
LoganBerryBrowser USING [CreateTool, DBInfoRec, Tool, ToolBody],
Rope USING [Concat, Equal, Fetch, Find, Length, ROPE, SkipTo, Substr];
LoganBerryViewerCommandsImpl: CEDAR PROGRAM
IMPORTS BlackBerry, Commander, Convert, IO, LoganBerry, LoganBerryBrowser, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
currentName: ROPE ¬ "#";
currentDB: LoganBerry.OpenDB ¬ LoganBerry.nullDB; -- cache of most recently used db
LoganBerry commands
MakeBrowserTool: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
ENABLE LoganBerry.Error => {
IO.PutF[cmd.err, "Error: %g - %g\n", IO.atom[ec], IO.rope[explanation]];
GOTO End;
};
ParseSwitch: PROC [arg: ROPE] RETURNS [found: BOOLEAN ¬ FALSE] ~ {
IF Rope.Fetch[dbname, 0] = '- THEN { -- parse switch
found ¬ TRUE;
SELECT Rope.Fetch[dbname, 1] FROM
'T, 't => limit ¬ Convert.IntFromRope[Rope.Substr[dbname, 2] ! Convert.Error => GOTO BadSwitch];
ENDCASE => GOTO BadSwitch;
};
EXITS
BadSwitch => msg ¬ "Invalid switch.\n";
};
dbname: ROPE;
tool: LoganBerryBrowser.Tool ¬ NEW[LoganBerryBrowser.ToolBody];
argStream: IO.STREAM ¬ IO.RIS[cmd.commandLine];
limit: INT ¬ 0;
DO
dbname ¬ IO.GetTokenRope[argStream, IO.IDProc ! IO.EndOfStream => EXIT].token;
IF ParseSwitch[dbname] THEN LOOP;
tool.databases ¬ CONS[NEW[LoganBerryBrowser.DBInfoRec ¬ [db: Open[dbname]]], tool.databases];
ENDLOOP;
IF tool.databases = NIL THEN RETURN[result: NIL, msg: "No database name supplied.\n"];
IF limit#0 THEN {
BlackBerry.SetCountLimit[limit];
tool.display ¬ BlackBerry.PrintEntry;
};
LoganBerryBrowser.CreateTool[tool: tool];
EXITS
End => RETURN;
};
Open: PROC [dbname: ROPE] RETURNS [db: LoganBerry.OpenDB] ~ {
Opens the database with the given name; a distinquished name "#" indicates that the most recently opened database should be used. A cache of opened databases could be maintained, but we don't bother for now. If the name is missing an explicit extension and version then ".df!H" is assumed.
prev, loc: INT ¬ 0;
IF Rope.Equal[dbname, currentName] THEN RETURN[currentDB];
WHILE loc < Rope.Length[dbname] DO
prev ¬ loc;
loc ¬ Rope.SkipTo[s: dbname, pos: prev+1, skip: "/>]"];
ENDLOOP;
IF Rope.Find[dbname, "!", prev] = -1 AND Rope.Find[dbname, ".", prev] = -1 THEN {
dbname ¬ Rope.Concat[dbname, ".df"];
};
db ¬ currentDB ¬ LoganBerry.Open[dbName: dbname];
};
Command registrations
Commander.Register[key: "LoganBerryBrowser", proc: MakeBrowserTool,
doc: "Create a LoganBerry browser.\n usage: LoganBerryBrowser <dbname> <dbname> ..." ];
Commander.Register[key: "LBBrowser", proc: MakeBrowserTool,
doc: "Create a LoganBerry browser.\n usage: LBBrowser <dbname> <dbname> ..." ];
END.