[augeas-devel] [PATCH] * src/fa.h: use 'struct fa *' instead of fa_t
David Lutterkort
lutter at redhat.com
Mon Mar 16 03:08:49 UTC 2009
---
src/fa.c | 24 ++++++------
src/fa.h | 38 ++++++++++----------
src/lens.c | 24 ++++++------
src/regexp.c | 2 +-
tests/fatest.c | 102 ++++++++++++++++++++++++++++----------------------------
5 files changed, 95 insertions(+), 95 deletions(-)
diff --git a/src/fa.c b/src/fa.c
index 9fce844..2b9ce4f 100644
--- a/src/fa.c
+++ b/src/fa.c
@@ -1968,7 +1968,7 @@ struct fa *fa_intersect(struct fa *fa1, struct fa *fa2) {
goto done;
}
-int fa_contains(fa_t fa1, fa_t fa2) {
+int fa_contains(struct fa *fa1, struct fa *fa2) {
int result = 0;
struct state_set *worklist; /* List of pairs of states */
struct state_set *visited; /* List of pairs of states */
@@ -2131,7 +2131,7 @@ struct fa *fa_overlap(struct fa *fa1, struct fa *fa2) {
return result;
}
-int fa_equals(fa_t fa1, fa_t fa2) {
+int fa_equals(struct fa *fa1, struct fa *fa2) {
return fa_contains(fa1, fa2) && fa_contains(fa2, fa1);
}
@@ -2187,7 +2187,7 @@ static char pick_char(struct trans *t) {
/* Generate an example string for FA. Traverse all transitions and record
* at each turn the "best" word found for that state.
*/
-char *fa_example(fa_t fa) {
+char *fa_example(struct fa *fa) {
/* Sort to avoid any ambiguity because of reordering of transitions */
sort_transition_intervals(fa);
@@ -2286,14 +2286,14 @@ static struct fa *expand_alphabet(struct fa *fa, int add_marker,
/* This algorithm is due to Anders Moeller, and can be found in class
* AutomatonOperations in dk.brics.grammar
*/
-char *fa_ambig_example(fa_t fa1, fa_t fa2, char **pv, char **v) {
+char *fa_ambig_example(struct fa *fa1, struct fa *fa2, char **pv, char **v) {
static const char X = '\001';
static const char Y = '\002';
#define Xs "\001"
#define Ys "\002"
/* These could become static constants */
- fa_t mp, ms, sp, ss;
+ struct fa *mp, *ms, *sp, *ss;
fa_compile( Ys Xs "(" Xs "(.|\n))+", &mp);
fa_compile( Ys Xs "(" Xs "(.|\n))*", &ms);
fa_compile( "(" Xs "(.|\n))+" Ys Xs, &sp);
@@ -2301,24 +2301,24 @@ char *fa_ambig_example(fa_t fa1, fa_t fa2, char **pv, char **v) {
#undef Xs
#undef Ys
- fa_t a1f = expand_alphabet(fa1, 0, X, Y);
- fa_t a1t = expand_alphabet(fa1, 1, X, Y);
- fa_t a2f = expand_alphabet(fa2, 0, X, Y);
- fa_t a2t = expand_alphabet(fa2, 1, X, Y);
+ struct fa *a1f = expand_alphabet(fa1, 0, X, Y);
+ struct fa *a1t = expand_alphabet(fa1, 1, X, Y);
+ struct fa *a2f = expand_alphabet(fa2, 0, X, Y);
+ struct fa *a2t = expand_alphabet(fa2, 1, X, Y);
/* Compute b1 = ((a1f . mp) & a1t) . ms */
concat_in_place(a1f, mp);
- fa_t b1 = fa_intersect(a1f, a1t);
+ struct fa *b1 = fa_intersect(a1f, a1t);
concat_in_place(b1, ms);
/* Compute b2 = ss . ((sp . a2f) & a2t) */
concat_in_place(sp, a2f);
- fa_t b2 = fa_intersect(sp, a2t);
+ struct fa *b2 = fa_intersect(sp, a2t);
concat_in_place(ss, b2);
b2 = ss;
/* The automaton we are really interested in */
- fa_t amb = fa_intersect(b1, b2);
+ struct fa *amb = fa_intersect(b1, b2);
/* Clean up intermediate automata */
fa_free(sp);
diff --git a/src/fa.h b/src/fa.h
index 461c38d..dbfd52a 100644
--- a/src/fa.h
+++ b/src/fa.h
@@ -27,7 +27,7 @@
#include <regex.h>
/* The type for a finite automaton. */
-typedef struct fa *fa_t;
+struct fa;
/* Denote some basic automata, used by fa_is_basic and fa_make_basic */
enum fa_basic {
@@ -68,48 +68,48 @@ extern int fa_minimization_algorithm;
* RE, and the function returns REG_NOERROR. Otherwise, FA is NULL, and the
* return value indicates the error.
*/
-int fa_compile(const char *re, fa_t *fa);
+int fa_compile(const char *re, struct fa **fa);
/* Make a new automaton that accepts one of the basic languages defined in
* the enum FA_BASIC.
*/
-fa_t fa_make_basic(unsigned int basic);
+struct fa *fa_make_basic(unsigned int basic);
/* Return 1 if FA accepts the basic language BASIC, which must be one of
* the constantsfrom enum FA_BASIC.
*/
-int fa_is_basic(fa_t fa, unsigned int basic);
+int fa_is_basic(struct fa *fa, unsigned int basic);
/* Minimize FA using Brzozowski's algorithm. As a side-effect, the
* automaton will also be deterministic after being minimized. Modifies the
* automaton in place.
*/
-void fa_minimize(fa_t fa);
+void fa_minimize(struct fa *fa);
/* Return a finite automaton that accepts the concatenation of the
* languages for FA1 and FA2, i.e. L(FA1).L(FA2)
*/
-fa_t fa_concat(fa_t fa1, fa_t fa2);
+struct fa *fa_concat(struct fa *fa1, struct fa *fa2);
/* Return a finite automaton that accepts the union of the languages that
* FA1 and FA2 accept (the '|' operator in regular expressions).
*/
-fa_t fa_union(fa_t fa1, fa_t fa2);
+struct fa *fa_union(struct fa *fa1, struct fa *fa2);
/* Return a finite automaton that accepts the intersection of the languages
* of FA1 and FA2.
*/
-fa_t fa_intersect(fa_t fa1, fa_t fa2);
+struct fa *fa_intersect(struct fa *fa1, struct fa *fa2);
/* Return a finite automaton that accepts the complement of the language of
* FA, i.e. the set of all words not accepted by FA
*/
-fa_t fa_complement(fa_t fa);
+struct fa *fa_complement(struct fa *fa);
/* Return a finite automaton that accepts the set difference of the
* languages of FA1 and FA2, i.e. L(FA1)\L(FA2)
*/
-fa_t fa_minus(fa_t fa1, fa_t fa2);
+struct fa *fa_minus(struct fa *fa1, struct fa *fa2);
/* Return a finite automaton that accepts a repetition of the language that
* FA accepts. If MAX == -1, the returned automaton accepts arbitrarily
@@ -126,35 +126,35 @@ fa_t fa_minus(fa_t fa1, fa_t fa2);
* - FA? = FA_ITER(FA, 0, 1)
* - FA{n,m} = FA_ITER(FA, n, m) with 0 <= n and m = -1 or n <= m
*/
-fa_t fa_iter(fa_t fa, int min, int max);
+struct fa *fa_iter(struct fa *fa, int min, int max);
/* Return 1 if the language of FA1 is contained in the language of FA2, 0
* otherwise.
*/
-int fa_contains(fa_t fa1, fa_t fa2);
+int fa_contains(struct fa *fa1, struct fa *fa2);
/* Return 1 if the language of FA1 equals the language of FA2 */
-int fa_equals(fa_t fa1, fa_t fa2);
+int fa_equals(struct fa *fa1, struct fa *fa2);
/* Free all memory used by FA */
-void fa_free(fa_t fa);
+void fa_free(struct fa *fa);
/* Print FA to OUT as a graphviz dot file */
-void fa_dot(FILE *out, fa_t fa);
+void fa_dot(FILE *out, struct fa *fa);
/* Return a finite automaton that accepts the overlap of the languages of
* FA1 and FA2. The overlap of two languages is the set of strings that can
* be split in more than one way into a left part accepted by FA1 and a
* right part accepted by FA2.
*/
-fa_t fa_overlap(fa_t fa1, fa_t fa2);
+struct fa *fa_overlap(struct fa *fa1, struct fa *fa2);
/* Produce an example for the language of FA. The example is not
* necessarily the shortest possible. The implementation works very hard to
* have printable characters (preferrably alphanumeric) in the example, and
* to avoid just an empty word.
*/
-char *fa_example(fa_t fa);
+char *fa_example(struct fa *fa);
/* Produce an example of an ambiguous word for the concatenation of the
* languages of FA1 and FA2. The return value is such a word (which must be
@@ -168,7 +168,7 @@ char *fa_example(fa_t fa);
* characters '\001' and '\002', as they are used during construction of
* the ambiguous word.
*/
-char *fa_ambig_example(fa_t fa1, fa_t fa2, char **pv, char **v);
+char *fa_ambig_example(struct fa *fa1, struct fa *fa2, char **pv, char **v);
/* Convert the finite automaton FA into a regular expression and set REGEXP
* to point to that. When REGEXP is compiled into another automaton, it is
@@ -181,7 +181,7 @@ char *fa_ambig_example(fa_t fa1, fa_t fa2, char **pv, char **v);
* 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(fa_t fa, char **regexp);
+int fa_as_regexp(struct fa *fa, char **regexp);
#endif
diff --git a/src/lens.c b/src/lens.c
index fb2ecf7..d8e3eb2 100644
--- a/src/lens.c
+++ b/src/lens.c
@@ -47,7 +47,7 @@ static const char *const tags[] = {
* return an exception.
*/
static struct value *str_to_fa(struct info *info, const char *pattern,
- fa_t *fa) {
+ struct fa **fa) {
int error;
struct value *exn = NULL;
size_t re_err_len;
@@ -75,7 +75,7 @@ static struct value *str_to_fa(struct info *info, const char *pattern,
return exn;
}
-static struct value *regexp_to_fa(struct regexp *regexp, fa_t *fa) {
+static struct value *regexp_to_fa(struct regexp *regexp, struct fa **fa) {
return str_to_fa(regexp->info, regexp->pattern->str, fa);
}
@@ -281,9 +281,9 @@ struct value *lns_make_prim(enum lens_tag tag, struct info *info,
struct regexp *regexp, struct string *string) {
struct lens *lens = NULL;
struct value *exn = NULL;
- fa_t fa_slash = NULL;
- fa_t fa_key = NULL;
- fa_t fa_isect = NULL;
+ struct fa *fa_slash = NULL;
+ struct fa *fa_key = NULL;
+ struct fa *fa_isect = NULL;
/* Typecheck */
if (tag == L_KEY) {
@@ -357,9 +357,9 @@ struct value *lns_make_prim(enum lens_tag tag, struct info *info,
*/
static struct value *disjoint_check(struct info *info, const char *msg,
struct regexp *r1, struct regexp *r2) {
- fa_t fa1 = NULL;
- fa_t fa2 = NULL;
- fa_t fa = NULL;
+ struct fa *fa1 = NULL;
+ struct fa *fa2 = NULL;
+ struct fa *fa = NULL;
struct value *exn = NULL;
exn = regexp_to_fa(r1, &fa1);
@@ -408,7 +408,7 @@ static struct value *typecheck_union(struct info *info,
return exn;
}
-static struct value *ambig_check(struct info *info, fa_t fa1, fa_t fa2,
+static struct value *ambig_check(struct info *info, struct fa *fa1, struct fa *fa2,
const char *msg) {
char *upv, *pv, *v;
upv = fa_ambig_example(fa1, fa2, &pv, &v);
@@ -437,8 +437,8 @@ static struct value *ambig_check(struct info *info, fa_t fa1, fa_t fa2,
static struct value *ambig_concat_check(struct info *info, const char *msg,
struct regexp *r1, struct regexp *r2) {
- fa_t fa1 = NULL;
- fa_t fa2 = NULL;
+ struct fa *fa1 = NULL;
+ struct fa *fa2 = NULL;
struct value *result = NULL;
result = regexp_to_fa(r1, &fa1);
@@ -479,7 +479,7 @@ static struct value *typecheck_concat(struct info *info,
static struct value *ambig_iter_check(struct info *info, const char *msg,
struct regexp *r) {
- fa_t fas = NULL, fa = NULL;
+ struct fa *fas = NULL, *fa = NULL;
struct value *result = NULL;
result = regexp_to_fa(r, &fa);
diff --git a/src/regexp.c b/src/regexp.c
index f96cb86..5b6471d 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -187,7 +187,7 @@ regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2) {
const char *p1 = r1->pattern->str;
const char *p2 = r2->pattern->str;
struct regexp *result = NULL;
- fa_t fa = NULL, fa1 = NULL, fa2 = NULL;
+ struct fa *fa = NULL, *fa1 = NULL, *fa2 = NULL;
int r;
char *s = NULL;
diff --git a/tests/fatest.c b/tests/fatest.c
index c733ba0..88c38ed 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -32,7 +32,7 @@
struct fa_list {
struct fa_list *next;
- fa_t fa;
+ struct fa *fa;
};
static struct fa_list *fa_list;
@@ -58,7 +58,7 @@ static void teardown(ATTRIBUTE_UNUSED CuTest *tc) {
list_free(fa_list);
}
-static fa_t mark(fa_t fa) {
+static struct fa *mark(struct fa *fa) {
struct fa_list *fl;
if (fa != NULL) {
@@ -69,10 +69,10 @@ static fa_t mark(fa_t fa) {
return fa;
}
-static void assertAsRegexp(CuTest *tc, fa_t fa) {
+static void assertAsRegexp(CuTest *tc, struct fa *fa) {
char *re;
- fa_t fa1, fa2;
- fa_t empty = mark(fa_make_basic(FA_EPSILON));
+ struct fa *fa1, *fa2;
+ struct fa *empty = mark(fa_make_basic(FA_EPSILON));
int r;
/* Jump through some hoops to make FA1 a copy of FA */
@@ -93,8 +93,8 @@ static void assertAsRegexp(CuTest *tc, fa_t fa) {
free(re);
}
-static fa_t make_fa(CuTest *tc, const char *regexp, int exp_err) {
- fa_t fa;
+static struct fa *make_fa(CuTest *tc, const char *regexp, int exp_err) {
+ struct fa *fa;
int r;
r = fa_compile(regexp, &fa);
@@ -112,7 +112,7 @@ static fa_t make_fa(CuTest *tc, const char *regexp, int exp_err) {
return fa;
}
-static fa_t make_good_fa(CuTest *tc, const char *regexp) {
+static struct fa *make_good_fa(CuTest *tc, const char *regexp) {
return make_fa(tc, regexp, REG_NOERROR);
}
@@ -161,7 +161,7 @@ static void testMonster(CuTest *tc) {
#undef CWS
#undef WORD
- fa_t fa, fas;
+ struct fa *fa, *fas;
char *upv, *pv, *v;
fa = make_good_fa(tc, monster);
@@ -194,7 +194,7 @@ static void testMonster(CuTest *tc) {
}
static void testChars(CuTest *tc) {
- fa_t fa1, fa2, fa3;
+ struct fa *fa1, *fa2, *fa3;
fa1 = make_good_fa(tc, ".");
fa2 = make_good_fa(tc, "[a-z]");
@@ -222,30 +222,30 @@ static void testManualAmbig(CuTest *tc) {
This uses X and Y as the markers*/
- fa_t a1f = make_good_fa(tc, "Xa|XaXb");
- fa_t a1t = make_good_fa(tc, "(YX)*Xa|(YX)*Xa(YX)*Xb");
- fa_t a2f = make_good_fa(tc, "Xa|XbXa");
- fa_t a2t = make_good_fa(tc, "(YX)*Xa|((YX)*Xb(YX)*Xa)");
- fa_t mp = make_good_fa(tc, "YX(X(.|\n))+");
- fa_t ms = make_good_fa(tc, "YX(X(.|\n))*");
- fa_t sp = make_good_fa(tc, "(X(.|\n))+YX");
- fa_t ss = make_good_fa(tc, "(X(.|\n))*YX");
-
- fa_t a1f_mp = mark(fa_concat(a1f, mp));
- fa_t a1f_mp$a1t = mark(fa_intersect(a1f_mp, a1t));
- fa_t b1 = mark(fa_concat(a1f_mp$a1t, ms));
-
- fa_t sp_a2f = mark(fa_concat(sp, a2f));
- fa_t sp_a2f$a2t = mark(fa_intersect(sp_a2f, a2t));
- fa_t b2 = mark(fa_concat(ss, sp_a2f$a2t));
-
- fa_t amb = mark(fa_intersect(b1, b2));
- fa_t exp = make_good_fa(tc, "XaYXXbYXXa");
+ struct fa *a1f = make_good_fa(tc, "Xa|XaXb");
+ struct fa *a1t = make_good_fa(tc, "(YX)*Xa|(YX)*Xa(YX)*Xb");
+ struct fa *a2f = make_good_fa(tc, "Xa|XbXa");
+ struct fa *a2t = make_good_fa(tc, "(YX)*Xa|((YX)*Xb(YX)*Xa)");
+ struct fa *mp = make_good_fa(tc, "YX(X(.|\n))+");
+ struct fa *ms = make_good_fa(tc, "YX(X(.|\n))*");
+ struct fa *sp = make_good_fa(tc, "(X(.|\n))+YX");
+ struct fa *ss = make_good_fa(tc, "(X(.|\n))*YX");
+
+ struct fa *a1f_mp = mark(fa_concat(a1f, mp));
+ struct fa *a1f_mp$a1t = mark(fa_intersect(a1f_mp, a1t));
+ struct fa *b1 = mark(fa_concat(a1f_mp$a1t, ms));
+
+ struct fa *sp_a2f = mark(fa_concat(sp, a2f));
+ struct fa *sp_a2f$a2t = mark(fa_intersect(sp_a2f, a2t));
+ struct fa *b2 = mark(fa_concat(ss, sp_a2f$a2t));
+
+ struct fa *amb = mark(fa_intersect(b1, b2));
+ struct fa *exp = make_good_fa(tc, "XaYXXbYXXa");
CuAssertTrue(tc, fa_equals(exp, amb));
}
static void testContains(CuTest *tc) {
- fa_t fa1, fa2, fa3;
+ struct fa *fa1, *fa2, *fa3;
fa1 = make_good_fa(tc, "ab*");
fa2 = make_good_fa(tc, "ab+");
@@ -264,7 +264,7 @@ static void testContains(CuTest *tc) {
}
static void testIntersect(CuTest *tc) {
- fa_t fa1, fa2, fa;
+ struct fa *fa1, *fa2, *fa;
fa1 = make_good_fa(tc, "[a-zA-Z]*[.:=]([0-9]|[^A-Z])*");
fa2 = make_good_fa(tc, "[a-z][:=][0-9a-z]+");
@@ -275,10 +275,10 @@ static void testIntersect(CuTest *tc) {
}
static void testComplement(CuTest *tc) {
- fa_t fa1 = make_good_fa(tc, "[b-y]+");
- fa_t fa2 = mark(fa_complement(fa1));
+ struct fa *fa1 = make_good_fa(tc, "[b-y]+");
+ struct fa *fa2 = mark(fa_complement(fa1));
/* We use '()' to match the empty word explicitly */
- fa_t fa3 = make_good_fa(tc, "(()|[b-y]*[^b-y](.|\n)*)");
+ struct fa *fa3 = make_good_fa(tc, "(()|[b-y]*[^b-y](.|\n)*)");
CuAssertTrue(tc, fa_equals(fa2, fa3));
@@ -287,10 +287,10 @@ static void testComplement(CuTest *tc) {
}
static void testOverlap(CuTest *tc) {
- fa_t fa1 = make_good_fa(tc, "a|ab");
- fa_t fa2 = make_good_fa(tc, "a|ba");
- fa_t p = mark(fa_overlap(fa1, fa2));
- fa_t exp = make_good_fa(tc, "b");
+ struct fa *fa1 = make_good_fa(tc, "a|ab");
+ struct fa *fa2 = make_good_fa(tc, "a|ba");
+ struct fa *p = mark(fa_overlap(fa1, fa2));
+ struct fa *exp = make_good_fa(tc, "b");
CuAssertTrue(tc, fa_equals(exp, p));
@@ -303,7 +303,7 @@ static void testOverlap(CuTest *tc) {
}
static void assertExample(CuTest *tc, const char *regexp, const char *exp) {
- fa_t fa = make_good_fa(tc, regexp);
+ struct fa *fa = make_good_fa(tc, regexp);
char *xmpl = fa_example(fa);
CuAssertStrEquals(tc, exp, xmpl);
free(xmpl);
@@ -327,7 +327,7 @@ static void testExample(CuTest *tc) {
assertExample(tc, "\001((\002.)*\001)+\002", "\001\001\002");
assertExample(tc, "\001((\001.)*\002)+\002", "\001\002\002");
- fa_t fa1 = mark(fa_make_basic(FA_EMPTY));
+ struct fa *fa1 = mark(fa_make_basic(FA_EMPTY));
CuAssertPtrEquals(tc, NULL, fa_example(fa1));
fa1 = mark(fa_make_basic(FA_EPSILON));
@@ -340,8 +340,8 @@ static void assertAmbig(CuTest *tc, const char *regexp1, const char *regexp2,
const char *exp_upv,
const char *exp_pv, const char *exp_v) {
- fa_t fa1 = make_good_fa(tc, regexp1);
- fa_t fa2 = make_good_fa(tc, regexp2);
+ struct fa *fa1 = make_good_fa(tc, regexp1);
+ struct fa *fa2 = make_good_fa(tc, regexp2);
char *pv, *v;
char *upv = fa_ambig_example(fa1, fa2, &pv, &v);
CuAssertPtrNotNull(tc, upv);
@@ -356,8 +356,8 @@ static void assertAmbig(CuTest *tc, const char *regexp1, const char *regexp2,
static void assertNotAmbig(CuTest *tc, const char *regexp1,
const char *regexp2) {
- fa_t fa1 = make_good_fa(tc, regexp1);
- fa_t fa2 = make_good_fa(tc, regexp2);
+ struct fa *fa1 = make_good_fa(tc, regexp1);
+ struct fa *fa2 = make_good_fa(tc, regexp2);
char *upv = fa_ambig_example(fa1, fa2, NULL, NULL);
CuAssertPtrEquals(tc, NULL, upv);
}
@@ -377,8 +377,8 @@ static void testAmbig(CuTest *tc) {
static void assertFaAsRegexp(CuTest *tc, const char *regexp) {
char *re;
- fa_t fa1 = make_good_fa(tc, regexp);
- fa_t fa2;
+ struct fa *fa1 = make_good_fa(tc, regexp);
+ struct fa *fa2;
int r;
r = fa_as_regexp(fa1, &re);
@@ -403,16 +403,16 @@ static void testAsRegexp(CuTest *tc) {
}
static void testAsRegexpMinus(CuTest *tc) {
- fa_t fa1 = make_good_fa(tc, "[A-Za-z]+");
- fa_t fa2 = make_good_fa(tc, "Deny(Users|Groups|Other)");
- fa_t fa = mark(fa_minus(fa1, fa2));
+ struct fa *fa1 = make_good_fa(tc, "[A-Za-z]+");
+ struct fa *fa2 = make_good_fa(tc, "Deny(Users|Groups|Other)");
+ struct fa *fa = mark(fa_minus(fa1, fa2));
char *re;
int r;
r = fa_as_regexp(fa, &re);
CuAssertIntEquals(tc, 0, r);
- fa_t far = make_good_fa(tc, re);
+ struct fa *far = make_good_fa(tc, re);
CuAssertTrue(tc, fa_equals(fa, far));
free(re);
@@ -451,7 +451,7 @@ int main(int argc, char **argv) {
}
for (int i=1; i<argc; i++) {
- fa_t fa;
+ struct fa *fa;
int r;
if ((r = fa_compile(argv[i], &fa)) != REG_NOERROR) {
print_regerror(r, argv[i]);
--
1.6.0.6
More information about the augeas-devel
mailing list