Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/grep/regex/tre-fastmatch.c
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | #define STORE_MBS_PAT \ | ||||
fg->len = siz; \ | fg->len = siz; \ | ||||
fg->pattern = malloc(siz + 1); \ | fg->pattern = malloc(siz + 1); \ | ||||
if (fg->pattern == NULL) \ | if (fg->pattern == NULL) \ | ||||
return REG_ESPACE; \ | return REG_ESPACE; \ | ||||
wcstombs(fg->pattern, fg->wpattern, siz); \ | wcstombs(fg->pattern, fg->wpattern, siz); \ | ||||
fg->pattern[siz] = '\0'; \ | fg->pattern[siz] = '\0'; \ | ||||
} \ | } \ | ||||
#define CONV_MBS_PAT(src, dest, destsz) \ | |||||
{ \ | |||||
destsz = wcstombs(NULL, src, 0); \ | |||||
if (destsz == (size_t)-1) \ | |||||
return REG_BADPAT; \ | |||||
dest = malloc(destsz + 1); \ | |||||
if (dest == NULL) \ | |||||
return REG_ESPACE; \ | |||||
wcstombs(dest, src, destsz); \ | |||||
dest[destsz] = '\0'; \ | |||||
} \ | |||||
#define IS_OUT_OF_BOUNDS \ | #define IS_OUT_OF_BOUNDS \ | ||||
((!fg->reversed \ | ((!fg->reversed \ | ||||
? ((type == STR_WIDE) ? ((j + fg->wlen) > len) \ | ? ((type == STR_WIDE) ? ((j + fg->wlen) > len) \ | ||||
: ((j + fg->len) > len)) \ | : ((j + fg->len) > len)) \ | ||||
: (j < 0))) | : (j < 0))) | ||||
/* | /* | ||||
* Checks whether the new position after shifting in the input string | * Checks whether the new position after shifting in the input string | ||||
▲ Show 20 Lines • Show All 609 Lines • ▼ Show 20 Lines | if (fg->hasdot || (fg->wescmap != NULL)) | ||||
if (fg->escmap == NULL) | if (fg->escmap == NULL) | ||||
{ | { | ||||
tre_free_fast(fg); | tre_free_fast(fg); | ||||
return REG_ESPACE; | return REG_ESPACE; | ||||
} | } | ||||
} | } | ||||
escaped = false; | escaped = false; | ||||
for (unsigned int i = 0; i < fg->len; i++) | char *_checkpat = NULL; | ||||
if (fg->pattern[i] == '\\') | size_t _checklen = 0; | ||||
unsigned int escofs = 0; | |||||
/* | |||||
* Make a copy here of the original pattern, because fg->pattern has | |||||
* already been stripped of all escape sequences in the above processing. | |||||
* This is necessary if we wish to later treat fg->escmap as an actual, | |||||
* functional replacement of fg->wescmap. | |||||
*/ | |||||
CONV_MBS_PAT(pat, _checkpat, _checklen); | |||||
for (unsigned int i = 0; i < n; i++) | |||||
if (_checkpat[i] == '\\') | |||||
{ | |||||
escaped = !escaped; | escaped = !escaped; | ||||
else if (fg->pattern[i] == '.' && fg->escmap && escaped) | if (escaped) | ||||
++escofs; | |||||
} | |||||
else if (_checkpat[i] == '.' && fg->escmap != NULL && escaped) | |||||
{ | { | ||||
fg->escmap[i] = true; | fg->escmap[i - escofs] = true; | ||||
escaped = false; | escaped = false; | ||||
} | } | ||||
else if (fg->pattern[i] == '.' && !escaped) | else if (_checkpat[i] == '.' && !escaped) | ||||
{ | { | ||||
hasdot = i; | hasdot = i; | ||||
if (firstdot == -1) | if (firstdot == -1) | ||||
firstdot = i; | firstdot = i; | ||||
} | } | ||||
else | else | ||||
escaped = false; | escaped = false; | ||||
free(_checkpat); | |||||
} | } | ||||
#else | #else | ||||
SAVE_PATTERN(tmp, pos, fg->pattern, fg->len); | SAVE_PATTERN(tmp, pos, fg->pattern, fg->len); | ||||
fg->escmap = _escmap; | fg->escmap = _escmap; | ||||
#endif | #endif | ||||
free(tmp); | free(tmp); | ||||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |