• R/O
  • SSH
  • HTTPS

tsukurimashou: Commit


Commit MetaInfo

Revision299 (tree)
Time2012-07-25 05:05:35
Authormskala

Log Message

associative matching, and test for it

Change Summary

Incremental Difference

--- trunk/idsgrep/assoc.c (revision 298)
+++ trunk/idsgrep/assoc.c (revision 299)
@@ -27,8 +27,98 @@
2727
2828 /**********************************************************************/
2929
30-NODE *assoc_match_fn(NODE *ms) { /* SNH */
31- /* FIXME */
32- ms->match_result=MR_TRUE; /* SNH */
33- return ms; /* SNH */
30+NODE *assoc_match_fn(NODE *ms) {
31+ NODE *needle_prime,*haystack_prime;
32+ NODE *tmpp,*tmpq,*rval;
33+ int np_arity,hp_arity,i;
34+
35+ if ((ms->nc_needle->child[0]->arity!=ms->nc_haystack->arity)
36+ || (ms->nc_needle->child[0]->functor!=ms->nc_haystack->functor)) {
37+ ms->match_result=MR_FALSE;
38+ return ms;
39+ }
40+
41+ if (ms->nc_needle->child[0]->arity==0) {
42+ ms->match_result=MR_TRUE;
43+ return ms;
44+ }
45+
46+ needle_prime=new_node();
47+ needle_prime->nc_needle=ms->nc_needle->child[0];
48+ needle_prime->nc_needle->refs++;
49+ np_arity=1;
50+
51+ for (tmpp=needle_prime;tmpp;) {
52+ if ((tmpp->nc_needle->arity==ms->nc_needle->child[0]->arity)
53+ && (tmpp->nc_needle->functor==ms->nc_needle->child[0]->functor)) {
54+ for (i=tmpp->nc_needle->arity-1;i>0;i--) {
55+ tmpq=new_node();
56+ tmpq->nc_next=tmpp->nc_next;
57+ tmpp->nc_next=tmpq;
58+ np_arity++;
59+ tmpq->nc_needle=tmpp->nc_needle->child[i];
60+ tmpq->nc_needle->refs++;
61+ }
62+ tmpq=tmpp->nc_needle;
63+ tmpp->nc_needle=tmpp->nc_needle->child[0];
64+ tmpp->nc_needle->refs++;
65+ free_node(tmpq);
66+ } else
67+ tmpp=tmpp->nc_next;
68+ }
69+
70+ haystack_prime=new_node();
71+ haystack_prime->nc_needle=ms->nc_haystack;
72+ haystack_prime->nc_needle->refs++;
73+ hp_arity=1;
74+
75+ for (tmpp=haystack_prime;tmpp;) {
76+ if ((tmpp->nc_needle->arity==ms->nc_needle->child[0]->arity)
77+ && (tmpp->nc_needle->functor==ms->nc_needle->child[0]->functor)) {
78+ for (i=tmpp->nc_needle->arity-1;i>0;i--) {
79+ tmpq=new_node();
80+ tmpq->nc_next=tmpp->nc_next;
81+ tmpp->nc_next=tmpq;
82+ hp_arity++;
83+ tmpq->nc_needle=tmpp->nc_needle->child[i];
84+ tmpq->nc_needle->refs++;
85+ }
86+ tmpq=tmpp->nc_needle;
87+ tmpp->nc_needle=tmpp->nc_needle->child[0];
88+ tmpp->nc_needle->refs++;
89+ free_node(tmpq);
90+ } else
91+ tmpp=tmpp->nc_next;
92+ }
93+
94+ if (np_arity!=hp_arity) {
95+ free_node(needle_prime);
96+ free_node(haystack_prime);
97+ ms->match_result=MR_FALSE;
98+ return ms;
99+ }
100+
101+ rval=ms;
102+ ms->match_result=MR_AND_MAYBE;
103+
104+ while (needle_prime) {
105+ tmpp=needle_prime->nc_next;
106+ tmpq=haystack_prime->nc_next;
107+
108+ needle_prime->nc_next=rval;
109+ rval->refs++;
110+ rval=needle_prime;
111+ rval->match_parent=ms;
112+
113+ needle_prime->nc_haystack=haystack_prime->nc_needle;
114+ needle_prime->nc_haystack->refs++;
115+
116+ needle_prime=tmpp;
117+ if (tmpq)
118+ tmpq->refs++;
119+ free_node(haystack_prime);
120+ haystack_prime=tmpq;
121+ }
122+
123+ return rval;
34124 }
--- trunk/idsgrep/Makefile.am (revision 298)
+++ trunk/idsgrep/Makefile.am (revision 299)
@@ -117,9 +117,9 @@
117117 tsukurimashou.eids
118118
119119 GCOV_TESTS = \
120- test/andor test/anynot test/basicmatch test/backslash test/bighash \
121- test/demorgan test/equal test/kvg-grone test/messages test/spacing \
122- test/tsu-grone test/unord test/utf8
120+ test/andor test/anynot test/assoc test/basicmatch test/backslash \
121+ test/bighash test/demorgan test/equal test/kvg-grone test/messages \
122+ test/spacing test/tsu-grone test/unord test/utf8
123123
124124 define GCDEP_RECIPE
125125 $1.log: test/rmgcda.log
Show on old repository browser