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)
20 for(struct oattr *a=o->attrs; a; a=a->next)
21 for(struct oattr *b=a; b; b=b->same)
22 printf("%c%s\n", (a==b ? a->attr : ' '), b->val);
26 oa_new(struct odes *o, uns x, byte *v)
28 struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + strlen(v));
30 a->next = a->same = NULL;
37 obj_new(struct mempool *pool)
39 struct odes *o = mp_alloc(pool, sizeof(struct odes));
42 o->cached_attr = NULL;
47 obj_read(struct fastbuf *f, struct odes *o)
51 while (bgets(f, buf, sizeof(buf)))
55 obj_add_attr(o, buf[0], buf+1);
61 obj_write(struct fastbuf *f, struct odes *d)
63 for(struct oattr *a=d->attrs; a; a=a->next)
64 for(struct oattr *b=a; b; b=b->same)
67 for(byte *z = b->val; *z; z++)
68 if (*z >= ' ' || *z == '\t')
73 log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
80 obj_write_nocheck(struct fastbuf *f, struct odes *d)
82 for(struct oattr *a=d->attrs; a; a=a->next)
83 for(struct oattr *b=a; b; b=b->same)
91 obj_find_attr(struct odes *o, uns x)
94 for(a=o->attrs; a && a->attr != x; a=a->next)
100 obj_find_attr_last(struct odes *o, uns x)
102 struct oattr *a = obj_find_attr(o, x);
113 obj_del_attr(struct odes *o, struct oattr *a)
115 struct oattr *x, **p, *y, *l;
118 o->cached_attr = NULL;
144 obj_find_aval(struct odes *o, uns x)
146 struct oattr *a = obj_find_attr(o, x);
148 return a ? a->val : NULL;
152 obj_set_attr(struct odes *o, uns x, byte *v)
154 struct oattr *a, **z;
181 obj_set_attr_num(struct odes *o, uns a, uns v)
186 return obj_set_attr(o, a, x);
190 obj_add_attr(struct odes *o, uns x, byte *v)
195 if (!(a = o->cached_attr) || a->attr != x)
197 if (!(a = obj_find_attr(o, x)))
213 obj_prepend_attr(struct odes *o, uns x, byte *v)
215 struct oattr *a, *b, **z;
237 obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v)
239 struct oattr *b = oa_new(o, first->attr, v);
240 b->same = after->same;