nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 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 # Instructions for using this script are in epan/dissectors/README.X11
8 #
9 # Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #
29  
30 use File::Spec;
31  
32 my $srcdir = shift;
33 die "'$srcdir' is not a directory" unless -d $srcdir;
34  
35 open(DECL, "> $srcdir/x11-declarations.h") || die;
36 open(REG, "> $srcdir/x11-register-info.h") || die;
37  
38 my $script_name = File::Spec->abs2rel ($0, $srcdir);
39  
40 sub add_generated_header {
41 my ($out) = @_;
42  
43 print $out <<eot
44 /* Do not modify this file. */
45 /* It was automatically generated by $script_name. */
46 eot
47 ;
48  
49 # Add license text
50 print $out <<eot
51 /*
52 * Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
53 *
54 * Wireshark - Network traffic analyzer
55 * By Gerald Combs <gerald[AT]wireshark.org>
56 * Copyright 1998 Gerald Combs
57 *
58 * This program is free software; you can redistribute it and/or modify
59 * it under the terms of the GNU General Public License as published by
60 * the Free Software Foundation; either version 2 of the License, or
61 * (at your option) any later version.
62 *
63 * This program is distributed in the hope that it will be useful,
64 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 * GNU General Public License for more details.
67 *
68 * You should have received a copy of the GNU General Public License along
69 * with this program; if not, write to the Free Software Foundation, Inc.,
70 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
71 */
72  
73 eot
74 ;
75 }
76  
77 add_generated_header(DECL);
78 add_generated_header(REG);
79  
80 $prefix = '';
81 $subfieldStringLength = 0;
82  
83 while(<>) {
84 s/#.*$//go;
85 next if /^\s*$/o;
86 s/^(\s*)//o;
87 $subfield = $1;
88  
89 if (length $subfield != $subfieldStringLength) {
90 if (!length $subfield) {
91 $prefix = '';
92 } elsif (length $subfield > $subfieldStringLength) {
93 $prefix .= "$lastAbbrev.";
94 } else {
95 $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
96 }
97 $subfieldStringLength = length $subfield;
98 }
99  
100 @fields = split /\s+/o ;
101 if ($fields[0] eq '#') {
102 #
103 # If the line begins with "#", treat it as a comment, by
104 # ignoring it.
105 #
106 # (We don't support comments at the end of a line; that would
107 # require some more pain in our simple parser.)
108 #
109 next;
110 }
111 $abbrev = shift @fields;
112 $type = shift @fields;
113 $lastAbbrev = $abbrev;
114  
115 $field = $prefix.$abbrev;
116  
117 if ($fields[0] =~ /^\d+$/o) {
118 #
119 # This is presumably a Boolean bitfield, and this is the number
120 # of bits in the parent field.
121 #
122 $fieldDisplay = shift @fields;
123 } else {
124 #
125 # The next token is the base for the field.
126 #
127 $fieldDisplay = "BASE_".shift @fields;
128 }
129  
130 if ($fields[0] eq 'VALS') {
131 #
132 # It's an enumerated field, with the value_string table having a
133 # name based on the field's name.
134 #
135 shift @fields;
136 $fieldStrings = "VALS(${abbrev}_vals)";
137 $fieldStrings =~ s/-/_/go;
138 } elsif ($fields[0] =~ /^VALS\(/o) {
139 #
140 # It's an enumerated field, with a specified name for the
141 # value_string table.
142 #
143 $fieldStrings = shift @fields;
144 $fieldStrings =~ s/\)/_vals\)/o;
145 } else {
146 #
147 # It's not an enumerated field.
148 #
149 $fieldStrings = 'NULL';
150 }
151  
152 if ($fields[0] =~ /^0x/) {
153 #
154 # The next token looks like a bitmask for a bitfield.
155 #
156 $mask = shift @fields;
157 } else {
158 $mask = 0;
159 }
160  
161 $rest = join(' ', @fields);
162 $longName = uc $name;
163 $longName = $rest if ($rest);
164 # Don't allow empty blurbs
165 $longName = $longName eq "" ? "NULL" : "\"$longName\"";
166  
167 $variable = $field;
168 $variable =~ s/-/_/go;
169 $variable =~ s/\./_/go;
170  
171 print DECL "static int hf_x11_$variable = -1;\n";
172  
173 print REG <<END;
174 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, $longName, HFILL }},
175 END
176 }
177  
178 #
179 # Editor modelines
180 #
181 # Local Variables:
182 # c-basic-offset: 4
183 # tab-width: 8
184 # indent-tabs-mode: nil
185 # End:
186 #
187 # ex: set shiftwidth=4 tabstop=8 expandtab:
188 # :indentSize=4:tabSize=8:noTabs=true:
189 #