Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18430/src
Modified Files:
matchbox.c
Log Message:
added "delete" functionality
Index: matchbox.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/matchbox.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** matchbox.c 5 Jul 2007 14:50:37 -0000 1.5
--- matchbox.c 24 Jul 2007 13:30:29 -0000 1.6
***************
*** 93,111 ****
}
! static void clearlistlist(t_listlist*list) {
! while(list){
! t_listlist*ll=list;
! list=list->next;
! if(ll->argv)freebytes(ll->argv, ll->argc*sizeof(t_atom));
! ll->argv=0;
! ll->argc=0;
! ll->next=0;
! freebytes(ll, sizeof(t_listlist));
}
}
-
-
/* -------------- here comes the matching algorithms ----------- */
--- 93,117 ----
}
! /* delete the _next_ element from the list */
! static t_listlist* deletelistnext(t_listlist*list) {
! if(!list || !list->next)return list; /* nothing to delete */
! t_listlist*ll=list->next;
! list->next=ll->next;
! if(ll->argv)freebytes(ll->argv, ll->argc*sizeof(t_atom));
! ll->argv=0;
! ll->argc=0;
! ll->next=0;
! freebytes(ll, sizeof(t_listlist));
! return list;
! }
! /* delete the entire list of lists */
! static void clearlistlist(t_listlist*list) {
! if(!list)return; /* nothing to delete */
! while(list->next){
! list=deletelistnext(list);
}
}
/* -------------- here comes the matching algorithms ----------- */
***************
*** 388,392 ****
}
! static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*searchlist, int p_argc, t_atom*p_argv, int flags) {
regex_t**regexpressions=0;
t_listlist*matchinglist=0, *sl;
--- 394,398 ----
}
! static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*searchlist, int p_argc, t_atom*p_argv, int flags, int delete_results) {
regex_t**regexpressions=0;
t_listlist*matchinglist=0, *sl;
***************
*** 422,429 ****
/* match the patterns to the tests */
! for(sl=searchlist; 0!=sl; sl=sl->next) {
! if(TRUE==listmatch_regex(p_argc, regexpressions, sl->argc, sl->argv)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
}
}
--- 428,450 ----
/* match the patterns to the tests */
! if(FALSE==delete_results) {
! for(sl=searchlist; 0!=sl; sl=sl->next) {
! if(TRUE==listmatch_regex(p_argc, regexpressions, sl->argc, sl->argv)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
! }
! }
! } else if (TRUE==delete_results) {
! /* yummy: delete matching lists! */
! t_listlist*lastgood=searchlist;
! for(sl=searchlist; 0!=sl; sl=sl->next) {
! if(TRUE==listmatch_regex(p_argc, regexpressions, sl->argc, sl->argv)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
!
! sl=deletelistnext(lastgood);
! } else {
! lastgood=sl;
! }
}
}
***************
*** 475,479 ****
}
! static t_listlist*matchlistlist(unsigned int*numresults, t_listlist*searchlist, int p_argc, t_atom*p_argv, int mode) {
unsigned int num=0;
t_listlist*matchinglist=0, *sl;
--- 496,500 ----
}
! static t_listlist*matchlistlist(unsigned int*numresults, t_listlist*searchlist, int p_argc, t_atom*p_argv, int mode, int delete_results) {
unsigned int num=0;
t_listlist*matchinglist=0, *sl;
***************
*** 482,496 ****
#ifdef MATCHBOX_REGEX
if(MATCHBOX_REGEX==mode) {
! matchinglist=matchlistlist_regex(&num, searchlist, p_argc, p_argv, 0);
} else
#endif /* MATCHBOX_REGEX */
/* normal matching */
! for(sl=searchlist; 0!=sl; sl=sl->next) {
! if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
}
}
!
if(numresults!=0)
*numresults=num;
--- 503,532 ----
#ifdef MATCHBOX_REGEX
if(MATCHBOX_REGEX==mode) {
! matchinglist=matchlistlist_regex(&num, searchlist, p_argc, p_argv, 0, delete_results);
} else
#endif /* MATCHBOX_REGEX */
/* normal matching */
! if(FALSE==delete_results) {
! for(sl=searchlist->next; 0!=sl; sl=sl->next) {
! if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
! }
! }
! } else if (TRUE==delete_results) {
! /* yummy: delete matching lists! */
! t_listlist*lastgood=searchlist;
! for(sl=searchlist->next; 0!=sl; sl=sl->next) {
! if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) {
! matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
! num++;
!
! sl=deletelistnext(lastgood);
! } else {
! lastgood=sl;
! }
}
}
!
if(numresults!=0)
*numresults=num;
***************
*** 502,506 ****
int results=0;
int mode=x->x_mode;
! t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode);
t_listlist*dummylist;
--- 538,542 ----
int results=0;
int mode=x->x_mode;
! t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, FALSE);
t_listlist*dummylist;
***************
*** 509,519 ****
for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next)
outlet_list(x->x_outResult, &s_list, dummylist->argc, dummylist->argv);
-
-
}
static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) {
// 1st match, whether we already have this entry
! if(matchlistlist(0, x->x_lists, argc, argv, MATCHBOX_EXACT)) {
// already there, skip the rest
z_verbose(1, "this list is already in the buffer!, skipping...");
--- 545,553 ----
for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next)
outlet_list(x->x_outResult, &s_list, dummylist->argc, dummylist->argv);
}
static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) {
// 1st match, whether we already have this entry
! if(matchlistlist(0, x->x_lists, argc, argv, MATCHBOX_EXACT, FALSE)) {
// already there, skip the rest
z_verbose(1, "this list is already in the buffer!, skipping...");
***************
*** 526,535 ****
}
static void matchbox_dump(t_matchbox*x) {
t_listlist*lp=0;
! if(0==x->x_lists){
outlet_float(x->x_outNumResults, 0);
return;
--- 560,582 ----
}
+ static void matchbox_delete(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) {
+ int results=0;
+ int mode=x->x_mode;
+ t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, TRUE);
+ t_listlist*dummylist;
+ t_symbol*delsym=gensym("deleted");
+
+ x->x_numlists-=results;
+ outlet_float(x->x_outNumResults, results);
+
+ for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next)
+ outlet_anything(x->x_outResult, delsym, dummylist->argc, dummylist->argv);
+ }
static void matchbox_dump(t_matchbox*x) {
t_listlist*lp=0;
! if(0==x->x_lists || 0==x->x_lists->next){
outlet_float(x->x_outNumResults, 0);
return;
***************
*** 538,542 ****
outlet_float(x->x_outNumResults, x->x_numlists);
! for(lp=x->x_lists; 0!=lp; lp=lp->next)
{
outlet_list(x->x_outResult, &s_list, lp->argc, lp->argv);
--- 585,589 ----
outlet_float(x->x_outNumResults, x->x_numlists);
! for(lp=x->x_lists->next; 0!=lp; lp=lp->next)
{
outlet_list(x->x_outResult, &s_list, lp->argc, lp->argv);
***************
*** 547,552 ****
static void matchbox_clear(t_matchbox*x) {
clearlistlist(x->x_lists);
-
- x->x_lists=0;
x->x_numlists=0;
}
--- 594,597 ----
***************
*** 584,588 ****
! x->x_lists=0;
x->x_numlists=0;
--- 629,636 ----
! x->x_lists=(t_listlist*)getbytes(sizeof(t_listlist));
! x->x_lists->next=0;
! x->x_lists->argc=0;
! x->x_lists->argv=0;
x->x_numlists=0;
***************
*** 600,603 ****
--- 648,653 ----
{
matchbox_clear(x);
+ freebytes(x->x_lists, sizeof(t_listlist));
+ x->x_lists=0;
}
***************
*** 620,623 ****
--- 670,674 ----
class_addmethod(matchbox_class, (t_method)matchbox_add, gensym("add"), A_GIMME, 0);
+ class_addmethod(matchbox_class, (t_method)matchbox_delete, gensym("delete"), A_GIMME, 0);
class_addmethod(matchbox_class, (t_method)matchbox_clear, gensym("clear"), A_NULL, 0);
class_addmethod(matchbox_class, (t_method)matchbox_dump, gensym("dump"), A_NULL);