--- a/xc/extras/Xpm/lib/WrFFrI.c 2004-09-15 17:47:39.000000000 +0200 +++ b/xc/extras/Xpm/lib/WrFFrI.c 2004-12-04 23:28:42.282557910 +0100 @@ -98,7 +102,7 @@ XpmWriteFileFromXpmImage(filename, image XpmInfo *info; { xpmData mdata; - char *name, *dot, *s, new_name[BUFSIZ]; + char *name, new_name[BUFSIZ] = "image_name"; int ErrorStatus; /* open file to write */ @@ -106,43 +110,38 @@ XpmWriteFileFromXpmImage(filename, image return (ErrorStatus); /* figure out a name */ + name = new_name; if (filename) { -#ifdef VMS - name = filename; -#else - if (!(name = rindex(filename, '/')) + const char* s = filename + strlen(filename); + name = new_name + sizeof(new_name); + *--name = '\0'; + while ( s > filename ) + { + --s; +#ifndef VMS /* filesystem has a structure: take only the last element */ + if ( '/' == *s ) + break; #ifdef AMIGA - && !(name = rindex(filename, ':')) + if ( ':' == *s ) + break; #endif - ) - name = filename; - else - name++; #endif - /* let's try to make a valid C syntax name */ - if (index(name, '.')) { - strcpy(new_name, name); - /* change '.' to '_' */ - name = s = new_name; - while ((dot = index(s, '.'))) { - *dot = '_'; - s = dot; + if ( new_name == name ) + break; + --name; + switch ( *s ) + { + case '.': + case '-': + *name = '_'; + break; + default: + *name = *s <= 32 ? '_': *s; } + /* if ( !strcmp(s, ".Z") || !strcmp(s, ".gz") ) + name = new_name + sizeof(new_name) - 1; */ } - if (index(name, '-')) { - if (name != new_name) { - strcpy(new_name, name); - name = new_name; - } - /* change '-' to '_' */ - s = name; - while ((dot = index(s, '-'))) { - *dot = '_'; - s = dot; - } - } - } else - name = "image_name"; + } /* write the XpmData from the XpmImage */ if (ErrorStatus == XpmSuccess)