]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
Cleanup of word type name macros.
[libucw.git] / lib / index.h
1 /*
2  *      Sherlock Gatherer: Data structures used in indices
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 /* Words */
8
9 #define MAX_WORD_LEN            64
10
11 /* Word types */
12
13 enum word_type {
14   WT_RESERVED,                          /* Reserved word type */
15   WT_TEXT,                              /* Ordinary text */
16   WT_EMPH,                              /* Emphasized text */
17   WT_SMALL,                             /* Small font */
18   WT_TITLE,                             /* Document title */
19   WT_SMALL_HEADING,                     /* Heading */
20   WT_BIG_HEADING,                       /* Larger heading */
21   WT_KEYWORD,                           /* Explicitly marked keyword */
22   WT_META,                              /* Various meta-information */
23   WT_ALT,                               /* Alternate texts for graphical elements */
24   WT_MAX
25 };
26
27 /* Descriptive names used for user output */
28 #define WORD_TYPE_USER_NAMES                                                    \
29    "reserved", "text", "emph", "small", "title", "hdr1", "hdr2", "keywd",       \
30    "meta", "alt", "type10", "type11", "type12", "type13", "type14", "type15"
31
32 /* Keywords for word type names */
33 #define WORD_TYPE_NAMES                         \
34         T(WORD, ~0)                             \
35         T(TEXT, 1 << WT_TEXT)                   \
36         T(EMPH, 1 << WT_EMPH)                   \
37         T(SMALL, 1 << WT_SMALL)                 \
38         T(TITLE, 1 << WT_TITLE)                 \
39         T(HDR, (1 << WT_SMALL_HEADING) | (1 << WT_BIG_HEADING))  \
40         T(HDR1, 1 << WT_SMALL_HEADING)          \
41         T(HDR2, 1 << WT_BIG_HEADING)            \
42         T(KEYWD, 1 << WT_KEYWORD)               \
43         T(META, 1 << WT_META)                   \
44         T(ALT, 1 << WT_ALT)
45
46 /* String types */
47
48 enum string_type {
49   ST_RESERVED,                          /* Reserved string type */
50   ST_URL,                               /* URL of the document */
51   ST_HOST,                              /* Host name */
52   ST_DOMAIN,                            /* Domain name */
53   ST_REF,                               /* URL reference */
54   ST_BACKREF,                           /* Back-reference (frame or redirect source) */
55   ST_MAX
56 };
57
58 #define STRING_TYPE_USER_NAMES                                                  \
59    "URL", "host", "domain", "ref", "backref", "type5", "type6", "type7",        \
60    "type8", "type9", "type10", "type11", "type12", "type13", "type14", "type15"
61
62 #define STRING_TYPE_NAMES                       \
63         T(URL, 1 << ST_URL)                     \
64         T(HOST, 1 << ST_HOST)                   \
65         T(DOMAIN, 1 << ST_DOMAIN)               \
66         T(REF, 1 << ST_REF)                     \
67         T(BACKREF, 1 << ST_BACKREF)
68
69 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF))
70 /* These must be indexed in lowercase form */
71 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
72
73 /* Index card attributes */
74
75 struct card_attr {
76   u32 card;                             /* Reference to card description (either oid or filepos) */
77   u32 site_id;
78   byte weight;
79   byte flags;
80   byte rfu[2];
81 };
82
83 enum card_flag {
84   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
85   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
86   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
87   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
88 };
89
90 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
91
92 /* String fingerprints */
93
94 struct fingerprint {
95   byte hash[12];
96 };
97
98 void fingerprint(byte *string, struct fingerprint *fp);
99
100 static inline u32
101 fp_hash(struct fingerprint *fp)
102 {
103   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
104 }
105
106 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
107
108 #define GET_TAGGED_CHAR(p,u) do {                               \
109   u = *p;                                                       \
110   if (u >= 0xc0)                                                \
111     GET_UTF8(p,u);                                              \
112   else if (u >= 0x80)                                           \
113     {                                                           \
114       p++;                                                      \
115       if (u >= 0xb0)                                            \
116         {                                                       \
117           if (u != 0xb0)                                        \
118             ASSERT(0);                                          \
119           u += 0x80020000;                                      \
120         }                                                       \
121       else if (u >= 0xa0)                                       \
122         {                                                       \
123           ASSERT(*p >= 0x80 && *p <= 0xbf);                     \
124           u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);   \
125         }                                                       \
126       else                                                      \
127         u += 0x80000000;                                        \
128     }                                                           \
129   else                                                          \
130     p++;                                                        \
131 } while (0)