*
* Revisions :
* $Log: pcrs.h,v $
+ * Revision 1.10 2002/03/08 13:44:48 oes
+ * Hiding internal functions, preventing double inclusion of pcre.h
+ *
+ * Revision 1.9 2001/08/18 11:35:29 oes
+ * - Introduced pcrs_strerror()
+ * - added pcrs_execute_list()
+ *
+ * Revision 1.8 2001/08/15 15:32:50 oes
+ * Replaced the hard limit for the maximum number of matches
+ * by dynamic reallocation
+ *
* Revision 1.7 2001/08/05 13:13:11 jongfoster
* Making parameters "const" where possible.
*
*
*********************************************************************/
-#define PCRS_H_VERSION "$Id: pcrs.h,v 1.8 2001/08/15 15:26:58 oes Exp $"
+#define PCRS_H_VERSION "$Id: pcrs.h,v 1.10 2002/03/08 13:44:48 oes Exp $"
\f
+#ifndef _PCRE_H
#include <pcre.h>
+#endif
#ifdef __cplusplus
extern "C" {
#define TRUE 1
/* Capacity */
-#define PCRS_MAX_SUBMATCHES 33 /* Maximum number of capturing subpatterns allowed. FIXME: Should be dynamic */
+#define PCRS_MAX_SUBMATCHES 33 /* Maximum number of capturing subpatterns allowed. MUST be <= 99! 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 */
+#define PCRS_MAX_MATCH_GROW 1.6 /* Factor by which storage for matches is extended if exhausted */
/* Error codes */
#define PCRS_ERR_NOMEM -10 /* Failed to acquire memory. */
#define PCRS_ERR_CMDSYNTAX -11 /* Syntax of s///-command */
#define PCRS_ERR_STUDY -12 /* pcre error while studying the pattern */
#define PCRS_ERR_BADJOB -13 /* NULL job pointer, pattern or substitute */
+#define PCRS_WARN_BADREF -14 /* Backreference out of range */
/* Flags */
#define PCRS_GLOBAL 1 /* Job should be applied globally, as with perl's g option */
/* 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 */
- int block_offset[PCRS_MAX_SUBMATCHES]; /* Array with the offsets of all plaintext blocks in text */
- int block_length[PCRS_MAX_SUBMATCHES]; /* Array with the lengths of all plaintext blocks in text */
- int backref[PCRS_MAX_SUBMATCHES]; /* Array with the backref number for all plaintext block borders */
- int backref_count[PCRS_MAX_SUBMATCHES]; /* Array with the number of reference to each backref index */
+typedef struct {
+ char *text; /* The plaintext part of the substitute, with all backreferences stripped */
+ int backrefs; /* The number of backreferences */
+ int block_offset[PCRS_MAX_SUBMATCHES]; /* Array with the offsets of all plaintext blocks in text */
+ size_t block_length[PCRS_MAX_SUBMATCHES]; /* Array with the lengths of all plaintext blocks in text */
+ int backref[PCRS_MAX_SUBMATCHES]; /* Array with the backref number for all plaintext block borders */
+ int backref_count[PCRS_MAX_SUBMATCHES + 2]; /* Array with the number of references 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
+ * Note: The zeroth is the whole match, the PCRS_MAX_SUBMATCHES + 0th
+ * is the range before the match, the PCRS_MAX_SUBMATCHES + 1th is the
* range after the match.
*/
-typedef struct PCRS_MATCH {
- 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 */
+typedef struct {
+ int submatches; /* Number of captured subpatterns */
+ int submatch_offset[PCRS_MAX_SUBMATCHES + 2]; /* Offset for each submatch in the subject */
+ size_t submatch_length[PCRS_MAX_SUBMATCHES + 2]; /* Length of each submatch in the subject */
} pcrs_match;
-/* A pcrs job */
+
+/* A PCRS job */
typedef struct PCRS_JOB {
pcre *pattern; /* The compiled pcre pattern */
struct PCRS_JOB *next; /* Pointer for chaining jobs to joblists */
} pcrs_job;
+
/*
* Prototypes:
*/
/* Main usage */
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);
+extern int pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **result, size_t *result_length);
+extern int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length);
/* Freeing jobs */
extern pcrs_job *pcrs_free_job(pcrs_job *job);
extern void pcrs_free_joblist(pcrs_job *joblist);
-/* Expert usage */
-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);
+/* Info on errors: */
+extern const char *pcrs_strerror(const int error);
+
#ifdef __cplusplus
} /* extern "C" */