From 7a3afeed4c190c95b4b4c4292295b41ee8e0cae1 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sat, 21 Apr 2007 15:05:27 +0000 Subject: [PATCH] ebl cleanup git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4581 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/patches/testing/breg.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/bacula/patches/testing/breg.c b/bacula/patches/testing/breg.c index 7468c6572d..0cc18c8091 100644 --- a/bacula/patches/testing/breg.c +++ b/bacula/patches/testing/breg.c @@ -375,17 +375,20 @@ char *bregexp_escape_string(char *dest, char *src, char sep) return ret; } +static char regexp_sep = '!'; +static char *str_strip_prefix = "!%s!!i"; +static char *str_add_prefix = "!^!%s!"; +static char *str_add_suffix = "!([^/])$!$1%s!"; + int bregexp_get_build_where_size(char *strip_prefix, char *add_prefix, char *add_suffix) { - /* strip_prefix = !strip_prefix!!i 4 bytes - * add_prefix = !^!add_prefix! 5 bytes - * add_suffix = !([^/])$!$1add_suffix! 13 bytes - */ - int str_size = ((strip_prefix?strlen(strip_prefix)+4:0) + - (add_prefix?strlen(add_prefix)+5 :0) + /* escape + 3*, + \0 */ - (add_suffix?strlen(add_suffix)+14 :0) ) * 2 + 3 + 1; + int str_size = ((strip_prefix?strlen(strip_prefix)+strlen(str_strip_prefix):0) + + (add_prefix?strlen(add_prefix)+strlen(str_add_prefix) :0) + + (add_suffix?strlen(add_suffix)+strlen(str_add_suffix) :0) ) + /* escape + 3*, + \0 */ + * 2 + 3 + 1; Dmsg1(1, "bregexp_get_build_where_size = %i\n", str_size); return str_size; @@ -397,7 +400,7 @@ int bregexp_get_build_where_size(char *strip_prefix, * int len = bregexp_get_build_where_size(a,b,c) ; * char *dest = (char *) bmalloc (len * sizeof(char)); * bregexp_build_where(dest, len, a, b, c); - * free(dest); + * bfree(dest); * */ char *bregexp_build_where(char *dest, int str_size, @@ -406,29 +409,28 @@ char *bregexp_build_where(char *dest, int str_size, char *add_suffix) { int len=0; - char sep = '!'; POOLMEM *str_tmp = get_memory(str_size); *str_tmp = *dest = '\0'; if (strip_prefix) { - len += bsnprintf(dest, str_size - len, "!%s!!i", - bregexp_escape_string(str_tmp, strip_prefix, sep)); + len += bsnprintf(dest, str_size - len, str_strip_prefix, + bregexp_escape_string(str_tmp, strip_prefix, regexp_sep)); } if (add_suffix) { if (len) dest[len++] = ','; - len += bsnprintf(dest + len, str_size - len, "!([^/])$!$1%s!", - bregexp_escape_string(str_tmp, add_suffix, sep)); + len += bsnprintf(dest + len, str_size - len, str_add_suffix, + bregexp_escape_string(str_tmp, add_suffix, regexp_sep)); } if (add_prefix) { if (len) dest[len++] = ','; - len += bsnprintf(dest + len, str_size - len, "!^!%s!", - bregexp_escape_string(str_tmp, add_prefix, sep)); + len += bsnprintf(dest + len, str_size - len, str_add_prefix, + bregexp_escape_string(str_tmp, add_prefix, regexp_sep)); } free_pool_memory(str_tmp); @@ -441,5 +443,5 @@ void BREGEXP::debug() { printf("expr=[%s]\n", expr); printf("subst=[%s]\n", subst); - printf("result=%s\n", result?result:"(null)"); + printf("result=%s\n", NPRT(result)); } -- 2.39.5