]> mj.ucw.cz Git - libucw.git/commitdiff
Merging IS branch: New customization code and its use for images.
authorMartin Mares <mj@ucw.cz>
Sat, 8 Jun 2002 13:27:56 +0000 (13:27 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 8 Jun 2002 13:27:56 +0000 (13:27 +0000)
lib/Makefile
lib/config.h
lib/custom.c
lib/custom.h
lib/index.h

index 273e3fda9bf27b83c5126a595fc6c553fe110516..c6ef7e945e56c4361ced93037e3a50edc04f1d1c 100644 (file)
@@ -8,9 +8,9 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists
        prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \
        wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \
        finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \
-       hashfunc.o custom.o base224.o fb-temp.o
+       hashfunc.o base224.o fb-temp.o
 
-obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS))
+obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) $(CUSTOM_MODULES)
 
 obj/lib/hashfunc.o: CFLAGS += -funroll-loops
 
index c6e7c7509aae426cc9427f9b4524bfdce99faf4a..85d6a464926a8eb02f0a3fdd83f2fd8c89e0f0ba 100644 (file)
@@ -13,7 +13,7 @@
 
 /* Version */
 
-#define SHER_VER "2.2a" SHER_SUFFIX
+#define SHER_VER "2.2a" SHERLOCK_VERSION_SUFFIX
 
 /* Paths */
 
@@ -41,10 +41,6 @@ typedef unsigned int sh_time_t;              /* Timestamp */
 
 typedef u32 oid_t;                     /* Object ID */
 
-/* Custom stuff */
-
-#include "lib/custom.h"
-
 /* Data types and functions for accessing file positions */
 
 #ifdef SHERLOCK_CONFIG_LARGE_DB
index cba8412a2f647441f36ed1e56e384461d905aa77..a1aec75f5e25e390246d4b1b40e62f13c04a3820 100644 (file)
@@ -9,8 +9,97 @@
 
 #include <stdlib.h>
 
+#ifdef CONFIG_IMAGES
+
+void
+custom_create_attrs(struct odes *odes, struct card_attr *ca)
+{
+  byte *x;
+  uns ox, oy, tw, th, ncolors;
+  uns ifmt, isize, icol;
+  byte ocspace[10];
+  byte *ctype;
+
+  x = obj_find_aval(odes, 'G');
+  ctype = obj_find_aval(odes, 'T');
+  if (!x || !ctype || sscanf(x, "%d%d%s%d%d%d", &ox, &oy, ocspace, &ncolors, &tw, &th) != 6)
+    {
+      ca->image_flags = 0;
+      return;
+    }
+
+  if (!strcasecmp(ctype, "image/jpeg"))
+    ifmt = 1;
+  else if (!strcasecmp(ctype, "image/png"))
+    ifmt = 2;
+  else if (!strcasecmp(ctype, "image/gif"))
+    ifmt = 3;
+  else
+    {
+      log(L_ERROR, "Unknown image content-type: %s", ctype);
+      ifmt = 0;
+    }
+
+  if (ox <= 100 && oy <= 100)
+    isize = 0;
+  else if (ox <= 320 && oy <= 200)
+    isize = 1;
+  else if (ox <= 640 && oy <= 480)
+    isize = 2;
+  else
+    isize = 3;
+
+  if (!strcasecmp(ocspace, "GRAY"))
+    icol = 0;
+  else if (ncolors <= 16)
+    icol = 1;
+  else if (ncolors <= 256)
+    icol = 2;
+  else
+    icol = 3;
+
+  ca->image_flags = ifmt | (isize << 2) | (icol << 4);
+}
+
+byte *
+custom_it_parse(u32 *dest, byte *value, uns intval)
+{
+  if (value)
+    return "IMGTYPE: number expected";
+  if (intval > 3)
+    return "IMGTYPE out of range";
+  *dest = intval;
+  return NULL;
+}
+
+byte *
+custom_is_parse(u32 *dest, byte *value, uns intval)
+{
+  if (value)
+    return "IMGSIZE: number expected";
+  if (intval > 3)
+    return "IMGSIZE out of range";
+  *dest = intval;
+  return NULL;
+}
+
+byte *
+custom_ic_parse(u32 *dest, byte *value, uns intval)
+{
+  if (value)
+    return "IMGCOLORS: number expected";
+  if (intval > 3)
+    return "IMGCOLORS out of range";
+  *dest = intval;
+  return NULL;
+}
+
+#endif
+
 #if 0          /* Example */
 
