Lines Matching defs:cl
90 seq_get_num_entries_db(struct _citrus_lookup *cl)
92 return cl->cl_dbnum;
96 seq_next_db(struct _citrus_lookup *cl,
100 if (cl->cl_key) {
102 _region_init(key, cl->cl_key, cl->cl_keylen);
103 return _db_lookup_by_s(cl->cl_db, cl->cl_key, data,
104 &cl->cl_dblocator);
107 if (cl->cl_rewind) {
108 cl->cl_dbidx = 0;
110 cl->cl_rewind = 0;
111 if (cl->cl_dbidx >= cl->cl_dbnum)
114 return _db_get_entry(cl->cl_db, cl->cl_dbidx++, key, data);
118 seq_lookup_db(struct _citrus_lookup *cl, const char *key,
121 cl->cl_rewind = 0;
122 free(cl->cl_key);
123 cl->cl_key = strdup(key);
124 if (cl->cl_ignore_case)
125 _bcs_convert_to_lower(cl->cl_key);
126 cl->cl_keylen = strlen(cl->cl_key);
127 _db_locator_init(&cl->cl_dblocator);
128 return _db_lookup_by_s(cl->cl_db, cl->cl_key, data, &cl->cl_dblocator);
132 seq_close_db(struct _citrus_lookup *cl)
134 _db_close(cl->cl_db);
135 _unmap_file(&cl->cl_dbfile);
139 seq_open_db(struct _citrus_lookup *cl, const char *name)
150 ret = _db_open(&cl->cl_db, &r, _CITRUS_LOOKUP_MAGIC,
157 cl->cl_dbfile = r;
158 cl->cl_dbnum = _db_get_num_entries(cl->cl_db);
159 cl->cl_dbidx = 0;
160 cl->cl_rewind = 1;
161 cl->cl_lookup = &seq_lookup_db;
162 cl->cl_next = &seq_next_db;
163 cl->cl_num_entries = &seq_get_num_entries_db;
164 cl->cl_close = &seq_close_db;
171 seq_next_plain(struct _citrus_lookup *cl, struct _region *key,
177 if (cl->cl_rewind)
178 _memstream_bind(&cl->cl_plainms, &cl->cl_plainr);
179 cl->cl_rewind = 0;
182 p = _memstream_getln(&cl->cl_plainms, &len);
196 if (cl->cl_key && ((size_t)(q-p) != cl->cl_keylen ||
197 memcmp(p, cl->cl_key, (size_t)(q-p)) != 0))
211 seq_get_num_entries_plain(struct _citrus_lookup *cl)
216 while (seq_next_plain(cl, NULL, NULL) == 0)
223 seq_lookup_plain(struct _citrus_lookup *cl, const char *key,
229 cl->cl_rewind = 0;
230 free(cl->cl_key);
231 cl->cl_key = strdup(key);
232 if (cl->cl_ignore_case)
233 _bcs_convert_to_lower(cl->cl_key);
234 cl->cl_keylen = strlen(cl->cl_key);
235 _memstream_bind(&cl->cl_plainms, &cl->cl_plainr);
236 p = _memstream_matchline(&cl->cl_plainms, cl->cl_key, &len, 0);
246 seq_close_plain(struct _citrus_lookup *cl)
248 _unmap_file(&cl->cl_plainr);
252 seq_open_plain(struct _citrus_lookup *cl, const char *name)
257 ret = _map_file(&cl->cl_plainr, name);
261 cl->cl_rewind = 1;
262 cl->cl_next = &seq_next_plain;
263 cl->cl_lookup = &seq_lookup_plain;
264 cl->cl_num_entries = &seq_get_num_entries_plain;
265 cl->cl_close = &seq_close_plain;
275 struct _citrus_lookup *cl;
277 cl = malloc(sizeof(*cl));
278 if (cl == NULL)
281 cl->cl_key = NULL;
282 cl->cl_keylen = 0;
283 cl->cl_ignore_case = ignore_case;
284 ret = seq_open_db(cl, name);
286 ret = seq_open_plain(cl, name);
288 *rcl = cl;
290 free(cl);
296 _citrus_lookup_seq_rewind(struct _citrus_lookup *cl)
298 cl->cl_rewind = 1;
299 free(cl->cl_key);
300 cl->cl_key = NULL;
301 cl->cl_keylen = 0;
305 _citrus_lookup_seq_next(struct _citrus_lookup *cl,
308 return (*cl->cl_next)(cl, key, data);
312 _citrus_lookup_seq_lookup(struct _citrus_lookup *cl, const char *key,
315 return (*cl->cl_lookup)(cl, key, data);
319 _citrus_lookup_get_number_of_entries(struct _citrus_lookup *cl)
321 return (*cl->cl_num_entries)(cl);
325 _citrus_lookup_seq_close(struct _citrus_lookup *cl)
327 free(cl->cl_key);
328 (*cl->cl_close)(cl);
329 free(cl);
337 struct _citrus_lookup *cl;
340 ret = _citrus_lookup_seq_open(&cl, name, ignore_case);
344 ret = _citrus_lookup_seq_lookup(cl, key, &data);
346 _citrus_lookup_seq_close(cl);
353 _citrus_lookup_seq_close(cl);