Lines Matching refs:cl

87 seq_get_num_entries_db(struct _citrus_lookup *cl)
90 return (cl->cl_dbnum);
94 seq_next_db(struct _citrus_lookup *cl, struct _region *key,
98 if (cl->cl_key) {
100 _region_init(key, cl->cl_key, cl->cl_keylen);
101 return (_db_lookup_by_s(cl->cl_db, cl->cl_key, data,
102 &cl->cl_dblocator));
105 if (cl->cl_rewind) {
106 cl->cl_dbidx = 0;
108 cl->cl_rewind = 0;
109 if (cl->cl_dbidx >= cl->cl_dbnum)
112 return (_db_get_entry(cl->cl_db, cl->cl_dbidx++, key, data));
116 seq_lookup_db(struct _citrus_lookup *cl, const char *key, struct _region *data)
119 cl->cl_rewind = 0;
120 free(cl->cl_key);
121 cl->cl_key = strdup(key);
122 if (cl->cl_ignore_case)
123 _bcs_convert_to_lower(cl->cl_key);
124 cl->cl_keylen = strlen(cl->cl_key);
125 _db_locator_init(&cl->cl_dblocator);
126 return (_db_lookup_by_s(cl->cl_db, cl->cl_key, data,
127 &cl->cl_dblocator));
131 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)
249 _unmap_file(&cl->cl_plainr);
253 seq_open_plain(struct _citrus_lookup *cl, const char *name)
258 ret = _map_file(&cl->cl_plainr, name);
262 cl->cl_rewind = 1;
263 cl->cl_next = &seq_next_plain;
264 cl->cl_lookup = &seq_lookup_plain;
265 cl->cl_num_entries = &seq_get_num_entries_plain;
266 cl->cl_close = &seq_close_plain;
276 struct _citrus_lookup *cl;
278 cl = malloc(sizeof(*cl));
279 if (cl == NULL)
282 cl->cl_key = NULL;
283 cl->cl_keylen = 0;
284 cl->cl_ignore_case = ignore_case;
285 ret = seq_open_db(cl, name);
287 ret = seq_open_plain(cl, name);
289 *rcl = cl;
291 free(cl);
297 _citrus_lookup_seq_rewind(struct _citrus_lookup *cl)
300 cl->cl_rewind = 1;
301 free(cl->cl_key);
302 cl->cl_key = NULL;
303 cl->cl_keylen = 0;
307 _citrus_lookup_seq_next(struct _citrus_lookup *cl,
311 return ((*cl->cl_next)(cl, key, data));
315 _citrus_lookup_seq_lookup(struct _citrus_lookup *cl, const char *key,
319 return ((*cl->cl_lookup)(cl, key, data));
323 _citrus_lookup_get_number_of_entries(struct _citrus_lookup *cl)
326 return ((*cl->cl_num_entries)(cl));
330 _citrus_lookup_seq_close(struct _citrus_lookup *cl)
333 free(cl->cl_key);
334 (*cl->cl_close)(cl);
335 free(cl);
342 struct _citrus_lookup *cl;
346 ret = _citrus_lookup_seq_open(&cl, name, ignore_case);
350 ret = _citrus_lookup_seq_lookup(cl, key, &data);
352 _citrus_lookup_seq_close(cl);
359 _citrus_lookup_seq_close(cl);