aboutsummaryrefslogtreecommitdiffstats
path: root/tools/process-x11-fields.pl
blob: 71e732dfff5100190ea618022bf51a4babdbce43 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/perl
#
# Script to convert "x11-fields" file, listing fields for
# X11 dissector, into header files declaring field-index
# values and field definitions for those fields.
#
# Instructions for using this script are in epan/dissectors/README.X11
#
# Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

open(DECL, ">x11-declarations.h") || die;
open(REG, ">x11-register-info.h") || die;

sub add_generated_header {
    my ($out) = @_;

    print $out <<eot
/* Do not modify this file. */
/* It was automatically generated by $0. */
eot
    ;

    # Add license text
    print $out <<eot
/*
 * Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald[AT]wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

eot
    ;
}

add_generated_header(DECL);
add_generated_header(REG);

$prefix = '';
$subfieldStringLength = 0;

while(<>) {
    s/#.*$//go;
    next if /^\s*$/o;
    s/^(\s*)//o;
    $subfield = $1;

    if (length $subfield != $subfieldStringLength) {
	if (!length $subfield) {
	    $prefix = '';
	} elsif (length $subfield > $subfieldStringLength) {
	    $prefix .= "$lastAbbrev.";
	} else {
	    $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
	}
	$subfieldStringLength = length $subfield;
    }

    @fields = split /\s+/o ;
    if ($fields[0] eq '#') {
	#
	# If the line begins with "#", treat it as a comment, by
	# ignoring it.
	#
	# (We don't support comments at the end of a line; that would
	# require some more pain in our simple parser.)
	#
	next;
    }
    $abbrev = shift @fields;
    $type = shift @fields;
    $lastAbbrev = $abbrev;

    $field = $prefix.$abbrev;

    if ($fields[0] =~ /^\d+$/o) {
	#
	# This is presumably a Boolean bitfield, and this is the number
	# of bits in the parent field.
	#
	$fieldDisplay = shift @fields;
    } else {
	#
	# The next token is the base for the field.
	#
	$fieldDisplay = "BASE_".shift @fields;
    }

    if ($fields[0] eq 'VALS') {
	#
	# It's an enumerated field, with the value_string table having a
	# name based on the field's name.
	#
	shift @fields;
	$fieldStrings = "VALS(${abbrev}_vals)";
	$fieldStrings =~ s/-/_/go;
    } elsif ($fields[0] =~ /^VALS\(/o) {
	#
	# It's an enumerated field, with a specified name for the
	# value_string table.
	#
	$fieldStrings = shift @fields;
	$fieldStrings =~ s/\)/_vals\)/o;
    } else {
	#
	# It's not an enumerated field.
	#
	$fieldStrings = 'NULL';
    }

    if ($fields[0] =~ /^0x/) {
	#
	# The next token looks like a bitmask for a bitfield.
	#
	$mask = shift @fields;
    } else {
	$mask = 0;
    }

    $rest = join(' ', @fields);
    $longName = uc $name;
    $longName = $rest if ($rest);
    # Don't allow empty blurbs
    $longName = $longName eq "" ? "NULL" : "\"$longName\"";

    $variable = $field;
    $variable =~ s/-/_/go;
    $variable =~ s/\./_/go;

    print DECL "static int hf_x11_$variable = -1;\n";

    print REG <<END;
{ &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, $longName, HFILL }},
END
}