Skip to content
Snippets Groups Projects
Commit 598586a2 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

fixed image external to conform with the new implementation of @pd_extra (and...

fixed image external to conform with the new implementation of @pd_extra (and later other possible sys args) of the file path parser
parent 93d4eda1
No related branches found
No related tags found
No related merge requests found
#N canvas 0 26 462 397 10;
#X obj 265 274 image logo100.gif;
#X obj 265 274 image @pd_extra/ggee/logo100.gif
;
#X text 19 18 Incorporate images. This is instantiated with;
#X text 19 34 [image logo100.gif];
#X text 17 57 [image] works with .gif \, .ppm \, and .pgm image formats
......@@ -26,7 +27,6 @@ Wilkes for Pd version 0.42.;
#X text 12 65 INLET_0 open size;
#X text 12 85 OUTLET_0 bang;
#X restore 412 375 pd META;
#X connect 0 0 7 0;
#X connect 4 0 0 0;
#X connect 5 0 6 0;
#X connect 6 0 4 0;
......
......@@ -24,68 +24,17 @@ typedef struct _image
/* widget helper functions */
char * image_path_replace(
char const * const original,
char const * const pattern,
char const * const replacement
) {
size_t const replen = strlen(replacement);
size_t const patlen = strlen(pattern);
size_t const orilen = strlen(original);
size_t patcnt = 0;
const char * oriptr;
const char * patloc;
// find how many times the pattern occurs in the original string
for (oriptr = original; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
{
patcnt++;
}
{
// allocate memory for the new string
size_t const retlen = orilen + patcnt * (replen - patlen);
char * const returned = (char *) malloc( sizeof(char) * (retlen + 1) );
if (returned != NULL)
{
// copy the original string,
// replacing all the instances of the pattern
char * retptr = returned;
for (oriptr = original; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
{
size_t const skplen = patloc - oriptr;
// copy the section until the occurence of the pattern
strncpy(retptr, oriptr, skplen);
retptr += skplen;
// copy the replacement
strncpy(retptr, replacement, replen);
retptr += replen;
}
// copy the rest of the string.
strcpy(retptr, oriptr);
}
return returned;
}
}
void image_doopen(t_image* x) {
if (strlen(x->x_fname->s_name) != 0) {
char fname[MAXPDSTRING];
canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
fname, MAXPDSTRING);
//check for @sys_extra path and replace
if (strstr(fname, "@pd_extra") != NULL) {
t_namelist *path = pd_extrapath;
while (path->nl_next)
path = path->nl_next;
const char *new_fname = image_path_replace(x->x_fname->s_name, "@pd_extra", path->nl_string);
strcpy(fname, new_fname);
freebytes(new_fname, strlen(new_fname));
}
//check for sys path arguments and replace
char *new_fname = canvas_parse_sys_filename_args(x->x_fname->s_name);
strcpy(fname, new_fname);
freebytes(new_fname, strlen(new_fname));
sys_vgui("catch {image delete $img%x}\n", x);
sys_vgui("set img%x [image create photo -file {%s}]\n", x, fname);
sys_vgui(".x%x.c itemconfigure %xS -image $img%x\n",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment