aboutsummaryrefslogtreecommitdiff
path: root/src/libndb/ndbparse.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-11 19:41:16 +0000
committerrsc <devnull@localhost>2005-02-11 19:41:16 +0000
commitd957951b75df08a9bb0293e3e13ff87759afbb92 (patch)
tree4d7868b0d223956217cbc8819d7afb3bec532cca /src/libndb/ndbparse.c
parentad017cfbf5530cfc3ae2fafd723cdade2a4405f6 (diff)
downloadplan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.tar.gz
plan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.tar.bz2
plan9port-d957951b75df08a9bb0293e3e13ff87759afbb92.zip
new
Diffstat (limited to 'src/libndb/ndbparse.c')
-rw-r--r--src/libndb/ndbparse.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/libndb/ndbparse.c b/src/libndb/ndbparse.c
new file mode 100644
index 00000000..86a108dc
--- /dev/null
+++ b/src/libndb/ndbparse.c
@@ -0,0 +1,57 @@
+#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;
+ if(first)
+ last->entry = t;
+ else
+ first = t;
+ last = t;
+ while(last->entry)
+ last = last->entry;
+ }
+ setmalloctag(first, getcallerpc(&db));
+ return first;
+}