#!/usr/bin/perl -w # reads a 2-color XPM; outputs space for white, asterisk for black use strict; $/ = undef; my $text = <>; $text =~ s{^[^"]*\n}{}gm; # remove noise lines $text =~ s{^\s*"\s*([^"]*\S)\s*"\s*,\s*$}{$1}gm; # unquote others $text =~ s{^\d+\s+\d+\s+(\d+)\s+(\d+)\n # dimensions (.)\s+c\s+\#([0-9a-fA-F]+)\n # colormap 0 (.)\s+c\s+\#([0-9a-fA-F]+)\n }{}mx; # colormap 1 die "has too many colors or is in wrong format\n" if $1 > 2 || $2 > 1; my ($w, $b) = hex($4) > hex($6) ? ( $3,$5 ) : ( $5,$3 ); eval "\$text =~ tr/$w$b/ */"; print $text;