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>
11 # Wireshark - Network traffic analyzer
12 # By Gerald Combs <gerald@wireshark.org>
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;
33 $comment = "/* This file is generated by $0, do not edit. */\n\n";
38 $subfieldStringLength = 0;
46 if (length $subfield != $subfieldStringLength) {
47 if (!length $subfield) {
49 } elsif (length $subfield > $subfieldStringLength) {
50 $prefix .= "$lastAbbrev.";
52 $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
54 $subfieldStringLength = length $subfield;
57 @fields = split /\s+/o ;
58 if ($fields[0] eq '#') {
60 # If the line begins with "#", treat it as a comment, by
63 # (We don't support comments at the end of a line; that would
64 # require some more pain in our simple parser.)
68 $abbrev = shift @fields;
69 $type = shift @fields;
70 $lastAbbrev = $abbrev;
72 $field = $prefix.$abbrev;
74 if ($fields[0] =~ /^\d+$/o) {
76 # This is presumably a Boolean bitfield, and this is the number
77 # of bits in the parent field.
79 $fieldDisplay = shift @fields;
82 # The next token is the base for the field.
84 $fieldDisplay = "BASE_".shift @fields;
87 if ($fields[0] eq 'VALS') {
89 # It's an enumerated field, with the value_string table having a
90 # name based on the field's name.
93 $fieldStrings = "VALS(${abbrev}_vals)";
94 $fieldStrings =~ s/-/_/go;
95 } elsif ($fields[0] =~ /^VALS\(/o) {
97 # It's an enumerated field, with a specified name for the
100 $fieldStrings = shift @fields;
101 $fieldStrings =~ s/\)/_vals\)/o;
104 # It's not an enumerated field.
106 $fieldStrings = 'NULL';
109 if ($fields[0] =~ /^0x/) {
111 # The next token looks like a bitmask for a bitfield.
113 $mask = shift @fields;
118 $rest = join(' ', @fields);
119 $longName = uc $name;
120 $longName = $rest if ($rest);
123 $variable =~ s/-/_/go;
124 $variable =~ s/\./_/go;
126 print DECL "static int hf_x11_$variable = -1;\n";
129 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, "$longName", HFILL }},