Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
purr-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
brittney allen
purr-data
Commits
c2b9f6a2
Commit
c2b9f6a2
authored
8 years ago
by
Jonathan Wilkes
Browse files
Options
Downloads
Patches
Plain Diff
port 9dd405d0a4dd3c3007c75f5bd716eaf0bd28d19b from Pd-l2ork: added list fromsymbol and tosymbol
parent
de698bf1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pd/src/x_list.c
+104
-5
104 additions, 5 deletions
pd/src/x_list.c
with
104 additions
and
5 deletions
pd/src/x_list.c
+
104
−
5
View file @
c2b9f6a2
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include
"m_pd.h"
#include
"m_pd.h"
#include
"s_stuff.h"
#include
"s_stuff.h"
/*
#include <string.h>
*/
#include
<string.h>
#ifdef HAVE_MALLOC_H
#ifdef HAVE_MALLOC_H
#include
<malloc.h>
#include
<malloc.h>
...
@@ -18,15 +18,20 @@
...
@@ -18,15 +18,20 @@
extern
t_pd
*
newest
;
extern
t_pd
*
newest
;
#ifndef HAVE_ALLOCA
/* can work without alloca() but we never need it */
#define HAVE_ALLOCA 1
#endif
#define LIST_NGETBYTE 100
/* bigger that this we use alloc, not alloca */
#define LIST_NGETBYTE 100
/* bigger that this we use alloc, not alloca */
/* the "list" object family.
/* the "list" object family.
list append - append a list to another
list append - append a list to another
list prepend - prepend a list to another
list prepend - prepend a list to another
list split - first n elements to first outlet, rest to second outlet
list split - first n elements to first outlet, rest to second outlet
list trim - trim off "list" selector
list trim - trim off "list" selector
list length - output number of items in list
list length - output number of items in list
list fromsymbol - "explode" a symbol into a list of character codes
list cat - build a list by accumulating elements
list cat - build a list by accumulating elements
Need to think more about:
Need to think more about:
...
@@ -44,6 +49,16 @@ Probably don't need:
...
@@ -44,6 +49,16 @@ Probably don't need:
/* -------------- utility functions: storage, copying -------------- */
/* -------------- utility functions: storage, copying -------------- */
#if HAVE_ALLOCA
#define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)((n) < LIST_NGETBYTE ? \
alloca((n) * sizeof(t_atom)) : getbytes((n) * sizeof(t_atom))))
#define ATOMS_FREEA(x, n) ( \
((n) < LIST_NGETBYTE || (freebytes((x), (n) * sizeof(t_atom)), 0)))
#else
#define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)getbytes((n) * sizeof(t_atom)))
#define ATOMS_FREEA(x, n) (freebytes((x), (n) * sizeof(t_atom)))
#endif
void
atoms_copy
(
int
argc
,
t_atom
*
from
,
t_atom
*
to
)
void
atoms_copy
(
int
argc
,
t_atom
*
from
,
t_atom
*
to
)
{
{
int
i
;
int
i
;
...
@@ -591,6 +606,84 @@ static void list_length_setup(void)
...
@@ -591,6 +606,84 @@ static void list_length_setup(void)
class_sethelpsymbol
(
list_length_class
,
&
s_list
);
class_sethelpsymbol
(
list_length_class
,
&
s_list
);
}
}
/* ------------- list fromsymbol --------------------- */
t_class
*
list_fromsymbol_class
;
typedef
struct
_list_fromsymbol
{
t_object
x_obj
;
}
t_list_fromsymbol
;
static
void
*
list_fromsymbol_new
(
void
)
{
t_list_fromsymbol
*
x
=
(
t_list_fromsymbol
*
)
pd_new
(
list_fromsymbol_class
);
outlet_new
(
&
x
->
x_obj
,
&
s_list
);
return
(
x
);
}
static
void
list_fromsymbol_symbol
(
t_list_fromsymbol
*
x
,
t_symbol
*
s
)
{
t_atom
*
outv
;
int
n
,
outc
=
strlen
(
s
->
s_name
);
ATOMS_ALLOCA
(
outv
,
outc
);
for
(
n
=
0
;
n
<
outc
;
n
++
)
SETFLOAT
(
outv
+
n
,
(
unsigned
char
)
s
->
s_name
[
n
]);
outlet_list
(
x
->
x_obj
.
ob_outlet
,
&
s_list
,
outc
,
outv
);
ATOMS_FREEA
(
outv
,
outc
);
}
static
void
list_fromsymbol_setup
(
void
)
{
list_fromsymbol_class
=
class_new
(
gensym
(
"list fromsymbol"
),
(
t_newmethod
)
list_fromsymbol_new
,
0
,
sizeof
(
t_list_fromsymbol
),
0
,
0
);
class_addsymbol
(
list_fromsymbol_class
,
list_fromsymbol_symbol
);
class_sethelpsymbol
(
list_fromsymbol_class
,
&
s_list
);
}
/* ------------- list tosymbol --------------------- */
t_class
*
list_tosymbol_class
;
typedef
struct
_list_tosymbol
{
t_object
x_obj
;
}
t_list_tosymbol
;
static
void
*
list_tosymbol_new
(
void
)
{
t_list_tosymbol
*
x
=
(
t_list_tosymbol
*
)
pd_new
(
list_tosymbol_class
);
outlet_new
(
&
x
->
x_obj
,
&
s_symbol
);
return
(
x
);
}
static
void
list_tosymbol_list
(
t_list_tosymbol
*
x
,
t_symbol
*
s
,
int
argc
,
t_atom
*
argv
)
{
int
i
;
#if HAVE_ALLOCA
char
*
str
=
alloca
(
argc
+
1
);
#else
char
*
str
=
getbytes
(
argc
+
1
);
#endif
for
(
i
=
0
;
i
<
argc
;
i
++
)
str
[
i
]
=
(
char
)
atom_getfloatarg
(
i
,
argc
,
argv
);
str
[
argc
]
=
0
;
outlet_symbol
(
x
->
x_obj
.
ob_outlet
,
gensym
(
str
));
#if HAVE_ALLOCA
#else
freebytes
(
str
,
argc
+
1
);
#endif
}
static
void
list_tosymbol_setup
(
void
)
{
list_tosymbol_class
=
class_new
(
gensym
(
"list tosymbol"
),
(
t_newmethod
)
list_tosymbol_new
,
0
,
sizeof
(
t_list_tosymbol
),
0
,
0
);
class_addlist
(
list_tosymbol_class
,
list_tosymbol_list
);
class_sethelpsymbol
(
list_tosymbol_class
,
&
s_list
);
}
/* ------------- list ------------------- */
/* ------------- list ------------------- */
static
void
*
list_new
(
t_pd
*
dummy
,
t_symbol
*
s
,
int
argc
,
t_atom
*
argv
)
static
void
*
list_new
(
t_pd
*
dummy
,
t_symbol
*
s
,
int
argc
,
t_atom
*
argv
)
...
@@ -606,12 +699,16 @@ static void *list_new(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
...
@@ -606,12 +699,16 @@ static void *list_new(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
newest
=
list_cat_new
();
newest
=
list_cat_new
();
else
if
(
s2
==
gensym
(
"prepend"
))
else
if
(
s2
==
gensym
(
"prepend"
))
newest
=
list_prepend_new
(
s
,
argc
-
1
,
argv
+
1
);
newest
=
list_prepend_new
(
s
,
argc
-
1
,
argv
+
1
);
else
if
(
s2
==
gensym
(
"split"
))
else
if
(
s2
==
gensym
(
"split"
))
newest
=
list_split_new
(
atom_getfloatarg
(
1
,
argc
,
argv
));
newest
=
list_split_new
(
atom_getfloatarg
(
1
,
argc
,
argv
));
else
if
(
s2
==
gensym
(
"trim"
))
else
if
(
s2
==
gensym
(
"trim"
))
newest
=
list_trim_new
();
newest
=
list_trim_new
();
else
if
(
s2
==
gensym
(
"length"
))
else
if
(
s2
==
gensym
(
"length"
))
newest
=
list_length_new
();
newest
=
list_length_new
();
else
if
(
s2
==
gensym
(
"fromsymbol"
))
newest
=
list_fromsymbol_new
();
else
if
(
s2
==
gensym
(
"tosymbol"
))
newest
=
list_tosymbol_new
();
else
else
{
{
error
(
"list %s: unknown function"
,
s2
->
s_name
);
error
(
"list %s: unknown function"
,
s2
->
s_name
);
...
@@ -630,5 +727,7 @@ void x_list_setup(void)
...
@@ -630,5 +727,7 @@ void x_list_setup(void)
list_split_setup
();
list_split_setup
();
list_trim_setup
();
list_trim_setup
();
list_length_setup
();
list_length_setup
();
list_fromsymbol_setup
();
list_tosymbol_setup
();
class_addcreator
((
t_newmethod
)
list_new
,
&
s_list
,
A_GIMME
,
0
);
class_addcreator
((
t_newmethod
)
list_new
,
&
s_list
,
A_GIMME
,
0
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment