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