[PD-cvs] pd/src kernel.c,1.1.2.59,1.1.2.60

Mathieu Bouchard matju at users.sourceforge.net
Wed Jul 18 09:11:42 CEST 2007


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

Modified Files:
      Tag: desiredata
	kernel.c 
Log Message:
added atom_ostream; removed some MAXPDSTRING; removed special atom stringifications for small buffer sizes


Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.59
retrieving revision 1.1.2.60
diff -C2 -d -r1.1.2.59 -r1.1.2.60
*** kernel.c	18 Jul 2007 04:50:35 -0000	1.1.2.59
--- kernel.c	18 Jul 2007 07:11:40 -0000	1.1.2.60
***************
*** 236,247 ****
  */
  
! static int should_quote(char *s) {
! 	return *s==';' || *s==',' || *s=='\\' || (*s=='$' && isdigit(s[1]));
  }
  
  void atom_init(t_atom *a, size_t n) {
! 	for (unsigned int i=0; i<n; i++) {
  		a[i].a_type = A_FLOAT;
! 		a[i].a_w.w_float = 0.0;
  	}
  }
--- 236,275 ----
  */
  
! static int should_quote(char *s) {return *s==';' || *s==',' || *s=='\\' || (*s=='$' && isdigit(s[1]));}
! 
! void atom_ostream(t_atom *a, ostream &buf) {
!     switch(a->a_type) {
!     case A_SEMI:    buf << ";"; break;
!     case A_COMMA:   buf << ","; break;
!     case A_POINTER: buf << "(pointer)"; break;
!     case A_FLOAT:   buf << a->a_float; break;
!     case A_SYMBOL: {
!         bool quote=0;
!         for (char *sp = a->a_symbol->name; *sp; sp++) if (should_quote(sp)) quote = 1;
!         if (quote) {
!             for (char *sp = a->a_symbol->name; *sp; sp++) {
!                 if (should_quote(sp)) buf << '\\';
!                 buf << *sp;
!             }
!         } else buf << a->a_symbol->name;
!     } break;
!     case A_DOLLAR:  buf << "$" << a->a_index; break;
!     case A_DOLLSYM: buf << a->a_symbol->name; break;
!     default: bug("atom_string");
!     }
! }
! 
! /* this is not completely compatible with Miller's, as it won't do anything special for short bufsizes. */
! void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
!      ostringstream b;
!      atom_ostream(a,b);
!      strncpy(buf,b.str().data(),bufsize);
!      buf[bufsize-1]=0;
  }
  
  void atom_init(t_atom *a, size_t n) {
! 	for (size_t i=0; i<n; i++) {
  		a[i].a_type = A_FLOAT;
! 		a[i].a_float = 0.0;
  	}
  }
***************
*** 256,306 ****
  }
  
- void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
-     switch(a->a_type) {
-     case A_SEMI:    strcpy(buf, ";"); break;
-     case A_COMMA:   strcpy(buf, ","); break;
-     case A_POINTER: strcpy(buf, "(pointer)"); break;
-     case A_FLOAT: {
-         char tbuf[30];
-         sprintf(tbuf, "%g", a->a_float);
-         if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf); else strcpy(buf, a->a_float < 0 ? "-" : "+");
-     } break;
-     case A_SYMBOL: {
-         char *sp;
-         unsigned int len=0;
-         int quote=0;
-         for (sp = a->a_symbol->name; *sp; sp++, len++) if (should_quote(sp)) quote = 1;
-         if (quote) {
-             char *bp = buf, *ep = buf + (bufsize-2);
-             sp = a->a_symbol->name;
-             while (bp < ep && *sp) {
-                 if (should_quote(sp)) *bp++ = '\\';
-                 *bp++ = *sp++;
-             }
-             if (*sp) *bp++ = '*';
-             *bp = 0;
-         } else {
-             if (len < bufsize-1) {
- 		strcpy(buf, a->a_symbol->name);
-             } else {
-                 strncpy(buf, a->a_symbol->name, bufsize - 2);
-                 strcpy(buf + (bufsize - 2), "*");
-             }
-         }
-     } break;
-     case A_DOLLAR:  sprintf(buf, "$%ld", a->a_index); break;
-     case A_DOLLSYM: strncpy(buf, a->a_symbol->name, bufsize); buf[bufsize-1] = 0; break;
-     default: bug("atom_string");
-     }
- }
- 
- /*
- void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
-      ostringstream b;
-      atom_ostream(a,b,bufsize-1);
-      strcpy(buf,b.str().data());
- }
- */
- 
  /* in which the value has bit 0 set if the key object is not a zombie,
     and has bit 1 set if the object has been uploaded to the client */
--- 284,287 ----





More information about the Pd-cvs mailing list