• Home
  • Raw
  • Download

Lines Matching +full:char +full:- +full:regex

12  * regex.h/c were introduced to hold all dependencies on the regular
13 * expression back-end when we started supporting PCRE2. regex.h defines a
17 #include "regex.h"
39 char *src;
41 char *dst;
48 char *regex_str; /* regular expression string for diagnostics */
49 char *type_str; /* type string for diagnostic messages */
50 struct regex_data * regex; /* backend dependent regular expression data */ member
51 bool regex_compiled; /* bool to indicate if the regex is compiled */
52 pthread_mutex_t regex_lock; /* lock for lazy compilation of regex */
55 int stem_id; /* indicates which stem-compression item */
56 char hasMetaChars; /* regular expression has meta-chars */
57 char from_mmap; /* this spec is from an mmap of the data */
63 char *buf;
65 char from_mmap;
100 static inline mode_t string_to_mode(char *mode) in string_to_mode()
107 if (mode[0] != '-' || len != 2) in string_to_mode()
108 return -1; in string_to_mode()
122 case '-': in string_to_mode()
125 return -1; in string_to_mode()
136 if (data->nspec < data->alloc_specs) in grow_specs()
139 new_specs = data->nspec + 16; in grow_specs()
140 total_specs = data->nspec + new_specs; in grow_specs()
142 specs = realloc(data->spec_arr, total_specs * sizeof(*specs)); in grow_specs()
145 return -1; in grow_specs()
149 memset(&specs[data->nspec], 0, new_specs * sizeof(*specs)); in grow_specs()
151 data->spec_arr = specs; in grow_specs()
152 data->alloc_specs = total_specs; in grow_specs()
159 char *c; in spec_hasMetaChars()
161 char *end; in spec_hasMetaChars()
163 c = spec->regex_str; in spec_hasMetaChars()
164 len = strlen(spec->regex_str); in spec_hasMetaChars()
167 spec->hasMetaChars = 0; in spec_hasMetaChars()
168 spec->prefix_len = len; in spec_hasMetaChars()
184 spec->hasMetaChars = 1; in spec_hasMetaChars()
185 spec->prefix_len = c - spec->regex_str; in spec_hasMetaChars()
207 spec_copy = malloc(len * data->nspec); in sort_specs()
209 return -1; in sort_specs()
213 back = data->nspec - 1; in sort_specs()
214 for (i = 0; i < data->nspec; i++) { in sort_specs()
215 if (data->spec_arr[i].hasMetaChars) in sort_specs()
216 memcpy(&spec_copy[front++], &data->spec_arr[i], len); in sort_specs()
218 memcpy(&spec_copy[back--], &data->spec_arr[i], len); in sort_specs()
226 back = data->nspec - 1; in sort_specs()
235 back--; in sort_specs()
238 free(data->spec_arr); in sort_specs()
239 data->spec_arr = spec_copy; in sort_specs()
246 static inline int get_stem_from_spec(const char *const buf) in get_stem_from_spec()
248 const char *tmp = strchr(buf + 1, '/'); in get_stem_from_spec()
249 const char *ind; in get_stem_from_spec()
258 return tmp - buf; in get_stem_from_spec()
264 static inline int find_stem(struct saved_data *data, const char *buf, in find_stem()
269 for (i = 0; i < data->num_stems; i++) { in find_stem()
270 if (stem_len == data->stem_arr[i].len && in find_stem()
271 !strncmp(buf, data->stem_arr[i].buf, stem_len)) in find_stem()
275 return -1; in find_stem()
279 static inline int store_stem(struct saved_data *data, char *buf, int stem_len) in store_stem()
281 int num = data->num_stems; in store_stem()
283 if (data->alloc_stems == num) { in store_stem()
285 int alloc_stems = data->alloc_stems * 2 + 16; in store_stem()
286 tmp_arr = realloc(data->stem_arr, in store_stem()
289 return -1; in store_stem()
291 data->alloc_stems = alloc_stems; in store_stem()
292 data->stem_arr = tmp_arr; in store_stem()
294 data->stem_arr[num].len = stem_len; in store_stem()
295 data->stem_arr[num].buf = buf; in store_stem()
296 data->stem_arr[num].from_mmap = 0; in store_stem()
297 data->num_stems++; in store_stem()
303 * or existing stem, (or -1 if there is no possible stem - IE for a file in
304 * the root directory or a regex that is too complex for us). */
305 static inline int find_stem_from_spec(struct saved_data *data, const char *buf) in find_stem_from_spec()
309 char *stem; in find_stem_from_spec()
313 return -1; in find_stem_from_spec()
322 return -1; in find_stem_from_spec()
331 /* This will always check for buffer over-runs and either read the next entry
336 if (bytes > fp->next_len) in next_entry()
337 return -1; in next_entry()
340 memcpy(buf, fp->next_addr, bytes); in next_entry()
342 fp->next_addr = (char *)fp->next_addr + bytes; in next_entry()
343 fp->next_len -= bytes; in next_entry()
347 static inline int compile_regex(struct spec *spec, const char **errbuf) in compile_regex()
349 char *reg_buf, *anchored_regex, *cp; in compile_regex()
351 static char regex_error_format_buffer[256]; in compile_regex()
362 __atomic_load_n(&spec->regex_compiled, __ATOMIC_ACQUIRE); in compile_regex()
366 regex_compiled = spec->regex_compiled; in compile_regex()
372 __pthread_mutex_lock(&spec->regex_lock); in compile_regex()
373 /* Check if another thread compiled the regex while we waited in compile_regex()
377 __atomic_load_n(&spec->regex_compiled, __ATOMIC_ACQUIRE); in compile_regex()
381 regex_compiled = spec->regex_compiled; in compile_regex()
384 __pthread_mutex_unlock(&spec->regex_lock); in compile_regex()
388 reg_buf = spec->regex_str; in compile_regex()
395 __pthread_mutex_unlock(&spec->regex_lock); in compile_regex()
396 return -1; in compile_regex()
407 rc = regex_prepare_data(&spec->regex, anchored_regex, &error_data); in compile_regex()
416 __pthread_mutex_unlock(&spec->regex_lock); in compile_regex()
417 return -1; in compile_regex()
422 __atomic_store_n(&spec->regex_compiled, true, __ATOMIC_RELEASE); in compile_regex()
425 spec->regex_compiled = true; in compile_regex()
428 __pthread_mutex_unlock(&spec->regex_lock); in compile_regex()
435 const char *path, const char *prefix, in process_line()
436 char *line_buf, unsigned lineno) in process_line()
439 char *regex = NULL, *type = NULL, *context = NULL; in process_line() local
440 struct saved_data *data = (struct saved_data *)rec->data; in process_line()
442 unsigned int nspec = data->nspec; in process_line()
443 const char *errbuf = NULL; in process_line()
445 items = read_spec_entries(line_buf, &errbuf, 3, &regex, &type, &context); in process_line()
456 return -1; in process_line()
467 free(regex); in process_line()
469 return -1; in process_line()
476 len = get_stem_from_spec(regex); in process_line()
477 if (len && prefix && strncmp(prefix, regex, len)) { in process_line()
478 /* Stem of regex does not match requested prefix, discard. */ in process_line()
479 free(regex); in process_line()
489 spec_arr = data->spec_arr; in process_line()
492 spec_arr[nspec].stem_id = find_stem_from_spec(data, regex); in process_line()
493 spec_arr[nspec].regex_str = regex; in process_line()
504 * bump data->nspecs to cause closef() to cover it in its free in process_line()
507 data->nspec++; in process_line()
509 if (rec->validating in process_line()
512 "%s: line %u has invalid regex %s: %s\n", in process_line()
513 path, lineno, regex, errbuf); in process_line()
515 return -1; in process_line()
521 if (mode == (mode_t)-1) { in process_line()
526 return -1; in process_line()
535 if (strcmp(context, "<<none>>") && rec->validating) in process_line()