From b8db9f68d61b39169542648429f89b59d088c7bd Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 19 Mar 2007 22:59:24 +0000 Subject: [PATCH] ebl update git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4371 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/patches/testing/breg.h | 7 +++- bacula/patches/testing/resubst.c | 64 ++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/bacula/patches/testing/breg.h b/bacula/patches/testing/breg.h index e8d2e8dacc..746e04db42 100644 --- a/bacula/patches/testing/breg.h +++ b/bacula/patches/testing/breg.h @@ -35,8 +35,12 @@ #ifndef __BREG_H_ #define __BREG_H_ 1 -//#include "bregex.h" + +#ifndef HAVE_REGEX_H +#include "bregex.h" +#else #include +#endif /* Usage: * @@ -58,7 +62,6 @@ public: char *replace(const char *fname); void debug(); - /* private */ POOLMEM *expr; /* search epression */ POOLMEM *subst; /* substitution */ diff --git a/bacula/patches/testing/resubst.c b/bacula/patches/testing/resubst.c index 3e5b4d61c1..5bba54d34e 100644 --- a/bacula/patches/testing/resubst.c +++ b/bacula/patches/testing/resubst.c @@ -12,11 +12,32 @@ * edit() */ +typedef struct { + char *subst; + char *motif; + int nmatch; + regex_t preg; +} breg_t ; + +breg_t *breg_new(char *regexp) +{ + Dmsg0(500, "breg: creating new breg_t object\n"); + RUNSCRIPT *cmd = (RUNSCRIPT *)malloc(sizeof(RUNSCRIPT)); + memset(cmd, 0, sizeof(RUNSCRIPT)); + cmd->reset_default(); + + return cmd; + +} + + int compute_dest_len(char *fname, char *subst, regmatch_t *pmatch, int nmatch) { int len=0; char *p; + int no; + if (!fname || !subst || !pmatch || !nmatch) { return 0; } @@ -26,7 +47,6 @@ int compute_dest_len(char *fname, char *subst, return 0; } - int no; for (p = subst++; *p ; p = subst++) { /* match $1 \1 back references */ if ((*p == '$' || *p == '\\') && ('0' <= *subst && *subst <= '9')) { @@ -56,6 +76,44 @@ int compute_dest_len(char *fname, char *subst, */ bool extract_regexp(char *motif, regex_t *preg, POOLMEM **subst) { + if (!motif || !preg || !subst) { + return false; + } + /* extract 1st part */ + POOLMEM *dest = bstrdup(motif); + char sep = motif[0]; + char *search = motif + 1; + char *replace; + bool ok = false; + bool found_motif = false; + + while (*search && !ok) { + if (*search == sep && *dest == '\\') { + *dest++ = *++search; /* we skip separator */ + + } else if (*search == sep) { + *dest++ = '\0'; + if (found_motif) { /* already have found motif */ + ok = true; + } else { + replace = dest; /* get replaced string */ + found_motif = true; + } + } else { + *dest++ = *search++; + } + } + *dest = '\0'; /* in case of */ + + if (!ok || !found_motif) { + /* bad regexp */ + free(dest); + return false; + } + + + + /* rechercher le 1er car sans \ devant */ /* compiler la re dans preg */ /* extraire le subst */ @@ -67,6 +125,8 @@ char *edit_subst(char *fname, char *subst, regmatch_t *pmatch, char *dest) { int i; char *p; + int no; + int len; /* il faut recopier fname dans dest * on recopie le debut fname -> pmatch[0].rm_so @@ -78,8 +138,6 @@ char *edit_subst(char *fname, char *subst, regmatch_t *pmatch, char *dest) /* on recopie le motif de remplacement (avec tous les $x) */ - int no; - int len; for (p = subst++; *p ; p = subst++) { /* match $1 \1 back references */ if ((*p == '$' || *p == '\\') && ('0' <= *subst && *subst <= '9')) { -- 2.39.5