[PD-cvs] externals/loaders/hexloader hexloader.c,1.3,1.4
IOhannes m zmölnig
zmoelnig at users.sourceforge.net
Wed Oct 17 16:31:28 CEST 2007
Update of /cvsroot/pure-data/externals/loaders/hexloader
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29287
Modified Files:
hexloader.c
Log Message:
added a first support for loading patches;
there is still the issue with implicit dependencies of patches not correctly resolved
(if the patch depends on a lib it has to be loaded beforehand or via the [declare -lib])
Index: hexloader.c
===================================================================
RCS file: /cvsroot/pure-data/externals/loaders/hexloader/hexloader.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** hexloader.c 17 Oct 2007 13:56:51 -0000 1.3
--- hexloader.c 17 Oct 2007 14:31:26 -0000 1.4
***************
*** 18,21 ****
--- 18,24 ----
#include "m_pd.h"
+
+ #if (PD_MINOR_VERSION >= 40)
+
#include "s_stuff.h"
#include "g_canvas.h"
***************
*** 40,43 ****
--- 43,62 ----
+ #define HEXLOADER_PATCHES
+
+ #ifdef HEXLOADER_PATCHES
+ void canvas_popabstraction(t_canvas *x);
+ static void*hexloader_fakenew(t_symbol *s, int argc, t_atom *argv);
+ t_pd pd_objectmaker; /* factory for creating "object" boxes */
+ #endif
+
+ typedef struct _filepath
+ {
+ t_symbol*filename;
+ t_symbol*pathname;
+ } t_filepath;
+
+
+
typedef void (*t_hexloader_setup)(void);
***************
*** 129,132 ****
--- 148,152 ----
*/
+
/* -------------------- utilities --------------------- */
***************
*** 553,557 ****
! static void*hexloader_new(t_symbol *s, int argc, t_atom *argv);
/**
* try to open a file (given via pathname+filename) as a patcher
--- 573,577 ----
!
/**
* try to open a file (given via pathname+filename) as a patcher
***************
*** 563,573 ****
*/
/* this only gets called if we have already found an abstraction-file */
! static int hexloader_loadpatch(char*pathname, char*filename, char*altclassname, char*realclassname)
{
char fullfile[MAXPDSTRING];
sprintf(fullfile, "%s/%s", pathname, filename);
post("BUG: hexloader not loading patch: %s (not yet implemented)", fullfile);
return 0;
}
--- 583,605 ----
*/
+
/* this only gets called if we have already found an abstraction-file */
! static t_filepath*hexloader_loadpatch(char*pathname, char*filename, char*altclassname, char*realclassname)
{
char fullfile[MAXPDSTRING];
sprintf(fullfile, "%s/%s", pathname, filename);
+ #ifdef HEXLOADER_PATCHES
+ class_addcreator((t_newmethod)hexloader_fakenew, gensym(realclassname), A_GIMME, 0);
+ {
+ t_filepath*result=getbytes(sizeof(t_filepath));
+ result->filename=gensym(filename);
+ result->pathname=gensym(pathname);
+ return result;
+ }
+
+ #else
post("BUG: hexloader not loading patch: %s (not yet implemented)", fullfile);
+ #endif /* HEXLOADER_PATCHES */
return 0;
}
***************
*** 597,602 ****
* @return 1 on success, 0 on failure
*/
! static int hexloader_doloader(t_canvas *canvas, filelist_t*altnames0, char*classname)
! {
int fd = -1;
char dirbuf[MAXPDSTRING];
--- 629,634 ----
* @return 1 on success, 0 on failure
*/
!
! static int hexloader_trylibraries(filelist_t*altnames0) {
int fd = -1;
char dirbuf[MAXPDSTRING];
***************
*** 624,627 ****
--- 656,667 ----
}
+ return 0;
+ }
+ static t_filepath*hexloader_trypatches(filelist_t*altnames0, char*classname) {
+ int fd = -1;
+ char dirbuf[MAXPDSTRING];
+ char*nameptr;
+ filelist_t*altnames=altnames0;
+
/* try patches */
altnames=altnames0;
***************
*** 632,641 ****
while(extent!=0) {
if ((fd = open_via_path(".", altname, extent, dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) {
close (fd);
! if(hexloader_loadpatch(dirbuf, nameptr, altname, classname)) {
! return 1;
}
}
-
extindex++;
extent=patch_extent[extindex];
--- 672,682 ----
while(extent!=0) {
if ((fd = open_via_path(".", altname, extent, dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) {
+ t_symbol*s;
close (fd);
! t_filepath*fp=hexloader_loadpatch(dirbuf, nameptr, altname, classname);
! if(fp) {
! return fp;
}
}
extindex++;
extent=patch_extent[extindex];
***************
*** 643,646 ****
--- 684,703 ----
altnames=altnames->next;
}
+
+ return 0;
+ }
+
+ static int hexloader_doloader(t_canvas *canvas, filelist_t*altnames0, char*classname)
+ {
+ t_filepath*fp=0;
+ if(hexloader_trylibraries(altnames0))
+ return 1;
+
+ fp=hexloader_trypatches(altnames0, classname);
+ if(fp) {
+ freebytes(fp, sizeof(t_filepath));
+ return 1;
+ }
+
return 0;
}
***************
*** 675,686 ****
}
! static void*hexloader_new(t_symbol *s, int argc, t_atom *argv)
! {
! if(s==gensym("hexloader")) {
! t_hexloader*x = (t_hexloader*)pd_new(hexloader_class);
! return (x);
}
! return 0;
}
--- 732,775 ----
}
! #ifdef HEXLOADER_PATCHES
! static void*hexloader_fakenew(t_symbol*s, int argc, t_atom*argv) {
! t_pd*current = s__X.s_thing;
! t_filepath*fp=0;
! filelist_t*altnames=0;
!
! post("hexloader: disguising as '%s'", s->s_name);
!
! if(!pd_objectmaker) {
! post("BUG: no pd_objectmaker found");
! return 0;
}
! /* get alternatives */
! altnames=hexloader_getalternatives(s->s_name);
! /* do the loading */
! fp=hexloader_trypatches(altnames, s->s_name);
! /* clean up */
! filelist_clear(altnames);
!
! if(fp) {
! canvas_setargs(argc, argv);
! binbuf_evalfile(fp->filename, fp->pathname);
! freebytes(fp, sizeof(t_filepath));
! if (s__X.s_thing != current)
! canvas_popabstraction((t_canvas *)(s__X.s_thing));
! canvas_setargs(0, 0);
! return pd_newest();
! } else
! return 0;
! }
! #endif /* HEXLOADER_PATCHES */
!
! #endif /* PD_MINOR_VERSION>=40 */
!
!
! static void*hexloader_new(t_symbol *s, int argc, t_atom *argv)
! {
! t_hexloader*x = (t_hexloader*)pd_new(hexloader_class);
! return (x);
}
More information about the Pd-cvs
mailing list