Commit d527ff2f authored by Miller Puckette's avatar Miller Puckette
Browse files

0-42-0 test 1 - patched for declare absolute pathnames

parent 625cfe29
......@@ -1338,6 +1338,22 @@ void canvas_savedeclarationsto(t_canvas *x, t_binbuf *b)
}
}
static void canvas_completepath(char *from, char *to)
{
if (sys_isabsolutepath(from))
{
to[0] = '\0';
}
else
{ // if not absolute path, append Pd lib dir
strncpy(to, sys_libdir->s_name, FILENAME_MAX-4);
to[FILENAME_MAX-3] = '\0';
strcat(to, "/");
}
strncat(to, from, FILENAME_MAX-strlen(to));
to[FILENAME_MAX-1] = '\0';
}
static void canvas_declare(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
{
int i;
......@@ -1359,12 +1375,7 @@ static void canvas_declare(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
}
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;
canvas_completepath(atom_getsymbolarg(i+1, argc, argv)->s_name, strbuf);
e->ce_path = namelist_append(e->ce_path, strbuf, 0);
i++;
}
......@@ -1375,12 +1386,7 @@ static void canvas_declare(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
}
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;
canvas_completepath(atom_getsymbolarg(i+1, argc, argv)->s_name, strbuf);
sys_load_lib(0, strbuf);
i++;
}
......@@ -1427,9 +1433,16 @@ int canvas_open(t_canvas *x, const char *name, const char *ext,
for (nl = y->gl_env->ce_path; nl; nl = nl->nl_next)
{
char realname[MAXPDSTRING];
strncpy(realname, dir, MAXPDSTRING);
realname[MAXPDSTRING-3] = 0;
strcat(realname, "/");
if (sys_isabsolutepath(nl->nl_string))
{
realname[0] = '\0';
}
else
{ /* if not absolute path, append Pd lib dir */
strncpy(realname, dir, MAXPDSTRING);
realname[MAXPDSTRING-3] = 0;
strcat(realname, "/");
}
strncat(realname, nl->nl_string, MAXPDSTRING-strlen(realname));
realname[MAXPDSTRING-1] = 0;
if ((fd = sys_trytoopenone(realname, name, ext,
......
......@@ -9,9 +9,9 @@ extern "C" {
#endif
#define PD_MAJOR_VERSION 0
#define PD_MINOR_VERSION 41
#define PD_BUGFIX_VERSION 4
#define PD_TEST_VERSION ""
#define PD_MINOR_VERSION 42
#define PD_BUGFIX_VERSION 0
#define PD_TEST_VERSION "test1"
/* old name for "MSW" flag -- we have to take it for the sake of many old
"nmakefiles" for externs, which will define NT and not MSW */
......@@ -461,6 +461,7 @@ EXTERN void sys_ouch(void);
/* ------------ system interface routines ------------------- */
EXTERN int sys_isreadablefile(const char *name);
EXTERN int sys_isabsolutepath(const char *dir);
EXTERN void sys_bashfilename(const char *from, char *to);
EXTERN void sys_unbashfilename(const char *from, char *to);
EXTERN int open_via_path(const char *name, const char *ext, const char *dir,
......
......@@ -69,6 +69,24 @@ void sys_unbashfilename(const char *from, char *to)
*to = 0;
}
/* test if path is absolute or relative, based on leading /, env vars, ~, etc */
int sys_isabsolutepath(const char *dir)
{
if (dir[0] == '/' || dir[0] == '~'
#ifdef MSW
|| dir[0] == '%' || (dir[1] == ':' && dir[2] == '/')
#endif
)
{
return 1;
}
else
{
return 0;
}
}
/******************* Utility functions used below ******************/
/*!
......@@ -250,11 +268,7 @@ int sys_trytoopenone(const char *dir, const char *name, const char* ext,
int sys_open_absolute(const char *name, const char* ext,
char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp)
{
if (name[0] == '/'
#ifdef MSW
|| (name[1] == ':' && name[2] == '/')
#endif
)
if (sys_isabsolutepath(name))
{
char dirbuf[MAXPDSTRING];
int dirlen = (strrchr(name, '/') - name);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment