[PD-cvs] pd/src m_binbuf.c,1.4.4.1.2.5,1.4.4.1.2.6

Thomas Grill xovo at users.sourceforge.net
Thu Jun 29 15:02:37 CEST 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29662

Modified Files:
      Tag: devel_0_39
	m_binbuf.c 
Log Message:
integrated Iohannes' multi-dollarg patch #1405137

Index: m_binbuf.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_binbuf.c,v
retrieving revision 1.4.4.1.2.5
retrieving revision 1.4.4.1.2.6
diff -C2 -d -r1.4.4.1.2.5 -r1.4.4.1.2.6
*** m_binbuf.c	13 Jun 2006 07:45:33 -0000	1.4.4.1.2.5
--- m_binbuf.c	29 Jun 2006 13:02:34 -0000	1.4.4.1.2.6
***************
*** 437,460 ****
  int canvas_getdollarzero( void);
  
  /* LATER remove the dependence on the current canvas for $0; should be another
  argument. */
  t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew)
  {
!     int argno = atol(s->s_name), lastnum;
!     char buf[MAXPDSTRING], c, *sp;
!     for (lastnum = 0, sp = s->s_name; ((c = *sp) && c >= '0' && c <= '9');
!         sp++, lastnum++)
!     if (!c || argno < 0 || argno > ac)
!     {
!         if (!tonew)
!             return (0);
!         else sprintf(buf, "$%d", argno);
      }
!     else if (argno == 0)
!         sprintf(buf, "%d", canvas_getdollarzero());
!     else
!         atom_string(av+(argno-1), buf, MAXPDSTRING/2-1);
!     strncat(buf, sp, MAXPDSTRING/2-1);
!     return (gensym(buf));
  }
  
--- 437,541 ----
  int canvas_getdollarzero( void);
  
+ /* JMZ:
+  * s points to the first character after the $
+  * (e.g. if the org.symbol is "$1-bla", then s will point to "1-bla")
+  * (e.g. org.symbol="hu-$1mu", s="1mu")
+  * LATER: think about more complex $args, like ${$1+3}
+  *
+  * the return value holds the length of the $arg (in most cases: 1)
+  * buf holds the expanded $arg
+  *
+  * if some error occured, "-1" is returned
+  *
+  * e.g. "$1-bla" with list "10 20 30"
+  * s="1-bla"
+  * buf="10"
+  * return value = 1; (s+1=="-bla")
+  */
+ int binbuf_expanddollsym(char*s, char*buf,t_atom dollar0, int ac, t_atom *av, int tonew)
+ {
+   int argno=atol(s);
+   int arglen=0;
+   char*cs=s;
+   char c=*cs;
+   *buf=0;
+ 
+   while(c&&(c>='0')&&(c<='9')){
+     c=*cs++;
+     arglen++;
+   }
+ 
+   if (cs==s) { /* invalid $-expansion (like "$bla") */
+     sprintf(buf, "$");
+     return 0;
+   }
+   else if (argno < 0 || argno > ac) /* undefined argument */
+     {
+       if(!tonew)return 0;
+       sprintf(buf, "$%d", argno);
+     }
+   else if (argno == 0){ /* $0 */
+     atom_string(&dollar0, buf, MAXPDSTRING/2-1);
+   }
+   else{ /* fine! */
+     atom_string(av+(argno-1), buf, MAXPDSTRING/2-1);
+   }
+   return (arglen-1);
+ }
+ 
  /* LATER remove the dependence on the current canvas for $0; should be another
  argument. */
  t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew)
  {
!     char buf[MAXPDSTRING];
!     char buf2[MAXPDSTRING];
!     char*str=s->s_name;
!     char*substr;
!     int next=0, i=MAXPDSTRING;
!     t_atom dollarnull;
!     SETFLOAT(&dollarnull, canvas_getdollarzero());
!     while(i--)buf2[i]=0;
! 
! #if 0
!     /* JMZ: currently, a symbol is detected to be A_DOLLSYM if it starts with '$'
!      * the leading $ is stripped and the rest stored in "s"
!      * i would suggest to NOT strip the leading $
!      * and make everything a A_DOLLSYM that contains(!) a $
!      *
!      * whenever this happened, enable this code
!      */
!     substr=strchr(str, '$');
!     if(substr){
!       strncat(buf2, str, (substr-str));
!       str=substr+1;
      }
! #endif
! 
!     while((next=binbuf_expanddollsym(str, buf, dollarnull, ac, av, tonew))>=0)
!       {
!       /*
!        * JMZ: i am not sure what this means, so i might have broken it
!        * it seems like that if "tonew" is set and the $arg cannot be expanded (or the dollarsym is in reality a A_DOLLAR)
!        * 0 is returned from binbuf_realizedollsym
!        * this happens, when expanding in a message-box, but does not happen when the A_DOLLSYM is the name of a subpatch
!        */
! 	if(!tonew&&(0==next)&&(0==*buf)){
! 	  return 0; /* JMZ: this should mimick the original behaviour */
! 	}
! 
! 	strncat(buf2, buf, MAXPDSTRING/2-1);
! 	str+=next;
! 	substr=strchr(str, '$');
! 	if(substr){
! 	  strncat(buf2, str, (substr-str));
! 	  str=substr+1;
! 	} else {
! 	  strcat(buf2, str);
! 
! 	  return gensym(buf2);
! 	}
!       }
! 
!     return (gensym(buf2));
  }
  





More information about the Pd-cvs mailing list