bdb1e47296d39170eaa5bc7e5862f7833d2b31d1
[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.2  2001/05/25 11:03:55  oes
30  *    Added sanity check for NULL jobs to pcrs_exec_substitution
31  *
32  *    Revision 1.1.1.1  2001/05/15 13:59:02  oes
33  *    Initial import of version 2.9.3 source tree
34  *
35  *    Revision 1.4  2001/05/11 01:57:02  rodney
36  *    Added new file header standard w/RCS control tags.
37  *
38  *    revision 1.3  2001/05/08 02:38:13  rodney
39  *    Changed C++ "//" style comment to C style comments.
40  *
41  *    revision 1.2  2001/04/30 02:39:24  rodney
42  *    Made this pcrs.h file conditionally included.
43  *
44  *    revision 1.1  2001/04/16 21:10:38  rodney
45  *    Initial checkin
46  *
47  *********************************************************************/
48
49 #define PCRS_H_VERSION "$Id: pcrs.h,v 1.2 2001/05/25 11:03:55 oes Exp $"
50 \f
51
52
53 #include <pcre.h>
54
55 #define FALSE 0
56 #define TRUE 1
57 #define PCRS_MAX_MATCHES 300
58 #define PCRS_MAX_SUBMATCHES 33
59
60 #define PCRS_ERR_NOMEM     -10      /* Failed to acquire memory. */
61 #define PCRS_ERR_CMDSYNTAX -11      /* Syntax of s///-command */
62 #define PCRS_ERR_STUDY     -12      /* pcre error while studying the pattern */
63 #define PCRS_ERR_BADJOB    -13      /* NULL job pointer, pattern or substitute */
64
65 typedef struct S_PCRS_SUBSTITUTE {
66   char *text;
67   int backrefs;
68   int block_offset[PCRS_MAX_SUBMATCHES];
69   int block_length[PCRS_MAX_SUBMATCHES];
70   int backref[PCRS_MAX_SUBMATCHES];
71   int backref_count[PCRS_MAX_SUBMATCHES];
72 } pcrs_substitute;
73
74 typedef struct S_PCRS_MATCH {
75   /* char *buffer; */
76   int submatches;
77   int submatch_offset[PCRS_MAX_SUBMATCHES];
78   int submatch_length[PCRS_MAX_SUBMATCHES];
79 } pcrs_match;
80
81 typedef struct S_PCRS_JOB {
82   pcre *pattern;
83   pcre_extra *hints;
84   int options;
85   int globalflag;
86   int successflag;
87   pcrs_substitute *substitute;
88   struct S_PCRS_JOB *next;
89 } pcrs_job;
90
91 extern int              pcrs_compile_perl_options(char *optstring, int *globalflag);
92 extern pcrs_substitute *pcrs_compile_replacement(char *replacement, int *errptr);
93 extern pcrs_job        *pcrs_free_job(pcrs_job *job);
94 extern pcrs_job        *pcrs_make_job(char *command, int *errptr);
95 extern pcrs_job        *create_pcrs_job(pcre *pattern, pcre_extra *hints, int options, int globalflag, pcrs_substitute *substitute, int *errptr);
96 extern int              pcrs_exec_substitution(pcrs_job *job, char *subject, int subject_length, char **result, int *result_length);
97
98
99 #endif /* ndef _PCRS_H */
100
101 /*
102   Local Variables:
103   tab-width: 3
104   end:
105 */