[PD-cvs] externals/zexy/src strcmp.c,1.3,1.4

IOhannes m zmölnig zmoelnig at users.sourceforge.net
Thu Jan 26 13:16:50 CET 2006


Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12846

Modified Files:
	strcmp.c 
Log Message:
accept lists AND symbols on both inlets
strip the trailing space when converting lists to text


Index: strcmp.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/strcmp.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** strcmp.c	25 Jan 2006 16:27:08 -0000	1.3
--- strcmp.c	26 Jan 2006 12:16:47 -0000	1.4
***************
*** 28,69 ****
  
  static t_class *strcmp_class;
  
  typedef struct _strcmp
  {
    t_object x_obj;
  
    t_binbuf *bbuf1, *bbuf2;
  } t_strcmp;
  
  static void strcmp_bang(t_strcmp *x)
  {
-   char *str1=0, *str2=0;
-   int n1=0, n2=0;
    int result = 0;
  
!   binbuf_gettext(x->bbuf1, &str1, &n1);
!   binbuf_gettext(x->bbuf2, &str2, &n2);
! 
!   result = strcmp(str1, str2);
! 
!   freebytes(str1, n1);
!   freebytes(str2, n2);
  
    outlet_float(x->x_obj.ob_outlet, result);
  }
  
! static void strcmp_secondlist(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
  {
!   binbuf_clear(x->bbuf2);
!   binbuf_add(x->bbuf2, argc, argv);
  }
  
  static void strcmp_list(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
  {
!   binbuf_clear(x->bbuf1);
!   binbuf_add(x->bbuf1, argc, argv);
!   
    strcmp_bang(x);
  }
  
  static void *strcmp_new(t_symbol *s, int argc, t_atom *argv)
--- 28,119 ----
  
  static t_class *strcmp_class;
+ static t_class *strcmp_proxy_class;
+ 
  
  typedef struct _strcmp
  {
    t_object x_obj;
+   struct _strcmp_proxy  *x_proxy;
  
    t_binbuf *bbuf1, *bbuf2;
+   char *str1, *str2;
+   int n1, n2;
  } t_strcmp;
  
+ typedef struct _strcmp_proxy
+ {
+   t_pd  p_pd;
+   t_strcmp    *p_master;
+   t_inlet *p_in;
+ } t_strcmp_proxy;
+ 
  static void strcmp_bang(t_strcmp *x)
  {
    int result = 0;
  
!   if(x->str1){
!     if(x->str2)
!       result = strcmp(x->str1, x->str2);
!     else
!       result = *x->str1;
!   } else {
!     if(x->str2)
!       result = -*x->str2;
!     else
!       result = 0;
!   }
  
    outlet_float(x->x_obj.ob_outlet, result);
  }
  
! static void list2binbuf(t_binbuf**bbuf, int *n, char**str, int argc, t_atom*argv)
  {
!   int i=0;
!   char*s=0;
!   if(*str&&*n)freebytes(str, *n);
! 
!   binbuf_clear(*bbuf);
!   binbuf_add(*bbuf, argc, argv);
! 
!   binbuf_gettext(*bbuf, str, n);
! 
!   i=*n;
!   s=*str;
! 
!   if(' '==s[i])s[i]=0;
  }
  
  static void strcmp_list(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
  {
!   list2binbuf(&x->bbuf1, &x->n1, &x->str1, argc, argv);
    strcmp_bang(x);
  }
+ static void strcmp_symbol(t_strcmp *x, t_symbol *s)
+ {
+   if(x->str1&&x->n1)freebytes(x->str1, x->n1);
+   x->n1=0;
+   x->str1=s->s_name;
+   strcmp_bang(x);
+ }
+ 
+ static void strcmp_secondlist(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
+ {
+   list2binbuf(&x->bbuf2, &x->n2, &x->str2, argc, argv);
+ }
+ static void strcmp_secondsymbol(t_strcmp *x, t_symbol *s)
+ {
+   if(x->str2&&x->n2)freebytes(x->str2, x->n2);
+   x->n2=0;
+   x->str2=s->s_name;
+ }
+ 
+ static void strcmp_proxy_list(t_strcmp_proxy *y, t_symbol *s, int argc, t_atom *argv)
+ {
+   strcmp_secondlist(y->p_master, s, argc, argv);
+ }
+ static void strcmp_proxy_symbol(t_strcmp_proxy *y, t_symbol *s)
+ {
+   if(s)strcmp_secondsymbol(y->p_master, s);
+ }
  
  static void *strcmp_new(t_symbol *s, int argc, t_atom *argv)
***************
*** 71,82 ****
    t_strcmp *x = (t_strcmp *)pd_new(strcmp_class);
  
    outlet_new(&x->x_obj, 0);
-   inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2"));
  
    x->bbuf1 = binbuf_new();
    x->bbuf2 = binbuf_new();
  
  
!   strcmp_secondlist(x, gensym("list"), argc, argv);
  
    return (x);
--- 121,139 ----
    t_strcmp *x = (t_strcmp *)pd_new(strcmp_class);
  
+   x->x_proxy=(t_strcmp_proxy*)pd_new(strcmp_proxy_class);
+   x->x_proxy->p_master = x;
+   x->x_proxy->p_in = inlet_new ((t_object*)x, (t_pd*)x->x_proxy, 0,0);
+ 
    outlet_new(&x->x_obj, 0);
  
    x->bbuf1 = binbuf_new();
    x->bbuf2 = binbuf_new();
  
+   x->str1=0;
+   x->str2=0;
+   x->n1=0;
+   x->n2=0;
  
!   if(argc)strcmp_secondlist(x, gensym("list"), argc, argv);
  
    return (x);
***************
*** 87,90 ****
--- 144,154 ----
    binbuf_free(x->bbuf1);
    binbuf_free(x->bbuf2);
+ 
+   if(x->str1&&x->n1)freebytes(x->str1, x->n1);
+   if(x->str2&&x->n2)freebytes(x->str2, x->n2);
+ 
+   inlet_free(x->x_proxy->p_in);
+   x->x_proxy->p_master=0;
+   pd_free(&x->x_proxy->p_pd);
  }
  
***************
*** 96,101 ****
  
    class_addbang    (strcmp_class, strcmp_bang);
    class_addlist    (strcmp_class, strcmp_list);
!   class_addmethod  (strcmp_class, (t_method)strcmp_secondlist, gensym("lst2"), A_GIMME, 0);
  
    class_sethelpsymbol(strcmp_class, gensym("zexy/strcmp"));
--- 160,171 ----
  
    class_addbang    (strcmp_class, strcmp_bang);
+   class_addsymbol  (strcmp_class, strcmp_symbol);
    class_addlist    (strcmp_class, strcmp_list);
! 
!   strcmp_proxy_class = class_new(gensym("strcmp proxy"), 0, 0,
!                                  sizeof(t_strcmp_proxy),
!                                  CLASS_PD | CLASS_NOINLET, 0);
!   class_addsymbol(strcmp_proxy_class, strcmp_proxy_symbol);
!   class_addlist(strcmp_proxy_class, strcmp_proxy_list);
  
    class_sethelpsymbol(strcmp_class, gensym("zexy/strcmp"));





More information about the Pd-cvs mailing list