Lines Matching defs:fg

48 static int	fastcmp(const fastmatch_t *fg, const void *data,
56 if (fg->pattern) \
57 free(fg->pattern); \
58 if (fg->wpattern) \
59 free(fg->wpattern); \
60 if (fg->qsBc_table) \
61 hashtable_free(fg->qsBc_table); \
62 fg = NULL; \
85 * it in fg->pattern. Sets fg->len to the byte length of the
92 siz = wcstombs(NULL, fg->wpattern, 0); \
95 fg->len = siz; \
96 fg->pattern = malloc(siz + 1); \
97 if (fg->pattern == NULL) \
99 wcstombs(fg->pattern, fg->wpattern, siz); \
100 fg->pattern[siz] = '\0'; \
116 ((!fg->reversed \
117 ? ((type == STR_WIDE) ? ((j + fg->wlen) > len) \
118 : ((j + fg->len) > len)) \
143 if (!fg->hasdot) \
145 if (u != 0 && (unsigned)mismatch == fg->wlen - 1 - shift) \
147 v = fg->wlen - 1 - mismatch; \
148 r = hashtable_get(fg->qsBc_table, \
149 &str_wide[!fg->reversed ? (size_t)j + fg->wlen \
151 gs = fg->bmGs[mismatch]; \
153 bc = (r == HASH_OK) ? bc : fg->defBc; \
160 if (!fg->hasdot) \
162 if (u != 0 && (unsigned)mismatch == fg->len - 1 - shift) \
164 v = fg->len - 1 - mismatch; \
165 gs = fg->sbmGs[mismatch]; \
167 bc = fg->qsBc[((const unsigned char *)str_byte) \
168 [!fg->reversed ? (size_t)j + fg->len \
175 if (fg->hasdot) \
183 u = MIN((type == STR_WIDE ? fg->wlen : fg->len) - shift, v); \
192 j = !fg->reversed ? j + shift : j - shift; \
216 if (fg->reversed) \
227 fg->qsBc[i] = fg->len - hasdot; \
228 for (unsigned int i = hasdot + 1; i < fg->len; i++) \
230 fg->qsBc[(unsigned char)fg->pattern[i]] = fg->len - i; \
231 DPRINT(("BC shift for char %c is %zu\n", fg->pattern[i], \
232 fg->len - i)); \
233 if (fg->icase) \
235 char c = islower((unsigned char)fg->pattern[i]) ? \
236 toupper((unsigned char)fg->pattern[i]) : \
237 tolower((unsigned char)fg->pattern[i]); \
238 fg->qsBc[(unsigned char)c] = fg->len - i; \
239 DPRINT(("BC shift for char %c is %zu\n", c, fg->len - i)); \
245 fg->qsBc[i] = firstdot + 1; \
248 fg->qsBc[(unsigned char)fg->pattern[i]] = i + 1; \
249 DPRINT(("Reverse BC shift for char %c is %d\n", fg->pattern[i], \
251 if (fg->icase) \
253 char c = islower((unsigned char)fg->pattern[i]) ? \
254 toupper((unsigned char)fg->pattern[i]) : \
255 tolower((unsigned char)fg->pattern[i]); \
256 fg->qsBc[(unsigned char)c] = i + 1; \
271 if (fg->reversed) \
282 fg->defBc = fg->wlen - whasdot; \
285 fg->qsBc_table = hashtable_init(fg->wlen * (fg->icase ? 8 : 4), \
287 if (!fg->qsBc_table) \
289 for (unsigned int i = whasdot + 1; i < fg->wlen; i++) \
291 int k = fg->wlen - i; \
294 r = hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \
297 DPRINT(("BC shift for wide char " CHF " is %d\n", fg->wpattern[i],\
299 if (fg->icase) \
301 tre_char_t wc = iswlower(fg->wpattern[i]) ? \
302 towupper(fg->wpattern[i]) : towlower(fg->wpattern[i]); \
303 r = hashtable_put(fg->qsBc_table, &wc, &k); \
312 fg->defBc = (size_t)wfirstdot; \
315 fg->qsBc_table = hashtable_init(fg->wlen * (fg->icase ? 8 : 4), \
317 if (!fg->qsBc_table) \
324 r = hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \
328 fg->wpattern[i], k)); \
329 if (fg->icase) \
331 tre_char_t wc = iswlower(fg->wpattern[i]) ? \
332 towupper(fg->wpattern[i]) : towlower(fg->wpattern[i]); \
333 r = hashtable_put(fg->qsBc_table, &wc, &k); \
354 if (fg->len > 0 && !fg->hasdot) \
356 fg->sbmGs = malloc(fg->len * sizeof(*fg->sbmGs)); \
357 if (!fg->sbmGs) \
359 if (fg->len == 1) \
360 fg->sbmGs[0] = 1; \
362 _FILL_BMGS(fg->sbmGs, fg->pattern, fg->len, false); \
363 DPRINT_BMGS(fg->len, "GS shift for pos %d is %d\n", fg->sbmGs); \
370 if (fg->wlen > 0 && !fg->hasdot) \
372 fg->bmGs = malloc(fg->wlen * sizeof(*fg->bmGs)); \
373 if (!fg->bmGs) \
375 if (fg->wlen == 1) \
376 fg->bmGs[0] = 1; \
378 _FILL_BMGS(fg->bmGs, fg->wpattern, fg->wlen, true); \
379 DPRINT_BMGS(fg->wlen, "GS shift (wide) for pos %d is %d\n", \
380 fg->bmGs); \
390 if (fg->icase) \
405 if (fg->icase) \
477 memset(fg, 0, sizeof(*fg)); \
478 fg->icase = (cflags & REG_ICASE); \
479 fg->word = (cflags & REG_WORD); \
480 fg->newline = (cflags & REG_NEWLINE); \
481 fg->nosub = (cflags & REG_NOSUB); \
484 if (fg->icase && (TRE_MB_CUR_MAX > 1) && n > 0) \
499 fg->eol = true; \
504 fg->matchall = true; \
505 fg->pattern = malloc(sizeof(char)); \
506 if (!fg->pattern) \
508 fg->pattern[0] = '\0'; \
509 fg->wpattern = malloc(sizeof(tre_char_t)); \
510 if (!fg->wpattern) \
512 fg->wpattern[0] = TRE_CHAR('\0'); \
521 tre_compile_literal(fastmatch_t *fg, const tre_char_t *pat, size_t n,
532 if (fg->word && (TRE_MB_CUR_MAX > 1))
536 SAVE_PATTERN(pat, n, fg->wpattern, fg->wlen);
539 SAVE_PATTERN(pat, n, fg->pattern, fg->len);
543 "newline %c\n", fg->pattern, fg->len, fg->icase ? 'y' : 'n',
544 fg->word ? 'y' : 'n', fg->newline ? 'y' : 'n'));
560 tre_compile_fast(fastmatch_t *fg, const tre_char_t *pat, size_t n,
574 fg->bol = true;
589 fg->word = true;
593 if (fg->word && (TRE_MB_CUR_MAX > 1))
669 fg->eol = true;
710 fg->hasdot = wfirstdot > -1;
718 SAVE_PATTERN(tmp, pos, fg->wpattern, fg->wlen);
719 fg->wescmap = _escmap;
727 if (fg->hasdot || (fg->wescmap != NULL))
729 if (fg->wescmap != NULL)
731 fg->escmap = calloc(fg->len, sizeof(bool));
732 if (fg->escmap == NULL)
734 tre_free_fast(fg);
744 * Make a copy here of the original pattern, because fg->pattern has
746 * This is necessary if we wish to later treat fg->escmap as an actual,
747 * functional replacement of fg->wescmap.
757 else if (_checkpat[i] == '.' && fg->escmap != NULL && escaped)
759 fg->escmap[i - escofs] = true;
773 SAVE_PATTERN(tmp, pos, fg->pattern, fg->len);
774 fg->escmap = _escmap;
780 "icase: %c, word: %c, newline %c\n", fg->pattern, fg->len,
781 fg->bol ? 'y' : 'n', fg->eol ? 'y' : 'n',
782 fg->icase ? 'y' : 'n', fg->word ? 'y' : 'n',
783 fg->newline ? 'y' : 'n'));
786 if ((wfirstdot > -1) && (fg->wlen - whasdot + 1 < (size_t)wfirstdot) &&
787 fg->nosub)
789 fg->reversed = true;
806 j = !fg->reversed ? j + shift : j - shift; \
819 ((j + fg->wlen == len) || !(tre_isalnum(str_wide[j + fg->wlen]) || \
820 (str_wide[j + fg->wlen] == TRE_CHAR('_')))) : \
821 ((j + fg->len == len) || !(tre_isalnum(str_byte[j + fg->len]) || \
822 (str_byte[j + fg->len] == '_'))))
853 ? ((j + fg->wlen == len) || \
854 (str_wide[j + fg->wlen] == TRE_CHAR('\n'))) \
855 : ((j + fg->len == len) || (str_byte[j + fg->wlen] == '\n')))
870 tre_match_fast(const fastmatch_t *fg, const void *data, size_t len,
894 if (fg->matchall)
896 if (!fg->nosub && nmatch >= 1)
901 if (fg->bol && fg->eol)
911 if (len < fg->wlen)
913 shift = fg->wlen;
916 if (len < fg->len)
918 shift = fg->len;
925 if (fg->bol && (eflags & REG_NOTBOL))
932 if (fg->eol && (eflags & REG_NOTEOL))
935 if (fg->reversed)
936 j = len - (type == STR_WIDE ? fg->wlen : fg->len);
940 if ((fg->bol || fg->eol) && !fg->newline && !(eflags & REG_NOTBOL) &&
944 if (!((fg->bol && fg->eol) &&
945 (type == STR_WIDE ? (len != fg->wlen) : (len != fg->len))))
948 j = fg->eol ? len - (type == STR_WIDE ? fg->wlen : fg->len) : 0;
950 mismatch = fastcmp(fg, startptr, type);
953 if (fg->word && !IS_ON_WORD_BOUNDARY)
955 if (!fg->nosub && nmatch >= 1)
958 pmatch[0].rm_eo = j + (type == STR_WIDE ? fg->wlen : fg->len);
970 mismatch = fastcmp(fg, startptr, type);
973 if (fg->word)
975 if (fg->bol)
977 if (fg->eol)
979 if (!fg->nosub && nmatch >= 1)
982 pmatch[0].rm_eo = j + ((type == STR_WIDE) ? fg->wlen : fg->len);
999 tre_free_fast(fastmatch_t *fg)
1003 fg->pattern));
1006 hashtable_free(fg->qsBc_table);
1007 if (!fg->hasdot)
1008 free(fg->bmGs);
1009 if (fg->wescmap)
1010 free(fg->wescmap);
1011 free(fg->wpattern);
1013 if (!fg->hasdot)
1014 free(fg->sbmGs);
1015 if (fg->escmap)
1016 free(fg->escmap);
1017 free(fg->pattern);
1026 fastcmp(const fastmatch_t *fg, const void *data, tre_str_type_t type)
1029 const char *pat_byte = fg->pattern;
1031 const tre_char_t *pat_wide = fg->wpattern;
1032 const bool *escmap = (type == STR_WIDE) ? fg->wescmap : fg->escmap;
1033 size_t len = (type == STR_WIDE) ? fg->wlen : fg->len;
1043 if (fg->hasdot && pat_wide[i] == TRE_CHAR('.') &&
1045 (!fg->newline || (str_wide[i] != TRE_CHAR('\n'))))
1049 if (fg->icase ? (towlower(pat_wide[i]) == towlower(str_wide[i]))
1055 if (fg->hasdot && pat_byte[i] == '.' &&
1057 (!fg->newline || (str_byte[i] != '\n')))
1061 if (fg->icase ? (tolower((unsigned char)pat_byte[i]) == tolower((unsigned char)str_byte[i]))