This site's content was compiled from 1993 to 2006. Beyond that, Google is your friend.

xpm2e

Maintainer

Pirmin Kalberer

Description

A Perl script that converts xpm image files to Eiffel declarations

Categories

Versions

Features

The script reads an XPM file and writes an Eiffel class containing the XPM image as an ARRAY[STRING].

The script is a short one, and is included here in full:

#!/usr/bin/perl # # xpm2e, V0.1 (17.8.99) # # xpm2e, a script that converts xpm files to Eiffel declarations # # Copyright (C) 1999 Pirmin Kalberer <kalberer@spin.ch> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. print <<EOF; class ICONS feature EOF while(<>){ # Remove C-comment s/^\/\*.*\*\///g; # % in string s/%/%%/g; # End of string declaration s/\} *; *$/ >>\n end/g; # Beginning of declaration if (/static +char *\* *([a-z_]+)/i) { $xpmname = $1; $xpmname=~tr [A-Z] [a-z]; print <<EOF; $xpmname\_d : ARRAY[STRING] is once Result := << EOF } else { print "\t\t$_" } } print "\nend\n";

Example

Here is an XPM file. It's a "flame" icon from the Ghostscript application:

/* XPM */ static char * gs_s_xpm[] = { /* width height ncolors cpp [x_hot y_hot] */ "24 24 6 1 0 0", /* colors */ " s none m none c none", ". c #808080808080", "X s iconColor1 m black c black", "o c #C0C0C0C0C0C0", "O s iconColor2 m white c white", "+ c #00000000FFFF", /* pixels */ " ", " .. ", " XoOo. ", " X.OoX ", " X.OoX. ", " .XXXXXX.oOoXX ", " ..XXXXXXXX.oOO.XX ", " XXXXXXXX..oOOOo.XX ", " XXXXXXX.OOOOOo.XXXX. ", " XXXXXX.OOOOOOOXXXXXXX ", " .XXXXX.OOOO+OOXXXXXXXX ", " XXXXXXOOO+O+OOXXXXXXXX ", " XXXXXXOOO+OOOOXXXXXXXX ", " XXXXXXOOOOOOOOOXXXXXXX ", " .XXXXXOOOOOOOOOO.XXXXX ", " XXXXXXOOOOO++OOO.XXXX ", " .XXXXX.OOOO++OOOoXXX ", " XXXXXX.OOOOOOOOOXXX ", " .XXXXXXoOOOOOOOoXX ", " .XXXXXXoOOOOOo.X ", " .XXXXXOOOOO.X ", " .XXXXOOOOO.. ", " XXXXXOOOOOOOO ", " "};

We invoke the conversion like this:

cat flame.xpm | ./xpm2e

Here's the resulting Eiffel file:

class ICONS feature gs_s_xpm_d : ARRAY[STRING] is once Result := << "24 24 6 1 0 0", " s none m none c none", ". c #808080808080", "X s iconColor1 m black c black", "o c #C0C0C0C0C0C0", "O s iconColor2 m white c white", "+ c #00000000FFFF", " ", " .. ", " XoOo. ", " X.OoX ", " X.OoX. ", " .XXXXXX.oOoXX ", " ..XXXXXXXX.oOO.XX ", " XXXXXXXX..oOOOo.XX ", " XXXXXXX.OOOOOo.XXXX. ", " XXXXXX.OOOOOOOXXXXXXX ", " .XXXXX.OOOO+OOXXXXXXXX ", " XXXXXXOOO+O+OOXXXXXXXX ", " XXXXXXOOO+OOOOXXXXXXXX ", " XXXXXXOOOOOOOOOXXXXXXX ", " .XXXXXOOOOOOOOOO.XXXXX ", " XXXXXXOOOOO++OOO.XXXX ", " .XXXXX.OOOO++OOOoXXX ", " XXXXXX.OOOOOOOOOXXX ", " .XXXXXXoOOOOOOOoXX ", " .XXXXXXoOOOOOo.X ", " .XXXXXOOOOO.X ", " .XXXXOOOOO.. ", " XXXXXOOOOOOOO ", " " >> end end

Licensing

Google
 
Web eiffelzone.com