X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=pcrs.h;h=9c29ca73215c1f024a8bdc1ac1eeea1e43c4e147;hb=e1fcf9e251441c56e4a81962a268feee59568dfa;hp=31fb8871a634c8e27e9d9a3e6bc1dab885ddeef6;hpb=5b35453b1f37ce1059d8b99c9a64b2d123fdbfe9;p=privoxy.git diff --git a/pcrs.h b/pcrs.h index 31fb8871..9c29ca73 100644 --- a/pcrs.h +++ b/pcrs.h @@ -5,27 +5,18 @@ * * File : $Source: /cvsroot/ijbswa/current/pcrs.h,v $ * - * Purpose : This is the pre-pre-alpha realease of libpcrs. It is only - * published at this (ugly) stage of development, because it is - * needed for a new feature in JunkBuster. + * Purpose : Header file for pcrs.c * - * Apart from the code being quite a mess, no inconsistencies, - * memory leaks or functional bugs **should** be present. - * - * While you ROTFL at the code, you could just as well mail me - * (oes@paradis.rhein.de) with advice for improvement. - * - * pcrs is a supplement to the brilliant pcre library by Philip - * Hazel (ph10@cam.ac.uk) and adds Perl-style substitution. That - * is, it mimics Perl's 's' operator. - * - * Currently, there's no documentation besides comments and the - * source itself ;-) - * - * Copyright : Written and copyright 2001 by Sourceforge IJBSWA team. + * Copyright : see pcrs.c * * Revisions : * $Log: pcrs.h,v $ + * Revision 1.7 2001/08/05 13:13:11 jongfoster + * Making parameters "const" where possible. + * + * Revision 1.6 2001/07/29 18:52:06 jongfoster + * Renaming _PCRS_H, and adding "extern C {}" + * * Revision 1.5 2001/07/18 17:27:00 oes * Changed interface; Cosmetics * @@ -57,7 +48,7 @@ * *********************************************************************/ -#define PCRS_H_VERSION "$Id: pcrs.h,v 1.5 2001/07/18 17:27:00 oes Exp $" +#define PCRS_H_VERSION "$Id: pcrs.h,v 1.8 2001/08/15 15:26:58 oes Exp $" #include @@ -74,8 +65,9 @@ extern "C" { #define TRUE 1 /* Capacity */ -#define PCRS_MAX_MATCHES 300 -#define PCRS_MAX_SUBMATCHES 33 +#define PCRS_MAX_SUBMATCHES 33 /* Maximum number of capturing subpatterns allowed. FIXME: Should be dynamic */ +#define PCRS_MAX_MATCH_INIT 40 /* Initial amount of matches that can be stored in global searches */ +#define PCRS_MAX_MATCH_GROW 1.5 /* Factor by which storage for matches is extended if exhausted */ /* Error codes */ #define PCRS_ERR_NOMEM -10 /* Failed to acquire memory. */ @@ -85,14 +77,16 @@ extern "C" { /* Flags */ #define PCRS_GLOBAL 1 /* Job should be applied globally, as with perl's g option */ -#define PCRS_SUCCESS 2 /* Job did previously match */ -#define PCRS_TRIVIAL 4 /* Backreferences in the substitute are ignored */ +#define PCRS_TRIVIAL 2 /* Backreferences in the substitute are ignored */ +#define PCRS_SUCCESS 4 /* Job did previously match */ + /* * Data types: */ /* A compiled substitute */ + typedef struct PCRS_SUBSTITUTE { char *text; /* The plaintext part of the substitute, with all backreferences stripped */ int backrefs; /* The number of backreferences */ @@ -102,19 +96,27 @@ typedef struct PCRS_SUBSTITUTE { int backref_count[PCRS_MAX_SUBMATCHES]; /* Array with the number of reference to each backref index */ } pcrs_substitute; +/* + * A match, including all captured subpatterns (submatches) + * Note: The zeroth is the whole match, the PCRS_MAX_SUBMATCHES + 1st + * is the range before the match, the PCRS_MAX_SUBMATCHES + 2nd is the + * range after the match. + */ + typedef struct PCRS_MATCH { - /* char *buffer; */ - int submatches; /* Number of submatches. Note: The zeroth is the whole match */ - int submatch_offset[PCRS_MAX_SUBMATCHES]; /* Offset for each submatch in the subject */ - int submatch_length[PCRS_MAX_SUBMATCHES]; /* Length of each submatch in the subject */ + int submatches; /* Number of submatches */ + int submatch_offset[PCRS_MAX_SUBMATCHES + 2]; /* Offset for each submatch in the subject */ + int submatch_length[PCRS_MAX_SUBMATCHES + 2]; /* Length of each submatch in the subject */ } pcrs_match; +/* A pcrs job */ + typedef struct PCRS_JOB { pcre *pattern; /* The compiled pcre pattern */ pcre_extra *hints; /* The pcre hints for the pattern */ int options; /* The pcre options (numeric) */ int flags; /* The pcrs and user flags (see "Flags" above) */ - pcrs_substitute *substitute; /* The compiles pcrs substitute */ + pcrs_substitute *substitute; /* The compiled pcrs substitute */ struct PCRS_JOB *next; /* Pointer for chaining jobs to joblists */ } pcrs_job; @@ -123,8 +125,8 @@ typedef struct PCRS_JOB { */ /* Main usage */ -extern pcrs_job *pcrs_compile_command(char *command, int *errptr); -extern pcrs_job *pcrs_compile(char *pattern, char *substitute, char *options, int *errptr); +extern pcrs_job *pcrs_compile_command(const char *command, int *errptr); +extern pcrs_job *pcrs_compile(const char *pattern, const char *substitute, const char *options, int *errptr); extern int pcrs_execute(pcrs_job *job, char *subject, int subject_length, char **result, int *result_length); /* Freeing jobs */ @@ -132,8 +134,8 @@ extern pcrs_job *pcrs_free_job(pcrs_job *job); extern void pcrs_free_joblist(pcrs_job *joblist); /* Expert usage */ -extern int pcrs_compile_perl_options(char *optstring, int *flags); -extern pcrs_substitute *pcrs_compile_replacement(char *replacement, int trivialflag, int *errptr); +extern int pcrs_parse_perl_options(const char *optstring, int *flags); +extern pcrs_substitute *pcrs_compile_replacement(const char *replacement, int trivialflag, int capturecount, int *errptr); #ifdef __cplusplus } /* extern "C" */