Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

associative matching and test for it

  • Loading branch information...
commit 2b277619bde56c9b73a071aab3677ac585dfdcaf 1 parent 0313d76
Matthew Skala authored
6 idsgrep/Makefile.am
View
@@ -117,9 +117,9 @@ tsukurimashou.eids: @with_tsuku_build@/txt/tsukurimashou.eids
tsukurimashou.eids
GCOV_TESTS = \
- test/andor test/anynot test/basicmatch test/backslash test/bighash \
- test/demorgan test/equal test/kvg-grone test/messages test/spacing \
- test/tsu-grone test/unord test/utf8
+ test/andor test/anynot test/assoc test/basicmatch test/backslash \
+ test/bighash test/demorgan test/equal test/kvg-grone test/messages \
+ test/spacing test/tsu-grone test/unord test/utf8
define GCDEP_RECIPE
$1.log: test/rmgcda.log
98 idsgrep/assoc.c
View
@@ -27,8 +27,98 @@
/**********************************************************************/
-NODE *assoc_match_fn(NODE *ms) { /* SNH */
- /* FIXME */
- ms->match_result=MR_TRUE; /* SNH */
- return ms; /* SNH */
+NODE *assoc_match_fn(NODE *ms) {
+ NODE *needle_prime,*haystack_prime;
+ NODE *tmpp,*tmpq,*rval;
+ int np_arity,hp_arity,i;
+
+ if ((ms->nc_needle->child[0]->arity!=ms->nc_haystack->arity)
+ || (ms->nc_needle->child[0]->functor!=ms->nc_haystack->functor)) {
+ ms->match_result=MR_FALSE;
+ return ms;
+ }
+
+ if (ms->nc_needle->child[0]->arity==0) {
+ ms->match_result=MR_TRUE;
+ return ms;
+ }
+
+ needle_prime=new_node();
+ needle_prime->nc_needle=ms->nc_needle->child[0];
+ needle_prime->nc_needle->refs++;
+ np_arity=1;
+
+ for (tmpp=needle_prime;tmpp;) {
+ if ((tmpp->nc_needle->arity==ms->nc_needle->child[0]->arity)
+ && (tmpp->nc_needle->functor==ms->nc_needle->child[0]->functor)) {
+ for (i=tmpp->nc_needle->arity-1;i>0;i--) {
+ tmpq=new_node();
+ tmpq->nc_next=tmpp->nc_next;
+ tmpp->nc_next=tmpq;
+ np_arity++;
+ tmpq->nc_needle=tmpp->nc_needle->child[i];
+ tmpq->nc_needle->refs++;
+ }
+ tmpq=tmpp->nc_needle;
+ tmpp->nc_needle=tmpp->nc_needle->child[0];
+ tmpp->nc_needle->refs++;
+ free_node(tmpq);
+ } else
+ tmpp=tmpp->nc_next;
+ }
+
+ haystack_prime=new_node();
+ haystack_prime->nc_needle=ms->nc_haystack;
+ haystack_prime->nc_needle->refs++;
+ hp_arity=1;
+
+ for (tmpp=haystack_prime;tmpp;) {
+ if ((tmpp->nc_needle->arity==ms->nc_needle->child[0]->arity)
+ && (tmpp->nc_needle->functor==ms->nc_needle->child[0]->functor)) {
+ for (i=tmpp->nc_needle->arity-1;i>0;i--) {
+ tmpq=new_node();
+ tmpq->nc_next=tmpp->nc_next;
+ tmpp->nc_next=tmpq;
+ hp_arity++;
+ tmpq->nc_needle=tmpp->nc_needle->child[i];
+ tmpq->nc_needle->refs++;
+ }
+ tmpq=tmpp->nc_needle;
+ tmpp->nc_needle=tmpp->nc_needle->child[0];
+ tmpp->nc_needle->refs++;
+ free_node(tmpq);
+ } else
+ tmpp=tmpp->nc_next;
+ }
+
+ if (np_arity!=hp_arity) {
+ free_node(needle_prime);
+ free_node(haystack_prime);
+ ms->match_result=MR_FALSE;
+ return ms;
+ }
+
+ rval=ms;
+ ms->match_result=MR_AND_MAYBE;
+
+ while (needle_prime) {
+ tmpp=needle_prime->nc_next;
+ tmpq=haystack_prime->nc_next;
+
+ needle_prime->nc_next=rval;
+ rval->refs++;
+ rval=needle_prime;
+ rval->match_parent=ms;
+
+ needle_prime->nc_haystack=haystack_prime->nc_needle;
+ needle_prime->nc_haystack->refs++;
+
+ needle_prime=tmpp;
+ if (tmpq)
+ tmpq->refs++;
+ free_node(haystack_prime);
+ haystack_prime=tmpq;
+ }
+
+ return rval;
}
1  idsgrep/check-coverage
View
@@ -87,6 +87,7 @@ foreach $fn (@ARGV) {
if ($totshouldexec==0) {
$totgoodexecp=1;
$totshouldexecp=1;
+ $snherror=1;
} else {
$totgoodexecp=$totgoodexec;
$totshouldexecp=$totshouldexec;
124 idsgrep/test/assoc
View
@@ -0,0 +1,124 @@
+#!/bin/sh
+
+cat <<EOF > as-in.$$
+(nullary one)
+(nullary two)
+,x(zero)
+.u.,x(one)
+.u..u.,x(two)
+.u..u..u.,x(three)
+.u..u..u..u.,x(four)
+,a,b,c,de
+,a,b,,cde
+,a,,bc,de
+,a,,b,cde
+,a,,,bcde
+,,ab,c,de
+,,ab,,cde
+,,a,bc,de
+,,,abc,de
+,,a,b,cde
+,,a,,bcde
+,,,ab,cde
+,,,a,bcde
+,,,,abcde
+{t}{t}abcde
+{t}a{t}bcde
+{t}ab{t}cde
+EOF
+
+./idsgrep '@(nullary one)' as-in.$$ > as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@.u.,x?' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@,a,b,c,de' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@,,,,abcde' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@,,??,??' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep ',?@,,cde' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@{t}???' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@{t}{t}abcde' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@{t}a{t}bcde' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+./idsgrep '@{t}ab{t}cde' as-in.$$ >> as-out.$$
+echo === >> as-out.$$
+
+if diff -c as-out.$$ - <<EOF
+(nullary one)
+===
+.u.,x(one)
+.u..u.,x(two)
+.u..u..u.,x(three)
+.u..u..u..u.,x(four)
+===
+,a,b,c,de
+,a,b,,cde
+,a,,bc,de
+,a,,b,cde
+,a,,,bcde
+,,ab,c,de
+,,ab,,cde
+,,a,bc,de
+,,,abc,de
+,,a,b,cde
+,,a,,bcde
+,,,ab,cde
+,,,a,bcde
+,,,,abcde
+===
+,a,b,c,de
+,a,b,,cde
+,a,,bc,de
+,a,,b,cde
+,a,,,bcde
+,,ab,c,de
+,,ab,,cde
+,,a,bc,de
+,,,abc,de
+,,a,b,cde
+,,a,,bcde
+,,,ab,cde
+,,,a,bcde
+,,,,abcde
+===
+===
+,,ab,c,de
+,,ab,,cde
+===
+===
+{t}{t}abcde
+{t}a{t}bcde
+{t}ab{t}cde
+===
+{t}{t}abcde
+{t}a{t}bcde
+{t}ab{t}cde
+===
+{t}{t}abcde
+{t}a{t}bcde
+{t}ab{t}cde
+===
+EOF
+then
+ rm -f as-in.$$
+ rm -f as-out.$$
+ exit 0
+else
+ rm -f as-in.$$
+ rm -f as-out.$$
+ exit 1
+fi
5 idsgrep/test/gcov
View
@@ -1,6 +1,9 @@
#!/bin/sh
-( gcov -r *.c || gcov *.c ) > /dev/null 2> /dev/null
+for srcfile in *.c
+do
+ ( gcov -r $srcfile || gcov $srcfile ) > /dev/null 2> /dev/null
+done
if perl -CS ./check-coverage *.gcov
then
exit 0
Please sign in to comment.
Something went wrong with that request. Please try again.