2 * Generating Buckets from Objects
4 * (c) 2004, Robert Spalek <robert@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/fastbuf.h"
12 #include "lib/ff-utf8.h"
13 #include "lib/bucket.h"
14 #include "lib/object.h"
22 attr_set_type(uns type)
26 case BUCKET_TYPE_PLAIN:
31 case BUCKET_TYPE_V33_LIZARD:
35 die("Don't know how to generate buckets of type %08x", type);
40 put_attr(byte *ptr, uns type, byte *val, uns len)
45 memcpy(ptr, val, len);
52 memcpy(ptr, val, len);
60 put_attr_str(byte *ptr, uns type, byte *val)
62 return put_attr(ptr, type, val, strlen(val));
66 put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va)
70 uns len = vsprintf(ptr+1, mask, va);
73 byte tmp[6], *tmp_end = tmp;
74 PUT_UTF8(tmp_end, len+1);
75 uns l = tmp_end - tmp;
76 memmove(ptr+l, ptr+1, len);
90 ptr += vsprintf(ptr, mask, va);
97 put_attr_format(byte *ptr, uns type, char *mask, ...)
101 byte *ret = put_attr_vformat(ptr, type, mask, va);
107 put_attr_num(byte *ptr, uns type, uns val)
111 uns len = sprintf(ptr+1, "%d", val) + 1;
117 ptr += sprintf(ptr, "%c%d\n", type, val);
122 bput_attr(struct fastbuf *b, uns type, byte *val, uns len)
139 bput_attr_str(struct fastbuf *b, uns type, byte *val)
141 bput_attr(b, type, val, strlen(val));
145 bput_attr_vformat(struct fastbuf *b, uns type, byte *mask, va_list va)
149 int len = vsnprintf(NULL, 0, mask, va);
151 die("vsnprintf() does not support size=0");
153 vbprintf(b, mask, va);
159 vbprintf(b, mask, va);
165 bput_attr_format(struct fastbuf *b, uns type, char *mask, ...)
169 bput_attr_vformat(b, type, mask, va);
174 bput_attr_num(struct fastbuf *b, uns type, uns val)
179 uns len = sprintf(tmp, "%d", val);
185 bprintf(b, "%c%d\n", type, val);