"Fossies" - the Fresh Open Source Software Archive

Member "imapfilter-2.8.2/src/regexp.c" (26 Dec 2023, 793 Bytes) of package /linux/privat/imapfilter-2.8.2.tar.gz:


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 "regexp.c" see the Fossies "Dox" file reference documentation.

    1 #include <stdio.h>
    2 #include <sys/types.h>
    3 #include <regex.h>
    4 
    5 #include "imapfilter.h"
    6 #include "regexp.h"
    7 
    8 
    9 /*
   10  * Compile all the patterns and allocate the necessary space for the substring
   11  * matching.
   12  */
   13 void
   14 regexp_compile(regexp *reg)
   15 {
   16     regexp *re;
   17 
   18     for (re = reg; re->pattern != NULL; re++) {
   19         re->preg = (regex_t *)xmalloc(sizeof(regex_t));
   20         regcomp(re->preg, re->pattern, REG_EXTENDED | REG_ICASE);
   21         re->nmatch = re->preg->re_nsub + 1;
   22         re->pmatch = (regmatch_t *)xmalloc(sizeof(regmatch_t) *
   23             re->nmatch);
   24     }
   25 }
   26 
   27 
   28 /*
   29  * Free the compiled regular expressions and the space allocated for the
   30  * substring matching.
   31  */
   32 void
   33 regexp_free(regexp *reg)
   34 {
   35     regexp *re;
   36 
   37     for (re = reg; re->pattern != NULL; re++) {
   38         regfree(re->preg);
   39         xfree(re->preg);
   40         xfree(re->pmatch);
   41     }
   42 }