return NULL;
}
- static int _start[RE_NREGS];
- static int _end[RE_NREGS];
-
self->result = get_pool_memory(PM_FNAME);
self->result[0] = '\0';
/* Apply all regexps to fname
*/
-char *apply_bregexps(const char *fname, alist *bregexps)
+bool apply_bregexps(const char *fname, alist *bregexps, char **result)
{
BREGEXP *elt;
+ bool ok=false;
+
char *ret = (char *) fname;
foreach_alist(elt, bregexps) {
ret = elt->replace(ret);
+ ok = ok || elt->success;
}
Dmsg2(500, "bregexp: fname=%s ret=%s\n", fname, ret);
- return ret;
+
+ *result = ret;
+ return ok;
}
/* return an alist of BREGEXP or return NULL if it's not a
if (!(sep == '!' ||
sep == ':' ||
sep == ';' ||
- sep == 'ยง' ||
+ sep == '|' ||
sep == ',' ||
sep == '&' ||
sep == '%' ||
char *search = (char *) motif + 1;
int options = REG_EXTENDED | REG_NEWLINE;
bool ok = false;
- bool found_motif = false;
/* extract 1st part */
char *dest = expr = bstrdup(motif);
/* 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);
if (len) {
result = check_pool_memory_size(result, len);
edit_subst(fname, ®s);
-
+ success = true;
Dmsg2(500, "bregexp: len = %i, result_len = %i\n", len, strlen(result));
} else { /* error in substitution */
class BREGEXP {
public:
POOLMEM *result; /* match result */
- char *replace(const char *fname);
+ bool success; /* match is ok */
+
+ char *replace(const char *fname); /* return this.result */
void debug();
/* private */
/* fill an alist with BREGEXP from where */
alist *get_bregexps(const char *where);
-char *apply_bregexps(const char *fname, alist *bregexps);
+/* apply every regexps from the alist */
+bool apply_bregexps(const char *fname, alist *bregexps, char **result);
/* foreach_alist free RUNSCRIPT */
void free_bregexps(alist *bregexps); /* you have to free alist */
while (fgets(data, sizeof(data)-1, fd)) {
strip_trailing_newline(data);
- p = apply_bregexps(data, list);
+ apply_bregexps(data, list, &p);
printf("%s => %s\n", data, p);
}
fclose(fd);