summaryrefslogtreecommitdiff
path: root/module/attrdb.m
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 20:52:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 20:52:35 +0000
commit46439007cf417cbd9ac8049bb4122c890097a0fa (patch)
tree6fdb25e5f3a2b6d5657eb23b35774b631d4d97e4 /module/attrdb.m
parent37da2899f40661e3e9631e497da8dc59b971cbd0 (diff)
20060303-partial
Diffstat (limited to 'module/attrdb.m')
-rw-r--r--module/attrdb.m110
1 files changed, 110 insertions, 0 deletions
diff --git a/module/attrdb.m b/module/attrdb.m
new file mode 100644
index 00000000..bbd2a6ba
--- /dev/null
+++ b/module/attrdb.m
@@ -0,0 +1,110 @@
+Attrdb: module
+{
+ PATH: con "/dis/lib/attrdb.dis";
+
+ Attr: adt {
+ attr: string;
+ val: string;
+ tag: int; # application-defined data, initially 0
+ };
+
+ Tuples: adt {
+ n: int;
+ pairs: list of ref Attr;
+
+ hasattr: fn(t: self ref Tuples, attr: string): int;
+ haspair: fn(t: self ref Tuples, attr: string, value: string): int;
+ find: fn(t: self ref Tuples, attr: string): list of ref Attr;
+ findbyattr: fn(t: self ref Tuples, attr: string, value: string, rattr: string): list of ref Attr;
+ };
+
+ Dbentry: adt {
+ n: int;
+ lines: list of ref Tuples;
+
+ find: fn(e: self ref Dbentry, attr: string): list of (ref Tuples, list of ref Attr);
+ findfirst: fn(e: self ref Dbentry, attr: string): string;
+ findpair: fn(e: self ref Dbentry, attr: string, value: string): list of ref Tuples;
+ findbyattr: fn(e: self ref Dbentry, attr: string, value: string, rattr: string): list of (ref Tuples, list of ref Attr);
+ };
+
+ Dbptr: adt {
+ dbs: list of ref Dbf;
+ index: ref Attrindex->Index;
+ pick{
+ Direct =>
+ offset: int;
+ Hash =>
+ current: int;
+ next: int;
+ }
+ };
+
+ Dbf: adt {
+ fd: ref Bufio->Iobuf;
+ name: string;
+ dir: ref Sys->Dir;
+ indices: list of ref Attrindex->Index;
+ lockc: chan of int;
+
+ open: fn(path: string): ref Dbf;
+ sopen: fn(data: string): ref Dbf;
+ changed: fn(f: self ref Dbf): int;
+ reopen: fn(f: self ref Dbf): int;
+
+ # for supporting commands:
+ readentry: fn(dbf: self ref Dbf, offset: int, attr: string, value: string, useval: int): (ref Dbentry, int, int);
+ };
+
+ Db: adt {
+ dbs: list of ref Dbf;
+
+ open: fn(path: string): ref Db;
+ sopen: fn(data: string): ref Db;
+ append: fn(db1: self ref Db, db2: ref Db): ref Db;
+ changed: fn(db: self ref Db): int;
+ reopen: fn(db: self ref Db): int;
+
+ find: fn(db: self ref Db, start: ref Dbptr, attr: string): (ref Dbentry, ref Dbptr);
+ findpair: fn(db: self ref Db, start: ref Dbptr, attr: string, value: string): (ref Dbentry, ref Dbptr);
+ findbyattr: fn(db: self ref Db, start: ref Dbptr, attr: string, value: string, rattr: string): (ref Dbentry, ref Dbptr);
+ };
+
+ init: fn(): string;
+
+ parseentry: fn(s: string, lno: int): (ref Dbentry, int, string);
+ parseline: fn(s: string, lno: int): (ref Tuples, string);
+};
+
+Attrindex: module
+{
+ PATH: con "/dis/lib/attrhash.dis";
+
+ Index: adt {
+ fd: ref Sys->FD;
+ attr: string;
+ mtime: int;
+ size: int;
+ tab: array of byte;
+
+ open: fn(dbf: Attrdb->Dbf, attr: string, fd: ref Sys->FD): ref Index;
+ };
+
+ init: fn(): string;
+};
+
+Attrhash: module
+{
+ PATH: con "/dis/lib/attrhash.dis";
+
+ NDBPLEN: con 3; # file pointer length in bytes
+ NDBHLEN: con 4+4; # file header length (mtime[4], length[4])
+ NDBSPEC: con 1<<23; # flag bit for something special
+ NDBCHAIN: con NDBSPEC; # pointer to collision chain
+ NDBNAP: con NDBSPEC | 1; # not a pointer
+
+ init: fn(): string;
+ attrindex: fn(): Attrindex;
+ hash: fn(s: string, hlen: int): int;
+ get3, get4: fn(a: array of byte): int;
+};