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"
18 obj_dump(struct odes *o)
22 for(a=o->attrs; a; a=a->next)
23 for(b=a; b; b=b->same)
24 printf("%c%s\n", (a==b ? a->attr : ' '), b->val);
28 oa_new(struct odes *o, uns x, byte *v)
30 struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v));
32 a->next = a->same = NULL;
39 obj_new(struct mempool *pool)
43 o = mp_alloc(pool, sizeof(struct odes));
46 o->cached_attr = NULL;
51 obj_read(struct fastbuf *f, struct odes *o)
55 while (bgets(f, buf, sizeof(buf)))
59 obj_add_attr(o, buf[0], buf+1);
65 obj_write(struct fastbuf *f, struct odes *d)
70 for(a=d->attrs; a; a=a->next)
71 for(b=a; b; b=b->same)
74 for(z = b->val; *z; z++)
75 if (*z >= ' ' || *z == '\t')
80 log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
87 obj_find_attr(struct odes *o, uns x)
91 for(a=o->attrs; a && a->attr != x; a=a->next)
97 obj_find_attr_last(struct odes *o, uns x)
99 struct oattr *a = obj_find_attr(o, x);
110 obj_del_attr(struct odes *o, struct oattr *a)
112 struct oattr *x, **p, *y, *l;
115 o->cached_attr = NULL;
141 obj_find_aval(struct odes *o, uns x)
143 struct oattr *a = obj_find_attr(o, x);
145 return a ? a->val : NULL;
149 obj_set_attr(struct odes *o, uns x, byte *v)
151 struct oattr *a, **z;
178 obj_set_attr_num(struct odes *o, uns a, uns v)
183 return obj_set_attr(o, a, x);
187 obj_add_attr(struct odes *o, uns x, byte *v)
192 if (!(a = o->cached_attr) || a->attr != x)
194 if (!(a = obj_find_attr(o, x)))
210 obj_prepend_attr(struct odes *o, uns x, byte *v)
212 struct oattr *a, *b, **z;
234 obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v)
238 b = oa_new(o, first->attr, v);
239 b->same = after->same;