File: msgtypes.pl

package info (click to toggle)
crossfire-client 1.75.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,936 kB
  • sloc: ansic: 17,281; python: 758; perl: 78; sh: 23; xml: 17; makefile: 12
file content (75 lines) | stat: -rwxr-xr-x 2,182 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
#!/usr/bin/perl
#
#   Copyright (C) 2007 Mark Wedel & Crossfire Development Team
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   The author can be reached via e-mail to crossfire-devel@real-time.com
#

# $ARGV[0] is the source directory. We need to know it for out of tree builds.

use strict;

open(IN,"<$ARGV[0]/shared/newclient.h") || die("Can not open newclient.h file\n");
open(OUT,">msgtypes.h") || die("Can not open msgtypes.h file\n");

print OUT "/* This file is automatically generated. Editing by hand is strongly */\n";
print OUT "/* discouraged.  Look at the newclient.h file and the msgtypes.pl conversion */\n";
print OUT "/* script. */\n";

print OUT "\nconst Msg_Type_Names msg_type_names[] = {\n";
print OUT "{0, 0, \"generic\"},\n";

my $on_subtypes=0;
my $last_type=0;
my $type;
my $lc;
my @types;
my $max_types;

while(<IN>) {
    if (/^#define\s+MSG_TYPE_(\S*)/) {
	if ($1 eq "LAST" || $1 eq "SUBTYPE_NONE") {
	    $on_subtypes=1;
	    next;
	}
	$type = $1;
	$lc = $1;
	$lc =~ tr /A-Z/a-z/;
	if (! $on_subtypes) {
	    $types[$max_types++] = $1;
	    print OUT "{MSG_TYPE_$1, 0, \"$lc\"},\n";
	} else {
	    if ($type !~ /^$types[$last_type]/ ) {
		my $i;
		for ($i=0; $i< $max_types; $i++) {
		    if ($type =~ /^$types[$i]/) {
			$last_type=$i;
			last;
		    }
		}
		if ($i == $max_types) {
		    print STDERR "Unable to find right type for $type\n";
		}
	    }
	    print OUT "{MSG_TYPE_$types[$last_type], MSG_TYPE_$type, \"$lc\"},\n";
	}
    }
}
close(IN);

print OUT "};\n";
close(OUT);