2 * Sherlock Library -- Object Functions
4 * (c) 1997--2001 Martin Mares <mj@ucw.cz>
9 #include "lib/fastbuf.h"
14 #define OBJ_POOL_SIZE 4096
17 obj_dump(struct odes *o)
21 for(a=o->attrs; a; a=a->next)
22 for(b=a; b; b=b->same)
23 printf("%c%s\n", (a==b ? a->attr : ' '), b->val);
27 oa_new(struct odes *o, uns x, byte *v)
29 struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v));
31 a->next = a->same = NULL;
39 obj_new(struct mempool *pool)
41 struct mempool *lp = pool;
45 lp = mp_new(OBJ_POOL_SIZE);
46 o = mp_alloc(lp, sizeof(struct odes));
48 o->local_pool = (pool == lp) ? NULL : lp;
54 obj_free(struct odes *o)
57 mp_delete(o->local_pool);
61 obj_read(struct fastbuf *f, struct odes *o)
64 struct oattr **last = &o->attrs;
69 while (bgets(f, buf, sizeof(buf)))
73 a = oa_new(o, buf[0], buf+1);
74 if (!la || la->attr != a->attr)
75 for(la=o->attrs; la && la->attr != a->attr; la=la->next)
79 la->last_same->same = a;
93 obj_write(struct fastbuf *f, struct odes *d)
98 for(a=d->attrs; a; a=a->next)
99 for(b=a; b; b=b->same)
102 for(z = b->val; *z; z++)
108 log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
115 obj_find_attr(struct odes *o, uns x)
119 for(a=o->attrs; a && a->attr != x; a=a->next)
125 obj_find_attr_last(struct odes *o, uns x)
127 struct oattr *a = obj_find_attr(o, x);
129 return a ? a->last_same : NULL;
133 obj_del_attr(struct odes *o, struct oattr *a)
135 struct oattr *x, **p, *y, *l;
150 if (y->last_same == x)
165 obj_find_aval(struct odes *o, uns x)
167 struct oattr *a = obj_find_attr(o, x);
169 return a ? a->val : NULL;
173 obj_set_attr(struct odes *o, uns x, byte *v)
175 struct oattr *a, **z;
201 obj_set_attr_num(struct odes *o, uns a, uns v)
206 return obj_set_attr(o, a, x);
210 obj_add_attr(struct odes *o, struct oattr *a, uns x, byte *v)
216 a = obj_find_attr(o, x);
218 return obj_set_attr(o, x, v);
221 a->last_same->same = b;