1#!/usr/local/bin/perl
2
3$MAXVAL=256;
4
5# Number of subscripts
6$SUBS=64;
7
8$lastval=-1;
9
10open(ITEMS,"<$ARGV[0]/item-types") || die("can not open item-types file");
11while(<ITEMS>) {
12	next if (/^#/ || /^\s*$/);
13	if (/^(\d*):/) {
14		$lastval=$1;
15	}
16	# skip empty lines
17	else {
18	    chomp;
19	    die("Got item name before item number: $_\n") if ($lastval == -1);
20	    push @{ $names[$lastval]} , $_;
21	}
22}
23close(ITEMS);
24
25open(ITEMS, ">item-types.h") || die("Can not open item-types.h\n");
26
27print ITEMS "/* This file is automatically generated editing by hand is strongly*/\n";
28print ITEMS "/* discouraged.  Look at the item-types file and the items.pl conversion */\n";
29print ITEMS "/* script. */\n";
30
31print ITEMS "\n#define NUM_ITEM_TYPES $MAXVAL\n";
32print ITEMS "#define MAX_NAMES_PER_TYPE $SUBS\n\n";
33
34print ITEMS "static const char * const item_types[$MAXVAL][$SUBS] = {\n";
35
36for ($i=0; $i<$MAXVAL; $i++) {
37    print ITEMS "{ ";
38    for ($j=0; $j<= $#{ $names[$i] }; $j++) {
39	print ITEMS "\"$names[$i][$j]\", ";
40    }
41    print ITEMS "NULL }, \n";
42}
43print ITEMS "}; \n";
44close(ITEMS);
45