Skip to content

Commit

Permalink
Merge branch 'aggraef/purr-data-fix-791'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Wilkes committed Apr 1, 2021
2 parents 653fbd2 + 062904f commit d275d00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
17 changes: 11 additions & 6 deletions pd/src/g_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2412,24 +2412,29 @@ static int do_replace_subpatches(t_canvas *x, const char* label, t_binbuf *origi
static void abstracthandler_callback(t_abstracthandler *x, t_symbol *s)
{
char fullpath[MAXPDSTRING], label[MAXPDSTRING], *dir, *filename;
char basename[MAXPDSTRING], buf[MAXPDSTRING];
memset(fullpath, '\0', MAXPDSTRING);
memset(basename, '\0', MAXPDSTRING);
memset(label, '\0', MAXPDSTRING);
sys_unbashfilename(s->s_name, fullpath);
if (strlen(fullpath) < 3 || strcmp(fullpath+strlen(fullpath)-3, ".pd"))
strcat(fullpath, ".pd");
filename = strrchr(fullpath, '/') + 1;
fullpath[filename - fullpath - 1] = '\0';
dir = fullpath;

strncpy(basename, filename, strlen(filename) - 3);
int flag, prefix = 0;
strncpy(buf,
canvas_getdir(canvas_getrootfor(x->tarjet))->s_name,
MAXPDSTRING);
buf[MAXPDSTRING-1] = 0;
if (flag =
sys_relativizepath(canvas_getdir(canvas_getrootfor(x->tarjet))->s_name,
dir, label))
sys_relativizepath(buf, dir, label))
{
int len = strlen(label), creator, fd = -1;
if (len && label[len-1] != '/')
label[len] = '/';
strncat(label, filename, MAXPDSTRING - 4);
strncat(label, basename, MAXPDSTRING - strlen(label) - 1);
/* check if there is a creator with the same name or if it's one of
the built-in methods */
t_symbol *sym = gensym(label);
Expand Down Expand Up @@ -2465,7 +2470,7 @@ static void abstracthandler_callback(t_abstracthandler *x, t_symbol *s)
if (flag && prefix)
{
strcpy(label, "./");
strncat(label, filename, MAXPDSTRING - 4);
strncat(label, basename, MAXPDSTRING - strlen(label) - 1);
}
else if (!flag)
error("warning: couldn't use relative path, there is a coincidence "
Expand All @@ -2476,7 +2481,7 @@ static void abstracthandler_callback(t_abstracthandler *x, t_symbol *s)
memset(label, '\0', MAXPDSTRING);
strcpy(label, dir);
strcat(label, "/");
strncat(label, filename, strlen(label) - 3);
strncat(label, basename, MAXPDSTRING - strlen(label) - 1);
/* should check if 'filename' is one of the built-in special methods
in order to inform the user about the nameclash problem */
}
Expand Down
20 changes: 14 additions & 6 deletions pd/src/s_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,17 @@ int sys_isabsolutepath(const char *dir)
}

int sys_relativizepath(const char *from, const char *to, char *result)
// precond: from and to fit into char[MAXPDSTRING]
// postcond: result will fit into char[MAXPDSTRING]
{
char fromext[FILENAME_MAX];
char fromext[MAXPDSTRING];
sys_unbashfilename(from, fromext);
char toext[FILENAME_MAX];
char toext[MAXPDSTRING];
sys_unbashfilename(to, toext);
// this will be large enough to hold the result in any case (FLW)
char buf[4*MAXPDSTRING];

memset(buf, '\0', 4*MAXPDSTRING);

int i = 0, j;
while(fromext[i] && toext[i] && fromext[i] == toext[i]) i++;
Expand All @@ -221,22 +227,24 @@ int sys_relativizepath(const char *from, const char *to, char *result)
{
if(k == 0)
{
strcpy(result+k, "..");
strcpy(buf+k, "..");
k += 2;
}
else
{
strcpy(result+k, "/..");
strcpy(buf+k, "/..");
k += 3;
}
}
i++;
}
if(toext[j])
{
result[k] = '/';
strcpy(result+k+1, toext+j+1);
buf[k] = '/';
strcpy(buf+k+1, toext+j+1);
}
strncpy(result, buf, MAXPDSTRING);
result[MAXPDSTRING-1] = '\0';
}
else if(!fromext[i] && toext[j])
{
Expand Down

0 comments on commit d275d00

Please sign in to comment.