aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/delsplit/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/delsplit/main.cpp')
-rwxr-xr-xexternals/grill/delsplit/main.cpp133
1 files changed, 71 insertions, 62 deletions
diff --git a/externals/grill/delsplit/main.cpp b/externals/grill/delsplit/main.cpp
index bfd2b52c..bf65a6b7 100755
--- a/externals/grill/delsplit/main.cpp
+++ b/externals/grill/delsplit/main.cpp
@@ -2,16 +2,18 @@
delsplit - split a delimited list-in-a-symbol
-Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net)
+Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
+#define FLEXT_ATTRIBUTES 1
+
#include <flext.h>
-#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401)
-#error You need at least flext version 0.4.1
+#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500)
+#error You need at least flext version 0.5.0
#endif
#include <string.h>
@@ -19,15 +21,8 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <stdio.h>
#include <ctype.h>
-#define I int
-#define L long
-#define F float
-#define D double
-#define V void
-#define C char
-#define BL bool
-#define VERSION "0.1.2"
+#define VERSION "0.1.4"
#ifdef __MWERKS__
#define STD std
@@ -42,52 +37,54 @@ class delsplit:
FLEXT_HEADER_S(delsplit,flext_base,Setup)
public:
- delsplit(I argc,const t_atom *argv);
+ delsplit(int argc,const t_atom *argv);
protected:
- V m_list(const t_symbol *s);
- V m_del(const t_symbol *s);
+ void m_list(const t_symbol *s);
+ void m_del(const t_symbol *s,int argc,const t_atom *argv);
const t_symbol *delim;
- virtual void m_help();
-
- static V SetAtom(t_atom &l,const C *s);
+ static void SetAtom(t_atom &l,const char *s);
private:
- static V Setup(t_classid c);
+ static void Setup(t_classid c);
+ static const t_symbol *sym__space;
+
FLEXT_CALLBACK_S(m_list)
- FLEXT_CALLBACK_S(m_del)
+ FLEXT_CALLBACK_A(m_del)
+ FLEXT_ATTRVAR_S(delim)
};
FLEXT_NEW_V("delsplit",delsplit)
-V delsplit::Setup(t_classid c)
+const t_symbol *delsplit::sym__space = NULL;
+
+void delsplit::Setup(t_classid c)
{
+ sym__space = MakeSymbol(" ");
+
FLEXT_CADDMETHOD(c,0,m_list);
FLEXT_CADDMETHOD(c,1,m_del);
+ FLEXT_CADDATTR_VAR1(c,"del",delim);
}
-delsplit::delsplit(I argc,const t_atom *argv):
- delim(NULL)
+delsplit::delsplit(int argc,const t_atom *argv):
+ delim(sym__)
{
AddInAnything("Symbol in, representing the delimited list");
- AddInSymbol("Set the Delimiter");
+ AddInAnything("Set the Delimiter");
AddOutList("The split list");
- if(argc && IsSymbol(argv[0])) delim = GetSymbol(argv[0]);
+ m_del(sym_list,argc,argv);
}
-V delsplit::m_help()
-{
- post("%s version " VERSION " (using flext " FLEXT_VERSTR "), (C) 2002 Thomas Grill",thisName());
-}
/** \brief check whether string represents a number
\ret 0..integer, 1..float, -1..no number
*/
-static I chknum(const C *s)
+static int chknum(const char *s)
{
int num = 0,pts = 0;
for(const char *si = s; *s; ++s) {
@@ -98,49 +95,61 @@ static I chknum(const C *s)
return (num > 0 && pts <= 1)?pts:-1;
}
-V delsplit::SetAtom(t_atom &l,const C *s)
+void delsplit::m_del(const t_symbol *s,int argc,const t_atom *argv)
+{
+ delim = NULL;
+ if(s == sym_symbol) {
+ FLEXT_ASSERT(argc == 1 && IsSymbol(argv[0]));
+ delim = GetSymbol(argv[0]);
+ }
+ else if(s == sym_list) {
+ if(argc == 0)
+ delim = sym__space;
+ else if(argc >= 1 && IsSymbol(argv[0]))
+ delim = GetSymbol(argv[0]);
+ }
+
+ if(!delim) {
+ post("%s - Argument must be a symbol, list or int/float/bang",thisName());
+ delim = sym__space;
+ }
+}
+
+void delsplit::SetAtom(t_atom &l,const char *s)
{
- I n = chknum(s);
+ int n = chknum(s);
if(n < 0)
SetString(l,s);
else if(n == 0)
SetInt(l,atoi(s));
else
- SetFloat(l,(F)atof(s));
+ SetFloat(l,(float)atof(s));
}
-V delsplit::m_list(const t_symbol *sym)
+void delsplit::m_list(const t_symbol *sym)
{
- if(delim) {
- t_atom lst[256];
- int cnt = 0;
- const C *sdel = GetString(delim);
- I ldel = strlen(sdel);
- C str[1024];
- strcpy(str,GetString(sym));
-
- for(const char *s = str; *s; ) {
- C *e = strstr(s,sdel);
- if(!e) {
- SetAtom(lst[cnt++],s);
- break;
- }
- else {
- *e = 0;
- SetAtom(lst[cnt++],s);
- s = e+ldel;
- }
+ FLEXT_ASSERT(delim);
+
+ t_atom lst[256];
+ int cnt = 0;
+ const char *sdel = GetString(delim);
+ int ldel = strlen(sdel);
+ char str[1024];
+ strcpy(str,GetString(sym));
+
+ for(const char *s = str; *s; ) {
+ char *e = strstr(s,sdel);
+ if(!e) {
+ SetAtom(lst[cnt++],s);
+ break;
+ }
+ else {
+ *e = 0;
+ SetAtom(lst[cnt++],s);
+ s = e+ldel;
}
-
- ToOutList(0,cnt,lst);
}
- else
- post("%s - No delimiter defined",thisName());
-}
-
-V delsplit::m_del(const t_symbol *s)
-{
- delim = s;
+
+ ToOutList(0,cnt,lst);
}
-