aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--externals/grill/flext/source/flatom_pr.cpp59
-rw-r--r--externals/grill/flext/source/flsupport.h77
2 files changed, 35 insertions, 101 deletions
diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp
index 47430366..d589f657 100644
--- a/externals/grill/flext/source/flatom_pr.cpp
+++ b/externals/grill/flext/source/flatom_pr.cpp
@@ -88,41 +88,34 @@ bool flext::PrintList(int argc,const t_atom *argv,char *buf,size_t bufsz)
}
-bool flext::ScanAtom(t_atom &a,const char *buf)
+const char *flext::ScanAtom(t_atom &a,const char *c)
{
- // skip whitespace
- while(*buf && isspace(*buf)) ++buf;
- if(!*buf) return false;
-
- char tmp[1024];
- strcpy(tmp,buf);
- char *c = tmp;
-
- // check for word type (s = 0,1,2 ... int,float,symbol)
- int s = 0;
- for(; *c && !isspace(*c); ++c) {
- if(!isdigit(*c))
- s = (*c != '.' || s == 1)?2:1;
+ // skip leading whitespace
+ while(*c && isspace(*c)) ++c;
+ if(!*c) return NULL;
+
+ // go to next space and save character
+ char *end = const_cast<char *>(c);
+ while(*end && !isspace(*end)) ++end;
+ char sv = *end;
+
+ float fres;
+ // first try float
+ char *endp;
+ // see if it's a float - thanks to Frank Barknecht
+ fres = (float)strtod(c,&endp);
+ if(!*c && endp != c) {
+ int ires = (int)fres; // try a cast
+ if(fres == ires)
+ SetInt(a,ires);
+ else
+ SetFloat(a,fres);
}
+ // no, it's a symbol
+ else
+ SetString(a,c);
- switch(s) {
- case 0: // integer
-#if FLEXT_SYS == FLEXT_SYS_MAX
- SetInt(a,atol(tmp));
- break;
-#endif
- case 1: // float
- SetFloat(a,(float)atof(tmp));
- break;
- default: { // anything else is a symbol
- char t = *c; *c = 0;
- SetString(a,tmp);
- *c = t;
- break;
- }
- }
+ *end = sv;
- return true;
+ return c;
}
-
-
diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h
index 25622b07..3d96ebef 100644
--- a/externals/grill/flext/source/flsupport.h
+++ b/externals/grill/flext/source/flsupport.h
@@ -170,9 +170,6 @@ public:
@{
*/
-// not for Jmax at the moment
-#if FLEXT_SYS != FLEXT_SYS_JMAX
-
//! Class for platform independent buffer handling
class FLEXT_SHARE buffer:
public flext_root
@@ -314,7 +311,6 @@ public:
#endif
};
-#endif // jmax
//! @} FLEXT_S_BUFFER
@@ -329,8 +325,11 @@ public:
//! Print an atom
static bool PrintAtom(const t_atom &a,char *buf,size_t bufsz);
- //! Scan an atom
- static bool ScanAtom(t_atom &a,const char *buf);
+
+ /*! Scan an atom until whitespace
+ \return next token position, or NULL on failure
+ */
+ static const char *ScanAtom(t_atom &a,const char *buf);
//! Copy a list of atoms
static t_atom *CopyList(int argc,const t_atom *argv);
@@ -389,17 +388,10 @@ public:
//! \note This is used in macros where the type of the arg is not clear
static const t_symbol *MakeSymbol(const t_symbol *s) { return s; }
-#if FLEXT_SYS == FLEXT_SYS_JMAX
- //! Make a symbol from a string
- static const t_symbol *MakeSymbol(const char *s) { return ::fts_new_symbol(s); }
- //! Get symbol string
- static const char *GetString(const t_symbol *s); // ** TODO **
-#else
//! Make a symbol from a string
static const t_symbol *MakeSymbol(const char *s) { return ::gensym(const_cast<char *>(s)); }
//! Get symbol string
static const char *GetString(const t_symbol *s) { return s->s_name; }
-#endif
//! Check for symbol and get string
static const char *GetAString(const t_symbol *s,const char *def = NULL) { return s?GetString(s):def; }
@@ -412,18 +404,6 @@ public:
// there are some more comparison functions for t_atom types outside the class
-#if FLEXT_SYS == FLEXT_SYS_JMAX
- //! Set atom from another atom
- static int GetType(const t_atom &a); // ** TODO **
-
- //! Check whether the atom is nothing
- static bool IsNothing(const t_atom &a) { return fts_is_a(&a,fts_void_class); }
- //! Set the atom to represent nothing
- static void SetNothing(t_atom &a) { fts_set_void(&a); }
-
- //! Check whether the atom is a float
- static bool IsFloat(const t_atom &a) { return fts_is_a(&a,fts_float_class); }
-#else
//! Set atom from another atom
static int GetType(const t_atom &a) { return a.a_type; }
@@ -434,20 +414,10 @@ public:
//! Check whether the atom is a float
static bool IsFloat(const t_atom &a) { return a.a_type == A_FLOAT; }
-#endif
//! Check whether the atom can be represented as a float
static bool CanbeFloat(const t_atom &a) { return IsFloat(a) || IsInt(a); }
-#if FLEXT_SYS == FLEXT_SYS_JMAX
- //! Access the float value (without type check)
- static float GetFloat(const t_atom &a) { return fts_get_float(&a); }
- //! Set the atom to represent a float
- static void SetFloat(t_atom &a,float v) { fts_set_float(&a,v); }
-
- //! Check whether the atom is a symbol
- static bool IsSymbol(const t_atom &a) { return fts_is_a(&a,fts_symbol_class); }
-#else
//! Access the float value (without type check)
static float GetFloat(const t_atom &a) { return a.a_w.w_float; }
//! Set the atom to represent a float
@@ -455,7 +425,6 @@ public:
//! Check whether the atom is a symbol
static bool IsSymbol(const t_atom &a) { return a.a_type == A_SYMBOL; }
-#endif
#if FLEXT_SYS == FLEXT_SYS_PD
//! Access the symbol value (without type check)
@@ -467,11 +436,6 @@ public:
static t_symbol *GetSymbol(const t_atom &a) { return a.a_w.w_sym; }
//! Set the atom to represent a symbol
static void SetSymbol(t_atom &a,const t_symbol *s) { a.a_type = A_SYMBOL; a.a_w.w_sym = const_cast<t_symbol *>(s); }
-#elif FLEXT_SYS == FLEXT_SYS_JMAX
- //! Access the symbol value (without type check)
- static t_symbol *GetSymbol(const t_atom &a); // ** TODO **
- //! Set the atom to represent a symbol
- static void SetSymbol(t_atom &a,const t_symbol *s) { fts_set_symbol(&a,s); }
#else
#error
#endif
@@ -539,29 +503,6 @@ public:
static void *GetAPointer(const t_atom &a,void *def = NULL) { return IsInt(a)?(void *)GetInt(a):def; }
//! Set the atom to represent a pointer
static void SetPointer(t_atom &a,void *p) { SetInt(a,(int)p); }
-#elif FLEXT_SYS == FLEXT_SYS_JMAX
- //! Check for a float and get its value
- static float GetAFloat(const t_atom &a,float def = 0) { return IsFloat(a)?GetFloat(a):(IsInt(a)?GetInt(a):def); }
-
- //! Check whether the atom is an int
- static bool IsInt(const t_atom &a) { return fts_is_a(&a,fts_int_class); }
- //! Access the integer value (without type check)
- static int GetInt(const t_atom &a) { return fts_get_int(&a); }
- //! Check for an integer and get its value
- static int GetAInt(const t_atom &a,int def = 0) { return IsInt(a)?GetInt(a):(IsFloat(a)?(int)GetFloat(a):def); }
- //! Set the atom to represent an integer
- static void SetInt(t_atom &a,int v) { fts_set_int(&a,v); }
-
- //! Check whether the atom strictly is a pointer
- static bool IsPointer(const t_atom &a) { return fts_is_a(&a,fts_pointer_class); }
- //! Check whether the atom can be a pointer
- static bool CanbePointer(const t_atom &a) { return IsPointer(a); }
- //! Access the pointer value (without type check)
- static void *GetPointer(const t_atom &a) { return fts_get_pointer(&a); }
- //! Check for a pointer and get its value
- static void *GetAPointer(const t_atom &a,void *def = NULL) { return IsPointer(a)?GetPointer(a):def; }
- //! Set the atom to represent a pointer
- static void SetPointer(t_atom &a,void *p) { fts_set_pointer(&a,p); }
#else
#error "Platform not supported"
#endif
@@ -710,13 +651,13 @@ public:
{
public:
explicit AtomAnything(): hdr(NULL) {}
-#if FLEXT_SYS != FLEXT_SYS_JMAX
- //! Construct anything
+
+ //! Construct anything
explicit AtomAnything(const t_symbol *h,int argc = 0,const t_atom *argv = NULL)
: AtomList(argc,argv),hdr(h?h:sym__)
{}
-#endif
- //! Construct anything
+
+ //! Construct anything
explicit AtomAnything(const char *h,int argc = 0,const t_atom *argv = NULL)
: AtomList(argc,argv),hdr(MakeSymbol(h))
{}