forsyth20121205-174063a80cc13 years agoHistory
215 lines · 4.9 KB · Text
RawDownload
.TH ATTRDB 2.SH NAMEattrdb \- database of attribute-value pairs.SH SYNOPSIS.EXinclude "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);.EE.SH DESCRIPTION.B Attrdbfetches data from textual databases that contain groups of attribute-value pairs.The format is defined by.IR attrdb (6)..PP.B Initmust be called before any other function in the module..PPEach logical database is represented by a.B Dbvalue.It can span several physical files, named in the body of a.B databaseattribute in the primary file of the database.(If no such attribute appears, there is just the one physical file in the database.).TP.BI Db.open( path )Opens.I pathas a database, andreturns a (reference to a).B Dbvalue that represents it.On an error, it returns nil and the system error string contains a diagnostic.If.I pathcontains a.B databaseattribute with associated attributes of the form.BI file= filename,the logical database is formed by (logically) concatenating the contentsof each.I filenamein the order listed.See.IR attrdb (6)for details..TP.BI Db.sopen( data )Treat the contents of the string.I dataas a database, and return a.B Dbvalue representing it..TP.IB db1 .append( db2 )Return a.B Dbvalue that represents the result of logically appendingthe contents of database.I db2to.IR db1 ..TP.IB db .changed()Return true iff one or more of the underlying files have changed since they were last read..TP.IB db .reopen()Discard any cached data, and reopen the database files.Return 0 on success but -1 if any file could not be reopened..TP.IB db .find( ptr , attr )Starting at.IR ptr ,look in.I dbfor the next entry that contains an attribute.I attrand return a tuple.BI ( e , ptr )where.I eis a.B Dbentryvalue representing the whole entry, and.I ptris a database pointer for the next entry.If.I attrcannot be found,.I eis nil..TP.IB db .findpair( ptr\fP,\fP\ attr\fP,\fP\ value\fP)Starting at.IR ptr ,look in.I dbfor the next entry that contains the pair.IB attr = value,and return a tuple.BI ( e , ptr )where.I eis a.B Dbentryvalue representing the whole entry, and.I ptris a database pointer for the next entry.If the given paircannot be found,.I eis nil..TP.IB db .findbyattr( ptr\fP,\fP\ attr\fP,\fP\ value\fP,\fP\ rattr\fP )Starting at.I ptrin.IR db ,look for the next entry containing both the pair.IB attr = valueand a pair with attribute.IR rattr ;return a tuple.BI ( e , ptr )where.I eis a.B Dbentryvalue representing the whole entry, and.I ptris a database pointer for the next entry.If no such entry can be found,.I eis nil..PP.B Parselinetakes a line containing a set of space-separated.IB attribute = valuepairs, and returns a tuple.BI ( ts , err ) .If the line's syntax is correct,.I tsis a.B Tuplesvalue that represents the pairs as a list of.B Attrvalues.If the syntax is wrong (eg, unmatched quote),.I tsis nil and.I errcontains a diagnostic..SH SOURCE.B /appl/lib/attrdb.b.SH SEE ALSO.IR cfg (2),.IR attrdb (6),.IR ndb (6)