[PD-cvs] pd/src desire.c,1.1.2.217.2.40,1.1.2.217.2.41

Mathieu Bouchard matju at users.sourceforge.net
Fri Dec 8 07:01:43 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5921

Modified Files:
      Tag: desiredata
	desire.c 
Log Message:
0.40: added canvas_open and [declare]


Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.217.2.40
retrieving revision 1.1.2.217.2.41
diff -C2 -d -r1.1.2.217.2.40 -r1.1.2.217.2.41
*** desire.c	7 Dec 2006 23:31:31 -0000	1.1.2.217.2.40
--- desire.c	8 Dec 2006 06:01:39 -0000	1.1.2.217.2.41
***************
*** 15,24 ****
  #include "m_pd.h"
  #include "desire.h"
- 
- extern "C" {
- #include "m_imp.h"
  #include "s_stuff.h"
- };
- 
  #include <ctype.h>
  #include <math.h>
--- 15,19 ----
***************
*** 360,364 ****
  #define CANVAS_DEFCANVASHEIGHT 300
  
! #ifdef MACOSX
  #define CANVAS_DEFCANVASYLOC 22
  #else
--- 355,359 ----
  #define CANVAS_DEFCANVASHEIGHT 300
  
! #ifdef __APPLE__
  #define CANVAS_DEFCANVASYLOC 22
  #else
***************
*** 7503,7506 ****
--- 7498,7648 ----
  }
  
