Lines Matching defs:fg

47 static int	fastcmp(const fastmatch_t *fg, const void *data,
55 if (fg->pattern) \
56 xfree(fg->pattern); \
57 if (fg->wpattern) \
58 xfree(fg->wpattern); \
59 if (fg->qsBc_table) \
60 hashtable_free(fg->qsBc_table); \
61 fg = NULL; \
84 * it in fg->pattern. Sets fg->len to the byte length of the
91 siz = wcstombs(NULL, fg->wpattern, 0); \
94 fg->len = siz; \
95 fg->pattern = xmalloc(siz + 1); \
96 if (fg->pattern == NULL) \
98 wcstombs(fg->pattern, fg->wpattern, siz); \
99 fg->pattern[siz] = '\0'; \
103 ((!fg->reversed \
104 ? ((type == STR_WIDE) ? ((j + fg->wlen) > len) \
105 : ((j + fg->len) > len)) \
130 if (!fg->hasdot) \
132 if (u != 0 && (unsigned)mismatch == fg->wlen - 1 - shift) \
134 v = fg->wlen - 1 - mismatch; \
135 r = hashtable_get(fg->qsBc_table, \
136 &str_wide[!fg->reversed ? (size_t)j + fg->wlen \
138 gs = fg->bmGs[mismatch]; \
140 bc = (r == HASH_OK) ? bc : fg->defBc; \
147 if (!fg->hasdot) \
149 if (u != 0 && (unsigned)mismatch == fg->len - 1 - shift) \
151 v = fg->len - 1 - mismatch; \
152 gs = fg->sbmGs[mismatch]; \
154 bc = fg->qsBc[((const unsigned char *)str_byte) \
155 [!fg->reversed ? (size_t)j + fg->len \
162 if (fg->hasdot) \
170 u = MIN((type == STR_WIDE ? fg->wlen : fg->len) - shift, v); \
179 j = !fg->reversed ? j + shift : j - shift; \
203 if (fg->reversed) \
214 fg->qsBc[i] = fg->len - hasdot; \
215 for (unsigned int i = hasdot + 1; i < fg->len; i++) \
217 fg->qsBc[(unsigned char)fg->pattern[i]] = fg->len - i; \
218 DPRINT(("BC shift for char %c is %zu\n", fg->pattern[i], \
219 fg->len - i)); \
220 if (fg->icase) \
222 char c = islower((unsigned char)fg->pattern[i]) ? \
223 toupper((unsigned char)fg->pattern[i]) : \
224 tolower((unsigned char)fg->pattern[i]); \
225 fg->qsBc[(unsigned char)c] = fg->len - i; \
226 DPRINT(("BC shift for char %c is %zu\n", c, fg->len - i)); \
232 fg->qsBc[i] = firstdot + 1; \
235 fg->qsBc[(unsigned char)fg->pattern[i]] = i + 1; \
236 DPRINT(("Reverse BC shift for char %c is %d\n", fg->pattern[i], \
238 if (fg->icase) \
240 char c = islower((unsigned char)fg->pattern[i]) ? \
241 toupper((unsigned char)fg->pattern[i]) : \
242 tolower((unsigned char)fg->pattern[i]); \
243 fg->qsBc[(unsigned char)c] = i + 1; \
258 if (fg->reversed) \
269 fg->defBc = fg->wlen - whasdot; \
272 fg->qsBc_table = hashtable_init(fg->wlen * (fg->icase ? 8 : 4), \
274 if (!fg->qsBc_table) \
276 for (unsigned int i = whasdot + 1; i < fg->wlen; i++) \
278 int k = fg->wlen - i; \
281 r = hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \
284 DPRINT(("BC shift for wide char " CHF " is %d\n", fg->wpattern[i],\
286 if (fg->icase) \
288 tre_char_t wc = iswlower(fg->wpattern[i]) ? \
289 towupper(fg->wpattern[i]) : towlower(fg->wpattern[i]); \
290 r = hashtable_put(fg->qsBc_table, &wc, &k); \
299 fg->defBc = (size_t)wfirstdot; \
302 fg->qsBc_table = hashtable_init(fg->wlen * (fg->icase ? 8 : 4), \
304 if (!fg->qsBc_table) \
311 r = hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \
315 fg->wpattern[i], k)); \
316 if (fg->icase) \
318 tre_char_t wc = iswlower(fg->wpattern[i]) ? \
319 towupper(fg->wpattern[i]) : towlower(fg->wpattern[i]); \
320 r = hashtable_put(fg->qsBc_table, &wc, &k); \
341 if (!fg->hasdot) \
343 fg->sbmGs = xmalloc(fg->len * sizeof(int)); \
344 if (!fg->sbmGs) \
346 if (fg->len == 1) \
347 fg->sbmGs[0] = 1; \
349 _FILL_BMGS(fg->sbmGs, fg->pattern, fg->len, false); \
350 DPRINT_BMGS(fg->len, "GS shift for pos %d is %d\n", fg->sbmGs); \
357 if (!fg->hasdot) \
359 fg->bmGs = xmalloc(fg->wlen * sizeof(int)); \
360 if (!fg->bmGs) \
362 if (fg->wlen == 1) \
363 fg->bmGs[0] = 1; \
365 _FILL_BMGS(fg->bmGs, fg->wpattern, fg->wlen, true); \
366 DPRINT_BMGS(fg->wlen, "GS shift (wide) for pos %d is %d\n", \
367 fg->bmGs); \
377 if (fg->icase) \
392 if (fg->icase) \
464 memset(fg, 0, sizeof(*fg)); \
465 fg->icase = (cflags & REG_ICASE); \
466 fg->word = (cflags & REG_WORD); \
467 fg->newline = (cflags & REG_NEWLINE); \
468 fg->nosub = (cflags & REG_NOSUB); \
471 if (fg->icase && (TRE_MB_CUR_MAX > 1) && n > 0) \
486 fg->eol = true; \
491 fg->matchall = true; \
492 fg->pattern = xmalloc(sizeof(char)); \
493 if (!fg->pattern) \
495 fg->pattern[0] = '\0'; \
496 fg->wpattern = xmalloc(sizeof(tre_char_t)); \
497 if (!fg->wpattern) \
499 fg->wpattern[0] = TRE_CHAR('\0'); \
508 tre_compile_literal(fastmatch_t *fg, const tre_char_t *pat, size_t n,
519 if (fg->word && (TRE_MB_CUR_MAX > 1))
523 SAVE_PATTERN(pat, n, fg->wpattern, fg->wlen);
526 SAVE_PATTERN(pat, n, fg->pattern, fg->len);
530 "newline %c\n", fg->pattern, fg->len, fg->icase ? 'y' : 'n',
531 fg->word ? 'y' : 'n', fg->newline ? 'y' : 'n'));
547 tre_compile_fast(fastmatch_t *fg, const tre_char_t *pat, size_t n,
561 fg->bol = true;
576 fg->word = true;
580 if (fg->word && (TRE_MB_CUR_MAX > 1))
656 fg->eol = true;
697 fg->hasdot = wfirstdot > -1;
705 SAVE_PATTERN(tmp, pos, fg->wpattern, fg->wlen);
706 fg->wescmap = _escmap;
714 if (fg->hasdot || (fg->wescmap != NULL))
716 if (fg->wescmap != NULL)
718 fg->escmap = xmalloc(fg->len * sizeof(bool));
719 if (!fg->escmap)
721 tre_free_fast(fg);
727 for (unsigned int i = 0; i < fg->len; i++)
728 if (fg->pattern[i] == '\\')
730 else if (fg->pattern[i] == '.' && escaped)
732 fg->escmap[i] = true;
735 else if (fg->pattern[i] == '.' && !escaped)
745 SAVE_PATTERN(tmp, pos, fg->pattern, fg->len);
746 fg->escmap = _escmap;
752 "icase: %c, word: %c, newline %c\n", fg->pattern, fg->len,
753 fg->bol ? 'y' : 'n', fg->eol ? 'y' : 'n',
754 fg->icase ? 'y' : 'n', fg->word ? 'y' : 'n',
755 fg->newline ? 'y' : 'n'));
758 if ((wfirstdot > -1) && (fg->wlen - whasdot + 1 < (size_t)wfirstdot) &&
759 fg->nosub)
761 fg->reversed = true;
778 j = !fg->reversed ? j + shift : j - shift; \
791 ((j + fg->wlen == len) || !(tre_isalnum(str_wide[j + fg->wlen]) || \
792 (str_wide[j + fg->wlen] == TRE_CHAR('_')))) : \
793 ((j + fg->len == len) || !(tre_isalnum(str_byte[j + fg->len]) || \
794 (str_byte[j + fg->len] == '_'))))
825 ? ((j + fg->wlen == len) || \
826 (str_wide[j + fg->wlen] == TRE_CHAR('\n'))) \
827 : ((j + fg->len == len) || (str_byte[j + fg->wlen] == '\n')))
842 tre_match_fast(const fastmatch_t *fg, const void *data, size_t len,
866 if (fg->matchall)
868 if (!fg->nosub && nmatch >= 1)
873 if (fg->bol && fg->eol)
883 if (len < fg->wlen)
885 shift = fg->wlen;
888 if (len < fg->len)
890 shift = fg->len;
897 if (fg->bol && (eflags & REG_NOTBOL))
904 if (fg->eol && (eflags & REG_NOTEOL))
907 if (fg->reversed)
908 j = len - (type == STR_WIDE ? fg->wlen : fg->len);
912 if ((fg->bol || fg->eol) && !fg->newline && !(eflags & REG_NOTBOL) &&
916 if (!((fg->bol && fg->eol) &&
917 (type == STR_WIDE ? (len != fg->wlen) : (len != fg->len))))
920 j = fg->eol ? len - (type == STR_WIDE ? fg->wlen : fg->len) : 0;
922 mismatch = fastcmp(fg, startptr, type);
925 if (fg->word && !IS_ON_WORD_BOUNDARY)
927 if (!fg->nosub && nmatch >= 1)
930 pmatch[0].rm_eo = j + (type == STR_WIDE ? fg->wlen : fg->len);
942 mismatch = fastcmp(fg, startptr, type);
945 if (fg->word)
947 if (fg->bol)
949 if (fg->eol)
951 if (!fg->nosub && nmatch >= 1)
954 pmatch[0].rm_eo = j + ((type == STR_WIDE) ? fg->wlen : fg->len);
971 tre_free_fast(fastmatch_t *fg)
975 fg->pattern));
978 hashtable_free(fg->qsBc_table);
979 if (!fg->hasdot)
980 xfree(fg->bmGs);
981 if (fg->wescmap)
982 xfree(fg->wescmap);
983 xfree(fg->wpattern);
985 if (!fg->hasdot)
986 xfree(fg->sbmGs);
987 if (fg->escmap)
988 xfree(fg->escmap);
989 xfree(fg->pattern);
998 fastcmp(const fastmatch_t *fg, const void *data, tre_str_type_t type)
1001 const char *pat_byte = fg->pattern;
1003 const tre_char_t *pat_wide = fg->wpattern;
1004 const bool *escmap = (type == STR_WIDE) ? fg->wescmap : fg->escmap;
1005 size_t len = (type == STR_WIDE) ? fg->wlen : fg->len;
1015 if (fg->hasdot && pat_wide[i] == TRE_CHAR('.') &&
1017 (!fg->newline || (str_wide[i] != TRE_CHAR('\n'))))
1021 if (fg->icase ? (towlower(pat_wide[i]) == towlower(str_wide[i]))
1027 if (fg->hasdot && pat_byte[i] == '.' &&
1029 (!fg->newline || (str_byte[i] != '\n')))
1033 if (fg->icase ? (tolower((unsigned char)pat_byte[i]) == tolower((unsigned char)str_byte[i]))