-const char pcrs_rcs[] = "$Id: pcrs.c,v 1.19 2002/03/08 14:47:48 oes Exp $";
+const char pcrs_rcs[] = "$Id: pcrs.c,v 2.4 2003/01/21 02:49:27 david__schmidt Exp $";
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/pcrs.c,v $
+ * File : $Source: /cvsroot/ijbswa/current/src/pcrs.c,v $
*
* Purpose : pcrs is a supplement to the pcre library by Philip Hazel
* <ph10@cam.ac.uk> and adds Perl-style substitution. That
*
* Revisions :
* $Log: pcrs.c,v $
+ * Revision 2.4 2003/01/21 02:49:27 david__schmidt
+ * Developer TODO 612294: src: C++ keyword as variable name
+ * I changed all ocurrences of 'new' to 'new_something' wherever I found
+ * one. I also brought up all the source files in MSDEV to see if I could
+ * spot any highlighted keywords that really were variables. Non-scientific,
+ * but at least I tried. :-)
+ *
+ * Revision 2.3 2002/10/08 16:25:30 oes
+ * Bugfix: Need to check validity of backreferences explicitly, because when max_matches are reached and matches is expanded, realloc() does not zero the memory. Fixes Bug # 606227
+ *
+ * Revision 2.2 2002/09/04 15:52:02 oes
+ * Synced with the stable branch:
+ * Revision 1.19.2.1 2002/08/10 11:23:40 oes
+ * Include prce.h via project.h, where the appropriate
+ * source will have been selected
+ *
+ * Revision 2.1 2002/08/26 11:18:24 sarantis
+ * Fix typo.
+ *
+ * Revision 2.0 2002/06/04 14:34:21 jongfoster
+ * Moving source files to src/
+ *
* Revision 1.19 2002/03/08 14:47:48 oes
* Cosmetics
*
*********************************************************************/
\f
-#include <pcre.h>
+/*
+ * Include project.h just so that the right pcre.h gets
+ * included from there
+ */
+#include "project.h"
+
#include <string.h>
#include <ctype.h>
*
* Returns : On success, the number of substitutions that were made.
* May be > 1 if job->flags contained PCRS_GLOBAL
- * On failiure, the (negative) pcre error code describing the
- * failiure, which may be translated to text using pcrs_strerror().
+ * On failure, the (negative) pcre error code describing the
+ * failure, which may be translated to text using pcrs_strerror().
*
*********************************************************************/
int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length)
{
pcrs_job *job;
- char *old, *new;
+ char *old_item, *new_item;
int hits, total_hits;
- old = subject;
+ old_item = subject;
*result_length = subject_length;
hits = total_hits = 0;
for (job = joblist; job != NULL; job = job->next)
{
- hits = pcrs_execute(job, old, *result_length, &new, result_length);
+ hits = pcrs_execute(job, old_item, *result_length, &new_item, result_length);
- if (old != subject) free(old);
+ if (old_item != subject) free(old_item);
if (hits < 0)
{
else
{
total_hits += hits;
- old = new;
+ old_item = new_item;
}
}
- *result = new;
+ *result = new_item;
return(total_hits);
}
*
* Returns : On success, the number of substitutions that were made.
* May be > 1 if job->flags contained PCRS_GLOBAL
- * On failiure, the (negative) pcre error code describing the
- * failiure, which may be translated to text using pcrs_strerror().
+ * On failure, the (negative) pcre error code describing the
+ * failure, which may be translated to text using pcrs_strerror().
*
*********************************************************************/
int pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **result, size_t *result_length)
else
offset = offsets[1];
}
- /* Pass pcre error through if (bad) failiure */
+ /* Pass pcre error through if (bad) failure */
if (submatches < PCRE_ERROR_NOMATCH)
{
free(matches);
if (k != job->substitute->backrefs
/* ..in legal range.. */
&& job->substitute->backref[k] < PCRS_MAX_SUBMATCHES + 2
- /* ..and referencing a nonempty match.. */
+ /* ..and referencing a real submatch.. */
+ && job->substitute->backref[k] < matches[i].submatches
+ /* ..that is nonempty.. */
&& matches[i].submatch_length[job->substitute->backref[k]] > 0)
{
/* ..copy the submatch that is ref'd. */