From 598586a2922f74b62eaec48f9c1472f665f2554d Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Thu, 1 Aug 2013 19:28:47 -0400
Subject: [PATCH] fixed image external to conform with the new implementation
 of @pd_extra (and later other possible sys args) of the file path parser

---
 externals/ggee/gui/image-help.pd |  4 +--
 externals/ggee/gui/image.c       | 61 +++-----------------------------
 2 files changed, 7 insertions(+), 58 deletions(-)

diff --git a/externals/ggee/gui/image-help.pd b/externals/ggee/gui/image-help.pd
index 3bf84aa83..b3a6807cd 100644
--- a/externals/ggee/gui/image-help.pd
+++ b/externals/ggee/gui/image-help.pd
@@ -1,5 +1,6 @@
 #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;
diff --git a/externals/ggee/gui/image.c b/externals/ggee/gui/image.c
index 2c24122b2..cb9cbf463 100644
--- a/externals/ggee/gui/image.c
+++ b/externals/ggee/gui/image.c
@@ -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", 
-- 
GitLab