]> mj.ucw.cz Git - libucw.git/blobdiff - lib/buck2obj.c
Moved object reading and writing functions where they belong.
[libucw.git] / lib / buck2obj.c
index b19963f7803284acdbaed5c5f53ef9d8d7db9bfa..7d651dfe6b65f6941f375a4c32ef53f88033c06d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Bucket -> Object Converter
+ *     Generating Objects from Buckets
  *
  *     (c) 2004, Robert Spalek <robert@ucw.cz>
  *     (c) 2004, Martin Mares <mj@ucw.cz>
@@ -9,11 +9,11 @@
 #include "lib/unaligned.h"
 #include "lib/pools.h"
 #include "lib/fastbuf.h"
-#include "charset/unicode.h"
+#include "lib/unicode.h"
 #include "lib/object.h"
 #include "lib/bucket.h"
 #include "lib/lizard.h"
-#include "lib/buck2obj.h"
+#include "lib/bbuf.h"
 
 #include <stdlib.h>
 #include <errno.h>
 
 #define        RET_ERR(num)    ({ errno = num; return -1; })
 
-#define        GBUF_TYPE       byte
-#define        GBUF_PREFIX(x)  bb_##x
-#include "lib/gbuf.h"
-
 struct buck2obj_buf
 {
   bb_t bb;
@@ -167,3 +163,27 @@ obj_read_bucket(struct buck2obj_buf *buf, struct mempool *pool, uns buck_type, u
   else
     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);
+}