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"
13 #include "lib/object.h"
19 obj_dump(struct odes *o)
21 for(struct oattr *a=o->attrs; a; a=a->next)
22 for(struct oattr *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;
38 obj_new(struct mempool *pool)
40 struct odes *o = mp_alloc(pool, sizeof(struct odes));
43 o->cached_attr = NULL;
48 obj_read(struct fastbuf *f, struct odes *o)
52 while (bgets(f, buf, sizeof(buf)))
56 obj_add_attr(o, buf[0], buf+1);
62 obj_write(struct fastbuf *f, struct odes *d)
64 for(struct oattr *a=d->attrs; a; a=a->next)
65 for(struct oattr *b=a; b; b=b->same)
68 for(byte *z = b->val; *z; z++)
69 if (*z >= ' ' || *z == '\t')
74 log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U'));
81 obj_write_nocheck(struct fastbuf *f, struct odes *d)
83 for(struct oattr *a=d->attrs; a; a=a->next)
84 for(struct oattr *b=a; b; b=b->same)
92 obj_find_attr(struct odes *o, uns x)
95 for(a=o->attrs; a && a->attr != x; a=a->next)
101 obj_find_attr_last(struct odes *o, uns x)
103 struct oattr *a = obj_find_attr(o, x);
114 obj_del_attr(struct odes *o, struct oattr *a)
116 struct oattr *x, **p, *y, *l;
119 o->cached_attr = NULL;
145 obj_find_aval(struct odes *o, uns x)
147 struct oattr *a = obj_find_attr(o, x);
149 return a ? a->val : NULL;
153 obj_set_attr(struct odes *o, uns x, byte *v)
155 struct oattr *a, **z;
182 obj_set_attr_num(struct odes *o, uns a, uns v)
187 return obj_set_attr(o, a, x);
191 obj_add_attr(struct odes *o, uns x, byte *v)
196 if (!(a = o->cached_attr) || a->attr != x)
198 if (!(a = obj_find_attr(o, x)))
214 obj_prepend_attr(struct odes *o, uns x, byte *v)
216 struct oattr *a, *b, **z;
238 obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v)
240 struct oattr *b = oa_new(o, first->attr, v);
241 b->same = after->same;