"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/groupselect.c" (28 Dec 2021, 1538 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "groupselect.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.11.12_vs_1.12.0.

    1 /* (C) Copyright 2002 - 2021 Matthias Andree, see COPYING for license. */
    2 
    3 #include <string.h>
    4 
    5 #include "config.h"
    6 #include "groupselect.h"
    7 #include "ln_log.h"
    8 
    9 pcre2_code_8 *gs_compile(const unsigned char *regex) {
   10     int regex_errcode;
   11     size_t regex_errpos;
   12     pcre2_code_8 *re;
   13 
   14     if (NULL == (re = pcre2_compile_8(regex, PCRE2_ZERO_TERMINATED, PCRE2_MULTILINE, &regex_errcode,
   15                       &regex_errpos, NULL))) {
   16     unsigned char regex_errmsg[1024];
   17     int len = pcre2_get_error_message_8(regex_errcode, regex_errmsg, sizeof(regex_errmsg));
   18     ln_log(LNLOG_SERR, LNLOG_CTOP, "Invalid group pattern "
   19         "in \"%s\" at char #%lu: %s%s", regex, (unsigned long)regex_errpos, regex_errmsg,
   20            len == PCRE2_ERROR_NOMEMORY ? "[...]" : "");
   21     }
   22     return re;
   23 }
   24 
   25 /* match s against PCRE p
   26  * WARNING: If p is NULL, every string s is considered a match
   27  * returns 1 for match, 0 for mismatch, negative for error */
   28 int gs_match(const pcre2_code_8 *re, const unsigned char *s) {
   29     int match;
   30     pcre2_match_data_8 *match_data;
   31 
   32     if (re == NULL) return 1;
   33     match_data = pcre2_match_data_create_8(1, NULL);
   34     if (NULL == match_data) {
   35         ln_log(LNLOG_SERR, LNLOG_CTOP, "gs_match: out of memory allocating match_data");
   36         return -1;
   37     }
   38 
   39     match = pcre2_match_8(re, s, PCRE2_ZERO_TERMINATED, 0,
   40         PCRE2_ANCHORED, match_data, NULL);
   41 
   42     pcre2_match_data_free_8(match_data);
   43     if (match == PCRE2_ERROR_NOMATCH) return 0;
   44     if (match >= 0) return 1;
   45     return match; /* match < 0, but not PCRE2_ERROR_NOMATCH */
   46 }