From a8ddce3a4948d1ba4c6a3b3b20bc3d46fd2b809d Mon Sep 17 00:00:00 2001 From: "N.N." Date: Wed, 3 Jun 2009 00:52:16 +0000 Subject: added pd (global) method "symbol_table" to get a sorted list of all symbols. svn path=/trunk/; revision=11636 --- desiredata/src/desire.c | 4 ++-- desiredata/src/kernel.c | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'desiredata') 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 #include #include +#include +#include #include #include #include @@ -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 all; + for (size_t i=0; inext) all.push_back(s); + sort(all.begin(),all.end(),symbol_lt); + for (size_t i=0; ithing) 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: { -- cgit v1.2.1