From 199b120897fa3bc9a802d2ce6d5f3484f673cd00 Mon Sep 17 00:00:00 2001
From: Thomas Grill <xovo@users.sourceforge.net>
Date: Thu, 18 Nov 2004 03:32:31 +0000
Subject: enhanced and optimized atom parsing roll back to working version
 conform to ISO C++

svn path=/trunk/; revision=2286
---
 externals/grill/pool/pool.vcproj     |  6 ++--
 externals/grill/pool/readme.txt      |  1 +
 externals/grill/pool/source/pool.cpp | 69 ++++++++++++++++--------------------
 3 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/externals/grill/pool/pool.vcproj b/externals/grill/pool/pool.vcproj
index 593a3177..4eceac34 100644
--- a/externals/grill/pool/pool.vcproj
+++ b/externals/grill/pool/pool.vcproj
@@ -87,7 +87,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="f:\prog\pd\pd-cvs\src,f:\prog\max\flext\source"
+				AdditionalIncludeDirectories="&quot;c:\data\prog\pd\pd-cvs\src&quot;;c:\data\prog\max\flext\source"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FLEXT_SYS=2"
 				StringPooling="TRUE"
 				BasicRuntimeChecks="3"
@@ -108,9 +108,9 @@
 				Name="VCLinkerTool"
 				AdditionalDependencies="pd.lib"
 				OutputFile=".\pd-msvc/d/pool.dll"
-				LinkIncremental="1"
+				LinkIncremental="2"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="f:\prog\pd\pd-cvs\bin"
+				AdditionalLibraryDirectories="c:\data\prog\pd\pd-cvs\bin"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile=".\pd-msvc/d/pool.pdb"
 				ImportLibrary=".\pd-msvc/d/pool.lib"
diff --git a/externals/grill/pool/readme.txt b/externals/grill/pool/readme.txt
index 381feffe..9681dd00 100644
--- a/externals/grill/pool/readme.txt
+++ b/externals/grill/pool/readme.txt
@@ -93,6 +93,7 @@ Version history:
 - added "seti" message to set elements at index
 - added "clri" message to erase elements at index
 - fixed bad bug: pool::priv was not initialized
+- enhanced and optimized atom parsing
 
 0.2.0:
 - attributes (pool,private,echodir,absdir)
diff --git a/externals/grill/pool/source/pool.cpp b/externals/grill/pool/source/pool.cpp
index 8c89a676..d554a9b6 100644
--- a/externals/grill/pool/source/pool.cpp
+++ b/externals/grill/pool/source/pool.cpp
@@ -475,51 +475,44 @@ static C *ReadAtom(C *c,A *a)
 
 	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
+    // 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
-			    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;
-		}
-		}
-	}
+                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;
 }
 
 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]);
-	}
+    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;
 }
 
-- 
cgit v1.2.1