include "bufio.m"; include "attrdb.m"; attrdb := load Attrdb Attrdb->PATH; 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); }; Db: adt { open: fn(path: string): ref Db; sopen: fn(data: string): ref Db; changed: fn(db: self ref Db): int; reopen: fn(db: self ref Db): int; append: fn(db1: self ref Db, db2: ref Db): ref Db; 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);
Init must be called before any other function in the module.
Each logical database is represented by a Db value. It can span several physical files, named in the body of a database attribute in the primary file of the database. (If no such attribute appears, there is just the one physical file in the database.)
Parseline takes a line containing a set of space-separated attribute=value pairs, and returns a tuple (ts,err). If the line's syntax is correct, ts is a Tuples value that represents the pairs as a list of Attr values. If the syntax is wrong (eg, unmatched quote), ts is nil and err contains a diagnostic.
ATTRDB(2 ) | Rev: Mon Oct 27 19:35:44 GMT 2008 |