]> mj.ucw.cz Git - libucw.git/commitdiff
- use buck2obj_parse() instead of obj_read_bucket() to separate the header
authorRobert Spalek <robert@ucw.cz>
Sun, 4 Jul 2004 11:30:53 +0000 (11:30 +0000)
committerRobert Spalek <robert@ucw.cz>
Sun, 4 Jul 2004 11:30:53 +0000 (11:30 +0000)
  and the body
- use the new interface for writing the attributes to the buckets

lib/Makefile
lib/buckettool.c

index 9cee12776da053e8378aa45b2b60b4713b2c1f96..a3b5b805287eb4547a40aba72a350915fc3ee15d 100644 (file)
@@ -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)
index 2d1dd339f81c3da8dbfb5c768c89e5ee757e92be..aa61e515d39bad459620be935e9225a8b6984458 100644 (file)
@@ -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;
          }
        }