+/*********************************************************************
+ *
+ * Function : pcrs_execute_list
+ *
+ * Description : This is a multiple job wrapper for pcrs_execute().
+ * Apply the regular substitutions defined by the jobs in
+ * the joblist to the subject.
+ * The subject itself is left untouched, memory for the result
+ * is malloc()ed and it is the caller's responsibility to free
+ * the result when it's no longer needed.
+ *
+ * Parameters :
+ * 1 : joblist = the chained list of pcrs_jobs to be executed
+ * 2 : subject = the subject string
+ * 3 : subject_length = the subject's length
+ * INCLUDING the terminating zero, if string!
+ * 4 : result = char** for returning the result
+ * 5 : result_length = size_t* for returning the result's length
+ *
+ * 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().
+ *
+ *********************************************************************/
+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;
+ int hits, total_hits;
+
+ old = 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);
+
+ if (old != subject) free(old);
+
+ if (hits < 0)
+ {
+ return(hits);
+ }
+ else
+ {
+ total_hits += hits;
+ old = new;
+ }
+ }
+
+ *result = new;
+ return(total_hits);
+
+}
+
+