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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
Index: m_class.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_class.c,v
retrieving revision 1.3
diff -u -w -r1.3 m_class.c
--- m_class.c 6 Sep 2004 20:20:35 -0000 1.3
+++ m_class.c 22 Nov 2005 16:48:21 -0000
@@ -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 @@
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 @@
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_alt(dir->s_name, s->s_name,altname))
{
tryingalready = 1;
typedmess(dummy, s, argc, argv);
@@ -535,6 +573,8 @@
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)
{
Index: s_loader.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_loader.c,v
retrieving revision 1.4
diff -u -w -r1.4 s_loader.c
--- s_loader.c 6 Sep 2004 20:20:35 -0000 1.4
+++ s_loader.c 22 Nov 2005 16:48:22 -0000
@@ -46,10 +46,11 @@
void class_set_extern_dir(t_symbol *s);
-int sys_load_lib(char *dirname, char *classname)
+int sys_load_lib_alt(char *dirname, char *classname, char*altname)
{
char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
- classname2[MAXPDSTRING], *nameptr, *lastdot;
+ classname2[MAXPDSTRING], *nameptr, *lastdot,
+ altsymname[MAXPDSTRING];
void *dlobj;
t_xxx makeout = NULL;
int fd;
@@ -72,6 +73,25 @@
if ((fd = open_via_path(dirname, classname2, sys_dllextent,
dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
{
+ /* next try (alternative_classname).(sys_dllextent) */
+ if(altname)
+ {
+ if ((fd = open_via_path(dirname, altname, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+
+ /* next try (alternative_classname)/(alternative_classname).(sys_dllextent) ... */
+ strncpy(classname2, altname, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(classname2, "/");
+ strncat(classname2, altname, MAXPDSTRING-strlen(classname2));
+ filename[MAXPDSTRING-1] = 0;
+ if ((fd = open_via_path(dirname, classname2, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ return 0;
+ }
+ }
+ else
return (0);
}
}
@@ -93,9 +113,22 @@
#ifdef MACOSX
strcpy(symname, "_");
strcat(symname, nameptr);
+ if(altname)
+ {
+ strcpy(altsymname, "_alt_");
+ strcat(altsymname, altname);
+ strcat(altsymname, "_setup");
+ }
#else
strcpy(symname, nameptr);
+ if(altname)
+ {
+ strcpy(altsymname, "alt_");
+ strcat(altsymname, altname);
+ strcat(altsymname, "_setup");
+ }
#endif
+
/* if the last character is a tilde, replace with "_tilde" */
if (symname[strlen(symname) - 1] == '~')
strcpy(symname + (strlen(symname) - 1), "_tilde");
@@ -110,6 +143,7 @@
return (0);
}
makeout = (t_xxx)dlsym(dlobj, symname);
+ if(!makeout)makeout = (t_xxx)dlsym(dlobj, altsymname);
#endif
#ifdef MSW
sys_bashfilename(filename, filename);
@@ -121,6 +155,7 @@
return (0);
}
makeout = (t_xxx)GetProcAddress(ntdll, symname);
+ if(!makeout)makeout = (t_xxx)GetProcAddress(ntdll, altsymname);
#endif
#ifdef MACOSX
{
@@ -138,6 +173,8 @@
s = NSLookupSymbolInModule(ret, symname);
+ if(!s)s=NSLookupSymbolInModule(ret, altsymname);
+
if (s)
makeout = (t_xxx)NSAddressOfSymbol( s);
else makeout = 0;
@@ -147,6 +184,8 @@
if (!makeout)
{
post("load_object: Symbol \"%s\" not found", symname);
+ if(altname)
+ post("load_object: Symbol \"%s\" not found", altsymname);
class_set_extern_dir(&s_);
return 0;
}
@@ -155,6 +194,10 @@
return (1);
}
+int sys_load_lib(char *dirname, char *filename)
+{
+ return sys_load_lib_alt(dirname, filename, 0);
+}
Index: s_stuff.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v
retrieving revision 1.5
diff -u -w -r1.5 s_stuff.h
--- s_stuff.h 6 Sep 2004 20:20:36 -0000 1.5
+++ s_stuff.h 22 Nov 2005 16:48:22 -0000
@@ -47,6 +47,7 @@
/* s_loader.c */
int sys_load_lib(char *dirname, char *filename);
+int sys_load_lib_alt(char *dirname, char *filename, char* altname);
/* s_audio.c */
|