Esempio n. 1
0
static void plustot_env_evalfile(t_plustot_env *x, t_symbol *fname)
{
    char buf1[MAXPDSTRING], buf2[MAXPDSTRING], *nameptr, *dir;
    int fd;
    dir = canvas_getdir(x->x_glist)->s_name;
    if ((fd = open_via_path(dir, fname->s_name, "",
			    buf1, &nameptr, MAXPDSTRING, 0)) < 0)
    {
	loud_error((t_pd *)x, "file '%s' not found", fname->s_name);
    }
    else
    {
	Tcl_Interp *interp = plustin_getinterp(x->x_tin);
	FILE *fp;
    	close(fd);
	strcpy(buf2, buf1);
	strcat(buf2, "/");
	strcat(buf2, nameptr);
	sys_bashfilename(buf2, buf2);
	Tcl_Preserve(interp);
	if (Tcl_EvalFile(interp, buf2) != TCL_OK)
	{
	    strcpy(buf1, "evaluation failed (");
	    strncat(buf1, buf2, MAXPDSTRING - strlen(buf1) - 2);
	    strcat(buf1, ")");
	    plusloud_tclerror((t_pd *)x, interp, buf1);
	}
	Tcl_Release(interp);
    }
}
Esempio n. 2
0
FILE *fileread_open(char *filename, t_canvas *cv, int textmode)
{
    int fd;
    char path[MAXPDSTRING+2], *nameptr;
    t_symbol *dirsym = (cv ? canvas_getdir(cv) : 0);
    /* path arg is returned unbashed (system-independent) */
    if ((fd = open_via_path((dirsym ? dirsym->s_name : ""), filename,
			    "", path, &nameptr, MAXPDSTRING, 1)) < 0)
    	return (0);
    /* Closing/reopening dance.  This is unnecessary under linux, and we
       could have tried to convert fd to fp, but under windows open_via_path()
       returns what seems to be an invalid fd.
       LATER try to understand what is going on here... */
    close(fd);
    if (path != nameptr)
    {
	char *slashpos = path + strlen(path);
	*slashpos++ = '/';
	/* try not to be dependent on current open_via_path() implementation */
	if (nameptr != slashpos)
	    strcpy(slashpos, nameptr);
    }
    sys_bashfilename(path, path);
    return (fopen(path, (textmode ? "r" : "rb")));
}
Esempio n. 3
0
static const char* imagebang_get_filename(t_imagebang *x,char *file) {
	static char fname[MAXPDSTRING];
	char *bufptr;
	int fd;
	
	fd=open_via_path(canvas_getdir(glist_getcanvas(x->glist))->s_name, 
	    file, "",fname, &bufptr, MAXPDSTRING, 1);
	if(fd>0){
	  	fname[strlen(fname)]='/';
	  	DEBUG(post("image file: %s",fname);)
Esempio n. 4
0
static void blackboard_image(t_blackboard *x, t_symbol *s, int argc, t_atom *argv)
{
	int fd;
    char path[MAXPDSTRING];
	char name[MAXPDSTRING];
	char *nameptr;
    
    if(x->f_ninstructions >= _blackboard::maxcmd)
    {
        pd_error(x, "%s too many drawing commands.", eobj_getclassname(x)->s_name);
        return;
    }

    if(argc > 2 && argv)
    {
        if(atom_gettype(argv) == A_FLOAT && atom_gettype(argv+1) == A_FLOAT && atom_gettype(argv+2) == A_SYMBOL)
        {
            sprintf(path, "%s",atom_getsymbol(argv+2)->s_name);
            if(access(path, O_RDONLY) != -1)
            {
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
                return;
            }
            sprintf(path, "%s/%s", canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, atom_getsymbol(argv+2)->s_name);
            if(access(path, O_RDONLY) != -1)
            {
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
                return;
            }
			sprintf(name, "%s", atom_getsymbol(argv+2)->s_name);
			if(!strncmp(name+strlen(name)-4, ".gif", 4))
			{
				strncpy(name+strlen(name)-4, "\0", 4);
			}

			fd = open_via_path(canvas_getdir(x->j_box.b_obj.o_canvas)->s_name, name,  ".gif", path, &nameptr, MAXPDSTRING, 0);
            if(fd >= 0)
			{
                sprintf(x->f_instructions[x->f_ninstructions], "create image %d %d -anchor nw -image [image create photo -file %s/%s.gif]", (int)atom_getfloat(argv), (int)atom_getfloat(argv+1), path, name);
                
                x->f_ninstructions++;
                ebox_redraw((t_ebox *)x);
				return;
			}
        }
    }
    
}
Esempio n. 5
0
static void openit(const char *dirname, const char *filename)
{
    char dirbuf[MAXPDSTRING], *nameptr;
    int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr,
        MAXPDSTRING, 0);
    if (fd >= 0)
    {
        close (fd);
        glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
    }
    else
        error("%s: can't open", filename);
}
Esempio n. 6
0
    /* this routine is called when a new "object" is requested whose class Pd
    doesn't know.  Pd tries to load it as an extern, then as an abstraction. */
void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    t_pd *current;
    t_symbol *dir = canvas_getcurrentdir();
    int fd;
    char dirbuf[MAXPDSTRING], *nameptr;
    if (tryingalready) return;
    newest = 0;
    class_loadsym = s;
    if (sys_load_lib(dir->s_name, s->s_name))
    {
    	tryingalready = 1;
    	typedmess(dummy, s, argc, argv);
    	tryingalready = 0;
    	return;
    }
    class_loadsym = 0;
    current = s__X.s_thing;
    if ((fd = open_via_path(dir->s_name, s->s_name, ".pd",
    	dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
	    (fd = open_via_path(dir->s_name, s->s_name, ".pat",
    	    	dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
    {
    	close (fd);
	if (!pd_setloadingabstraction(s))
	{
    	    canvas_setargs(argc, argv); /* bug fix by Krzysztof Czaja */
    	    binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
    	    if (s__X.s_thing != current)
    	    	canvas_popabstraction((t_canvas *)(s__X.s_thing));
    	    canvas_setargs(0, 0);
	}
	else error("%s: can't load abstraction within itself\n", s->s_name);
    }
    else newest = 0;
}
Esempio n. 7
0
File: image.c Progetto: Angeldude/pd
const char *image_get_filename(t_image *x,char *file)
{
    static char fname[MAXPDSTRING];
    char *bufptr;
    int fd;

    fd=open_via_path(canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
                     file, "",fname, &bufptr, MAXPDSTRING, 1);
    if(fd>0)
    {
        fname[strlen(fname)]='/';
        close(fd);
        return fname;
    }
    else return 0;
}
Esempio n. 8
0
static void openit(const char *dirname, const char *filename)
{
    char dirbuf[FILENAME_MAX], *nameptr;
    int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr,
        FILENAME_MAX, 0);
    if (fd >= 0)
    {
        close (fd);
        glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
		sys_vgui("pdtk_set_current_dir %s\n", filename);
        //sys_vgui("::pd_menus::update_recentfiles_menu .mbar.file 0\n");
        sys_vgui("::pd_guiprefs::update_recentfiles %s 1\n", filename);
    }
    else
        error("%s: can't open", filename);
}
Esempio n. 9
0
static void freadln_open (t_freadln *x, t_symbol *s, t_symbol*type)
{
   char filenamebuf[MAXPDSTRING], *filenamebufptr;
   char*dirname=canvas_getdir(x->x_canvas)->s_name;
   int fd, len;

   freadln_close(x);

/*
   if(type!=gensym("cr")) {
     pd_error(x, "currently only 'cr' type files are implemented!");
     return;
   }
*/
   if (type==gensym("cr"))
      strcpy(x->linebreak_chr,"\n");
   else
      strcpy(x->linebreak_chr,";\n");
      

   /* directory, filename, extension, dirresult, nameresult, unsigned int size, int bin */
   if ((fd=open_via_path(dirname,
	       s->s_name,"", filenamebuf, &filenamebufptr, MAXPDSTRING,0)) < 0 ) {
      pd_error(x, "%s: failed to open %s", s->s_name, filenamebuf);
      return;
   }
   close(fd);
   len=strlen(filenamebuf);
   if (!(x->x_filename=(char*)getbytes(sizeof(char)*(len+strlen(s->s_name)+2)))) {
      pd_error(x, "out of memory");
      freadln_close(x);
      return;
   }
   strcpy(x->x_filename,filenamebuf);
   strcpy(x->x_filename+len,"/");
   strcpy(x->x_filename+len+1,s->s_name);
   if (!(x->x_file=fopen(x->x_filename, "r"))) {
      pd_error(x, "freadln: failed to open %128s",filenamebuf);
      return;
   }
   if (!(x->x_textbuf = (char *) getbytes (MIN_FREADLN_LENGTH * sizeof(char)))) {
      pd_error(x, "out of memory");
      freadln_close(x);
      return;
   }
   x->x_textbuf_length=MIN_FREADLN_LENGTH;
}
Esempio n. 10
0
void jsusfx_compile(t_jsusfx *x, t_symbol *newFile) {
    x->bypass = true;
 
    std::ifstream *is;

    if ( newFile != NULL ) {
        char result[1024], *bufptr;
        int fd = open_via_path(x->canvasdir, newFile->s_name, "", result, &bufptr, 1024, 1);
        if ( fd == 0 || result[0] == 0 ) {
            error("jsusfx~: unable to find script %s", newFile->s_name);
            return;
        }
        strncat(result, "/", 1024);
        strncat(result, newFile->s_name, 1024);

        is = new std::ifstream(result);   
        if ( ! is->is_open() ) {
            error("jsusfx~: error opening file %s", result);
            delete is;
            return;
        }
        strncpy(x->scriptpath, result, 1024);    
    } else {
        if ( x->scriptpath[0] == 0 )
            return;
        is = new std::ifstream(x->scriptpath);
        if ( ! is->is_open() ) {
            error("jsusfx~: error opening file %s", x->scriptpath);
            delete is;
            return;
        }  
    }

    x->fx->dspLock.Enter();
    if ( x->fx->compile(*is) ) {
        if ( x->fx->srate != 0 )
            x->fx->prepare(*(x->fx->srate), *(x->fx->blockPerSample));
    } else {
        x->bypass = true;
    }
    x->fx->dspLock.Leave();

    delete is;

    if ( ! x->bypass )
        jsusfx_describe(x);
}
Esempio n. 11
0
void dummies_setup(void)
{
    t_dummy_slot *sl;
    int i, mapsize;
    char **mapping = import_getmapping(&mapsize);
    int ndoomed = 0;
    dummy_nclasses = sizeof(dummy_slots)/sizeof(*dummy_slots);
    /* never freed: */
    dummy_classes = getbytes(dummy_nclasses * sizeof(*dummy_classes));
    for (i = 0, sl = dummy_slots; i < dummy_nclasses; i++, sl++)
    {
	int fd;
	char dirbuf[MAXPDSTRING], *nameptr;
	char *name = port_usemapping(sl->s_name, mapsize, mapping);
	if (name)
	    ndoomed++;
	else if (ndoomed && i < dummy_nclasses - 1)
	{
	    loudbug_bug("dummies_setup");
	    loudbug_post
		("(\"%s\": clashing or doomed dummy not registered for import)",
		 sl->s_name);
	}
	if ((fd = open_via_path("", sl->s_name, ".pd",
				dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
	{
	    close(fd);
	    dummy_nreps++;
	}
	else
	{
	    dummy_classes[i] =
		class_new((name ? gensym(name) : gensym(sl->s_name)),
			  sl->s_method ? sl->s_method : (t_newmethod)dummy_new,
			  0, sizeof(t_object),
			  (sl->s_nins ? 0 : CLASS_NOINLET), A_GIMME, 0);
	}
    }
    dummy_nclasses--;  /* use "_dummy" as a sentinel */

    ccdummies_class = class_new(gensym("_cc.dummies"), 0, 0,
				sizeof(t_pd), CLASS_PD | CLASS_NOINLET, 0);
    class_addbang(ccdummies_class, ccdummies_bang);
    pd_bind(pd_new(ccdummies_class), gensym("_cc.dummies"));  /* never freed */
}
Esempio n. 12
0
static void sdiflists_types(t_sdiflists *x, t_symbol *types)
{
                  
  if(x->markers[0].filepos != -1 ) 
    {
      t_colout *u;
      int j;
      SdifFClose(x->file);
      for(j=0; j < x->nframes; j++)
        x->markers[j].timetag = x->markers[j].filepos = 0;

      x->markers[0].timetag = -1;
   
      for ( j=0, u = x->data; j < x->n_outs; u++, j++)
        freebytes( u->outvec, x->max_vec * sizeof(t_atom));
  
#if DEBUG                         
      post("sdiflists::types: closed previous file");              
#endif  
      x->nframes = IFRAMES;
    }                     	
  //prepend the full path onto the filename
  char fullfilename[MAXPDSTRING], namebuf[MAXPDSTRING];
  char buf[MAXPDSTRING], *bufptr, *dirname;
  int fd = 0;
															
  dirname=canvas_getdir(x->canvas)->s_name;
  t_binbuf *bbuf = binbuf_new();
  fd = open_via_path(dirname,  types->s_name,"", buf, &bufptr, MAXPDSTRING, 0);
  if(fd > 0)
    {
      namebuf[0] = 0;
      if (*buf)  
        strcat(namebuf, buf), strcat(namebuf, "/");
      strcat(namebuf, bufptr);
      sys_bashfilename(namebuf, fullfilename);
               
      SdifGenKill (); // have to close it to read a new .STYP
      SdifGenInitCond (types->s_name);
               
      post("sdiflists: types-declaration file: %s", types->s_name);     
    }
  else post ("sdiflists: types file %s could not be opened", types->s_name);
}
Esempio n. 13
0
static int libdir_loader_legacy(t_canvas *canvas, char *classname)
{
    int fd = -1;
    char fullclassname[FILENAME_MAX], dirbuf[FILENAME_MAX];
    char *nameptr;

/* look for meta file (classname)/(classname)-meta.pd */
    libdir_get_fullname(fullclassname, FILENAME_MAX, classname);

    /* if this is being called from a canvas, then add the library path to the
     * canvas-local path */
    if(canvas)
      /* setting the canvas to NULL causes it to ignore any canvas-local path */
      fd = canvas_open(NULL, fullclassname, ".pd",
		       dirbuf, &nameptr, FILENAME_MAX, 0);
    else
      fd = open_via_path(".", fullclassname, ".pd",
			 dirbuf, &nameptr, FILENAME_MAX, 0);
    if(fd < 0)
    {
      return (0);
    }
    sys_close(fd);
#if 0
    if(!canvas) {
      char helppathname[FILENAME_MAX];
      strncpy(helppathname, sys_libdir->s_name, FILENAME_MAX-30);
      helppathname[FILENAME_MAX-30] = 0;
      strcat(helppathname, "/doc/5.reference/");
      strcat(helppathname, classname);
      sys_helppath = namelist_append(sys_helppath, helppathname, 0);
    }
#endif
    if(libdir_add_to_path(dirbuf, canvas))
      logpost(NULL, 3, "libdir_loader: added '%s' to the %s objectclass path",
	      classname, canvas?"canvas-local":"global");

    /* post("libdir_loader loaded fullclassname: '%s'\n", fullclassname); */
    logpost(NULL, 14, "Loaded libdir '%s' from '%s'", classname, dirbuf);

    return (1);
}
Esempio n. 14
0
std::string CPPExtern::findFile(const std::string f, const std::string e) const {
    char buf[MAXPDSTRING], buf2[MAXPDSTRING];
    char*bufptr=0;
    std::string result="";
    int fd=-1;

    t_canvas*canvas=const_cast<t_canvas*>(getCanvas());
    char*filename=const_cast<char*>(f.c_str());
    char*ext=const_cast<char*>(e.c_str());

    if ((fd=open_via_path(canvas_getdir(canvas)->s_name, filename, ext,
                          buf2, &bufptr, MAXPDSTRING, 1))>=0) {
        sys_close(fd);
        result=buf2;
        result+="/";
        result+=bufptr;
    } else {
        canvas_makefilename(canvas, filename, buf, MAXPDSTRING);
        result=buf;
    }
    return result;
}
Esempio n. 15
0
static t_symbol *iem_image_calc_size(t_iem_image *x)
{
    char dirbuf[MAXPDSTRING], *namebufptr;
    char namebuf[MAXPDSTRING];
    unsigned char buf[222];
    unsigned int i;
    char *c;
    int fd;
    FILE *fh;
    size_t items;

    if(!x->x_gifsym || !x->x_gifsym->s_name)
    {
        post("iem_image-ERROR: no gifname");
        x->x_gifsym = (t_symbol *)0;
        return((t_symbol *)0);
    }
    fd = open_via_path(canvas_getdir(glist_getcanvas(x->x_gui.x_glist))->s_name, x->x_gifsym->s_name,
                       "", dirbuf, &namebufptr, MAXPDSTRING, 1);
    if (fd < 0)
    {
        post("iem_image-ERROR: cannot open %s first time", x->x_gifsym->s_name);
        x->x_gifsym = (t_symbol *)0;
        return((t_symbol *)0);
    }
    else
    {
        if(fd >= 0)
            close(fd);
        strcpy(namebuf, dirbuf);
        strcat(namebuf, "/");
        strcat(namebuf, namebufptr);
        fh = fopen(namebuf, "r");
        if(fh == NULL)
        {
            post("iem_image-ERROR: cannot open %s second time", namebuf);
            x->x_gifsym = (t_symbol *)0;
            return((t_symbol *)0);
        }
        else
        {
            items=fread(buf, 22, sizeof(unsigned char), fh);
            if((items < 1)||(strlen((char*)buf)<7)) {
                post("iem_image-ERROR: can not read header in %s, only %d items read: %s.", namebuf, strlen((char*)buf), (char*) buf);
                x->x_gifsym = (t_symbol *)0;
                return((t_symbol *)0);
            };
            fclose(fh);
            c = (char *)buf;
            if((c[0] != 'G')||(c[1] != 'I')||(c[2] != 'F'))
            {
                post("iem_image-ERROR: %s is not a GIF-file", namebuf);
                x->x_gifsym = (t_symbol *)0;
                return((t_symbol *)0);
            }
            i = 256*(unsigned int)buf[7];
            i += (unsigned int)buf[6];
            x->x_gui.x_w = (int)i;
            i = 256*(unsigned int)buf[9];
            i += (unsigned int)buf[8];
            x->x_gui.x_h = (int)i;
            SETFLOAT(x->x_at_out, (t_float)x->x_gui.x_w);
            SETFLOAT(x->x_at_out+1, (t_float)x->x_gui.x_h);
            outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at_out);
            if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
                pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at_out);
            return(gensym(namebuf));
        }
    }
}
Esempio n. 16
0
static bool getmodulesub(const char *mod,char *dir,int len,const char *ext)
{
#if FLEXT_SYS == FLEXT_SYS_PD
    char *name;
    int fd = open_via_path("",mod,ext,dir,&name,len,0);
    if(fd >= 0) {
        fileclose(fd);
        FLEXT_ASSERT(name && *name);
    }
    else {
        // look for mod/__init__.py
        std::string tmp(mod); 
        int l = tmp.size();
        tmp += "/__init__";
        fd = open_via_path("",tmp.c_str(),ext,dir,&name,len,0);
        if(fd >= 0) {
            fileclose(fd);
            FLEXT_ASSERT(name && *name);

            // we must remove the module name from dir
            char *t = dir+strlen(dir)-l;
            FLEXT_ASSERT(!strcmp(mod,t) && t[-1] == '/');
            t[-1] = 0;
        }
        else
            name = NULL;
    }

    // if dir is current working directory... name points to dir
    if(dir == name) strcpy(dir,".");
    return name != NULL;
#elif FLEXT_SYS == FLEXT_SYS_MAX
    short path;
    long type;
    char smod[1024];
    strcpy(smod,mod);
    strcat(smod,ext);
    bool ok = !locatefile_extended(smod,&path,&type,&type,0);
    if(ok)
        // convert pathname to unix style
        path_topathname(path,NULL,smod);
    else {
        // do path/file.ext combinations work at all under Max?
        strcpy(smod,mod);

        short path;
        type = 'fold';
        ok = !locatefile_extended(smod,&path,&type,&type,1);
        if(ok) {
            // convert pathname to unix style (including trailing slash)
            path_topathname(path,NULL,smod);
            char *end = smod+strlen(smod);
            strcpy(end,mod);
            strcat(end,"/__init__");
            strcat(end,ext);

            // check if file is really existing: try to open it
            FILE *f = fopen(smod,"r");
            if(f) {
                *end = 0;  // clear module part ... we only need base path
                fclose(f);
            }
            else
                ok = false;
        }
    }
    
    if(ok) {
        // convert path into slash style needed for Python
#if 0
        // Max API function uses Volume:/Path notation
        path_nameconform(smod,dir,PATH_STYLE_SLASH,PATH_TYPE_ABSOLUTE);
#else
#if FLEXT_OS == FLEXT_OS_WIN
        char *colon = NULL;
#else
        char *colon = strchr(smod,':');
#endif
        if(colon) {
            *colon = 0;
            strcpy(dir,"/Volumes/");
            strcat(dir,smod);
            strcat(dir,colon+1);
        }
        else
            strcpy(dir,smod);
#endif
        return true;
    }
    else
        // not found
        return false;
#else
#pragma message("Not implemented");
    return false;
#endif
}
Esempio n. 17
0
/*-------------------open files, STYP first if given, then SDIF-----------------*/
static void sdiflists_open(t_sdiflists *x,  t_symbol *s, int argcount, t_atom *argvec)
{	
    int i,j;
    unsigned int StreamSpecified = 0;
    
    for (i = 0; i < argcount; i++)
    {
          if (argvec[i].a_type == A_FLOAT)
          {//TODO: check if this was given after file, cuz that would be useless
                x->streamid = (int) argvec[i].a_w.w_float;
               StreamSpecified = 1;
               post("stream specified:#%d", x->streamid);
          }
 
      if (argvec[i].a_type == A_SYMBOL)
      {
          char *sym =  argvec[i].a_w.w_symbol->s_name;                 
          if(!strcmp( sym + strlen(sym)-5 , ".sdif" ) || 
                        !strcmp( sym + strlen(sym)-5 , ".SDIF" ))
          {
              t_colout *u;
              if(x->markers[0].timetag != -1) 
              {
                  post("closing file... ");
                  SdifFClose(x->file);
                  for(j=0; j < x->nframes; j++)  x->markers[j].timetag = x->markers[j].filepos = 0;
                  for(j=0, u = x->data; j < x->n_outs; u++, j++) freebytes( u->outvec, x->max_vec * sizeof(t_atom));
		 
                  x->markers[0].timetag = -1;
                  x->index = -1;
                  x->nframes = IFRAMES;
#if DEBUG                         
                  post("sdiflists::open: closed previous file");              
#endif  
	      }// end if x->file exists
              unsigned int rows = 0;
              unsigned int cols = 0;

              t_int eof, m, updatepos;
              t_int firstframe = 1;
              t_int timepos = 0;
              size_t bytesread = 0;  
              SdiffPosT currpos;
              float currtime = 0;
                  				
              /*method for opening file in canvas directory.
                Based on zexy's [msgfile], which is based on
                Pd's [textfile]*/
              char filnam[MAXPDSTRING], namebuf[MAXPDSTRING];
              char buf[MAXPDSTRING], *bufptr, *readbuf;
              int fd; // used to check if file exists
              char *dirname;
              
              dirname = canvas_getdir(x->canvas)->s_name;
              t_binbuf *bbuf = binbuf_new();
              
              fd = open_via_path(dirname, sym,"", buf, &bufptr, MAXPDSTRING, 0);
              if(fd < 0)
              {
                  error("sdiflists-open: %s cannot be found", sym);
                  return;
              }
              namebuf[0] = 0;
              if (*buf)   strcat(namebuf, buf), strcat(namebuf, "/");
              
              strcat(namebuf, bufptr);
              // open and get length 
              sys_bashfilename(namebuf, filnam);
              //this is hopefully a readable file
              
#if DEBUG
              post("(open_via_path) dirname: %s, filename->s_name: %s, buf: %s, bufptr: %s", dirname, sym, buf, bufptr);
              post("AFTER bashfilename: namebuf: %s, filnam: %s ", namebuf, filnam);
#endif
	      
              x->filename = gensym( namebuf );
	      
              /* Check if the file is a good SDIF file, skip function if not */
              if (SdifCheckFileFormat (x->filename->s_name))
              { 
                  post("sdiflists: reading %s", x->filename->s_name);
                  x->file = SdifFOpen ( x->filename->s_name, eReadFile); 
     		  bytesread += SdifFReadGeneralHeader  (x->file);       
                  bytesread += SdifFReadAllASCIIChunks (x->file);                 
                  eof = SdifFCurrSignature(x->file) == eEmptySignature;	
                  int err;
                  while (!eof) //frame loop
                  {
                      /*The frame positions must be indexed before the
                        frameheader is read, then check if it is a
                        selected frame.  If not, skip the frame and
                        overwrite the marker.*/
                      err = SdifFGetPos(x->file, &currpos);
                      if(err==-1) error("error SdifFGetPos");
						
						
                      /* Read frame header.  Current signature has already been read
                         by SdifFReadAllASCIIChunks or the last loop.) */
                      bytesread += SdifFReadFrameHeader (x->file);

                      if(!StreamSpecified)
                        {
                          x->streamid = SdifSelectGetFirstInt(x->file->Selection->stream, SdifFCurrID (x->file));
                          StreamSpecified = 1;
                          post("first stream used: #%d", x->streamid);
                        }

                      //PROBLEM: (maybe not...check)the last frame in the file is always acceptable... fix by using sel spec			
                      while (!SdifFCurrFrameIsSelected (x->file) ||  SdifFCurrID (x->file) != x->streamid )
                      {
	   //  post("frame skipped");
                          SdifFSkipFrameData (x->file);
                          if ((eof = SdifFGetSignature(x->file, &bytesread) == eEof)) break;  
                          SdifFGetPos(x->file, &currpos);			
                          bytesread += SdifFReadFrameHeader(x->file);			
                       }

                      if(eof) //have to check again...since it might have skipped to the end
                        break;
			
                      //check if this is a new time so successive frames don't overwrite filepos
                      currtime =  SdifFCurrTime (x->file);
                      if( !timepos ||  x->markers[timepos-1].timetag  != currtime )
                      {
                            x->markers[timepos].filepos = currpos;
                            x->markers[timepos].timetag  = currtime;
                            timepos++;
                            if( timepos >= x->nframes )
                            {
                                   x->markers = (t_pos *)resizebytes( x->markers, x->nframes * sizeof(t_pos),
		                               (x->nframes + IFRAMES) * sizeof(t_pos) );                                        
                                   x->nframes = x->nframes + IFRAMES;
                             }
                      }      						
                      /*matrices loop */
                      for ( m = 0; (unsigned int)m < SdifFCurrNbMatrix (x->file); m++)
                      {  
                          bytesread += SdifFReadMatrixHeader (x->file);
			  
                          if( SdifFCurrNbRow (x->file) > rows)
                          {
                              rows = SdifFCurrNbRow (x->file); //get matrix stats
                              cols = SdifFCurrNbCol (x->file);//should stay the same
                           }
                          //skip the actual matrices
                          bytesread += SdifFSkipMatrixData (x->file);
                      }// end for matrices
                      eof = SdifFGetSignature (x->file, &bytesread) == eEof; 
						
                 }// end while no eof
                 x->seconds = currtime;
                 x->nframes= timepos; //last timepos was the eof
#if DEBUG
                  post(" rows: %d , cols: %d , frames: %d , seconds: %f", rows, cols,  x->nframes, x->seconds);
                  post("sdiflists: %s opened. ", x->filename->s_name);
#endif
                  x->max_vec = rows; //needed to free memory
	 
                  //the following lines are a bug work-around... if the eof is reached, you cannot seek
                  //until the fle is closed, opened, and re-initialized... i posted about this on the sdif list.
                  SdifFClose (x->file);
                  x->file = SdifFOpen ( x->filename->s_name, eReadFile); 
                  SdifFReadGeneralHeader  (x->file); 
                  SdifFReadAllASCIIChunks (x->file); 
                  eof = SdifFCurrSignature(x->file) == eEmptySignature;  
		
                  //make room for the row lists
                  for ( i=0, u = x->data; i < x->n_outs; u++, i++)
	   u->outvec = (t_atom *)getbytes( x->max_vec * sizeof(t_atom));
	     
               } /* end if filetype check */
            }
        } //end if Symbol
    }//end for arguments
}