DIRECTORY
Commander USING [CommandProc, Handle, Register],
IO USING [atom, BreakProc, EndOfStream, GetTokenRope, IDProc, PutF, PutRope, TokenProc, RIS, rope, STREAM],
LoganBerryBrowser USING [AttributePatterns, CreateTool, FilteredQuery, PatternsToEntry, ReadAttributePatterns, SyntaxError, Tool, ToolBody],
LoganBerryStub USING [AttributeType, AttributeValue, BuildIndices, Close, CompactLogs, DeleteEntry, Describe, Entry, EntryProc, Error, Open, OpenDB, SchemaInfo, WriteEntry],
Process USING [CheckForAbort],
Rope USING [Equal, ROPE];
LoganBerry commands
DescribeCmd: 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;
};
dbname: ROPE;
info: LoganBerry.SchemaInfo;
[dbname,,msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
info ← LoganBerry.Describe[db: Open[dbname]];
IO.PutF[cmd.out, "Database: %g\n", IO.rope[info.dbName]];
IO.PutRope[cmd.out, " keys:"];
FOR k:
LIST
OF LoganBerry.AttributeType ← info.keys, k.rest
WHILE k #
NIL
DO
IO.PutF[cmd.out, " %g", IO.atom[k.first]];
ENDLOOP;
IO.PutRope[cmd.out, "\n"];
IO.PutRope[cmd.out, " index files:"];
FOR l:
LIST
OF
ROPE ← info.indexNames, l.rest
WHILE l #
NIL
DO
IO.PutF[cmd.out, " %g", IO.rope[l.first]];
ENDLOOP;
IO.PutRope[cmd.out, "\n"];
IO.PutRope[cmd.out, " log files:"];
FOR l:
LIST
OF
ROPE ← info.logNames, l.rest
WHILE l #
NIL
DO
IO.PutF[cmd.out, " %g", IO.rope[l.first]];
ENDLOOP;
IO.PutRope[cmd.out, "\n"];
};
QueryCmd: 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;
};
PrintEntry: LoganBerry.EntryProc = {
[entry: LoganBerry.Entry] RETURNS [continue: BOOL]
Process.CheckForAbort[];
FOR e: LoganBerry.Entry ← entry, e.rest
UNTIL e =
NIL
DO
IO.PutF[cmd.out, "%g: %g\n", IO.atom[e.first.type], IO.rope[e.first.value]];
ENDLOOP;
IO.PutRope[cmd.out, "\n"];
RETURN[TRUE];
};
dbname: ROPE;
ap: LoganBerryBrowser.AttributePatterns;
db: LoganBerry.OpenDB;
[dbname, ap, msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
db ← Open[dbname];
LoganBerryBrowser.FilteredQuery[db: db, patterns: ap, proc: PrintEntry];
};
WriteCmd: 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;
};
dbname: ROPE;
ap: LoganBerryBrowser.AttributePatterns;
db: LoganBerry.OpenDB;
entry: LoganBerry.Entry;
[dbname, ap, msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
db ← Open[dbname];
entry ← LoganBerryBrowser.PatternsToEntry[ap];
LoganBerry.WriteEntry[db: db, entry: entry];
};
DeleteCmd: 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;
};
GetAttributeValue:
PROC [entry: LoganBerry.Entry, type: LoganBerry.AttributeType]
RETURNS [LoganBerry.AttributeValue] ~ {
FOR e: LoganBerry.Entry ← entry, e.rest
WHILE e #
NIL
DO
IF e.first.type = type
THEN
RETURN[e.first.value];
ENDLOOP;
RETURN[NIL];
};
DeleteEntry: LoganBerry.EntryProc = {
[entry: LoganBerry.Entry] RETURNS [continue: BOOL]
value: LoganBerry.AttributeValue ← GetAttributeValue[entry, primaryKey];
Process.CheckForAbort[];
LoganBerry.DeleteEntry[db: db, key: primaryKey, value: value];
IO.PutF[cmd.out, "Deleted %g: %g\n", IO.atom[primaryKey], IO.rope[value]];
RETURN[TRUE];
};
dbname: ROPE;
ap: LoganBerryBrowser.AttributePatterns;
db: LoganBerry.OpenDB;
primaryKey: LoganBerry.AttributeType;
[dbname, ap, msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
db ← Open[dbname];
primaryKey ← LoganBerry.Describe[db: db].info.keys.first;
LoganBerryBrowser.FilteredQuery[db: db, patterns: ap, proc: DeleteEntry];
};
CloseCmd: 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;
};
dbname: ROPE;
[dbname,,msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
LoganBerry.Close[db: Open[dbname]];
};
BuildIndicesCmd: 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;
};
dbname: ROPE;
[dbname,,msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
LoganBerry.BuildIndices[db: Open[dbname]];
};
CompactLogsCmd: 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;
};
dbname: ROPE;
[dbname,,msg] ← ParseArgs[cmd];
IF msg#NIL THEN RETURN;
LoganBerry.CompactLogs[db: Open[dbname]];
};
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;
};
dbname: ROPE;
tool: LoganBerryBrowser.Tool ← NEW[LoganBerryBrowser.ToolBody];
argStream: IO.STREAM ← IO.RIS[cmd.commandLine];
dbname ← IO.GetTokenRope[argStream, IO.IDProc ! IO.EndOfStream => {msg ← "No database name supplied.\n"; GOTO End}].token;
LoganBerryBrowser.CreateTool[db: Open[dbname], tool: tool];
};
ParseArgs:
PROC [cmd: Commander.Handle]
RETURNS [dbname:
ROPE ←
NIL, ap: LoganBerryBrowser.AttributePatterns ←
NIL, errMsg:
ROPE ←
NIL] ~ {
argStream: IO.STREAM ← IO.RIS[cmd.commandLine];
dbname ← IO.GetTokenRope[argStream, IO.IDProc ! IO.EndOfStream => {errMsg ← "No database name supplied.\n"; GOTO End}].token;
ap ← LoganBerryBrowser.ReadAttributePatterns[argStream ! LoganBerryBrowser.SyntaxError => {errMsg ← explanation; GOTO End}];
};
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 Rope.Equal[dbname, currentName] THEN RETURN[currentDB];
db ← currentDB ← LoganBerry.Open[dbName: dbname];
};
Command registrations
Commander.Register[key: "LBDescribe", proc: DescribeCmd, interpreted:
FALSE,
doc: "Get schema information about a LoganBerry database.\n usage: LBDescribe <dbname>" ];
Commander.Register[key: "LBQuery", proc: QueryCmd, interpreted:
FALSE,
doc: "Query a LoganBerry database.\n usage: LBQuery <dbname> <atype(pattern):avalue> ..." ];
Commander.Register[key: "LBRead", proc: QueryCmd, interpreted:
FALSE,
doc: "synonym for LBQuery." ];
Commander.Register[key: "LBWrite", proc: WriteCmd, interpreted:
FALSE,
doc: "Write an entry into a LoganBerry database.\n usage: LBWrite <dbname> <atype:avalue> ..." ];
Commander.Register[key: "LBDelete", proc: DeleteCmd, interpreted:
FALSE,
doc: "Delete entries from a LoganBerry database.\n usage: LBDelete <dbname> <atype(pattern):avalue> ..." ];
Commander.Register[key: "LBClose", proc: CloseCmd, interpreted:
FALSE,
doc: "Close a LoganBerry database.\n usage: LBClose <dbname>" ];
Commander.Register[key: "LBBuildIndices", proc: BuildIndicesCmd, interpreted:
FALSE,
doc: "Rebuild the indices for a LoganBerry database.\n usage: LBBuildIndices <dbname>" ];
Commander.Register[key: "LBCompactLogs", proc: CompactLogsCmd, interpreted:
FALSE,
doc: "Compact a LoganBerry database.\n usage: LBCompactLogs <dbname>" ];
Commander.Register[key: "LoganBerryBrowser", proc: MakeBrowserTool,
doc: "Create a LoganBerry browser." ];
Commander.Register[key: "LBBrowser", proc: MakeBrowserTool,
doc: "Create a LoganBerry browser." ];
Doug Terry, October 20, 1986 10:45:54 am PDT
Created.
changes to: DIRECTORY, LoganBerryCommandsImpl, IMPORTS, EXPORTS, DescribeCmd, QueryCmd, WriteCmd, DeleteCmd, CloseCmd, BuildIndicesCmd, CompactLogsCmd, ParseArgs, Commander, Commander, Commander, Commander, Commander, Commander, Commander, Commander, END, ~, ParseArgs, AttributeBreakProc (local of ReadAttributePatterns), ReadAttributePattern (local of ReadAttributePatterns), Open, WriteAttributePatterns, DoQuery, NamedFilter, WriteAttributePattern (local of WriteAttributePatterns), OptimalStart, PrintEntry (local of QueryCmd), DeleteEntry (local of DeleteCmd), GetAttributeValue, FilteredQuery
Doug Terry, October 31, 1986 2:58:29 pm PST
Exports LoganBerryBrowser.
changes to: DIRECTORY, EXPORTS, QueryCmd, WriteCmd, DeleteCmd, ParseArgs, ReadAttributePatterns, ReadAttributePattern (local of ReadAttributePatterns), WriteAttributePatterns, WriteAttributePattern (local of WriteAttributePatterns), PatternsToEntry, EntryToPatterns, FilteredQuery