+/*********************************************************************
+ *
+ * Function : execute_single_pcrs_command
+ *
+ * Description : Apply single pcrs command 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 : subject = the subject (== original) string
+ * 2 : pcrs_command = the pcrs command as string (s@foo@bar@)
+ * 3 : hits = int* for returning the number of modifications
+ *
+ * Returns : NULL in case of errors, otherwise the
+ * result of the pcrs command.
+ *
+ *********************************************************************/
+char *execute_single_pcrs_command(char *subject, const char *pcrs_command, int *hits)
+{
+ int error;
+ size_t size;
+ char *result = NULL;
+ pcrs_job *job;
+
+ assert(subject);
+ assert(pcrs_command);
+
+ *hits = 0;
+ size = strlen(subject);
+
+ if (NULL == (job = pcrs_compile_command(pcrs_command, &error)))
+ {
+ log_error(LOG_LEVEL_ERROR, "Failed to compile pcrs command \"%s\". Error: %d.",
+ pcrs_command, error);
+ }
+ else if ((*hits = pcrs_execute(job, subject, size, &result, &size)) < 0)
+ {
+ log_error(LOG_LEVEL_ERROR, "Failed to execute pcrs command: %s", pcrs_strerror(*hits));
+ *hits = 0;
+ freez(result);
+ }
+
+ if (job)
+ {
+ job = pcrs_free_job(job);
+ }
+
+ return result;
+
+}