[155] | 1 | #ifndef ERE_H
|
---|
| 2 | #define ERE_H
|
---|
| 3 |
|
---|
| 4 | #ifndef BOOLEAN_DEFINED
|
---|
| 5 | #define BOOLEAN_DEFINED
|
---|
| 6 | typedef int BOOLEAN;
|
---|
[222] | 7 | #ifndef TRUE
|
---|
[155] | 8 | #define TRUE 1
|
---|
[222] | 9 | #endif
|
---|
| 10 | #ifndef FALSE
|
---|
[155] | 11 | #define FALSE 0
|
---|
| 12 | #endif
|
---|
[222] | 13 | #endif
|
---|
[155] | 14 |
|
---|
| 15 | #ifndef NO_ERROR
|
---|
| 16 | #define NO_ERROR 0
|
---|
| 17 | #endif
|
---|
| 18 |
|
---|
| 19 | #define ERROR_REGEXP_FIRST 44000
|
---|
| 20 | // #define EREE_OK 0
|
---|
| 21 | // #define EREE_MEM (ERROR_REGEXP_FIRST + 0)
|
---|
| 22 | #ifndef ERROR_NOT_ENOUGH_MEMORY
|
---|
| 23 | #define ERROR_NOT_ENOUGH_MEMORY 8L
|
---|
| 24 | #endif
|
---|
| 25 | #define EREE_UNF_SUB (ERROR_REGEXP_FIRST + 1)
|
---|
| 26 | #define EREE_UNEX_RANGE (ERROR_REGEXP_FIRST + 2)
|
---|
| 27 | #define EREE_UNF_RANGE (ERROR_REGEXP_FIRST + 3)
|
---|
| 28 | #define EREE_UNF_CCLASS (ERROR_REGEXP_FIRST + 4)
|
---|
| 29 | #define EREE_UNEX_RSQR (ERROR_REGEXP_FIRST + 5)
|
---|
| 30 | #define EREE_UNEX_RPAR (ERROR_REGEXP_FIRST + 6)
|
---|
| 31 | #define EREE_UNEX_QUERY (ERROR_REGEXP_FIRST + 7)
|
---|
| 32 | #define EREE_UNEX_PLUS (ERROR_REGEXP_FIRST + 8)
|
---|
| 33 | #define EREE_UNEX_STAR (ERROR_REGEXP_FIRST + 9)
|
---|
| 34 | #define EREE_UNEX_LCUR (ERROR_REGEXP_FIRST + 10)
|
---|
| 35 | #define EREE_UNEX_RCUR (ERROR_REGEXP_FIRST + 11)
|
---|
| 36 | #define EREE_BAD_CREP_M (ERROR_REGEXP_FIRST + 12)
|
---|
| 37 | #define EREE_BAD_CREP_N (ERROR_REGEXP_FIRST + 13)
|
---|
| 38 | #define EREE_UNF_CREP (ERROR_REGEXP_FIRST + 14)
|
---|
| 39 | #define EREE_BAD_CREP (ERROR_REGEXP_FIRST + 15)
|
---|
| 40 | #define EREE_TOO_MANY_SUB (ERROR_REGEXP_FIRST + 16)
|
---|
| 41 | #define EREE_COMPILE_FSM (ERROR_REGEXP_FIRST + 17)
|
---|
| 42 | #define EREE_POSIX_COLLATING (ERROR_REGEXP_FIRST + 18)
|
---|
| 43 | #define EREE_POSIX_EQUIVALENCE (ERROR_REGEXP_FIRST + 19)
|
---|
| 44 | #define EREE_POSIX_CCLASS_BAD (ERROR_REGEXP_FIRST + 20)
|
---|
| 45 | #define EREE_BAD_BACKSLASH (ERROR_REGEXP_FIRST + 21)
|
---|
| 46 | #define EREE_BAD_BACKREF (ERROR_REGEXP_FIRST + 22)
|
---|
| 47 | #define EREE_SUBS_LEN (ERROR_REGEXP_FIRST + 23)
|
---|
| 48 | #define ERROR_REGEXP_LAST (ERROR_REGEXP_FIRST + 23)
|
---|
| 49 |
|
---|
| 50 | #define ERECF_TOLOWER 0x01
|
---|
| 51 |
|
---|
| 52 | #define EREMF_SHORTEST 0x01
|
---|
| 53 | #define EREMF_ANY 0x02
|
---|
| 54 |
|
---|
| 55 | #define MAX_SPANS 9
|
---|
| 56 |
|
---|
| 57 | typedef struct { int pos, len; } ERE_SPAN;
|
---|
| 58 |
|
---|
| 59 | typedef struct
|
---|
| 60 | {
|
---|
| 61 | int n_spans;
|
---|
| 62 | ERE_SPAN spans[MAX_SPANS];
|
---|
| 63 | } ERE_MATCHINFO;
|
---|
| 64 |
|
---|
| 65 | #ifndef ERE_C
|
---|
| 66 |
|
---|
| 67 | typedef void ERE;
|
---|
| 68 |
|
---|
| 69 | extern ERE *rxpCompile(
|
---|
| 70 | const char *str,
|
---|
| 71 | int erecf,
|
---|
| 72 | int *rc
|
---|
| 73 | );
|
---|
| 74 |
|
---|
| 75 | extern int rxpMinLen(const ERE *ere);
|
---|
| 76 |
|
---|
| 77 | /* Returns the number of characters in the match, starting from pos characters
|
---|
| 78 | into the string to be searched. Details of sub-matches can also be returend.
|
---|
| 79 | Returns -1 if no match. */
|
---|
| 80 | extern int rxpMatch(
|
---|
| 81 | const ERE *ere,
|
---|
| 82 | int eremf,
|
---|
| 83 | const char *str, int pos,
|
---|
| 84 | ERE_MATCHINFO *mi /* can be NULL */
|
---|
| 85 | );
|
---|
| 86 |
|
---|
| 87 | /* Returns TRUE if a match can be found starting pos characters into the string
|
---|
| 88 | to be searched. Position and length of match are returned. Details of
|
---|
| 89 | sub-matches can also be returned. */
|
---|
| 90 | extern BOOLEAN rxpMatch_fwd(
|
---|
| 91 | const ERE *ere,
|
---|
| 92 | int eremf,
|
---|
| 93 | const char *str, int pos,
|
---|
| 94 | int *pos_match, int *len_match,
|
---|
| 95 | ERE_MATCHINFO *mi /* can be NULL */
|
---|
| 96 | );
|
---|
| 97 |
|
---|
| 98 | /* Returns TRUE if a match can be found starting pos characters into the string
|
---|
| 99 | to be searched and scanning backwards. Position and length of match are
|
---|
| 100 | returned. Details of sub-matches can also be returned. */
|
---|
| 101 | extern BOOLEAN rxpMatch_bwd(
|
---|
| 102 | const ERE *ere,
|
---|
| 103 | int eremf,
|
---|
| 104 | const char *str, int pos,
|
---|
| 105 | int *pos_match, int *len_match,
|
---|
| 106 | ERE_MATCHINFO *mi /* can be NULL */
|
---|
| 107 | );
|
---|
| 108 |
|
---|
| 109 | extern void rxpFree(ERE *ere);
|
---|
| 110 |
|
---|
| 111 | extern BOOLEAN rxpSubsWith(
|
---|
| 112 | const char *str, /* Original string searched */
|
---|
| 113 | int pos, int len, /* Span of the entire match */
|
---|
| 114 | ERE_MATCHINFO *mi, /* Details of sub-spans of match */
|
---|
| 115 | const char *with, /* Specification of replacement */
|
---|
| 116 | char *out, /* Substituted string buffer */
|
---|
| 117 | int len_out, /* How much room in output buffer */
|
---|
| 118 | int *rc /* Error, if FALSE returned */
|
---|
| 119 | );
|
---|
| 120 |
|
---|
| 121 | #endif
|
---|
| 122 |
|
---|
| 123 | #endif
|
---|