name change
[metze/wireshark/wip.git] / epan / dissectors / 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$
10 #
11 # Wireshark - Network traffic analyzer
12 # By Gerald Combs <gerald@wireshark.org>
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 $comment = "/* This file is generated by $0, do not edit. */\n\n";
34 print DECL $comment;
35 print REG  $comment;
36
37 $prefix = '';
38 $subfieldStringLength = 0;
39
40 while(<>) {
41     s/#.*$//go;
42     next if /^\s*$/o;
43     s/^(\s*)//o;
44     $subfield = $1;
45
46     if (length $subfield != $subfieldStringLength) {
47         if (!length $subfield) {
48             $prefix = '';
49         } elsif (length $subfield > $subfieldStringLength) {
50             $prefix .= "$lastAbbrev.";
51         } else {
52             $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
53         }
54         $subfieldStringLength = length $subfield;
55     }
56
57     @fields = split /\s+/o ;
58     if ($fields[0] eq '#') {
59         #
60         # If the line begins with "#", treat it as a comment, by
61         # ignoring it.
62         #
63         # (We don't support comments at the end of a line; that would
64         # require some more pain in our simple parser.)
65         #
66         next;
67     }
68     $abbrev = shift @fields;
69     $type = shift @fields;
70     $lastAbbrev = $abbrev;
71
72     $field = $prefix.$abbrev;
73
74     if ($fields[0] =~ /^\d+$/o) {
75         #
76         # This is presumably a Boolean bitfield, and this is the number
77         # of bits in the parent field.
78         #
79         $fieldDisplay = shift @fields;
80     } else {
81         #
82         # The next token is the base for the field.
83         #
84         $fieldDisplay = "BASE_".shift @fields;
85     }
86
87     if ($fields[0] eq 'VALS') {
88         #
89         # It's an enumerated field, with the value_string table having a
90         # name based on the field's name.
91         #
92         shift @fields;
93         $fieldStrings = "VALS(${abbrev}_vals)";
94         $fieldStrings =~ s/-/_/go;
95     } elsif ($fields[0] =~ /^VALS\(/o) {
96         #
97         # It's an enumerated field, with a specified name for the
98         # value_string table.
99         #
100         $fieldStrings = shift @fields;
101         $fieldStrings =~ s/\)/_vals\)/o;
102     } else {
103         #
104         # It's not an enumerated field.
105         #
106         $fieldStrings = 'NULL';
107     }
108
109     if ($fields[0] =~ /^0x/) {
110         #
111         # The next token looks like a bitmask for a bitfield.
112         #
113         $mask = shift @fields;
114     } else {
115         $mask = 0;
116     }
117
118     $rest = join(' ', @fields);
119     $longName = uc $name;
120     $longName = $rest if ($rest);
121
122     $variable = $field;
123     $variable =~ s/-/_/go;
124     $variable =~ s/\./_/go;
125
126     print DECL "static int hf_x11_$variable = -1;\n";
127
128     print REG <<END;
129 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, "$longName", HFILL }},
130 END
131 }