XPM variable names are over-mangled

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
inductiveload

XPM variable names are over-mangled

Post by inductiveload »

I was trying to convert a file to CPM format with the filename "logo-50.xpm". I was expecting the XPM header to read:

Code: Select all

/* XPM */
static char *logo_50_xpm[] = {
Instead, I got

Code: Select all

/* XPM */
static char *logo___[] = {
However, the filename gave no indication that the variable name in the XPM file was mangled in this way (I knew that the hyphen would be turned to an underscore, but GIMP saves with the numbers intact and suffixed with "_xpm". Thus the GIMP-generated file is:

Code: Select all

/* XPM */
static char *logo_50_xpm[] = {
The conversion of the numeric characters to underscores in very annoying when you want to convert files like "logo-50.xpm" and "logo-70.xpm", since both are mangled to "logo___". I fixed it for my purposes by changing coders/xpm.c and recompiling from source. The change I made was at line 972-975:

Code: Select all

    if (isalpha((int) ((unsigned char) basename[i])) == 0)
      basename[i]='_';
  (void) FormatMagickString(buffer,MaxTextExtent,
    "static char *%s[] = {\n",basename);

Code: Select all

    if (isalnum((int) ((unsigned char) basename[i])) == 0)
      basename[i]='_';
  (void) FormatMagickString(buffer,MaxTextExtent,
    "static char *%s_xpm[] = {\n",basename);
It may or may not be desirable to add some logic to look out for an initial numeric character as this wouldn't compile into a C program, but it would again provide different results to GIMP which may not be expected by a user. It may also be preferable to get the "_xpm" suffix by scanning the filename, but this would only be useful when people are saving XPM files with strange extensions.

Either way, the simple fix above prevents name collision of file names with digits in the same place, which is very common.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: XPM variable names are over-mangled

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.6.5-6 Beta available by sometime tomorrow. Thanks.
Post Reply