diff options
author | Miller Puckette <millerpuckette@users.sourceforge.net> | 2005-12-31 20:55:25 +0000 |
---|---|---|
committer | Miller Puckette <millerpuckette@users.sourceforge.net> | 2005-12-31 20:55:25 +0000 |
commit | d68f8326740a6a8d0b97b00e774d23c1a5c336a2 (patch) | |
tree | fe4a64fcea60bd35d214ac6813cd598af97b87ef /pd/src/m_class.c | |
parent | 1498e89f88d0a090a59ceb4cf19daf9d9c8963c5 (diff) |
Took a bunch of patches... more to come but these are the ones that might break stuff so I'll sync here.
svn path=/trunk/; revision=4336
Diffstat (limited to 'pd/src/m_class.c')
-rw-r--r-- | pd/src/m_class.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/pd/src/m_class.c b/pd/src/m_class.c index d2489b44..30aeb310 100644 --- a/pd/src/m_class.c +++ b/pd/src/m_class.c @@ -16,6 +16,7 @@ #include <stdarg.h> #include <string.h> +#include <stdio.h> static t_symbol *class_loadsym; /* name under which an extern is invoked */ static void pd_defaultfloat(t_pd *x, t_float f); @@ -513,6 +514,42 @@ extern t_pd *newest; t_symbol* pathsearch(t_symbol *s,char* ext); int pd_setloadingabstraction(t_symbol *sym); + +/* replace everything but [a-zA-Z0-9_] by "0x%x" */ +static char*alternative_classname(char*classname) +{ + char *altname=(char*)getbytes(sizeof(char)*MAXPDSTRING); + int count=0; + int i=0; + for(i=0; i<MAXPDSTRING; i++) + altname[i]=0; + i=0; + while(*classname) + { + char c=*classname; + if((c>=48 && c<=57)|| /* [0-9] */ + (c>=65 && c<=90)|| /* [A-Z] */ + (c>=97 && c<=122)||/* [a-z] */ + (c==95)) /* [_] */ + { + altname[i]=c; + i++; + } + else /* a "bad" character */ + { + sprintf(altname+i, "0x%02x", c); + i+=4; + count++; + } + classname++; + } + if(count>0)return altname; + /* seems like the given classname is fine as can be */ + freebytes(altname, sizeof(char)*MAXPDSTRING); + return 0; +} + + /* this routine is called when a new "object" is requested whose class Pd doesn't know. Pd tries to load it as an extern, then as an abstraction. */ void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv) @@ -521,10 +558,11 @@ void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv) t_symbol *dir = canvas_getcurrentdir(); int fd; char dirbuf[MAXPDSTRING], *nameptr; + char *altname=alternative_classname(s->s_name); if (tryingalready) return; newest = 0; class_loadsym = s; - if (sys_load_lib(dir->s_name, s->s_name)) + if (sys_load_lib(dir->s_name, s->s_name, altname)) { tryingalready = 1; typedmess(dummy, s, argc, argv); @@ -535,6 +573,8 @@ void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv) current = s__X.s_thing; if ((fd = open_via_path(dir->s_name, s->s_name, ".pd", dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 || + (altname && (fd = open_via_path(dir->s_name, altname, ".pd", + dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) || (fd = open_via_path(dir->s_name, s->s_name, ".pat", dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) { |