]> mj.ucw.cz Git - libucw.git/commitdiff
Completed merge with dev-img branch.
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 19 Oct 2006 08:34:16 +0000 (10:34 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 19 Oct 2006 08:34:16 +0000 (10:34 +0200)
- libimages library
- gatherer uses libimages instead of GraphicsMagick
- added indexation of image signatures and support
  for similar images to search server (IMAGESIM)
- CZ indexation split to text and images
- ... and more small changes

lib/Makefile
lib/bbuf.c [new file with mode: 0644]
lib/bbuf.h
lib/bbuf.t [new file with mode: 0644]
lib/clists.h
lib/sorter.h

index 775c7de6c89412b96a5812c0ad44b2d010dad9a5..15dc0a246d60df199676c55244b9cce182ae0052 100644 (file)
@@ -28,7 +28,8 @@ LIBUCW_MODS= \
        base64 base224 \
        sync \
        qache \
-       string
+       string \
+       bbuf
 
 LIBUCW_INCLUDES= \
        lib.h config.h math.h \
@@ -80,7 +81,7 @@ $(o)/lib/lizard-test: $(o)/lib/lizard-test.o $(LIBUCW)
 $(o)/lib/kmp-test: $(o)/lib/kmp-test.o $(LIBUCW) $(LIBCHARSET)
 $(o)/lib/ipaccess-test: $(o)/lib/ipaccess-test.o $(LIBUCW)
 
-TESTS+=$(addprefix $(o)/lib/,regex.test unicode-utf8.test hash-test.test mempool.test stkstring.test slists.test kmp-test.test)
+TESTS+=$(addprefix $(o)/lib/,regex.test unicode-utf8.test hash-test.test mempool.test stkstring.test slists.test kmp-test.test bbuf.test)
 $(o)/lib/regex.test: $(o)/lib/regex-t
 $(o)/lib/unicode-utf8.test: $(o)/lib/unicode-utf8-t
 $(o)/lib/hash-test.test: $(o)/lib/hash-test
@@ -89,6 +90,7 @@ $(o)/lib/stkstring.test: $(o)/lib/stkstring-t
 $(o)/lib/bitops.test: $(o)/lib/bit-ffs-t $(o)/lib/bit-fls-t
 $(o)/lib/slists.test: $(o)/lib/slists-t
 $(o)/lib/kmp-test.test: $(o)/lib/kmp-test
+$(o)/lib/bbuf.test: $(o)/lib/bbuf-t
 
 INCLUDES+=$(o)/lib/.include-stamp
 $(o)/lib/.include-stamp: $(addprefix $(s)/lib/,$(LIBUCW_INCLUDES))
diff --git a/lib/bbuf.c b/lib/bbuf.c
new file mode 100644 (file)
index 0000000..fae5870
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *     UCW Library -- A simple growing buffers for byte-sized items
+ *
+ *     (c) 2006 Pavel Charvat <pchar@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/bbuf.h"
+
+#include <stdio.h>
+
+char *
+bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args)
+{
+  bb_grow(bb, ofs + 1);
+  va_list args2;
+  va_copy(args2, args);
+  int cnt = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
+  va_end(args2);
+  if (cnt < 0)
+    {
+      /* Our C library doesn't support C99 return value of vsnprintf, so we need to iterate */
+      do
+        {
+         bb_do_grow(bb, bb->len + 1);
+          va_copy(args2, args);
+          cnt = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
+          va_end(args2);
+       }
+      while (cnt < 0);
+    }
+  else if ((uns)cnt >= bb->len - ofs)
+    {
+      bb_do_grow(bb, ofs + cnt + 1);
+      va_copy(args2, args);
+      int cnt2 = vsnprintf(bb->ptr + ofs, bb->len - ofs, fmt, args2);
+      va_end(args2);
+      ASSERT(cnt2 == cnt);
+    }
+  return bb->ptr + ofs;
+}
+
+char *
+bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...)
+{
+  va_list args;
+  va_start(args, fmt);
+  char *res = bb_vprintf_at(bb, ofs, fmt, args);
+  va_end(args);
+  return res;
+}
+
+char *
+bb_vprintf(bb_t *bb, char *fmt, va_list args)
+{
+  return bb_vprintf_at(bb, 0, fmt, args);
+}
+
+char *
+bb_printf(bb_t *bb, char *fmt, ...)
+{
+  va_list args;
+  va_start(args, fmt);
+  char *res = bb_vprintf_at(bb, 0, fmt, args);
+  va_end(args);
+  return res;
+}
+
+#ifdef TEST
+
+int main(void)
+{
+  bb_t bb;
+  bb_init(&bb);
+  char *x = bb_printf(&bb, "<Hello, %s!>", "World");
+  fputs(x, stdout);
+  x = bb_printf_at(&bb, 5, "<Hello, %50s!>\n", "World");
+  fputs(x, stdout);
+  bb_done(&bb);
+  return 0;
+}
+
+#endif
index 0d17f8ccfb77e372d8fb63d49a6ecf07393555a7..2585bec3c1fa9bd170bef9f06c160cca9bada5e7 100644 (file)
@@ -14,4 +14,9 @@
 #define        GBUF_PREFIX(x)  bb_##x
 #include "lib/gbuf.h"
 
+char *bb_vprintf(bb_t *bb, char *fmt, va_list args);
+char *bb_printf(bb_t *bb, char *fmt, ...);
+char *bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args);
+char *bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...);
+
 #endif
diff --git a/lib/bbuf.t b/lib/bbuf.t
new file mode 100644 (file)
index 0000000..cfc70b3
--- /dev/null
@@ -0,0 +1,4 @@
+# Tests for growing buffers
+
+Run:   obj/lib/bbuf-t
+Out:   <Hello, World!><Hello,                                              World!>
index 9c0f816a201e13175486c611092e700887d1dce4..4f1848d8d2fc903a9327cab05df40c444df6a171 100644 (file)
@@ -48,6 +48,8 @@ static inline int clist_empty(clist *l)
 #define CLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
 #define CLIST_FOR_EACH_DELSAFE(type,n,list,tmp) for(type n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
 
+#define CLIST_FOR_EACH_BACKWARDS(type,n,list) for(type n=(void*)(list).head.prev; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->prev)
+
 static inline void clist_insert_after(cnode *what, cnode *after)
 {
   cnode *before = after->next;
index 64092d6cafcc46f0bd9663ac9312c8c91b9a88a2..11daf95a0c933d53fb2699dc15e20f52e7e85466 100644 (file)
@@ -50,7 +50,7 @@
  *  int PREFIX_compare(SORT_KEY *a, *b)
  *                     compare two keys, result like strcmp
  *  int PREFIX_fetch_key(struct fastbuf *f, SORT_KEY *k)
- *                     fetch next key, returns 1=ok, 0=eof
+ *                     fetch next key, returns nonzero=ok, 0=eof
  *  void PREFIX_copy_data(struct fastbuf *src, *dest, SORT_KEY *k)
  *                     write just fetched key k to dest and copy all data
  *                     belonging to this key from src to dest.