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
|
#include "ext13.h"
#include "m_pd.h"
/*
#ifndef PD_MAJOR_VERSION
#include "s_stuff.h"
#else
#include "m_imp.h"
#endif*/
#include <sys/stat.h>
#include <stdio.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <string.h>
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
/* taken from m_imp.h */
EXTERN t_pd *glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir);
/* -------------------------- openpatch ------------------------------ */
static t_class *openpatch_class;
typedef struct _openpatch
{
t_object x_obj;
t_symbol *x_s;
t_symbol *x_path;
} t_openpatch;
static void *openpatch_new(t_symbol *s)
{
t_openpatch *x = (t_openpatch *)pd_new(openpatch_class);
x->x_s = s;
x->x_path=gensym("./");
symbolinlet_new(&x->x_obj, &x->x_path);
return (x);
}
static void openpatch_symbol(t_openpatch *x, t_symbol *s)
{
char *lastslash;
char path[MAXPDSTRING], filename[MAXPDSTRING];
x->x_s = s;
lastslash=strrchr (s->s_name,'/');
if (lastslash){
strncpy (path,s->s_name,lastslash-s->s_name+1);
path[lastslash-s->s_name]=0;
strcpy (filename,lastslash+1);
filename[lastslash-s->s_name+1]=0;
}
else {
strcpy (filename,s->s_name);
sprintf (path, "%s", x->x_path->s_name);
}
post ("path:%s , name:%s",path,filename);
glob_evalfile(0,gensym(filename),gensym(path));
}
static void openpatch_bang(t_openpatch *x)
{
if (x->x_s){openpatch_symbol (x,x->x_s);}
}
void openpatch_setup(void)
{
openpatch_class = class_new(gensym("openpatch"), (t_newmethod)openpatch_new, 0,
sizeof(t_openpatch), 0, A_DEFFLOAT, 0);
class_addcreator((t_newmethod)openpatch_new, gensym("opa"), A_DEFFLOAT, 0);
class_addbang(openpatch_class, openpatch_bang);
class_addsymbol(openpatch_class, openpatch_symbol);
}
|