diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libndb/ndbparse.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libndb/ndbparse.c')
-rwxr-xr-x | sys/src/libndb/ndbparse.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sys/src/libndb/ndbparse.c b/sys/src/libndb/ndbparse.c new file mode 100755 index 000000000..e551ada9d --- /dev/null +++ b/sys/src/libndb/ndbparse.c @@ -0,0 +1,58 @@ +#include <u.h> +#include <libc.h> +#include <bio.h> +#include <ctype.h> +#include <ndb.h> +#include "ndbhf.h" + +/* + * Parse a data base entry. Entries may span multiple + * lines. An entry starts on a left margin. All subsequent + * lines must be indented by white space. An entry consists + * of tuples of the forms: + * attribute-name + * attribute-name=value + * attribute-name="value with white space" + * + * The parsing returns a 2-dimensional structure. The first + * dimension joins all tuples. All tuples on the same line + * form a ring along the second dimension. + */ + +/* + * parse the next entry in the file + */ +Ndbtuple* +ndbparse(Ndb *db) +{ + char *line; + Ndbtuple *t; + Ndbtuple *first, *last; + int len; + + first = last = 0; + for(;;){ + if((line = Brdline(&db->b, '\n')) == 0) + break; + len = Blinelen(&db->b); + if(line[len-1] != '\n') + break; + if(first && !ISWHITE(*line) && *line != '#'){ + Bseek(&db->b, -len, 1); + break; + } + t = _ndbparseline(line); + if(t == 0) + continue; + setmalloctag(t, getcallerpc(&db)); + if(first) + last->entry = t; + else + first = t; + last = t; + while(last->entry) + last = last->entry; + } + ndbsetmalloctag(first, getcallerpc(&db)); + return first; +} |