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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
deljoin - join a list with delimiter
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 < 500)
#error You need at least flext version 0.5.0
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define VERSION "0.1.4"
#ifdef __MWERKS__
#define STD std
#else
#define STD
#endif
class deljoin:
public flext_base
{
FLEXT_HEADER_S(deljoin,flext_base,Setup)
public:
deljoin(int argc,const t_atom *argv);
protected:
void m_list(const t_symbol *s,int argc,const t_atom *argv);
void m_del(const t_symbol *s,int argc,const t_atom *argv);
const t_symbol *delim;
private:
static void Setup(t_classid c);
static const t_symbol *sym__space;
FLEXT_CALLBACK_A(m_list)
FLEXT_CALLBACK_A(m_del)
FLEXT_ATTRVAR_S(delim)
};
FLEXT_NEW_V("deljoin",deljoin)
const t_symbol *deljoin::sym__space = NULL;
void deljoin::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);
}
deljoin::deljoin(int argc,const t_atom *argv):
delim(sym__)
{
AddInAnything("Anything in - triggers output");
AddInAnything("Set the Delimiter");
AddOutSymbol("A symbol representing the joined list");
m_del(sym_list,argc,argv);
}
void deljoin::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) {
if(IsSymbol(argv[0]))
delim = GetSymbol(argv[0]);
else if(IsFloat(argv[0]) || IsInt(argv[0]))
delim = sym__;
}
}
else if(s == sym_bang || s == sym_float || s == sym_int)
delim = sym__;
if(!delim) {
post("%s - Argument must be a symbol, list or int/float/bang",thisName());
delim = sym__;
}
}
/** \brief convert incoming list to a concatenated string
Handles symbols, integers and floats
*/
void deljoin::m_list(const t_symbol *s,int argc,const t_atom *argv)
{
FLEXT_ASSERT(delim);
char tmp[1024],*t = tmp;
const char *sdel = GetString(delim);
int 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);
}
|