<> <> <> <> <<>> <> <<>> 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 <> 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] ~ { <> 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]; }; <> Commander.Register[key: "LoganBerryBrowser", proc: MakeBrowserTool, doc: "Create a LoganBerry browser.\n usage: LoganBerryBrowser ..." ]; Commander.Register[key: "LBBrowser", proc: MakeBrowserTool, doc: "Create a LoganBerry browser.\n usage: LBBrowser ..." ]; END. <<>> <<>>