File: makefallbacktiles

package info (click to toggle)
mah-jong 1.8-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,384 kB
  • ctags: 2,186
  • sloc: ansic: 26,312; perl: 393; makefile: 272; sh: 122
file content (87 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/local/bin/perl
# $Header: /home/jcb/newmj/RCS/makefallbacktiles,v 11.0 2001/05/17 18:23:12 jcb Rel $

#****************** COPYRIGHT STATEMENT **********************
#* This file is Copyright (c) 2000 by J. C. Bradfield.       *
#* Distribution and use is governed by the LICENCE file that *
#* accompanies this file.                                    *
#* The moral rights of the author are asserted.              *
#*                                                           *
#***************** DISCLAIMER OF WARRANTY ********************
#* This code is not warranted fit for any purpose. See the   *
#* LICENCE file for further information.                     *
#*                                                           *
#*************************************************************

# take a directory of tiles, and
# generate on stdout a module that exports a single symbol
# fallbackpixmaps, of type **char[].
# the xpm pixmap for tile t is in entry t;
# the ErrorTile is in entry 99;
# the tong pixmaps are in entries 10[1234].
$dir = $ARGV[0];
if ( ! defined($dir) ) {
  print "char ***fallbackpixmaps = 0;\n";
  exit;
}

if ( ! -d $dir ) { die("Not a directory."); }

# read an xpm file and spit it out, changing the variable name
# to pm_$i
sub readit {
  my($file,$i) = @_;

  open(STDIN,"<$dir/$file.xpm") || die("Can't open $dir/$file");

  while ( <STDIN> ) {
    s/\*\s*(\w*)\s*\[\]/\*pm_$i\[\]/;
    print;
  }
  # note it
  $vars[$i] = 1;
}

&readit('XX',99);
&readit('--',0);

$j = 1;
foreach $s ( 'B', 'C', 'D' ) {
  for ( $i = 1; $i < 10; $i++ ) {
    &readit("$i$s",$j*10+$i);
  }
  $j++;
}

$i = 1;
foreach $t ( 'E', 'S', 'W', 'N' ) {
  &readit("${t}W",40+$i);
  $i++;
}

$i = 1;
foreach $t ( 'R', 'W', 'G' ) {
  &readit("${t}D",50+$i);
  $i++;
}

$j = 6;
foreach $s ( 'F', 'S' ) {
  for ( $i = 1; $i < 5; $i++ ) {
    &readit("$i$s",$j*10+$i);
  }
  $j++;
}

&readit('tongE',101);
&readit('tongS',102);
&readit('tongW',103);
&readit('tongN',104);

# now define the external symbol
print "char **fallbackpixmaps[] = {\n";

for ( $i = 0 ; $i <= $#vars ; $i++ ) {
  print +($vars[$i] ? "pm_$i" : 0),", ";
}
print "\n};\n";