1#!/usr/local/bin/perl
2# $Header: /home/jcb/MahJong/newmj/RCS/makefallbacktiles,v 12.0 2009/06/28 20:43:12 jcb Rel $
3
4#****************** COPYRIGHT STATEMENT **********************
5#* This file is Copyright (c) 2000 by J. C. Bradfield.       *
6#* Distribution and use is governed by the LICENCE file that *
7#* accompanies this file.                                    *
8#* The moral rights of the author are asserted.              *
9#*                                                           *
10#***************** DISCLAIMER OF WARRANTY ********************
11#* This code is not warranted fit for any purpose. See the   *
12#* LICENCE file for further information.                     *
13#*                                                           *
14#*************************************************************
15
16# take a directory of tiles, and
17# generate on stdout a module that exports a single symbol
18# fallbackpixmaps, of type **char[].
19# the xpm pixmap for tile t is in entry t;
20# the ErrorTile is in entry 99;
21# the tong pixmaps are in entries 10[1234].
22$dir = $ARGV[0];
23if ( ! defined($dir) ) {
24  print "char ***fallbackpixmaps = 0;\n";
25  exit;
26}
27
28if ( ! -d $dir ) { die("Not a directory."); }
29
30# read an xpm file and spit it out, changing the variable name
31# to pm_$i
32sub readit {
33  my($file,$i) = @_;
34
35  open(STDIN,"<$dir/$file.xpm") || die("Can't open $dir/$file");
36
37  while ( <STDIN> ) {
38    s/\*\s*(\w*)\s*\[\]/\*pm_$i\[\]/;
39    print;
40  }
41  # note it
42  $vars[$i] = 1;
43}
44
45&readit('XX',99);
46&readit('--',0);
47
48$j = 1;
49foreach $s ( 'B', 'C', 'D' ) {
50  for ( $i = 1; $i < 10; $i++ ) {
51    &readit("$i$s",$j*10+$i);
52  }
53  $j++;
54}
55
56$i = 1;
57foreach $t ( 'E', 'S', 'W', 'N' ) {
58  &readit("${t}W",40+$i);
59  $i++;
60}
61
62$i = 1;
63foreach $t ( 'R', 'W', 'G' ) {
64  &readit("${t}D",50+$i);
65  $i++;
66}
67
68$j = 6;
69foreach $s ( 'F', 'S' ) {
70  for ( $i = 1; $i < 5; $i++ ) {
71    &readit("$i$s",$j*10+$i);
72  }
73  $j++;
74}
75
76&readit('tongE',101);
77&readit('tongS',102);
78&readit('tongW',103);
79&readit('tongN',104);
80
81# now define the external symbol
82print "char **fallbackpixmaps[] = {\n";
83
84for ( $i = 0 ; $i <= $#vars ; $i++ ) {
85  print +($vars[$i] ? "pm_$i" : 0),", ";
86}
87print "\n};\n";
88