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
|
Description: provide [creb] object
so the library can be loaded by creating the object
Author: IOhannes m zmölnig
Last-Update: 2015-10-27
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- pd-creb.orig/modules/setup.c
+++ pd-creb/modules/setup.c
@@ -43,6 +43,82 @@
#define CREB_VERSION "externals cvs"
#endif
+#include "m_imp.h"
+#include <fcntl.h>
+#include "s_stuff.h"
+
+#if PD_MAJOR_VERSION>0 || PD_MINOR_VERSION>47
+/* gone from the headers, but still present for binary compat */
+extern t_namelist *sys_searchpath;
+#endif
+static int _add_search_path(const char*libpath){
+ int major, minor, bugfix;
+ sys_getversion(&major, &minor, &bugfix);
+ if((major==0 && minor < 48)) {
+ sys_searchpath = namelist_append(sys_searchpath, libpath, 0);
+ } else {
+ char encoded[MAXPDSTRING];
+ char *inptr = libpath, *outptr = encoded;
+ t_atom ap[2];
+ *outptr++='+';
+ while(inptr && ((outptr+2) < (encoded+MAXPDSTRING))) {
+ *outptr++ = *inptr++;
+ if ('+'==inptr[-1])
+ *outptr++='+';
+ }
+ *outptr=0;
+ SETSYMBOL(ap+0, gensym(encoded));
+ SETFLOAT(ap+1, 0.f);
+ pd_typedmess(gensym("pd")->s_thing, gensym("add-to-path"), 2, ap);
+ }
+ return 1;
+}
+
+static t_class *creb_class;
+static void*creb_class_new(void)
+{
+ t_pd*x=pd_new(creb_class);
+ return (x);
+}
+/* check whether we can find the creb-abstractions
+ * (because they are already in Pd's path)
+ */
+void creb_class_setup(void) {
+ const char*absname="creb-dev.txt";
+ char buf[MAXPDSTRING];
+ char*bufptr=NULL;
+ const char*libpath=NULL;
+
+ int fd=-1;
+
+ /* create a [creb] objectclass */
+ creb_class = class_new(gensym("creb"), creb_class_new, 0, sizeof(t_object), CLASS_NOINLET, 0);
+
+ /* check whether we can find a creb-abstraction */
+ if ((fd=canvas_open(NULL, absname, "", buf, &bufptr, MAXPDSTRING, 1))>=0){
+ sys_close(fd);
+ return;
+ }
+
+ /* couldn't find creb-abstraction, print-warning */
+ libpath=creb_class->c_externdir->s_name;
+ /* check whether we can find the abstractions in creb's own path */
+ snprintf(buf, MAXPDSTRING-1, "%s/%s", libpath, absname);
+ buf[MAXPDSTRING-1]=0;
+ if ((fd=sys_open(buf, O_RDONLY))>=0){
+ sys_close(fd);
+ logpost(NULL, 3, "CREB: adding '%s' to your search-path", libpath);
+ if(!_add_search_path(libpath))
+ fd=-1;
+ }
+ if (fd<0) {
+ // can't find this abstraction...giving up
+ logpost(NULL, 1, "CREB: cannot find creb-abstractions");
+ logpost(NULL, 3, "CREB: please add path to '%s' to your search-path!", absname);
+ }
+}
+
+
void creb_setup(void)
{
@@ -95,4 +171,5 @@
abs_tilde_setup();
#endif
+ creb_class_setup();
}
|