X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fobject.c;h=6a2a90c5b5d46aeec6c8709be842121bd553f41a;hb=aac897f2337471637d9a47b38e1b7b35ab0359b5;hp=32beab2e895e0474825fba895afeeae97f5dc52c;hpb=fb9eb45ecf6702f7b3612194617e36a3a1f43872;p=libucw.git diff --git a/lib/object.c b/lib/object.c index 32beab2e..6a2a90c5 100644 --- a/lib/object.c +++ b/lib/object.c @@ -9,12 +9,13 @@ */ #include "lib/lib.h" -#include "lib/pools.h" +#include "lib/mempool.h" #include "lib/fastbuf.h" #include "lib/object.h" #include #include +#include void obj_dump(struct odes *o) @@ -57,56 +58,6 @@ obj_new(struct mempool *pool) return o; } -int -obj_read(struct fastbuf *f, struct odes *o) -{ - byte buf[MAX_ATTR_SIZE]; - - while (bgets(f, buf, sizeof(buf))) - { - if (!buf[0]) - return 1; - obj_add_attr(o, buf[0], buf+1); - } - return 0; -} - -void -obj_read_multi(struct fastbuf *f, struct odes *o) -{ - /* Read a multi-part object ending with either EOF or a NUL character */ - byte buf[MAX_ATTR_SIZE]; - while (bpeekc(f) > 0 && bgets(f, buf, sizeof(buf))) - if (buf[0]) - obj_add_attr(o, buf[0], buf+1); -} - -void -obj_write(struct fastbuf *f, struct odes *d) -{ - for(struct oattr *a=d->attrs; a; a=a->next) - for(struct oattr *b=a; b; b=b->same) - { - byte *z; - for (z = b->val; *z; z++) - if (*z < ' ' && *z != '\t') - { - log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U')); - *z = '?'; - } - ASSERT(z - b->val <= MAX_ATTR_SIZE-2); - bput_attr_str(f, a->attr, b->val); - } -} - -void -obj_write_nocheck(struct fastbuf *f, struct odes *d) -{ - for(struct oattr *a=d->attrs; a; a=a->next) - for(struct oattr *b=a; b; b=b->same) - bput_attr_str(f, a->attr, b->val); -} - struct oattr * obj_find_attr(struct odes *o, uns x) { @@ -167,6 +118,13 @@ obj_find_aval(struct odes *o, uns x) return a ? a->val : NULL; } +uns +obj_find_anum(struct odes *o, uns x, uns def) +{ + struct oattr *a = obj_find_attr(o, x); + return a ? (uns)atol(a->val) : def; +} + struct oattr * obj_set_attr(struct odes *o, uns x, byte *v) { @@ -208,14 +166,17 @@ obj_set_attr_num(struct odes *o, uns a, uns v) static inline struct oattr * obj_add_attr_internal(struct odes *o, struct oattr *b) { - struct oattr *a; + struct oattr *a, **z; if (!(a = o->cached_attr) || a->attr != b->attr) { - if (!(a = obj_find_attr(o, b->attr))) + z = &o->attrs; + while ((a = *z) && a->attr != b->attr) + z = &a->next; + if (!a) { - b->next = o->attrs; - o->attrs = b; + *z = b; + /* b->next is NULL */ goto done; } }