1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
deljoin - join a list with delimiter
Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
#include <flext.h>
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401)
#error You need at least flext version 0.4.1
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.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"
#ifdef __MWERKS__
#define STD std
#else
#define STD
#endif
class deljoin:
public flext_base
{
FLEXT_HEADER_S(deljoin,flext_base,Setup)
public:
deljoin(I argc,const t_atom *argv);
protected:
V m_list(const t_symbol *s,int argc,const t_atom *argv);
V m_del(const t_symbol *s);
const t_symbol *delim;
virtual void m_help();
private:
static V Setup(t_class *c);
FLEXT_CALLBACK_A(m_list)
FLEXT_CALLBACK_S(m_del)
};
FLEXT_NEW_V("deljoin",deljoin)
V deljoin::Setup(t_class *c)
{
FLEXT_CADDMETHOD(c,0,m_list);
FLEXT_CADDMETHOD(c,1,m_del);
}
deljoin::deljoin(I argc,const t_atom *argv):
delim(NULL)
{
AddInAnything("Anything in - triggers output");
AddInSymbol("Set the Delimiter");
AddOutSymbol("A symbol representing the joined list");
if(argc && IsSymbol(argv[0])) delim = GetSymbol(argv[0]);
}
V deljoin::m_help()
{
post("%s version " VERSION " (using flext " FLEXT_VERSTR "), (C) 2002 Thomas Grill",thisName());
}
/** \brief convert incoming list to a concatenated string
Handles symbols, integers and floats
*/
V deljoin::m_list(const t_symbol *s,int argc,const t_atom *argv)
{
if(delim) {
C tmp[1024],*t = tmp;
const C *sdel = GetString(delim);
I ldel = strlen(sdel);
if(s && s != sym_list && s != sym_float && s != sym_int) {
strcpy(t,GetString(s));
t += strlen(t);
}
for(int i = 0; i < argc; ++i) {
if(t != tmp) {
strcpy(t,sdel);
t += ldel;
}
const t_atom &a = argv[i];
if(IsSymbol(a))
strcpy(t,GetString(a));
else if(IsInt(a)) {
STD::sprintf(t,"%i",GetInt(a),10);
}
else if(IsFloat(a)) {
STD::sprintf(t,"%f",GetFloat(a),10);
}
// else do nothing
t += strlen(t);
}
ToOutString(0,tmp);
}
else
post("%s - No delimiter defined",thisName());
}
V deljoin::m_del(const t_symbol *s)
{
delim = s;
}
|