Added cross-compile defaults to the AC_CHECK_SIZEOF macros
[privoxy.git] / pcrs.h
1 #ifndef PCRS_H_INCLUDED
2 #define PCRS_H_INCLUDED
3
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/pcrs.h,v $
7  *
8  * Purpose     :  Header file for pcrs.c
9  *
10  * Copyright   :  see pcrs.c
11  *
12  * Revisions   :
13  *    $Log: pcrs.h,v $
14  *    Revision 1.8  2001/08/15 15:32:50  oes
15  *    Replaced the hard limit for the maximum number of matches
16  *    by dynamic reallocation
17  *
18  *    Revision 1.7  2001/08/05 13:13:11  jongfoster
19  *    Making parameters "const" where possible.
20  *
21  *    Revision 1.6  2001/07/29 18:52:06  jongfoster
22  *    Renaming _PCRS_H, and adding "extern C {}"
23  *
24  *    Revision 1.5  2001/07/18 17:27:00  oes
25  *    Changed interface; Cosmetics
26  *
27  *    Revision 1.4  2001/06/29 13:33:19  oes
28  *    - Cleaned up, commented and adapted to reflect the
29  *      changes in pcrs.c
30  *    - Introduced the PCRS_* flags
31  *
32  *    Revision 1.3  2001/06/09 10:58:57  jongfoster
33  *    Removing a single unused #define which referenced BUFSIZ
34  *
35  *    Revision 1.2  2001/05/25 11:03:55  oes
36  *    Added sanity check for NULL jobs to pcrs_exec_substitution
37  *
38  *    Revision 1.1.1.1  2001/05/15 13:59:02  oes
39  *    Initial import of version 2.9.3 source tree
40  *
41  *    Revision 1.4  2001/05/11 01:57:02  rodney
42  *    Added new file header standard w/RCS control tags.
43  *
44  *    revision 1.3  2001/05/08 02:38:13  rodney
45  *    Changed C++ "//" style comment to C style comments.
46  *
47  *    revision 1.2  2001/04/30 02:39:24  rodney
48  *    Made this pcrs.h file conditionally included.
49  *
50  *    revision 1.1  2001/04/16 21:10:38  rodney
51  *    Initial checkin
52  *
53  *********************************************************************/
54
55 #define PCRS_H_VERSION "$Id: pcrs.h,v 1.8 2001/08/15 15:32:50 oes Exp $"
56 \f
57
58 #include <pcre.h>
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 /*
65  * Constants:
66  */
67
68 #define FALSE 0
69 #define TRUE 1
70
71 /* Capacity */
72 #define PCRS_MAX_SUBMATCHES  33     /* Maximum number of capturing subpatterns allowed. MUST be <= 99! FIXME: Should be dynamic */
73 #define PCRS_MAX_MATCH_INIT  40     /* Initial amount of matches that can be stored in global searches */
74 #define PCRS_MAX_MATCH_GROW  1.6    /* Factor by which storage for matches is extended if exhausted */
75
76 /* Error codes */
77 #define PCRS_ERR_NOMEM     -10      /* Failed to acquire memory. */
78 #define PCRS_ERR_CMDSYNTAX -11      /* Syntax of s///-command */
79 #define PCRS_ERR_STUDY     -12      /* pcre error while studying the pattern */
80 #define PCRS_ERR_BADJOB    -13      /* NULL job pointer, pattern or substitute */
81 #define PCRS_WARN_BADREF   -14      /* Backreference out of range */
82
83 /* Flags */
84 #define PCRS_GLOBAL          1      /* Job should be applied globally, as with perl's g option */
85 #define PCRS_TRIVIAL         2      /* Backreferences in the substitute are ignored */
86 #define PCRS_SUCCESS         4      /* Job did previously match */
87
88
89 /*
90  * Data types:
91  */
92
93 /* A compiled substitute */
94
95 typedef struct {
96   char *text;                                 /* The plaintext part of the substitute, with all backreferences stripped */
97   int backrefs;                               /* The number of backreferences */
98   int block_offset[PCRS_MAX_SUBMATCHES];      /* Array with the offsets of all plaintext blocks in text */
99   int block_length[PCRS_MAX_SUBMATCHES];      /* Array with the lengths of all plaintext blocks in text */
100   int backref[PCRS_MAX_SUBMATCHES];           /* Array with the backref number for all plaintext block borders */
101   int backref_count[PCRS_MAX_SUBMATCHES + 2]; /* Array with the number of references to each backref index */
102 } pcrs_substitute;
103
104 /*
105  * A match, including all captured subpatterns (submatches)
106  * Note: The zeroth is the whole match, the PCRS_MAX_SUBMATCHES + 0th
107  * is the range before the match, the PCRS_MAX_SUBMATCHES + 1th is the
108  * range after the match.
109  */
110
111 typedef struct {
112   int submatches;                               /* Number of captured subpatterns */
113   int submatch_offset[PCRS_MAX_SUBMATCHES + 2]; /* Offset for each submatch in the subject */
114   int submatch_length[PCRS_MAX_SUBMATCHES + 2]; /* Length of each submatch in the subject */
115 } pcrs_match;
116
117 /* A pcrs job */
118
119 typedef struct PCRS_JOB {
120   pcre *pattern;                            /* The compiled pcre pattern */
121   pcre_extra *hints;                        /* The pcre hints for the pattern */
122   int options;                              /* The pcre options (numeric) */
123   int flags;                                /* The pcrs and user flags (see "Flags" above) */
124   pcrs_substitute *substitute;              /* The compiled pcrs substitute */
125   struct PCRS_JOB *next;                    /* Pointer for chaining jobs to joblists */
126 } pcrs_job;
127
128
129 /*
130  * Prototypes:
131  */
132
133 /* Main usage */
134 extern pcrs_job        *pcrs_compile_command(const char *command, int *errptr);
135 extern pcrs_job        *pcrs_compile(const char *pattern, const char *substitute, const char *options, int *errptr);
136 extern int              pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **result, size_t *result_length);
137 extern int              pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length);
138
139 /* Freeing jobs */
140 extern pcrs_job        *pcrs_free_job(pcrs_job *job);
141 extern void             pcrs_free_joblist(pcrs_job *joblist);
142
143 /* Info on errors: */
144 extern const char *pcrs_strerror(const int error);
145
146 /* Expert usage */
147 extern int              pcrs_parse_perl_options(const char *optstring, int *flags);
148 extern pcrs_substitute *pcrs_compile_replacement(const char *replacement, int trivialflag, int capturecount, int *errptr);
149
150
151 #ifdef __cplusplus
152 } /* extern "C" */
153 #endif
154
155 #endif /* ndef PCRS_H_INCLUDED */
156
157 /*
158   Local Variables:
159   tab-width: 3
160   end:
161 */