X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fobject.c;h=fb957bd7e61169271226a5689738e30f8a7fc8ae;hb=2cbdeacdc8f0fb3f4252c72a24407afba5788a6b;hp=fb5d231ff4e5dbd5194ff15dbdfd0e2736795af5;hpb=5235a735d59c73f528a4b1e9d212d63673005ddb;p=libucw.git diff --git a/lib/object.c b/lib/object.c index fb5d231f..fb957bd7 100644 --- a/lib/object.c +++ b/lib/object.c @@ -10,6 +10,7 @@ #include "lib/lib.h" #include "lib/pools.h" #include "lib/fastbuf.h" +#include "lib/object.h" #include #include @@ -46,7 +47,7 @@ obj_new(struct mempool *pool) int obj_read(struct fastbuf *f, struct odes *o) { - byte buf[1024]; + byte buf[MAX_ATTR_SIZE]; while (bgets(f, buf, sizeof(buf))) { @@ -63,8 +64,9 @@ 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; bputc(f, a->attr); - for(byte *z = b->val; *z; z++) + for(z = b->val; *z; z++) if (*z >= ' ' || *z == '\t') bputc(f, *z); else @@ -72,6 +74,7 @@ obj_write(struct fastbuf *f, struct odes *d) bputc(f, '?'); log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U')); } + ASSERT(z - b->val <= MAX_ATTR_SIZE-2); bputc(f, '\n'); } } @@ -241,3 +244,43 @@ obj_insert_attr(struct odes *o, struct oattr *first, struct oattr *after, byte * after->same = b; return b; } + +void +obj_move_attr_to_head(struct odes *o, uns x) +{ + struct oattr *a, **z; + + z = &o->attrs; + while (a = *z) + { + if (a->attr == x) + { + *z = a->next; + a->next = o->attrs; + o->attrs = a; + break; + } + z = &a->next; + } +} + +void +obj_move_attr_to_tail(struct odes *o, uns x) +{ + struct oattr *a, **z; + + z = &o->attrs; + while (a = *z) + { + if (a->attr == x) + { + *z = a->next; + while (*z) + z = &(*z)->next; + *z = a; + a->next = NULL; + break; + } + z = &a->next; + } +}