From 6db8a707bd82f914fc782831eacc37edd226076b Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Sun, 4 Jul 2004 11:30:53 +0000 Subject: [PATCH] - use buck2obj_parse() instead of obj_read_bucket() to separate the header and the body - use the new interface for writing the attributes to the buckets --- lib/Makefile | 4 ++-- lib/buckettool.c | 34 ++++++++++++++++------------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 9cee1277..a3b5b805 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -11,7 +11,7 @@ LIBSH_MODS=alloc alloc_str ctmatch db fastbuf fb-file fb-mem lists \ finger proctitle ipaccess profile bitsig randomkey \ hashfunc base64 base224 fb-temp fb-mmap fb-printf urlkey \ partmap fb-limfd fb-buffer mainloop exitstatus runcmd carefulio \ - lizard lizard-safe sighandler buck2obj + lizard lizard-safe sighandler buck2obj obj2buck ifdef CONFIG_OWN_REGEX include lib/regex/Makefile @@ -26,7 +26,7 @@ obj/lib/hashfunc.o obj/lib/hashfunc.oo: CFLAGS += -funroll-loops obj/lib/db-test: obj/lib/db-test.o $(LIBSH) obj/lib/db-tool: obj/lib/db-tool.o $(LIBSH) -obj/lib/buckettool: obj/lib/buckettool.o $(LIBCHARSET) $(LIBSH) +obj/lib/buckettool: obj/lib/buckettool.o $(LIBSH) $(LIBCHARSET) obj/lib/conf-test: obj/lib/conf-test.o $(LIBSH) obj/lib/sort-test: obj/lib/sort-test.o $(LIBSH) obj/lib/lfs-test: obj/lib/lfs-test.o $(LIBSH) diff --git a/lib/buckettool.c b/lib/buckettool.c index 2d1dd339..aa61e515 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -102,20 +102,22 @@ dump_oattr(struct fastbuf *out, struct oattr *oa) static void dump_parsed_bucket(struct fastbuf *out, struct obuck_header *h, struct fastbuf *b) { + struct odes *o_hdr, *o_body; mp_flush(pool); - struct odes *o = obj_read_bucket(buck_buf, pool, h->type, h->length, b, NULL); - if (!o) + o_hdr = obj_new(pool); + o_body = obj_new(pool); + if (buck2obj_parse(buck_buf, h->type, h->length, b, o_hdr, NULL, o_body) < 0) + { bprintf(out, "Cannot parse bucket %x of type %x and length %d: %m\n", h->oid, h->type, h->length); + return; + } else { -#define IS_HEADER(x) (x=='O' || x=='U') - for (struct oattr *oa = o->attrs; oa; oa = oa->next) - if (IS_HEADER(oa->attr)) - dump_oattr(out, oa); + for (struct oattr *oa = o_hdr->attrs; oa; oa = oa->next) + dump_oattr(out, oa); bputc(out, '\n'); - for (struct oattr *oa = o->attrs; oa; oa = oa->next) - if (!IS_HEADER(oa->attr)) - dump_oattr(out, oa); + for (struct oattr *oa = o_body->attrs; oa; oa = oa->next) + dump_oattr(out, oa); } } @@ -164,6 +166,7 @@ insert(byte *arg) type = BUCKET_TYPE_PLAIN; else if (sscanf(arg, "%x", &type) != 1) die("Type `%s' is not a hexadecimal number"); + attr_set_type(type); in = bfdopen_shared(0, 4096); obuck_init(1); @@ -182,26 +185,21 @@ insert(byte *arg) } if (!b) b = obuck_create(type); - if (type < BUCKET_TYPE_V33) - { - *e++ = '\n'; - bwrite(b, buf, e-buf); - } - else if (in_body == 1) + if (in_body == 1) { bputc(b, 0); in_body = 2; } - else if (type == BUCKET_TYPE_V33 || !in_body) + else if (type <= BUCKET_TYPE_V33 || !in_body) { - bwrite_v33(b, buf[0], buf+1, e-buf-1); + bput_attr(b, buf[0], buf+1, e-buf-1); } else { uns want_len = lizard_filled + (e-buf) + 6 + LIZARD_NEEDS_CHARS; // +6 is the maximum UTF-8 length bb_grow(&lizard_buf, want_len); byte *ptr = lizard_buf.ptr + lizard_filled; - WRITE_V33(ptr, buf[0], buf+1, e-buf-1); + ptr = put_attr(ptr, buf[0], buf+1, e-buf-1); lizard_filled = ptr - lizard_buf.ptr; } } -- 2.39.2