3 # Script to convert "x11-fields" file, listing fields for
4 # X11 dissector, into header files declaring field-index
5 # values and field definitions for those fields.
7 # Copyright 2000, Christophe Tronche <ch.tronche@computer.org>
9 # $Id: process-x11-fields.pl,v 1.5 2001/06/18 02:17:58 guy Exp $
11 # Ethereal - Network traffic analyzer
12 # By Gerald Combs <gerald@ethereal.com>
13 # Copyright 1998 Gerald Combs
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 open(DECL, ">x11-declarations.h") || die;
31 open(REG, ">x11-register-info.h") || die;
34 $subfieldStringLength = 0;
42 if (length $subfield != $subfieldStringLength) {
43 if (!length $subfield) {
45 } elsif (length $subfield > $subfieldStringLength) {
46 $prefix .= "$lastAbbrev.";
48 $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
50 $subfieldStringLength = length $subfield;
53 @fields = split /\s+/o ;
54 if ($fields[0] eq '#') {
56 # If the line begins with "#", treat it as a comment, by
59 # (We don't support comments at the end of a line; that would
60 # require some more pain in our simple parser.)
64 $abbrev = shift @fields;
65 $type = shift @fields;
66 $lastAbbrev = $abbrev;
68 $field = $prefix.$abbrev;
70 if ($fields[0] =~ /^\d+$/o) {
72 # This is presumably a Boolean bitfield, and this is the number
73 # of bits in the parent field.
75 $fieldDisplay = shift @fields;
78 # The next token is the base for the field.
80 $fieldDisplay = "BASE_".shift @fields;
83 if ($fields[0] eq 'VALS') {
85 # It's an enumerated field, with the value_string table having a
86 # name based on the field's name.
89 $fieldStrings = "VALS(${abbrev}_vals)";
90 $fieldStrings =~ s/-/_/go;
91 } elsif ($fields[0] =~ /^VALS\(/o) {
93 # It's an enumerated field, with a specified name for the
96 $fieldStrings = shift @fields;
97 $fieldStrings =~ s/\)/_vals\)/o;
100 # It's not an enumerated field.
102 $fieldStrings = 'NULL';
105 if ($fields[0] =~ /^0x/) {
107 # The next token looks like a bitmask for a bitfield.
109 $mask = shift @fields;
114 $rest = join(' ', @fields);
115 $longName = uc $name;
116 $longName = $rest if ($rest);
119 $variable =~ s/-/_/go;
120 $variable =~ s/\./_/go;
122 print DECL "static int hf_x11_$variable = -1;\n";
125 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, "$longName", HFILL }},