From: Eric Bollengier Date: Wed, 2 May 2007 13:26:44 +0000 (+0000) Subject: ebl use only POSIX regex stuff (drop GNU re_search) to fix X-Git-Tag: Release-7.0.0~6454 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d5ebf7ea0463d13b3c8abeb0120180ebe45bb31c;p=bacula%2Fbacula ebl use only POSIX regex stuff (drop GNU re_search) to fix compilation bug on freebsd git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4675 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/projects b/bacula/projects index 1e370d6970..add7b575f3 100644 --- a/bacula/projects +++ b/bacula/projects @@ -8,6 +8,7 @@ Items Completed: Item: 18 Quick release of FD-SD connection after backup. Item: 40 Include JobID in spool file name Item: 25 Implement huge exclude list support using dlist +Item: 41 Enable to relocate files and directories when restoring Summary: Item: 1 Accurate restoration of renamed/deleted files @@ -50,7 +51,7 @@ Item: 37 Add an item to the restore option where you can select a pool Item: 38 Include timestamp of job launch in "stat clients" output Item: 39 Message mailing based on backup types Item: 40* Include JobID in spool file name - +Item: 41* Enable to relocate files and directories when restoring Item 1: Accurate restoration of renamed/deleted files Date: 28 November 2005 @@ -1130,10 +1131,10 @@ Item 40: Include JobID in spool file name ****DONE**** stamp is useful (and should be retained). ============= New Freature Requests after vote of 26 Jan 2007 ======== -Item n: Enable to relocate files and directories when restoring +Item 41: Enable to relocate files and directories when restoring Date: 2007-03-01 Origin: Eric Bollengier - Status: + Status: Done. What: The where= option is not powerful enough. It will be a great feature if bacula can restore a file in the @@ -1157,8 +1158,7 @@ Item n: Enable to relocate files and directories when restoring Notes: I think we can enhance the where= option very easily by - allowing regexp expression. (by replacing bregex by libpcre - see http://en.wikipedia.org/wiki/PCRE and http://www.pcre.org/) + allowing regexp expression. Since, many users think that regexp are not user friendly, i think that bat, bconsole or brestore must provide a simple way to diff --git a/bacula/src/lib/breg.c b/bacula/src/lib/breg.c index 8c53e6a93b..2b121912a1 100644 --- a/bacula/src/lib/breg.c +++ b/bacula/src/lib/breg.c @@ -55,15 +55,6 @@ BREGEXP *new_bregexp(const char *motif) self->result = get_pool_memory(PM_FNAME); self->result[0] = '\0'; -#ifdef HAVE_REGEX_H - /* TODO: que devient cette memoire... */ - self->_regs_match = (int *) bmalloc (2*RE_NREGS * sizeof(int)); - - self->regs.num_regs = RE_NREGS; - self->regs.start = self->_regs_match; - self->regs.end = self->_regs_match+(RE_NREGS * sizeof(int)); -#endif - return self; } @@ -81,10 +72,6 @@ void free_bregexp(BREGEXP *self) if (self->result) { free_pool_memory(self->result); } - if (self->_regs_match) { - bfree(self->_regs_match); - } - regfree(&self->preg); bfree(self); } @@ -234,29 +221,23 @@ bool BREGEXP::extract_regexp(const char *motif) return true; } -#ifndef HAVE_REGEX_H - #define BREGEX_CAST unsigned -#else - #define BREGEX_CAST const -#endif - /* return regexp->result */ char *BREGEXP::replace(const char *fname) { success = false; /* use this.success to known if it's ok */ int flen = strlen(fname); - int rc = re_search(&preg, (BREGEX_CAST char*) fname, flen, 0, flen, ®s); + int rc = regexec(&preg, fname, RE_NREGS, regs, 0); - if (rc < 0) { + if (rc == REG_NOMATCH) { Dmsg0(500, "bregexp: regex mismatch\n"); return return_fname(fname, flen); } - int len = compute_dest_len(fname, ®s); + int len = compute_dest_len(fname, regs); if (len) { result = check_pool_memory_size(result, len); - edit_subst(fname, ®s); + edit_subst(fname, regs); success = true; Dmsg2(500, "bregexp: len = %i, result_len = %i\n", len, strlen(result)); @@ -275,7 +256,7 @@ char *BREGEXP::return_fname(const char *fname, int len) return result; } -int BREGEXP::compute_dest_len(const char *fname, struct re_registers *regs) +int BREGEXP::compute_dest_len(const char *fname, regmatch_t regs[]) { int len=0; char *p; @@ -287,7 +268,7 @@ int BREGEXP::compute_dest_len(const char *fname, struct re_registers *regs) } /* match failed ? */ - if (regs->start[0] < 0) { + if (regs[0].rm_so < 0) { return 0; } @@ -299,8 +280,8 @@ int BREGEXP::compute_dest_len(const char *fname, struct re_registers *regs) /* we check if the back reference exists */ /* references can not match if we are using (..)? */ - if (regs->start[no] >= 0 && regs->end[no] >= 0) { - len += regs->end[no] - regs->start[no]; + if (regs[no].rm_so >= 0 && regs[no].rm_eo >= 0) { + len += regs[no].rm_eo - regs[no].rm_so; } } else { @@ -309,13 +290,13 @@ int BREGEXP::compute_dest_len(const char *fname, struct re_registers *regs) } /* $0 is replaced by subst */ - len -= regs->end[0] - regs->start[0]; + len -= regs[0].rm_eo - regs[0].rm_so; len += strlen(fname) + 1; return len; } -char *BREGEXP::edit_subst(const char *fname, struct re_registers *regs) +char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[]) { int i; char *p; @@ -327,7 +308,7 @@ char *BREGEXP::edit_subst(const char *fname, struct re_registers *regs) * on recopie le debut fname -> regs->start[0] */ - for (i = 0; i < regs->start[0] ; i++) { + for (i = 0; i < regs[0].rm_so ; i++) { result[i] = fname[i]; } @@ -339,9 +320,9 @@ char *BREGEXP::edit_subst(const char *fname, struct re_registers *regs) no = *psubst++ - '0'; /* have a back reference ? */ - if (regs->start[no] >= 0 && regs->end[no] >= 0) { - len = regs->end[no] - regs->start[no]; - bstrncpy(result + i, fname + regs->start[no], len + 1); + if (regs[no].rm_so >= 0 && regs[no].rm_eo >= 0) { + len = regs[no].rm_eo - regs[no].rm_so; + bstrncpy(result + i, fname + regs[no].rm_so, len + 1); i += len ; } @@ -351,7 +332,7 @@ char *BREGEXP::edit_subst(const char *fname, struct re_registers *regs) } /* we copy what is out of the match */ - strcpy(result + i, fname + regs->end[0]); + strcpy(result + i, fname + regs[0].rm_eo); return result; } diff --git a/bacula/src/lib/breg.h b/bacula/src/lib/breg.h index 9c1e50a8c7..5ac23759a6 100644 --- a/bacula/src/lib/breg.h +++ b/bacula/src/lib/breg.h @@ -69,14 +69,12 @@ public: POOLMEM *expr; /* search epression */ POOLMEM *subst; /* substitution */ regex_t preg; /* regex_t result of regcomp() */ - struct re_registers regs; /* contains match */ + regmatch_t regs[RE_NREGS]; /* contains match */ char *eor; /* end of regexp in expr */ - int *_regs_match; - char *return_fname(const char *fname, int len); /* return fname as result */ - char *edit_subst(const char *fname, struct re_registers *regs); - int compute_dest_len(const char *fname, struct re_registers *regs); + char *edit_subst(const char *fname, regmatch_t regs[]); + int compute_dest_len(const char *fname, regmatch_t regs[]); bool extract_regexp(const char *motif); }; diff --git a/bacula/src/lib/bregex.c b/bacula/src/lib/bregex.c index 939c84cdc2..174b64dd38 100644 --- a/bacula/src/lib/bregex.c +++ b/bacula/src/lib/bregex.c @@ -1479,6 +1479,22 @@ int regcomp(regex_t * bufp, const char *regex, int cflags) return 0; } +void re_registers_to_regmatch(regexp_registers_t old_regs, + regmatch_t pmatch[], + size_t nmatch) +{ + size_t i=0; + + /* We have to set the last entry to -1 */ + nmatch = nmatch - 1; + for (i=0; (i < nmatch) && (old_regs->start[i] > -1) ; i++) { + pmatch[i].rm_so = old_regs->start[i]; + pmatch[i].rm_eo = old_regs->end[i]; + } + + pmatch[i].rm_eo = pmatch[i].rm_so = -1; +} + int regexec(regex_t * preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) { @@ -1486,6 +1502,7 @@ int regexec(regex_t * preg, const char *string, size_t nmatch, int len = strlen(string); struct re_registers regs; stat = re_search(preg, (unsigned char *)string, len, 0, len, ®s); + re_registers_to_regmatch(®s, pmatch, nmatch); /* stat is the start position in the string base 0 where * the pattern was found or negative if not found. */