FreeBSD/usr.bin/grep/regex/tre-fastmatch.c
/*
 * Returns:	-(i + 1) on failure (position that it failed with minus sign)
 *		error code on error
 *		REG_OK on success
 */
-(i + 1) on failure (position that it failed with minus sign)
error code on error
REG_OK on success
- ( i + 1 ) on failure ( position that it failed with minus sign ) error code on error REG_OK on success
static inline int
fastcmp(const fastmatch_t *fg, const void *data, tre_str_type_t type)
{
  const char *str_byte = data;
  const char *pat_byte = fg->pattern;
  const tre_char_t *str_wide = data;
  const tre_char_t *pat_wide = fg->wpattern;
  const bool *escmap = (type == STR_WIDE) ? fg->wescmap : fg->escmap;
  size_t len = (type == STR_WIDE) ? fg->wlen : fg->len;
  int ret = REG_OK;
  for (int i = len - 1; i >= 0; i--) {
    switch (type)
      {
	case STR_WIDE:
	  if (fg->hasdot && pat_wide[i] == TRE_CHAR('.') &&
	      (!escmap || !escmap[i]) &&
	      (!fg->newline || (str_wide[i] != TRE_CHAR('\n'))))
	    continue;
	  if (fg->icase ? (towlower(pat_wide[i]) == towlower(str_wide[i]))
		    : (pat_wide[i] == str_wide[i]))
	    continue;
	  break;
	default:
	  if (fg->hasdot && pat_byte[i] == '.' &&
	      (!escmap || !escmap[i]) &&
	      (!fg->newline || (str_byte[i] != '\n')))
	    continue;
	  if (fg->icase ? (tolower((unsigned char)pat_byte[i]) == tolower((unsigned char)str_byte[i]))
		    : (pat_byte[i] == str_byte[i]))
	  continue;
      }
    DPRINT(("fastcmp: mismatch at position %d\n", i));
    ret = -(i + 1);
    break;
  }
  return ret;
}
static inline int fastcmp ( const fastmatch_t * fg , const void * data , tre_str_type_t type ) { const char * str_byte = data ; const char * pat_byte = fg -> pattern ; const tre_char_t * str_wide = data ; const tre_char_t * pat_wide = fg -> wpattern ; const bool * escmap = ( type == STR_WIDE ) ? fg -> wescmap : fg -> escmap ; size_t len = ( type == STR_WIDE ) ? fg -> wlen : fg -> len ; int ret = REG_OK ; for ( int i = len - 1 ; i >= 0 ; i -- ) { switch ( type ) { case STR_WIDE : if ( fg -> hasdot && pat_wide [ i ] == TRE_CHAR ( ' ' ) && ( ! escmap || ! escmap [ i ] ) && ( ! fg -> newline || ( str_wide [ i ] != TRE_CHAR ( ' \n ' ) ) ) ) continue ; if ( fg -> icase ? ( towlower ( pat_wide [ i ] ) == towlower ( str_wide [ i ] ) ) : ( pat_wide [ i ] == str_wide [ i ] ) ) continue ; break ; default : if ( fg -> hasdot && pat_byte [ i ] == ' ' && ( ! escmap || ! escmap [ i ] ) && ( ! fg -> newline || ( str_byte [ i ] != ' \n ' ) ) ) continue ; if ( fg -> icase ? ( tolower ( ( unsigned char ) pat_byte [ i ] ) == tolower ( ( unsigned char ) str_byte [ i ] ) ) : ( pat_byte [ i ] == str_byte [ i ] ) ) continue ; } DPRINT ( ( " \n " , i ) ) ; ret = - ( i + 1 ) ; break ; } return ret ; }
Returns:     -(i + 1) on failure (position that it failed with minus sign)
              error code on error
              REG_OK on success
Returns : - ( i + 1 ) on failure ( position that it failed with minus sign ) error code on error REG_OK on success
/* Compare the pattern and the input char-by-char from the last position. */ /* Check dot */ /* Compare */ /* Check dot */ /* Compare */