Show the "negotiable/non-negotiable" flags as such.
[obnox/wireshark/wip.git] / process-x11-fields.pl
1 #!/usr/bin/perl
2 #
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.
6 #
7 # Copyright 2000, Christophe Tronche <ch.tronche@computer.org>
8 #
9 # $Id: process-x11-fields.pl,v 1.5 2001/06/18 02:17:58 guy Exp $
10 #
11 # Ethereal - Network traffic analyzer
12 # By Gerald Combs <gerald@ethereal.com>
13 # Copyright 1998 Gerald Combs
14 #
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.
19
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.
24
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.
28 #
29
30 open(DECL, ">x11-declarations.h") || die;
31 open(REG, ">x11-register-info.h") || die;
32
33 $prefix = '';
34 $subfieldStringLength = 0;
35
36 while(<>) {
37     s/#.*$//go;
38     next if /^\s*$/o;
39     s/^(\s*)//o;
40     $subfield = $1;
41
42     if (length $subfield != $subfieldStringLength) {
43         if (!length $subfield) {
44             $prefix = '';
45         } elsif (length $subfield > $subfieldStringLength) {
46             $prefix .= "$lastAbbrev.";
47         } else {
48             $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
49         }
50         $subfieldStringLength = length $subfield;
51     }
52
53     @fields = split /\s+/o ;
54     if ($fields[0] eq '#') {
55         #
56         # If the line begins with "#", treat it as a comment, by
57         # ignoring it.
58         #
59         # (We don't support comments at the end of a line; that would
60         # require some more pain in our simple parser.)
61         #
62         next;
63     }
64     $abbrev = shift @fields;
65     $type = shift @fields;
66     $lastAbbrev = $abbrev;
67
68     $field = $prefix.$abbrev;
69
70     if ($fields[0] =~ /^\d+$/o) {
71         #
72         # This is presumably a Boolean bitfield, and this is the number
73         # of bits in the parent field.
74         #
75         $fieldDisplay = shift @fields;
76     } else {
77         #
78         # The next token is the base for the field.
79         #
80         $fieldDisplay = "BASE_".shift @fields;
81     }
82
83     if ($fields[0] eq 'VALS') {
84         #
85         # It's an enumerated field, with the value_string table having a
86         # name based on the field's name.
87         #
88         shift @fields;
89         $fieldStrings = "VALS(${abbrev}_vals)";
90         $fieldStrings =~ s/-/_/go;
91     } elsif ($fields[0] =~ /^VALS\(/o) {
92         #
93         # It's an enumerated field, with a specified name for the
94         # value_string table.
95         #
96         $fieldStrings = shift @fields;
97         $fieldStrings =~ s/\)/_vals\)/o;
98     } else {
99         #
100         # It's not an enumerated field.
101         #
102         $fieldStrings = 'NULL';
103     }
104
105     if ($fields[0] =~ /^0x/) {
106         #
107         # The next token looks like a bitmask for a bitfield.
108         #
109         $mask = shift @fields;
110     } else {
111         $mask = 0;
112     }
113
114     $rest = join(' ', @fields);
115     $longName = uc $name;
116     $longName = $rest if ($rest);
117
118     $variable = $field;
119     $variable =~ s/-/_/go;
120     $variable =~ s/\./_/go;
121
122     print DECL "static int hf_x11_$variable = -1;\n";
123
124     print REG <<END;
125 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, "$longName", HFILL }},
126 END
127 }