xref: /inferno-os/module/attrdb.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1*46439007SCharles.ForsythAttrdb: module
2*46439007SCharles.Forsyth{
3*46439007SCharles.Forsyth	PATH:	con "/dis/lib/attrdb.dis";
4*46439007SCharles.Forsyth
5*46439007SCharles.Forsyth	Attr: adt {
6*46439007SCharles.Forsyth		attr:	string;
7*46439007SCharles.Forsyth		val:	string;
8*46439007SCharles.Forsyth		tag:	int;		# application-defined data, initially 0
9*46439007SCharles.Forsyth	};
10*46439007SCharles.Forsyth
11*46439007SCharles.Forsyth	Tuples: adt {
12*46439007SCharles.Forsyth		n:	int;
13*46439007SCharles.Forsyth		pairs:	list of ref Attr;
14*46439007SCharles.Forsyth
15*46439007SCharles.Forsyth		hasattr:	fn(t: self ref Tuples, attr: string): int;
16*46439007SCharles.Forsyth		haspair:	fn(t: self ref Tuples, attr: string, value: string): int;
17*46439007SCharles.Forsyth		find:	fn(t: self ref Tuples, attr: string): list of ref Attr;
18*46439007SCharles.Forsyth		findbyattr:	fn(t: self ref Tuples, attr: string, value: string, rattr: string): list of ref Attr;
19*46439007SCharles.Forsyth	};
20*46439007SCharles.Forsyth
21*46439007SCharles.Forsyth	Dbentry: adt {
22*46439007SCharles.Forsyth		n:	int;
23*46439007SCharles.Forsyth		lines:	list of ref Tuples;
24*46439007SCharles.Forsyth
25*46439007SCharles.Forsyth		find:	fn(e: self ref Dbentry, attr: string): list of (ref Tuples, list of ref Attr);
26*46439007SCharles.Forsyth		findfirst:	fn(e: self ref Dbentry, attr: string): string;
27*46439007SCharles.Forsyth		findpair:	fn(e: self ref Dbentry, attr: string, value: string): list of ref Tuples;
28*46439007SCharles.Forsyth		findbyattr:	fn(e: self ref Dbentry, attr: string, value: string, rattr: string): list of (ref Tuples, list of ref Attr);
29*46439007SCharles.Forsyth	};
30*46439007SCharles.Forsyth
31*46439007SCharles.Forsyth	Dbptr: adt {
32*46439007SCharles.Forsyth		dbs:	list of ref Dbf;
33*46439007SCharles.Forsyth		index:	ref Attrindex->Index;
34*46439007SCharles.Forsyth		pick{
35*46439007SCharles.Forsyth		Direct =>
36*46439007SCharles.Forsyth			offset:	int;
37*46439007SCharles.Forsyth		Hash =>
38*46439007SCharles.Forsyth			current:	int;
39*46439007SCharles.Forsyth			next:	int;
40*46439007SCharles.Forsyth		}
41*46439007SCharles.Forsyth	};
42*46439007SCharles.Forsyth
43*46439007SCharles.Forsyth	Dbf: adt {
44*46439007SCharles.Forsyth		fd:	ref Bufio->Iobuf;
45*46439007SCharles.Forsyth		name:	string;
46*46439007SCharles.Forsyth		dir:	ref Sys->Dir;
47*46439007SCharles.Forsyth		indices:	list of ref Attrindex->Index;
48*46439007SCharles.Forsyth		lockc:	chan of int;
49*46439007SCharles.Forsyth
50*46439007SCharles.Forsyth		open:	fn(path: string): ref Dbf;
51*46439007SCharles.Forsyth		sopen:	fn(data: string): ref Dbf;
52*46439007SCharles.Forsyth		changed:	fn(f: self ref Dbf): int;
53*46439007SCharles.Forsyth		reopen:	fn(f: self ref Dbf): int;
54*46439007SCharles.Forsyth
55*46439007SCharles.Forsyth		# for supporting commands:
56*46439007SCharles.Forsyth		readentry:	fn(dbf: self ref Dbf, offset: int, attr: string, value: string, useval: int): (ref Dbentry, int, int);
57*46439007SCharles.Forsyth	};
58*46439007SCharles.Forsyth
59*46439007SCharles.Forsyth	Db: adt {
60*46439007SCharles.Forsyth		dbs:		list of ref Dbf;
61*46439007SCharles.Forsyth
62*46439007SCharles.Forsyth		open:	fn(path: string): ref Db;
63*46439007SCharles.Forsyth		sopen:	fn(data: string): ref Db;
64*46439007SCharles.Forsyth		append:	fn(db1: self ref Db, db2: ref Db): ref Db;
65*46439007SCharles.Forsyth		changed:	fn(db: self ref Db): int;
66*46439007SCharles.Forsyth		reopen:	fn(db: self ref Db): int;
67*46439007SCharles.Forsyth
68*46439007SCharles.Forsyth		find:	fn(db: self ref Db, start: ref Dbptr, attr: string): (ref Dbentry, ref Dbptr);
69*46439007SCharles.Forsyth		findpair:	fn(db: self ref Db, start: ref Dbptr, attr: string, value: string): (ref Dbentry, ref Dbptr);
70*46439007SCharles.Forsyth		findbyattr:	fn(db: self ref Db, start: ref Dbptr, attr: string, value: string, rattr: string): (ref Dbentry, ref Dbptr);
71*46439007SCharles.Forsyth	};
72*46439007SCharles.Forsyth
73*46439007SCharles.Forsyth	init:	fn(): string;
74*46439007SCharles.Forsyth
75*46439007SCharles.Forsyth	parseentry:	fn(s: string, lno: int): (ref Dbentry, int, string);
76*46439007SCharles.Forsyth	parseline:	fn(s: string, lno: int): (ref Tuples, string);
77*46439007SCharles.Forsyth};
78*46439007SCharles.Forsyth
79*46439007SCharles.ForsythAttrindex: module
80*46439007SCharles.Forsyth{
81*46439007SCharles.Forsyth	PATH:	con "/dis/lib/attrhash.dis";
82*46439007SCharles.Forsyth
83*46439007SCharles.Forsyth	Index: adt {
84*46439007SCharles.Forsyth		fd:	ref Sys->FD;
85*46439007SCharles.Forsyth		attr:	string;
86*46439007SCharles.Forsyth		mtime:	int;
87*46439007SCharles.Forsyth		size:	int;
88*46439007SCharles.Forsyth		tab:	array of byte;
89*46439007SCharles.Forsyth
90*46439007SCharles.Forsyth		open:	fn(dbf: Attrdb->Dbf, attr: string, fd: ref Sys->FD): ref Index;
91*46439007SCharles.Forsyth	};
92*46439007SCharles.Forsyth
93*46439007SCharles.Forsyth	init:	fn(): string;
94*46439007SCharles.Forsyth};
95*46439007SCharles.Forsyth
96*46439007SCharles.ForsythAttrhash: module
97*46439007SCharles.Forsyth{
98*46439007SCharles.Forsyth	PATH:	con "/dis/lib/attrhash.dis";
99*46439007SCharles.Forsyth
100*46439007SCharles.Forsyth	NDBPLEN: con 3;	# file pointer length in bytes
101*46439007SCharles.Forsyth	NDBHLEN:	con 4+4;	# file header length (mtime[4], length[4])
102*46439007SCharles.Forsyth	NDBSPEC:	con 1<<23;	# flag bit for something special
103*46439007SCharles.Forsyth	NDBCHAIN: con NDBSPEC;	# pointer to collision chain
104*46439007SCharles.Forsyth	NDBNAP:	con NDBSPEC | 1;	# not a pointer
105*46439007SCharles.Forsyth
106*46439007SCharles.Forsyth	init:	fn(): string;
107*46439007SCharles.Forsyth	attrindex:	fn(): Attrindex;
108*46439007SCharles.Forsyth	hash:	fn(s: string, hlen: int): int;
109*46439007SCharles.Forsyth	get3, get4:	fn(a: array of byte): int;
110*46439007SCharles.Forsyth};
111