[augeas-devel] augeas: master - Allow NULLS in regexp_(union|concat)_n
David Lutterkort
lutter at fedoraproject.org
Tue Sep 1 18:09:11 UTC 2009
Gitweb: http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=eab014ed4358eb9d45bcea2c772526afbe2fe8bb
Commit: eab014ed4358eb9d45bcea2c772526afbe2fe8bb
Parent: 40b84befb36130bcb91e3597556384439c34f9ab
Author: David Lutterkort <lutter at redhat.com>
AuthorDate: Sun Dec 14 23:49:34 2008 -0800
Committer: David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Aug 31 14:36:27 2009 -0700
Allow NULLS in regexp_(union|concat)_n
It's sometimes useful to union/concat N regexps even if some of them are
NULL. regexp_(union|concat)_n will ignore them.
---
src/regexp.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/regexp.c b/src/regexp.c
index 886875f..df99656 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -139,13 +139,19 @@ regexp_union_n(struct info *info, int n, struct regexp **r) {
char *pat, *p;
for (int i=0; i < n; i++)
- len += strlen(r[i]->pattern->str) + 2;
+ if (r[i] != NULL)
+ len += strlen(r[i]->pattern->str) + strlen("()|");
- if (ALLOC_N(pat, len + (n-1) + 1) < 0)
+ if (len == 0)
+ return NULL;
+
+ if (ALLOC_N(pat, len) < 0)
return NULL;
p = pat;
for (int i=0; i < n; i++) {
+ if (r[i] == NULL)
+ continue;
if (i > 0)
*p++ = '|';
*p++ = '(';
@@ -172,13 +178,19 @@ regexp_concat_n(struct info *info, int n, struct regexp **r) {
char *pat, *p;
for (int i=0; i < n; i++)
- len += strlen(r[i]->pattern->str) + 2;
+ if (r[i] != NULL)
+ len += strlen(r[i]->pattern->str) + strlen("()");
+
+ if (len == 0)
+ return NULL;
if (ALLOC_N(pat, len+1) < 0)
return NULL;
p = pat;
for (int i=0; i < n; i++) {
+ if (r[i] == NULL)
+ continue;
*p++ = '(';
p = stpcpy(p, r[i]->pattern->str);
*p++ = ')';
More information about the augeas-devel
mailing list