[augeas-devel] [PATCH] * src/fa.h (fa_as_regexp): cleaner prototype

David Lutterkort lutter at redhat.com
Mon Mar 16 03:08:53 UTC 2009


---
 src/fa.c       |    5 ++++-
 src/fa.h       |    4 +++-
 src/regexp.c   |    3 ++-
 tests/fatest.c |   12 ++++++++----
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/fa.c b/src/fa.c
index afe907c..8abe459 100644
--- a/src/fa.c
+++ b/src/fa.c
@@ -3211,12 +3211,13 @@ static int re_collapse_trans(struct state *s1, struct state *s2,
  *     the transition INI -> FIN
  * (5) Convert that STRUCT RE to a string with RE_AS_STRING
  */
-int fa_as_regexp(struct fa *fa, char **regexp) {
+int fa_as_regexp(struct fa *fa, char **regexp, size_t *regexp_len) {
     int r;
     struct state *fin = NULL, *ini = NULL;
     struct re *eps = make_re(EPSILON);
 
     *regexp = NULL;
+    *regexp_len = 0;
     fa = fa_clone(fa);
 
     fin = add_state(fa,1);
@@ -3280,6 +3281,8 @@ int fa_as_regexp(struct fa *fa, char **regexp) {
         }
     }
     fa_free(fa);
+    if (*regexp != NULL)
+        *regexp_len = strlen(*regexp);
 
     return 0;
  error:
diff --git a/src/fa.h b/src/fa.h
index 5b0e4f1..08b3087 100644
--- a/src/fa.h
+++ b/src/fa.h
@@ -191,10 +191,12 @@ int fa_ambig_example(struct fa *fa1, struct fa *fa2,
  * expression short; to guarantee reasonably short regexps, the automaton
  * should be minimized before passing it to this routine.
  *
+ * On success, REGEXP_LEN is set to the length of REGEXP
+ *
  * Return 0 on success, and a negative number on failure. The only reason
  * to fail for FA_AS_REGEXP is running out of memory.
  */
-int fa_as_regexp(struct fa *fa, char **regexp);
+int fa_as_regexp(struct fa *fa, char **regexp, size_t *regexp_len);
 #endif
 
 
diff --git a/src/regexp.c b/src/regexp.c
index 5d02bcb..179d7c1 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -190,6 +190,7 @@ regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2) {
     struct fa *fa = NULL, *fa1 = NULL, *fa2 = NULL;
     int r;
     char *s = NULL;
+    size_t s_len;
 
     r = fa_compile(p1, strlen(p1), &fa1);
     if (r != REG_NOERROR)
@@ -203,7 +204,7 @@ regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2) {
     if (fa == NULL)
         goto error;
 
-    r = fa_as_regexp(fa, &s);
+    r = fa_as_regexp(fa, &s, &s_len);
     if (r < 0)
         goto error;
 
diff --git a/tests/fatest.c b/tests/fatest.c
index af8e2d2..fd0b66b 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -71,6 +71,7 @@ static struct fa *mark(struct fa *fa) {
 
 static void assertAsRegexp(CuTest *tc, struct fa *fa) {
     char *re;
+    size_t re_len;
     struct fa *fa1, *fa2;
     struct fa *empty = mark(fa_make_basic(FA_EPSILON));
     int r;
@@ -81,7 +82,7 @@ static void assertAsRegexp(CuTest *tc, struct fa *fa) {
     /* monster (~ 2MB) and fa_compile becomes incredibly slow          */
     fa_minimize(fa1);
 
-    r = fa_as_regexp(fa1, &re);
+    r = fa_as_regexp(fa1, &re, &re_len);
     CuAssertIntEquals(tc, 0, r);
 
     r = fa_compile(re, strlen(re), &fa2);
@@ -386,11 +387,12 @@ static void testAmbig(CuTest *tc) {
 
 static void assertFaAsRegexp(CuTest *tc, const char *regexp) {
     char *re;
+    size_t re_len;
     struct fa *fa1 = make_good_fa(tc, regexp);
     struct fa *fa2;
     int r;
 
-    r = fa_as_regexp(fa1, &re);
+    r = fa_as_regexp(fa1, &re, &re_len);
     CuAssertIntEquals(tc, 0, r);
 
     r = fa_compile(re, strlen(re), &fa2);
@@ -416,9 +418,10 @@ static void testAsRegexpMinus(CuTest *tc) {
     struct fa *fa2 = make_good_fa(tc, "Deny(Users|Groups|Other)");
     struct fa *fa = mark(fa_minus(fa1, fa2));
     char *re;
+    size_t re_len;
     int r;
 
-    r = fa_as_regexp(fa, &re);
+    r = fa_as_regexp(fa, &re, &re_len);
     CuAssertIntEquals(tc, 0, r);
 
     struct fa *far = make_good_fa(tc, re);
@@ -472,7 +475,8 @@ int main(int argc, char **argv) {
             printf("Example for %s: %s\n", argv[i], s);
             free(s);
             char *re;
-            r = fa_as_regexp(fa, &re);
+            size_t re_len;
+            r = fa_as_regexp(fa, &re, &re_len);
             if (r == 0) {
                 printf("/%s/ = /%s/\n", argv[i], re);
                 free(re);
-- 
1.6.0.6




More information about the augeas-devel mailing list