+/* FIXME: The example is wrong */
+
 void
 custom_get_lm(struct card_attr *ca, byte *attr)
 {
index d97e8dffd109b77891d4a0b34202f9b04228efac..226d76d87e979f748dc80112d2d58a074462dd38 100644 (file)
@@ -4,10 +4,6 @@
  *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
  */
 
-/* Name of this customization (version suffix) */
-
-#define SHER_SUFFIX ""
-
 /* Word types */
 
 enum word_type {
@@ -84,34 +80,79 @@ enum string_type {
 /*
  *  Definitions of custom attributes:
  *
- *  INT_ATTR(type, id, oattr, keyword, get_func, parse_func)
+ *  First of all, you need to define your own card_attr fields which will
+ *  contain your attributes: CUSTOM_CARD_ATTRS lists them.
+ *  Please order the attributes by decreasing size to get optimum padding.
+ *
+ *  Then define custom_create_attrs() which will get the object description
+ *  and set your card_attr fields accordingly.
+ *
+ *  Finally, you have to define CUSTOM_ATTRS with matching rules:
+ *
+ *  INT_ATTR(id, keyword, get_func, parse_func) -- unsigned integer attribute
  *
- *  type       data type used to hold the value
  *  id         C identifier of the attribute
- *  oattr      object attribute we get the value from
  *  keywd      search server keyword for the attribute
- *  void get_func(struct card_attr *ca, byte *attr)
- *             parse object attribute (may be NULL)
+ *  type get_func(struct card_attr *ca, byte *attr)
+ *             get attribute value from the card_attr
  *  byte *parse_func(u32 *dest, byte *value, uns intval)
  *             parse value in query (returns error message or NULL)
  *             for KEYWD = "string", it gets value="string", intval=0
  *             for KEYWD = num, it gets value=NULL, intval=num.
  *
+ *  SMALL_SET_ATTR(id, keyword, get_func, parse_func)
+ *    -- integers 0..31 with set matching
+ *
  *  A good place for definitions of the functions is lib/custom.c.
+ */
+
+struct card_attr;
+struct odes;
+
+#ifdef CONFIG_IMAGES
+
+/*
+ *  We store several image properties to card_attr->image_flags and
+ *  match them as custom attributes. The image_flags byte contains:
  *
- *  Please order the attributes by decreasing size to get optimum padding.
+ *  bits 0--1  image format (0: not an image, 1: JPEG, 2: PNG, 3: GIF)
+ *  bits 2--3   image size (0: <=100x100, 1: <=320x200, 2: <=640x480, 3: other)
+ *  bits 4--5   image colors (0: grayscale, 1: <=16, 2: <=256, 3: >256)
  */
 
-#if 0          /* Example */
+#define CUSTOM_CARD_ATTRS \
+       byte image_flags;
 
-#define CUSTOM_ATTRS INT_ATTR(u32, lm, 'L', LM, custom_get_lm, custom_parse_lm)
+#define CUSTOM_ATTRS \
+       SMALL_SET_ATTR(ifmt, IMGTYPE, custom_it_get, custom_it_parse)           \
+       SMALL_SET_ATTR(isize, IMGSIZE, custom_is_get, custom_is_parse)          \
+       SMALL_SET_ATTR(icolors, IMGCOLORS, custom_ic_get, custom_ic_parse)
 
-struct card_attr;
-void custom_get_lm(struct card_attr *ca, byte *attr);
-byte *custom_parse_lm(u32 *dest, byte *value, uns intval);
+void custom_create_attrs(struct odes *odes, struct card_attr *ca);
+
+/* These must be macros instead of inline functions, struct card_attr is not fully defined yet */
+#define custom_it_get(ca) ((ca)->image_flags & 3)
+#define custom_is_get(ca) (((ca)->image_flags >> 2) & 3)
+#define custom_ic_get(ca) (((ca)->image_flags >> 4) & 3)
+
+byte *custom_it_parse(u32 *dest, byte *value, uns intval);
+byte *custom_is_parse(u32 *dest, byte *value, uns intval);
+byte *custom_ic_parse(u32 *dest, byte *value, uns intval);
+
+#else
+
+#if 0
+
+/* FIXME: Add a simple example */
 
 #else
 
+/* No custom attributes defined */
+
+#define CUSTOM_CARD_ATTRS
 #define CUSTOM_ATTRS
+static inline void custom_create_attrs(struct odes *odes UNUSED, struct card_attr *ca UNUSED) { }
+
+#endif
 
 #endif
index 75b3b7dc2a73d940047589d30fe6c0c5cc569c4b..6579fc4d09aec556531726687a2ef1a3715272f0 100644 (file)
@@ -8,6 +8,7 @@
 #define _SHERLOCK_INDEX_H
 
 #include "lib/fastbuf.h"
+#include SHERLOCK_CUSTOM
 #include "charset/unistream.h"
 
 /* Words */
@@ -28,9 +29,7 @@ struct index_params {
 struct card_attr {
   u32 card;                            /* Reference to card description (either oid or filepos) */
   u32 site_id;
-#define INT_ATTR(t,i,o,k,g,p) t i;
-  CUSTOM_ATTRS                         /* Include all custom attributes */
-#undef INT_ATTR
+  CUSTOM_CARD_ATTRS                    /* Include all custom attributes */
   byte weight;
   byte flags;
   byte age;                            /* Document age in pseudo-logarithmic units wrt. reference time */