aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <matju@users.sourceforge.net>2009-06-03 00:52:16 +0000
committerN.N. <matju@users.sourceforge.net>2009-06-03 00:52:16 +0000
commita8ddce3a4948d1ba4c6a3b3b20bc3d46fd2b809d (patch)
tree67ab97c7f8230d0ad360d77b32ce686c0d5ebec7
parentc2cee723579786ab1527c53c0ae1f2c87e27bd53 (diff)
added pd (global) method "symbol_table" to get a sorted list of all symbols.
svn path=/trunk/; revision=11636
-rw-r--r--desiredata/src/desire.c4
-rw-r--r--desiredata/src/kernel.c29
2 files changed, 24 insertions, 9 deletions
diff --git a/desiredata/src/desire.c b/desiredata/src/desire.c
index 993c90e9..6369fbde 100644
--- a/desiredata/src/desire.c
+++ b/desiredata/src/desire.c
@@ -6927,7 +6927,7 @@ static void glob_object_table() {
long(object_table->size()-inlets-lists-zombies),long(inlets),long(lists),long(zombies));
}
-void glob_symbol_table ();
+void glob_symbol_table (t_pd *, float onlybound);
extern t_class *glob_pdobject;
extern "C" void glob_init () {
@@ -6981,7 +6981,7 @@ extern "C" void glob_init () {
class_addmethod2(c,glob_update_path, "update-path", "");
class_addmethod2(c,glob_help, "help", "s");
class_addmethod2(c,glob_object_table,"object_table","");
- class_addmethod2(c,glob_symbol_table,"symbol_table","");
+ class_addmethod2(c,glob_symbol_table,"symbol_table","F");
class_addanything(c, max_default);
pd_bind((t_pd *)&glob_pdobject, gensym("pd"));
}
diff --git a/desiredata/src/kernel.c b/desiredata/src/kernel.c
index 257ee97b..5e349de9 100644
--- a/desiredata/src/kernel.c
+++ b/desiredata/src/kernel.c
@@ -19,6 +19,8 @@
#include <stdarg.h>
#include <string.h>
#include <sstream>
+#include <vector>
+#include <algorithm>
#include <fcntl.h>
#include <stdio.h>
#include <ctype.h>
@@ -1081,10 +1083,9 @@ static int hash(const char *s, size_t n) {
return hash2;
}
-/* tb: made dogensym() threadsafe
- * supported by vibrez.net */
+/* tb: made dogensym() threadsafe */
+static t_symbol *symhash[HASHSIZE];
t_symbol *dogensym(const char *s, size_t n, t_symbol *oldsym) {
- static t_symbol *symhash[HASHSIZE];
#ifdef THREADSAFE_GENSYM
static pthread_mutex_t hash_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
@@ -1146,6 +1147,20 @@ extern "C" t_symbol *symprintf(const char *s, ...) {
return r;
}
+bool symbol_lt (t_symbol *a, t_symbol *b) {return strcmp(a->name,b->name)<0;}
+
+void glob_symbol_table (t_pd *, float onlybound) {
+ std::vector<t_symbol *> all;
+ for (size_t i=0; i<int(sizeof(symhash)/sizeof(*symhash)); i++) for (t_symbol *s=symhash[i]; s; s=s->next) all.push_back(s);
+ sort(all.begin(),all.end(),symbol_lt);
+ for (size_t i=0; i<all.size(); i++) {
+ int j=0;
+ if (all[i]->thing) j++;
+ //if (all[i]->thing->_class==bindlist_class) j++;
+ if (j>0 || !onlybound) printf(" %0*lx: %s (%d)\n",2*sizeof(void*),long(all[i]),all[i]->name,j);
+ }
+}
+
static int tryingalready;
extern "C" void canvas_popabstraction(t_canvas *x);
extern t_pd *newest;
@@ -1723,7 +1738,7 @@ void binbuf_print(t_binbuf *x) {
for (size_t i=0; i < x->n; i++) {
if (newline) {
if (startedpost) endpost();
- startpost("");
+ startpost("%s",""); /* dummy string to fool __attribute__ */
startedpost = 1;
}
postatom(1, x->v + i);
@@ -1825,8 +1840,8 @@ void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv) {
while (ac && (at->a_type == A_SEMI || at->a_type == A_COMMA)) {ac--; at++;}
if (!ac) break;
if (at->a_type == A_DOLLAR) {
- if (at->a_index <= 0 || at->a_index > argc) {error("$%d: not enough arguments supplied", at->a_index); goto cleanup;}
- else if (argv[at->a_index-1].a_type != A_SYMBOL) {error("$%d: symbol needed as receiver", at->a_index); goto cleanup;}
+ if (at->a_index<=0 || at->a_index>argc) {error("$%ld: not enough arguments supplied",long(at->a_index)); goto cleanup;}
+ else if (argv[at->a_index-1].a_type!=A_SYMBOL) {error("$%ld: symbol needed as receiver",long(at->a_index)); goto cleanup;}
else s = argv[at->a_index-1].a_symbol;
} else if (at->a_type == A_DOLLSYM) {
s = binbuf_realizedollsym(at->a_symbol, argc, argv, 0);
@@ -1870,7 +1885,7 @@ void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv) {
else if (at->a_index == 0) SETFLOAT(msp, canvas_getdollarzero());
else {
SETFLOAT(msp, 0);
- if (target != &pd_objectmaker) error("$%d: argument number out of range", at->a_index);
+ if (target != &pd_objectmaker) error("$%ld: argument number out of range",long(at->a_index));
}
break;
case A_DOLLSYM: {