From owner-svn-src-user@FreeBSD.ORG Mon Aug 15 00:38:15 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAA11106564A; Mon, 15 Aug 2011 00:38:14 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D8EB98FC08; Mon, 15 Aug 2011 00:38:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7F0cEDp086171; Mon, 15 Aug 2011 00:38:14 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7F0cE37086169; Mon, 15 Aug 2011 00:38:14 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108150038.p7F0cE37086169@svn.freebsd.org> From: Gabor Kovesdan Date: Mon, 15 Aug 2011 00:38:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r224873 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Aug 2011 00:38:15 -0000 Author: gabor Date: Mon Aug 15 00:38:14 2011 New Revision: 224873 URL: http://svn.freebsd.org/changeset/base/224873 Log: - Add some comments - One TRE-specific portability nit Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Sun Aug 14 23:26:32 2011 (r224872) +++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Mon Aug 15 00:38:14 2011 (r224873) @@ -324,6 +324,10 @@ static int fastcmp(const void *, const v free(suff); \ } +/* + * Copies the pattern pat having lenght n to p and stores + * the size in l. + */ #define SAVE_PATTERN(p, l) \ l = (n == 0) ? tre_strlen(pat) : n; \ p = xmalloc((l + 1) * sizeof(tre_char_t)); \ @@ -332,6 +336,9 @@ static int fastcmp(const void *, const v memcpy(p, pat, l * sizeof(tre_char_t)); \ p[l] = TRE_CHAR('\0'); +/* + * Initializes pattern compiling. + */ #define INIT_COMP \ /* Initialize. */ \ memset(fg, 0, sizeof(*fg)); \ @@ -473,9 +480,17 @@ tre_fastcomp(fastmatch_t *fg, const tre_ ((j + fg->len == len) || !(tre_isalnum(str_byte[j + fg->len]) || \ (str_byte[j + fg->len] == '_')))) +/* + * Condition to check whether the match on position j is on a + * word boundary. + */ #define IS_ON_WORD_BOUNDARY \ (_BBOUND_COND && _EBOUND_COND) +/* + * Checks word boundary and shifts one if match is not on a + * boundary. + */ #define CHECK_WORD_BOUNDARY \ if (!IS_ON_WORD_BOUNDARY) \ _SHIFT_ONE; @@ -484,6 +499,10 @@ tre_fastcomp(fastmatch_t *fg, const tre_ ((j == 0) || ((type == STR_WIDE) ? tre_isspace(str_wide[j - 1]) : \ isspace(str_byte[j - 1]))) +/* + * Checks BOL anchor and shifts one if match is not on a + * boundary. + */ #define CHECK_BOL_ANCHOR \ if (!_BOL_COND) \ _SHIFT_ONE; @@ -493,6 +512,10 @@ tre_fastcomp(fastmatch_t *fg, const tre_ ((j + fg->wlen == len) || tre_isspace(str_wide[j + fg->wlen])) : \ ((j + fg->len == len) || isspace(str_byte[j + fg->wlen]))) +/* + * Checks EOL anchor and shifts one if match is not on a + * boundary. + */ #define CHECK_EOL_ANCHOR \ if (!_EOL_COND) \ _SHIFT_ONE; @@ -512,11 +535,12 @@ tre_fastexec(const fastmatch_t *fg, cons const void *startptr = NULL; const tre_char_t *str_wide = data; + /* Calculate length if unspecified. */ if (len == (unsigned)-1) switch (type) { case STR_WIDE: - len = wcslen(str_wide); + len = tre_strlen(str_wide); break; default: len = strlen(str_byte); @@ -601,6 +625,9 @@ tre_fastexec(const fastmatch_t *fg, cons return ret; } +/* + * Frees the resources that were allocated when the pattern was compiled. + */ void tre_fastfree(fastmatch_t *fg) { @@ -627,21 +654,29 @@ fastcmp(const void *pat, const void *dat const tre_char_t *str_wide = data; const tre_char_t *pat_wide = pat; + /* Compare the pattern and the input char-by-char from the last position. */ for (int i = len - 1; i >= 0; i--) { switch (type) { case STR_WIDE: + + /* Check dot */ if (pat_wide[i] == TRE_CHAR('.') && (!newline || (str_wide[i] != TRE_CHAR('\n')))) continue; + + /* Compare */ if (icase ? (towlower(pat_wide[i]) == towlower(str_wide[i])) : (pat_wide[i] == str_wide[i])) continue; break; default: + /* Check dot */ if (pat_byte[i] == '.' && (!newline || (str_byte[i] != '\n'))) continue; + + /* Compare */ if (icase ? (tolower(pat_byte[i]) == tolower(str_byte[i])) : (pat_byte[i] == str_byte[i])) continue;