+ /* [declare] and canvas_open come from 0.40 */
+ /* ------------------------------- declare ------------------------ */
+ 
+ /* put "declare" objects in a patch to tell it about the environment in
+ which objects should be created in this canvas.  This includes directories to
+ search ("-path", "-stdpath") and object libraries to load
+ ("-lib" and "-stdlib").  These must be set before the patch containing
+ the "declare" object is filled in with its contents; so when the patch is
+ saved,  we throw early messages to the canvas to set the environment
+ before any objects are created in it. */
+ 
+ static t_class *declare_class;
+ 
+ typedef struct _declare
+ {
+     t_object x_obj;
+     t_canvas *x_canvas;
+     int x_useme;
+ } t_declare;
+ 
+ static void *declare_new(t_symbol *s, int argc, t_atom *argv)
+ {
+     t_declare *x = (t_declare *)pd_new(declare_class);
+     x->x_useme = 1;
+     x->x_canvas = canvas_getcurrent();
+         /* LATER update environment and/or load libraries */
+     return (x);
+ }
+ 
+ static void declare_free(t_declare *x)
+ {
+     x->x_useme = 0;
+         /* LATER update environment */
+ }
+ 
+ void canvas_savedeclarationsto(t_canvas *x, t_binbuf *b) {
+     canvas_each(y,x) {
+         if (pd_class(y) == declare_class)
+         {
+             binbuf_addv(b, "s", gensym("#X"));
+             binbuf_addbinbuf(b, ((t_declare *)y)->x_obj.te_binbuf);
+             binbuf_addv(b, ";");
+         }
+         else if (pd_class(y) == canvas_class)
+             canvas_savedeclarationsto((t_canvas *)y, b);
+     }
+ }
+ 
+ static void canvas_declare(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
+ {
+     int i;
+     t_canvasenvironment *e = canvas_getenv(x);
+ #if 0
+     startpost("declare:: %s", s->s_name);
+     postatom(argc, argv);
+     endpost();
+ #endif
+     for (i = 0; i < argc; i++)
+     {
+         char strbuf[MAXPDSTRING];
+         char *flag = atom_getsymbolarg(i, argc, argv)->s_name;
+         if ((argc > i+1) && !strcmp(flag, "-path"))
+         {
+             e->path = namelist_append(e->path, atom_getsymbolarg(i+1, argc, argv)->s_name, 0);
+             i++;
+         }
+         else if ((argc > i+1) && !strcmp(flag, "-stdpath"))
+         {
+             strncpy(strbuf, sys_libdir->s_name, MAXPDSTRING-3);
+             strbuf[MAXPDSTRING-4] = 0;
+             strcat(strbuf, "/");
+             strncpy(strbuf, atom_getsymbolarg(i+1, argc, argv)->s_name,
+                 MAXPDSTRING-strlen(strbuf));
+             strbuf[MAXPDSTRING-1] = 0;
+             e->path = namelist_append(e->path, strbuf, 0);
+             i++;
+         }
+         else if ((argc > i+1) && !strcmp(flag, "-lib"))
+         {
+ 	    pd_error(x, "not implemented for now, ask matju");
+             /* sys_load_lib(x, atom_getsymbolarg(i+1, argc, argv)->s_name); */
+             i++;
+         }
+         else if ((argc > i+1) && !strcmp(flag, "-stdlib"))
+         {
+             strncpy(strbuf, sys_libdir->s_name, MAXPDSTRING-3);
+             strbuf[MAXPDSTRING-4] = 0;
+             strcat(strbuf, "/");
+             strncpy(strbuf, atom_getsymbolarg(i+1, argc, argv)->s_name,
+                 MAXPDSTRING-strlen(strbuf));
+             strbuf[MAXPDSTRING-1] = 0;
+ 	    pd_error(x, "not implemented for now, ask matju");
+ /*            sys_load_lib(0, strbuf);*/
+             i++;
+         }
+         else post("declare: %s: unknown declaration", flag);
+     }
+ }
+ 
+     /* utility function to read a file, looking first down the canvas's search
+     path (set with "declare" objects in the patch and recursively in calling
+     patches), then down the system one.  The filename is the concatenation of
+     "name" and "ext".  "Name" may be absolute, or may be relative with
+     slashes.  If anything can be opened, the true directory
+     ais put in the buffer dirresult (provided by caller), which should
+     be "size" bytes.  The "nameresult" pointer will be set somewhere in
+     the interior of "dirresult" and will give the file basename (with
+     slashes trimmed).  If "bin" is set a 'binary' open is
+     attempted, otherwise ASCII (this only matters on Microsoft.) 
+     If "x" is zero, the file is sought in the directory "." or in the
+     global path.*/
+ 
+ int canvas_open(t_canvas *x, const char *name, const char *ext,
+ char *dirresult, char **nameresult, unsigned int size, int bin) {
+     int fd = -1;
+     t_canvas *y;
+ 
+     /* first check if "name" is absolute (and if so, try to open) */
+ /*FIXME: undefined symbol */
+ /*    if (sys_open_absolute(name, ext, dirresult, nameresult, size, bin, &fd)) return fd; */
+ 
+     /* otherwise "name" is relative; start trying in directories named
+     in this and parent environments */
+     for (y = x; y; y = y->owner) if (y->env) {
+         t_namelist *nl;
+         t_canvas *x2 = x;
+         while (x2 && x2->owner) x2 = x2->owner;
+         const char *dir = x2 ? canvas_getdir(x2)->s_name : ".";
+         for (nl = y->env->path; nl; nl = nl->nl_next)
+         {
+             char realname[MAXPDSTRING];
+             strncpy(realname, dir, MAXPDSTRING);
+             realname[MAXPDSTRING-3] = 0;
+             strcat(realname, "/");
+             strncat(realname, nl->nl_string, MAXPDSTRING-strlen(realname));
+             realname[MAXPDSTRING-1] = 0;
+ 	    /*FIXME: undefined symbol */
+             /*if ((fd = sys_trytoopenone(realname, name, ext, dirresult, nameresult, size, bin)) >= 0) return fd;*/
+         }
+     }
+     return (open_via_path((x ? canvas_getdir(x)->s_name : "."), name, ext,
+         dirresult, nameresult, size, bin));
+ }
+ /* end miller 0.40 */
+ 
+ 
+ 
  static void g_canvas_setup(void) {
      /* we prevent the user from typing "canvas" in an object box





More information about the Pd-cvs mailing list