| 1 | /* Regular expression matching on strings. |
| 2 | * |
| 3 | * SRE, Sun Jan 2 10:52:34 2005 [Zaragoza] |
| 4 | ****************************************************************** |
| 5 | * The regexp module is a wrapper around a modified version of Henry |
| 6 | * Spencer's regex library. Spencer's copyright notice appears below, |
| 7 | * after my wrappers, prefacing the section that includes his code. I |
| 8 | * believe you can obtain the original code from: |
| 9 | * ftp://ftp.zoo.toronto.edu/pub/bookregex.tar.Z |
| 10 | * Thanks, Henry! |
| 11 | ***************************************************************** |
| 12 | */ |
| 13 | #ifndef eslREGEXP_INCLUDED |
| 14 | #define eslREGEXP_INCLUDED |
| 15 | #include <esl_config.h> |
| 16 | |
| 17 | /* ESL_REGEXP_NSUB specifies the maximum number of () expressions |
| 18 | * in a regexp. The whole regexp counts as one, so 16 allows for |
| 19 | * parsing out up to 15 tokens from the match. |
| 20 | */ |
| 21 | #define ESL_REGEXP_NSUB 16 |
| 22 | |
| 23 | /* The esl__regexp structure is from the original Spencer code. |
| 24 | * It's wrapped by the ESL_REGEXP structure, below. |
| 25 | */ |
| 26 | typedef struct { |
| 27 | char *startp[ESL_REGEXP_NSUB]; /* ptrs to starts of submatches on target string */ |
| 28 | char *endp[ESL_REGEXP_NSUB]; /* ptrs to 1 char after ends of submatches */ |
| 29 | char regstart; /* Internal use only. */ |
| 30 | char reganch; /* Internal use only. */ |
| 31 | char *regmust; /* Internal use only. */ |
| 32 | int regmlen; /* Internal use only. */ |
| 33 | char program[1]; /* Unwarranted chumminess with compiler. */ |
| 34 | } esl__regexp; |
| 35 | |
| 36 | |
| 37 | /* This looks sort of stupid, wrapping a single ptr in a structure, but we |
| 38 | * want the machine to be persistent even if different NDFAs are |
| 39 | * compiled and used. Without this persistency, we would have to |
| 40 | * create/destroy every time we used a different pattern, instead of |
| 41 | * one create/destroy per block of code that uses regex matching |
| 42 | * functionaility. |
| 43 | * |
| 44 | * Plus, if we ever need to keep other persistent info |
| 45 | * beyond Spencer's compiled NDFA (which we'd rather not mess |
| 46 | * with), we have a place to put it. |
| 47 | */ |
| 48 | typedef struct { |
| 49 | esl__regexp *ndfa; /* a compiled regexp */ |
| 50 | } ESL_REGEXP; |
| 51 | |
| 52 | |
| 53 | /* Declaration of functions in the API |
| 54 | */ |
| 55 | extern ESL_REGEXP *esl_regexp_Create(void); |
| 56 | extern void esl_regexp_Destroy(ESL_REGEXP *machine); |
| 57 | |
| 58 | extern int esl_regexp_Compile (ESL_REGEXP *machine, const char *pattern); |
| 59 | extern int esl_regexp_Match (ESL_REGEXP *machine, const char *pattern, const char *s); |
| 60 | extern int esl_regexp_MultipleMatches(ESL_REGEXP *machine, char **sptr); |
| 61 | |
| 62 | extern int esl_regexp_GetMatch (ESL_REGEXP *machine, int which, char **ret_s, esl_pos_t *ret_n); |
| 63 | extern char *esl_regexp_SubmatchDup (ESL_REGEXP *machine, int elem); |
| 64 | extern int esl_regexp_SubmatchCopy (ESL_REGEXP *machine, int elem, char *buffer, int nc); |
| 65 | extern int esl_regexp_SubmatchCoords(ESL_REGEXP *machine, char *origin, int elem, int *ret_start, int *ret_end); |
| 66 | |
| 67 | extern int esl_regexp_ParseCoordString(const char *cstring, int64_t *ret_start, int64_t *ret_end); |
| 68 | |
| 69 | #endif /*eslREGEXP_INCLUDED*/ |
| 70 |