rem: i = strrchr(filepath, '/') - filepath + 1; if (i > strlen(filepath)) i = strlen(filepath);
add: tmp = wstrappend(panel->configurationPath, filename); } free(tmp);   if (!fetchImageFile (panel->configurationPath, filepath, filename)) {           free(filepath); filepath = wstrappend(panel->configurationPath, filename);   tmpImg = RLoadImage(scr->rcontext, filepath, 0); if (tmpImg) { if (panel->customPaletteImg) RDestroyImage(panel->customPaletteImg); panel->customPaletteImg = tmpImg;  customSetPalette(panel); WMAddPopUpButtonItem(panel->customPaletteHistoryBtn, filename);  panel->currentPalette = WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn)-1;  WMSetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn, panel->currentPalette); } } else { tmp = wstrappend(panel->configurationPath, filename);  i = remove(tmp);     WMRunAlertPanel(scr, panel->win, "File Error", "Invalid file format !", "OK", NULL, NULL); if (i != 0) { wsyserror("can't remove file %s", tmp); WMRunAlertPanel(scr, panel->win, "File Error", "Couldn't remove file from Configuration Directory !", "OK", NULL, NULL); }
context: customPaletteMenuNewFromFile(W_ColorPanel *panel){	W_Screen			*scr = WMWidgetScreen(panel->win);	WMOpenPanel			*browseP;	char				*filepath;	char				*filename = NULL;	char				path[PATH_MAX] = "\0";	char				*spath;	char				*tmp;	int				i;	RImage			*tmpImg = NULL;	if ((!panel->lastBrowseDir) || (strcmp(panel->lastBrowseDir,"\0") == 0)) {		strcpy(path, wgethomedir());		spath = wmalloc(strlen(path)+2);		strcpy(spath, path);	}	else {		spath = wmalloc(strlen(panel->lastBrowseDir)+2);		strcpy(spath, panel->lastBrowseDir);	}	browseP = WMGetOpenPanel(scr);	WMSetFilePanelCanChooseDirectories(browseP, 0);	WMSetFilePanelCanChooseFiles(browseP, 1);	/* Get a filename */	if (WMRunModalOpenPanelForDirectory(browseP, panel->win, wexpandpath(spath), "Open Palette", RSupportedFileFormats()) ) {		filepath = WMGetFilePanelFileName(browseP);		/* Get seperation position between path and filename */ 		i = strrchr(filepath, '/') - filepath + 1;		if (i > strlen(filepath))			i = strlen(filepath);		/* Store last browsed path */		if (panel->lastBrowseDir)			free(panel->lastBrowseDir);		panel->lastBrowseDir = wmalloc((i+1)*sizeof(char));		memset(panel->lastBrowseDir, 0, (i+1)*sizeof(char));		strncpy(panel->lastBrowseDir, filepath, i);		/* Get filename from path */		filename = wstrdup(filepath + i);		/* Check for duplicate files, and rename it if there are any */		tmp = wstrappend(panel->configurationPath, filename);		while (access (tmp, F_OK) == 0) {			free(tmp);			tmp = generateNewFilename(panel->configurationPath, filename);			filename = wstrdup(tmp);			free(tmp);			tmp = wstrappend(panel->configurationPath, filename);		}		free(tmp);		/* Copy the image to $(gnustepdir)/Library/Colors/ & Add the filename to the history menu */		if (!fetchImageFile (panel->configurationPath, filepath, filename)) {		/* error = -1 */			/* filepath is a "local" path now the file has been copied */			free(filepath);			filepath = wstrappend(panel->configurationPath, filename);			/* load the image & add menu entries */			tmpImg = RLoadImage(scr->rcontext, filepath, 0);			if (tmpImg) {				if (panel->customPaletteImg)					RDestroyImage(panel->customPaletteImg);				panel->customPaletteImg = tmpImg;				customSetPalette(panel);				WMAddPopUpButtonItem(panel->customPaletteHistoryBtn, filename);				WMSetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn, WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn)-1);				panel->currentPalette = WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn)-1;			}		}		else		{			tmp = wstrappend(panel->configurationPath, filename);			i = remove(tmp);	/* Delete the file, it doesn't belong here */						WMRunAlertPanel(scr, panel->win, "File Error", "Invalid file format !", "OK", NULL, NULL);			if (i != 0)				WMRunAlertPanel(scr, panel->win, "File Error", "Couldn't remove file from Configuration Directory !", "OK", NULL, NULL);			free(tmp);		}		free(filepath);		free(filename);	}	WMFreeFilePanel(browseP);}