File: items.pl

package info (click to toggle)
crossfire-client 0.95.4-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,028 kB
  • ctags: 1,144
  • sloc: ansic: 11,408; sh: 1,885; makefile: 237; perl: 48
file content (44 lines) | stat: -rwxr-xr-x 1,060 bytes parent folder | download
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
#!/usr/local/bin/perl

$MAXVAL=256;

# Number of subscripts
$SUBS=64;

$lastval=-1;

open(ITEMS,"<item_types") || die("can not open item_types file");
while(<ITEMS>) {
	next if (/^#/ || /^\s*$/);
	if (/^(\d*):/) {
		$lastval=$1;
	}
	# skip empty lines 
	else {
	    chomp;
	    die("Got item name before item number: $_\n") if ($lastval == -1);
	    push @{ $names[$lastval]} , $_;
	}
}
close(ITEMS);		

open(ITEMS, ">item_types.h") || die("Can not open item_types.h\n");

print ITEMS "/* This file is automatically generated editing by hand is strongly*/\n";
print ITEMS "/* discouraged.  Look ath the item_types file and the items.pl conversion */\n";
print ITEMS "/* script. */\n";

print ITEMS "\n#define NUM_ITEM_TYPES $MAXVAL\n";
print ITEMS "#define MAX_NAMES_PER_TYPE $SUBS\n\n";

print ITEMS "static char *item_types[$MAXVAL][$SUBS] = {\n";

for ($i=0; $i<$MAXVAL; $i++) {
    print ITEMS "{ ";
    for ($j=0; $j<= $#{ $names[$i] }; $j++) {
	print ITEMS "\"$names[$i][$j]\", ";
    }
    print ITEMS "NULL }, \n";
}
print ITEMS "}; \n";
close(ITEMS);