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