[PD-cvs] externals/grill/pool/source pool.cpp,1.10,1.11

Thomas Grill xovo at users.sourceforge.net
Thu Nov 18 04:32:34 CET 2004


Update of /cvsroot/pure-data/externals/grill/pool/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14880/source

Modified Files:
	pool.cpp 
Log Message:
enhanced and optimized atom parsing
roll back to working version
conform to ISO C++


Index: pool.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/pool/source/pool.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** pool.cpp	9 Nov 2004 03:33:19 -0000	1.10
--- pool.cpp	18 Nov 2004 03:32:31 -0000	1.11
***************
*** 476,507 ****
  	const C *m = c; // remember position
  
! 	// check for word type (s = 0,1,2 ... int,float,symbol)
! 	I s = 0;
! 	for(; *c && !isspace(*c); ++c) {
! 		if(!isdigit(*c))
!             if(!s && (*c == '-' || *c == '+')) {} // minus or plus is ok
!             else
! 			    s = (*c != '.' || s == 1)?2:1;
! 	}
  
! 	if(a) {
! 		switch(s) {
! 		case 0: // integer
! #if FLEXT_SYS == FLEXT_SYS_MAX
! 			flext::SetInt(*a,atoi(m));
! 			break;
! #endif
! 		case 1: // float
! 			flext::SetFloat(*a,(F)atof(m));
! 			break;
! 		default: { // anything else is a symbol
! 			C t = *c; *c = 0;
! 			flext::SetString(*a,m);
! 			*c = t;
! 			break;
! 		}
! 		}
! 	}
  
  	return c;
  }
--- 476,504 ----
  	const C *m = c; // remember position
  
!     // go to next whitespace
!     // \todo recognize symbol escapes
!     for(; *c && !isspace(*c); ++c) {}
  
!     // save character and set delimiter
!     char t = *c; *c = 0;
  
+     float fres;
+     // first try float
+     if(sscanf(m,"%f",&fres)) {
+         if(a) {
+             int ires = (int)fres; // try a cast
+             if(fres == ires)
+                 flext::SetInt(*a,ires);
+             else
+                 flext::SetFloat(*a,fres);
+         }
+     }
+     // no, it's a symbol
+     else {
+         if(a) flext::SetString(*a,m);
+     }
+ 
+     // set back the saved character
+     *c = t;
  	return c;
  }
***************
*** 509,524 ****
  static BL ParseAtoms(C *tmp,flext::AtomList &l)
  {
! 	I i,cnt;
! 	C *t = tmp;
! 	for(cnt = 0; ; ++cnt) {
! 		t = ReadAtom(t,NULL);
! 		if(!t) break;
! 	}
! 
! 	l(cnt);
! 	if(cnt) {
! 		for(i = 0,t = tmp; i < cnt; ++i)
! 			t = ReadAtom(t,&l[i]);
! 	}
  	return true;
  }
--- 506,517 ----
  static BL ParseAtoms(C *tmp,flext::AtomList &l)
  {
!     const int MAXATOMS = 1024;
!     int cnt = 0;
!     t_atom atoms[MAXATOMS];
!     for(char *t = tmp; *t && cnt < MAXATOMS; ++cnt) {
! 		t = ReadAtom(t,&atoms[cnt]);
!         if(!t) break;
!     }
!     l(cnt,atoms);
  	return true;
  }





More information about the Pd-cvs mailing list