xref: /inferno-os/appl/cmd/dbm/fetch.b (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1implement Dbmfetch;
2
3include "sys.m";
4	sys: Sys;
5
6include "draw.m";
7
8include "dbm.m";
9	dbm: Dbm;
10	Datum, Dbf: import dbm;
11
12Dbmfetch: module
13{
14	init: fn(nil: ref Draw->Context, args: list of string);
15};
16
17init(nil: ref Draw->Context, args: list of string)
18{
19	sys = load Sys Sys->PATH;
20	dbm = load Dbm Dbm->PATH;
21
22	dbm->init();
23
24	args = tl args;
25	db := Dbf.open(hd args, Sys->OREAD);
26	if(db == nil){
27		sys->fprint(sys->fildes(2), "dbm/fetch: %s: %r\n", hd args);
28		raise "fail:open";
29	}
30	args = tl args;
31	key := hd args;
32	data := db.fetch(array of byte key);
33	if(data == nil)
34		sys->fprint(sys->fildes(2), "not found\n");
35	else
36		sys->write(sys->fildes(1), data, len data);
37}
38