1 #ifndef PCRS_H_INCLUDED
2 #define PCRS_H_INCLUDED
4 /*********************************************************************
6 * File : $Source: /cvsroot/ijbswa/current/pcrs.h,v $
8 * Purpose : Header file for pcrs.c
10 * Copyright : see pcrs.c
12 *********************************************************************/
14 #define PCRS_H_VERSION "$Id: pcrs.h,v 1.17 2009/05/16 13:27:20 fabiankeil Exp $"
29 #define PCRS_MAX_SUBMATCHES 33 /* Maximum number of capturing subpatterns allowed. MUST be <= 99! FIXME: Should be dynamic */
30 #define PCRS_MAX_MATCH_INIT 40 /* Initial amount of matches that can be stored in global searches */
31 #define PCRS_MAX_MATCH_GROW 1.6 /* Factor by which storage for matches is extended if exhausted */
36 * They are supposed to be handled together with PCRE error
37 * codes and have to start with an offset to prevent overlaps.
39 * PCRE 6.7 uses error codes from -1 to -21, PCRS error codes
40 * below -100 should be safe for a while.
42 #define PCRS_ERR_NOMEM -100 /* Failed to acquire memory. */
43 #define PCRS_ERR_CMDSYNTAX -101 /* Syntax of s///-command */
44 #define PCRS_ERR_STUDY -102 /* pcre error while studying the pattern */
45 #define PCRS_ERR_BADJOB -103 /* NULL job pointer, pattern or substitute */
46 #define PCRS_WARN_BADREF -104 /* Backreference out of range */
47 #define PCRS_WARN_TRUNCATION -105 /* At least one pcrs variable was too big,
48 * only the first part was used. */
51 #define PCRS_GLOBAL 1 /* Job should be applied globally, as with perl's g option */
52 #define PCRS_TRIVIAL 2 /* Backreferences in the substitute are ignored */
53 #define PCRS_SUCCESS 4 /* Job did previously match */
60 /* A compiled substitute */
63 char *text; /* The plaintext part of the substitute, with all backreferences stripped */
64 size_t length; /* The substitute may not be a valid C string so we can't rely on strlen(). */
65 int backrefs; /* The number of backreferences */
66 int block_offset[PCRS_MAX_SUBMATCHES]; /* Array with the offsets of all plaintext blocks in text */
67 size_t block_length[PCRS_MAX_SUBMATCHES]; /* Array with the lengths of all plaintext blocks in text */
68 int backref[PCRS_MAX_SUBMATCHES]; /* Array with the backref number for all plaintext block borders */
69 int backref_count[PCRS_MAX_SUBMATCHES + 2]; /* Array with the number of references to each backref index */
74 * A match, including all captured subpatterns (submatches)
75 * Note: The zeroth is the whole match, the PCRS_MAX_SUBMATCHES + 0th
76 * is the range before the match, the PCRS_MAX_SUBMATCHES + 1th is the
77 * range after the match.
81 int submatches; /* Number of captured subpatterns */
82 int submatch_offset[PCRS_MAX_SUBMATCHES + 2]; /* Offset for each submatch in the subject */
83 size_t submatch_length[PCRS_MAX_SUBMATCHES + 2]; /* Length of each submatch in the subject */
89 typedef struct PCRS_JOB {
90 pcre *pattern; /* The compiled pcre pattern */
91 pcre_extra *hints; /* The pcre hints for the pattern */
92 int options; /* The pcre options (numeric) */
93 int flags; /* The pcrs and user flags (see "Flags" above) */
94 pcrs_substitute *substitute; /* The compiled pcrs substitute */
95 struct PCRS_JOB *next; /* Pointer for chaining jobs to joblists */
104 extern pcrs_job *pcrs_compile_command(const char *command, int *errptr);
105 extern pcrs_job *pcrs_compile(const char *pattern, const char *substitute, const char *options, int *errptr);
106 extern int pcrs_execute(pcrs_job *job, const char *subject, size_t subject_length, char **result, size_t *result_length);
107 extern int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length);
110 extern pcrs_job *pcrs_free_job(pcrs_job *job);
111 extern void pcrs_free_joblist(pcrs_job *joblist);
113 /* Info on errors: */
114 extern const char *pcrs_strerror(const int error);
116 extern int pcrs_job_is_dynamic(char *job);
117 extern char pcrs_get_delimiter(const char *string);
118 extern char *pcrs_execute_single_command(const char *subject, const char *pcrs_command, int *hits);
120 * Variable/value pair for dynamic pcrs commands.
129 extern pcrs_job *pcrs_compile_dynamic_command(char *pcrs_command, const struct pcrs_variable v[], int *error);
131 /* Only relevant for maximum pcrs variable size */
132 #ifndef PCRS_BUFFER_SIZE
133 #define PCRS_BUFFER_SIZE 4000
134 #endif /* ndef PCRS_BUFFER_SIZE */
136 #endif /* ndef PCRS_H_INCLUDED */