Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ctype.h>
5 #include <ndb.h>
6 #include "ndbhf.h"
8 /*
9 * Parse a data base entry. Entries may span multiple
10 * lines. An entry starts on a left margin. All subsequent
11 * lines must be indented by white space. An entry consists
12 * of tuples of the forms:
13 * attribute-name
14 * attribute-name=value
15 * attribute-name="value with white space"
16 *
17 * The parsing returns a 2-dimensional structure. The first
18 * dimension joins all tuples. All tuples on the same line
19 * form a ring along the second dimension.
20 */
22 /*
23 * parse the next entry in the file
24 */
25 Ndbtuple*
26 ndbparse(Ndb *db)
27 {
28 char *line;
29 Ndbtuple *t;
30 Ndbtuple *first, *last;
31 int len;
33 first = last = 0;
34 for(;;){
35 if((line = Brdline(&db->b, '\n')) == 0)
36 break;
37 len = Blinelen(&db->b);
38 if(line[len-1] != '\n')
39 break;
40 if(first && !ISWHITE(*line) && *line != '#'){
41 Bseek(&db->b, -len, 1);
42 break;
43 }
44 t = _ndbparseline(line);
45 if(t == 0)
46 continue;
47 if(first)
48 last->entry = t;
49 else
50 first = t;
51 last = t;
52 while(last->entry)
53 last = last->entry;
54 }
55 setmalloctag(first, getcallerpc(&db));
56 return first;
57 }