Package: pdp / 1:0.14.1+darcs20180201-6

searchpath_check.patch Patch series | download
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
Description: check whether searchpaths are setup-correctly
 pd-libraries should live in a subdirectory of .../pd/extra
 (e.g. .../pd/extra/pdp/), but pdp usually is installed directly
 into .../pd/extra/; since it comes with some abstractions, the user
 might want to add .../pd/extra/pdp to Pd's search path.
 this patch checks whether pdp-abstractions are findable.
 if the abstractions are not in Pd's search path, but live besides the
 pdp-binary, the path to the binary is automatically added.
 else a warning is printed, that the user ought to add the path manually.
Author: IOhannes m zmölnig
Last-Update: 2013-10-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- pd-pdp.orig/system/pdp.c
+++ pd-pdp/system/pdp.c
@@ -22,6 +22,11 @@
 #include "pdp_config.h"
 #include "pdp_post.h"
 
+#include "m_imp.h"
+#include <fcntl.h>
+
+#include "s_stuff.h"
+
 static int initialized = 0;
 
 /* all symbols are C style */
@@ -101,8 +106,77 @@
 /* testing */
 void pdp_dpd_test_setup(void);
 
-
-
+static t_class *pdp_class;
+static void*pdp_class_new(void)
+{
+  t_pd*x=pd_new(pdp_class);
+  return (x);
+}
+/* check whether we can find the pdp-abstractions
+ * (because they are already in Pd's path)
+ */
+#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;
+}
+
+void pdp_class_setup(void) {
+  const char*absname="pdp_tag.pd";
+  char buf[MAXPDSTRING];
+  char*bufptr=NULL;
+  const char*libpath=NULL;
+
+  int fd=-1;
+
+  /* create a [pdp] objectclass */
+  pdp_class = class_new(gensym("pdp"), pdp_class_new, 0, sizeof(t_object), CLASS_NOINLET, 0);
+
+  /* check whether we can find a pdp-abstraction */
+  if ((fd=canvas_open(NULL, absname, "", buf, &bufptr, MAXPDSTRING, 1))>=0){
+    sys_close(fd);
+    return;
+  }
+
+  /* couldn't find pdp-abstraction, print-warning */
+  libpath=pdp_class->c_externdir->s_name;
+  /* check whether we can find the abstractions in pdp'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, "PDP: adding '%s' to your search-path", libpath);
+    if(!_add_search_path(libpath))
+        fd=-1;
+  } else {
+    // can't find this abstraction...giving up
+    logpost(NULL, 1, "PDP: cannot find pdp-abstractions");
+  }
+  if (fd<0) {
+    logpost(NULL, 3, "PDP: please add path to '%s' to your search-path!", absname);
+  }
+}
 
 /* library setup routine */
 void pdp_setup(void){
@@ -122,6 +196,7 @@
 
 
     /* setup pdp system */
+    pdp_class_setup();
 
     /* kernel */
     pdp_pdsym_setup();