]> mj.ucw.cz Git - libucw.git/blob - lib/custom.h
HASH_WANT_FIND_NEXT fixed and its declaration changed
[libucw.git] / lib / custom.h
1 /*
2  *      Sherlock: Custom Parts of Configuration
3  *
4  *      (c) 2001--2002 Martin Mares <mj@ucw.cz>
5  */
6
7 /* Word types */
8
9 enum word_type {
10   WT_RESERVED,                          /* Reserved word type */
11   WT_TEXT,                              /* Ordinary text */
12   WT_EMPH,                              /* Emphasized text */
13   WT_SMALL,                             /* Small font */
14   WT_TITLE,                             /* Document title */
15   WT_SMALL_HEADING,                     /* Heading */
16   WT_BIG_HEADING,                       /* Larger heading */
17   WT_KEYWORD,                           /* Explicitly marked keyword */
18   WT_META,                              /* Various meta-information */
19   WT_ALT,                               /* Alternate texts for graphical elements */
20   WT_URL1,                              /* Word extracted from document URL (low and high weight) */
21   WT_URL2,
22   WT_FILE,                              /* Part of file name */
23   WT_LINK,                              /* Link text */
24   WT_CAT_TITLE,                         /* Catalog title */
25   WT_CAT_DESC,                          /* Catalog description */
26   WT_MAX
27 };
28
29 /* Descriptive names used for user output */
30 #define WORD_TYPE_USER_NAMES                                                    \
31    "reserved", "text", "emph", "small", "title", "hdr1", "hdr2", "keywd",       \
32    "meta", "alt", "urlword1", "urlword2", "nameword", "link", "ctitle", "cdesc"
33
34 /* Keywords for word type names */
35 #define WORD_TYPE_NAMES                         \
36         T(WORD, ~((1 << WT_FILE) | (1 << WT_LINK)))     \
37         T(TEXT, 1 << WT_TEXT)                   \
38         T(EMPH, 1 << WT_EMPH)                   \
39         T(SMALL, 1 << WT_SMALL)                 \
40         T(TITLE, 1 << WT_TITLE)                 \
41         T(HDR, (1 << WT_SMALL_HEADING) | (1 << WT_BIG_HEADING))  \
42         T(HDR1, 1 << WT_SMALL_HEADING)          \
43         T(HDR2, 1 << WT_BIG_HEADING)            \
44         T(KEYWD, 1 << WT_KEYWORD)               \
45         T(META, 1 << WT_META)                   \
46         T(ALT, 1 << WT_ALT)                     \
47         T(URLWORD, (1 << WT_URL1) | (1 << WT_URL2))     \
48         T(FILE, 1 << WT_FILE)                   \
49         T(LINK, 1 << WT_LINK)                   \
50         T(CTITLE, 1 << WT_CAT_TITLE)            \
51         T(CDESC, 1 << WT_CAT_DESC)
52
53 /* These types are not shown in document contexts */
54 #define WORD_TYPES_HIDDEN ((1 << WT_URL1) | (1 << WT_URL2) | (1 << WT_FILE))
55
56 /* These types are separated out when printing contexts */
57 #define WORD_TYPES_META (WORD_TYPES_HIDDEN | (1 << WT_TITLE) | (1 << WT_KEYWORD) | \
58         (1 << WT_META) | (1 << WT_CAT_TITLE) | (1 << WT_CAT_DESC))
59
60 /* These types are always matched without accents if accent mode is set to "auto" */
61 #define WORD_TYPES_NO_AUTO_ACCENT ((1 << WT_URL1) | (1 << WT_URL2) | (1 << WT_FILE) | (1 << WT_LINK))
62
63 /* String types */
64
65 enum string_type {
66   ST_RESERVED,                          /* Reserved string type */
67   ST_URL,                               /* URL of the document */
68   ST_HOST,                              /* Host name */
69   ST_DOMAIN,                            /* Domain name */
70   ST_REF,                               /* URL reference */
71   ST_MAX
72 };
73
74 #define STRING_TYPE_USER_NAMES                                                  \
75    "URL", "host", "domain", "ref", "type4", "type5", "type6", "type7",  \
76    "type8", "type9", "type10", "type11", "type12", "type13", "type14", "type15"
77
78 #define STRING_TYPE_NAMES                       \
79         T(URL, 1 << ST_URL)                     \
80         T(HOST, 1 << ST_HOST)                   \
81         T(DOMAIN, 1 << ST_DOMAIN)               \
82         T(REF, 1 << ST_REF)
83
84 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF))
85 /* These must be indexed in lowercase form */
86 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
87
88 /*
89  *  Definitions of custom attributes:
90  *
91  *  First of all, you need to define your own card_attr fields which will
92  *  contain your attributes: CUSTOM_CARD_ATTRS lists them.
93  *  Please order the attributes by decreasing size to get optimum padding.
94  *
95  *  Then define custom_create_attrs() which will get the object description
96  *  and set your card_attr fields accordingly.
97  *
98  *  Finally, you have to define CUSTOM_ATTRS with matching rules:
99  *
100  *  INT_ATTR(id, keyword, get_func, parse_func) -- unsigned integer attribute
101  *
102  *  id          C identifier of the attribute
103  *  keywd       search server keyword for the attribute
104  *  type get_func(struct card_attr *ca, byte *attr)
105  *              get attribute value from the card_attr
106  *  byte *parse_func(u32 *dest, byte *value, uns intval)
107  *              parse value in query (returns error message or NULL)
108  *              for KEYWD = "string", it gets value="string", intval=0
109  *              for KEYWD = num, it gets value=NULL, intval=num.
110  *
111  *  SMALL_SET_ATTR(id, keyword, get_func, parse_func)
112  *    -- integers 0..31 with set matching
113  *
114  *  A good place for definitions of the functions is lib/custom.c.
115  */
116
117 struct card_attr;
118 struct odes;
119
120 #ifdef CONFIG_IMAGES
121
122 /*
123  *  We store several image properties to card_attr->image_flags and
124  *  match them as custom attributes. The image_flags byte contains:
125  *
126  *  bits 0--1   image format (0: not an image, 1: JPEG, 2: PNG, 3: GIF)
127  *  bits 2--3   image size (0: <=100x100, 1: <=320x200, 2: <=640x480, 3: other)
128  *  bits 4--5   image colors (0: grayscale, 1: <=16, 2: <=256, 3: >256)
129  */
130
131 #define CUSTOM_CARD_ATTRS \
132         byte image_flags;
133
134 #define CUSTOM_ATTRS \
135         SMALL_SET_ATTR(ifmt, IMGTYPE, custom_it_get, custom_it_parse)           \
136         SMALL_SET_ATTR(isize, IMGSIZE, custom_is_get, custom_is_parse)          \
137         SMALL_SET_ATTR(icolors, IMGCOLORS, custom_ic_get, custom_ic_parse)
138
139 void custom_create_attrs(struct odes *odes, struct card_attr *ca);
140
141 /* These must be macros instead of inline functions, struct card_attr is not fully defined yet */
142 #define custom_it_get(ca) ((ca)->image_flags & 3)
143 #define custom_is_get(ca) (((ca)->image_flags >> 2) & 3)
144 #define custom_ic_get(ca) (((ca)->image_flags >> 4) & 3)
145
146 byte *custom_it_parse(u32 *dest, byte *value, uns intval);
147 byte *custom_is_parse(u32 *dest, byte *value, uns intval);
148 byte *custom_ic_parse(u32 *dest, byte *value, uns intval);
149
150 #else
151
152 /* No custom attributes defined */
153
154 #define CUSTOM_CARD_ATTRS
155 #define CUSTOM_ATTRS
156 static inline void custom_create_attrs(struct odes *odes UNUSED, struct card_attr *ca UNUSED) { }
157
158 #endif