2 * Sherlock Library -- Object Functions
4 * (c) 1997--2003 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/pools.h"
12 #include "lib/fastbuf.h"
17 #define OBJ_POOL_SIZE 4096
20 obj_dump(struct odes *o)
24 for(a=o->attrs; a; a=a->next)
25 for(b=a; b; b=b->same)
26 printf("%c%s\n", (a==b ? a->attr : ' '), b->val);
30 oa_new(struct odes *o, uns x, byte *v)
32 struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v));
34 a->next = a->same = NULL;
41 obj_new(struct mempool *pool)
45 o = mp_alloc(lp, sizeof(struct odes));
48 o->cached_attr = NULL;
53 obj_read(struct fastbuf *f, struct odes *o)
57 while (bgets(f, buf, sizeof(buf)))
61 obj_add_attr(o, buf[0], buf+1);
67 obj_write(struct fastbuf *f, struct odes *d)
72 for(a=d->attrs; a; a=a->next)
73 for(b=a; b; b=b->same)
76 for(z = b->val; *z; z++)
77 if (*z >= ' ' || *z == '\t')
82 log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
89 obj_find_attr(struct odes *o, uns x)
93 for(a=o->attrs; a && a->attr != x; a=a->next)
99 obj_find_attr_last(struct odes *o, uns x)
101 struct oattr *a = obj_find_attr(o, x);
112 obj_del_attr(struct odes *o, struct oattr *a)
114 struct oattr *x, **p, *y, *l;
117 o->cached_attr = NULL;
143 obj_find_aval(struct odes *o, uns x)
145 struct oattr *a = obj_find_attr(o, x);
147 return a ? a->val : NULL;
151 obj_set_attr(struct odes *o, uns x, byte *v)
153 struct oattr *a, **z;
180 obj_set_attr_num(struct odes *o, uns a, uns v)
185 return obj_set_attr(o, a, x);
189 obj_add_attr(struct odes *o, uns x, byte *v)
194 if (!(a = o->cached_attr) || a->attr != x)
196 if (!(a = obj_find_attr(o, x)))
212 obj_prepend_attr(struct odes *o, uns x, byte *v)
214 struct oattr *a, *b, **z;
236 obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v)
240 b = oa_new(o, first->attr, v);
241 b->same = after->same;