From: Martin Mares Date: Sat, 8 Jun 2002 14:00:33 +0000 (+0000) Subject: New functions for manipulating attribute lists: obj_prepend_attr() X-Git-Tag: holmes-import~1399 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=89556b90f1afb9b7ebe247c05721e0a04a7232c0;p=libucw.git New functions for manipulating attribute lists: obj_prepend_attr() and obj_insert_attr(). --- diff --git a/lib/lib.h b/lib/lib.h index 7b406dd9..7c3eb5ff 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -118,6 +118,8 @@ byte *obj_find_aval(struct odes *, uns); struct oattr *obj_set_attr(struct odes *, uns, byte *); struct oattr *obj_set_attr_num(struct odes *, uns, uns); struct oattr *obj_add_attr(struct odes *, struct oattr *, uns, byte *); +struct oattr *obj_prepend_attr(struct odes *, uns, byte *); +struct oattr *obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v); /* Content-Type pattern matching and filters */ diff --git a/lib/object.c b/lib/object.c index 839bc65e..0a068654 100644 --- a/lib/object.c +++ b/lib/object.c @@ -222,3 +222,39 @@ obj_add_attr(struct odes *o, struct oattr *a, uns x, byte *v) a->last_same = b; return a; } + +struct oattr * +obj_prepend_attr(struct odes *o, uns x, byte *v) +{ + struct oattr *a, *b, **z; + + b = oa_new(o, x, v); + z = &o->attrs; + while (a = *z) + { + if (a->attr == x) + { + b->same = a; + *z = b; + b->last_same = a->last_same; + return b; + } + z = &a->next; + } + b->next = o->attrs; + o->attrs = b; + return b; +} + +struct oattr * +obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte *v) +{ + struct oattr *b; + + b = oa_new(o, first->attr, v); + b->same = after->same; + after->same = b; + if (first->last_same == after) + first->last_same = b; + return b; +}