Removed all #ifdef PCRS and related code
[privoxy.git] / pcrs.h
1 #ifndef _PCRS_H
2 #define _PCRS_H
3
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/pcrs.h,v $
7  *
8  * Purpose     :  This is the pre-pre-alpha realease of libpcrs. It is only
9  *                published at this (ugly) stage of development, because it is
10  *                needed for a new feature in JunkBuster.
11  *
12  *                Apart from the code being quite a mess, no inconsistencies,
13  *                memory leaks or functional bugs **should** be present.
14  *
15  *                While you ROTFL at the code, you could just as well mail me
16  *                (oes@paradis.rhein.de) with advice for improvement.
17  *
18  *                pcrs is a supplement to the brilliant pcre library by Philip
19  *                Hazel (ph10@cam.ac.uk) and adds Perl-style substitution. That
20  *                is, it mimics Perl's 's' operator.
21  *
22  *                Currently, there's no documentation besides comments and the
23  *                source itself ;-)
24  *
25  * Copyright   :  Written and copyright 2001 by Sourceforge IJBSWA team.
26  *
27  * Revisions   :
28  *    $Log: pcrs.h,v $
29  *    Revision 1.3  2001/06/09 10:58:57  jongfoster
30  *    Removing a single unused #define which referenced BUFSIZ
31  *
32  *    Revision 1.2  2001/05/25 11:03:55  oes
33  *    Added sanity check for NULL jobs to pcrs_exec_substitution
34  *
35  *    Revision 1.1.1.1  2001/05/15 13:59:02  oes
36  *    Initial import of version 2.9.3 source tree
37  *
38  *    Revision 1.4  2001/05/11 01:57:02  rodney
39  *    Added new file header standard w/RCS control tags.
40  *
41  *    revision 1.3  2001/05/08 02:38:13  rodney
42  *    Changed C++ "//" style comment to C style comments.
43  *
44  *    revision 1.2  2001/04/30 02:39:24  rodney
45  *    Made this pcrs.h file conditionally included.
46  *
47  *    revision 1.1  2001/04/16 21:10:38  rodney
48  *    Initial checkin
49  *
50  *********************************************************************/
51
52 #define PCRS_H_VERSION "$Id: pcrs.h,v 1.3 2001/06/09 10:58:57 jongfoster Exp $"
53 \f
54
55 #include <pcre.h>
56
57 /*
58  * Constants:
59  */
60
61 #define FALSE 0
62 #define TRUE 1
63
64 /* Capacity */
65 #define PCRS_MAX_MATCHES 300
66 #define PCRS_MAX_SUBMATCHES 33
67
68 /* Error codes */
69 #define PCRS_ERR_NOMEM     -10      /* Failed to acquire memory. */
70 #define PCRS_ERR_CMDSYNTAX -11      /* Syntax of s///-command */
71 #define PCRS_ERR_STUDY     -12      /* pcre error while studying the pattern */
72 #define PCRS_ERR_BADJOB    -13      /* NULL job pointer, pattern or substitute */
73
74 /* Flags */
75 #define PCRS_GLOBAL          1      /* Job should be applied globally, as with perl's g option */
76 #define PCRS_SUCCESS         2      /* Job did previously match */
77 #define PCRS_TRIVIAL         4      /* No backreferences need to be parsed in the substitute */
78
79 /*
80  * Data types:
81  */
82
83 /* A compiled substitute */
84 typedef struct S_PCRS_SUBSTITUTE {
85   char *text;                               /* The plaintext part of the substitute, with all backreferences stripped */
86   int backrefs;                             /* The number of backreferences */
87   int block_offset[PCRS_MAX_SUBMATCHES];    /* Array with the offsets of all plaintext blocks in text */
88   int block_length[PCRS_MAX_SUBMATCHES];    /* Array with the lengths of all plaintext blocks in text */
89   int backref[PCRS_MAX_SUBMATCHES];         /* Array with the backref number for all plaintext block borders */
90   int backref_count[PCRS_MAX_SUBMATCHES];   /* Array with the number of reference to each backref index */
91 } pcrs_substitute;
92
93 typedef struct S_PCRS_MATCH {
94   /* char *buffer; */
95   int submatches;                           /* Number of submatches. Note: The zeroth is the whole match */
96   int submatch_offset[PCRS_MAX_SUBMATCHES]; /* Offset for each submatch in the subject */
97   int submatch_length[PCRS_MAX_SUBMATCHES]; /* Length of each submatch in the subject */
98 } pcrs_match;
99
100 typedef struct S_PCRS_JOB {
101   pcre *pattern;                            /* The compiled pcre pattern */
102   pcre_extra *hints;                        /* The pcre hints for the pattern */
103   int options;                              /* The pcre options (numeric) */
104   int flags;                                /* The pcrs and user flags (see "Flags" above) */
105   pcrs_substitute *substitute;              /* The compiles pcrs substitute */
106   struct S_PCRS_JOB *next;                  /* Pointer for chaining jobs to joblists */
107 } pcrs_job;
108
109 /*
110  * Prototypes:
111  */
112
113 /* Main usage */
114 extern pcrs_job        *pcrs_compile(char *command, int *errptr);
115 extern pcrs_job        *pcrs_make_job(char *pattern, char *substitute, char *options, int *errptr);
116 extern int              pcrs_execute(pcrs_job *job, char *subject, int subject_length, char **result, int *result_length);
117
118 /* Freeing jobs */
119 extern pcrs_job        *pcrs_free_job(pcrs_job *job);
120 extern void             pcrs_free_joblist(pcrs_job *joblist);
121
122 /* Expert usage */
123 extern int              pcrs_compile_perl_options(char *optstring, int *flags);
124 extern pcrs_substitute *pcrs_compile_replacement(char *replacement, int trivialflag, int *errptr);
125
126 #endif /* ndef _PCRS_H */
127
128 /*
129   Local Variables:
130   tab-width: 3
131   end:
132 */