]> mj.ucw.cz Git - libucw.git/blobdiff - lib/obj2buck.c
Added {b,}put_attr_separator().
[libucw.git] / lib / obj2buck.c
index 2a2fd1c97b1b98504e690faf81ed037b5e609c17..a38051a53416ef4bd9d933ddd3058fa3bbd6083e 100644 (file)
@@ -1,19 +1,23 @@
 /*
 /*
- *     Generating V33 buckets
+ *     Generating Buckets from Objects
  *
  *     (c) 2004, Robert Spalek <robert@ucw.cz>
  *
  *     (c) 2004, Robert Spalek <robert@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
  */
 
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
-#include "lib/obj2buck.h"
+#include "lib/ff-utf8.h"
 #include "lib/bucket.h"
 #include "lib/bucket.h"
-#include "charset/unistream.h"
+#include "lib/object.h"
 
 #include <string.h>
 #include <stdarg.h>
 
 static uns use_v33;
 
 #include <string.h>
 #include <stdarg.h>
 
 static uns use_v33;
+static int hdr_sep;
 
 void
 attr_set_type(uns type)
 
 void
 attr_set_type(uns type)
@@ -21,12 +25,17 @@ attr_set_type(uns type)
   switch (type)
     {
     case BUCKET_TYPE_PLAIN:
   switch (type)
     {
     case BUCKET_TYPE_PLAIN:
+      use_v33 = 0;
+      hdr_sep = -1;
+      break;
     case BUCKET_TYPE_V30:
       use_v33 = 0;
     case BUCKET_TYPE_V30:
       use_v33 = 0;
+      hdr_sep = '\n';
       break;
     case BUCKET_TYPE_V33:
     case BUCKET_TYPE_V33_LIZARD:
       use_v33 = 1;
       break;
     case BUCKET_TYPE_V33:
     case BUCKET_TYPE_V33_LIZARD:
       use_v33 = 1;
+      hdr_sep = 0;
       break;
     default:
       die("Don't know how to generate buckets of type %08x", type);
       break;
     default:
       die("Don't know how to generate buckets of type %08x", type);
@@ -115,6 +124,14 @@ put_attr_num(byte *ptr, uns type, uns val)
   return ptr;
 }
 
   return ptr;
 }
 
+byte *
+put_attr_separator(byte *ptr)
+{
+  if (hdr_sep >= 0)
+    *ptr++ = hdr_sep;
+  return ptr;
+}
+
 inline void
 bput_attr(struct fastbuf *b, uns type, byte *val, uns len)
 {
 inline void
 bput_attr(struct fastbuf *b, uns type, byte *val, uns len)
 {
@@ -181,3 +198,36 @@ bput_attr_num(struct fastbuf *b, uns type, uns val)
   else
     bprintf(b, "%c%d\n", type, val);
 }
   else
     bprintf(b, "%c%d\n", type, val);
 }
+
+void
+bput_attr_separator(struct fastbuf *b)
+{
+  if (hdr_sep >= 0)
+    bputc(b, hdr_sep);
+}
+
+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);
+}