Esempio n. 1
0
void sys_setextrapath(const char *p)
{
    char pathbuf[MAXPDSTRING];
    namelist_free(sys_staticpath);
    /* add standard place for users to install stuff first */
#ifdef __gnu_linux__
    sys_expandpath("~/pd-externals", pathbuf, MAXPDSTRING);
    sys_staticpath = namelist_append(0, pathbuf, 0);
    sys_staticpath = namelist_append(sys_staticpath, "/usr/local/lib/pd-externals", 0);
#endif

#ifdef __APPLE__
    sys_expandpath("~/Library/Pd", pathbuf, MAXPDSTRING);
    sys_staticpath = namelist_append(0, pathbuf, 0);
    sys_staticpath = namelist_append(sys_staticpath, "/Library/Pd", 0);
#endif

#ifdef _WIN32
    sys_expandpath("%ProgramFiles%/Common Files/Pd", pathbuf, MAXPDSTRING);
    sys_staticpath = namelist_append(0, pathbuf, 0);
    sys_expandpath("%UserProfile%/Application Data/Pd", pathbuf, MAXPDSTRING);
    sys_staticpath = namelist_append(sys_staticpath, pathbuf, 0);
#endif
    /* add built-in "extra" path last so its checked last */
    sys_staticpath = namelist_append(sys_staticpath, p, 0);
}
Esempio n. 2
0
int sys_trytoopenone(const char *dir, const char *name, const char* ext,
    char *dirresult, char **nameresult, unsigned int size, int bin)
{
    int fd;
    char buf[MAXPDSTRING];
    if (strlen(dir) + strlen(name) + strlen(ext) + 4 > size)
        return (-1);
    sys_expandpath(dir, buf, MAXPDSTRING);
    strcpy(dirresult, buf);
    if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
        strcat(dirresult, "/");
    strcat(dirresult, name);
    strcat(dirresult, ext);
    sys_bashfilename(dirresult, dirresult);

    DEBUG(post("looking for %s",dirresult));
        /* see if we can open the file for reading */
    if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
    {
            /* in unix, further check that it's not a directory */
#ifdef HAVE_UNISTD_H
        struct stat statbuf;
        int ok =  ((fstat(fd, &statbuf) >= 0) &&
            !S_ISDIR(statbuf.st_mode));
        if (!ok)
        {
            if (sys_verbose) post("tried %s; stat failed or directory",
                dirresult);
            close (fd);
            fd = -1;
        }
        else
#endif
        {
            char *slash;
            if (sys_verbose) post("tried %s and succeeded", dirresult);
            sys_unbashfilename(dirresult, dirresult);
            slash = strrchr(dirresult, '/');
            if (slash)
            {
                *slash = 0;
                *nameresult = slash + 1;
            }
            else *nameresult = dirresult;

            return (fd);  
        }
    }
    else
    {
        if (sys_verbose) post("tried %s and failed", dirresult);
    }
    return (-1);
}
Esempio n. 3
0
/* used for expanding paths for various objects */
void sys_expandpathelems(const char *name, char *result)
{
	//check for expandable elements in path (e.g. @pd_extra, ~/) and replace
	//fprintf(stderr,"sys_expandpathelems name=<%s>\n", name);
	char interim[FILENAME_MAX];
	if (strstr(name, "@pd_extra") != NULL) {
		t_namelist *path = pd_extrapath;
		while (path->nl_next)
			path = path->nl_next;
		sys_path_replace(name, interim, "@pd_extra", path->nl_string);
		//fprintf(stderr,"path->nl_string=<%s>\n", path->nl_string);
	} else {
		strcpy(interim, name);
	}
	//fprintf(stderr,"sys_expandpathelems interim=<%s>\n", interim);
	sys_expandpath(interim, result);
	//fprintf(stderr,"sys_expandpathelems result=<%s>\n", result);
}