ldap: assume GSS-SPNEGO as default
[wireshark-sm.git] / tools / process-x11-fields.pl
blob8aedef481a6e1037f53c9fa0b507b2b98a4f7e61
1 #!/usr/bin/perl
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 # Instructions for using this script are in epan/dissectors/README.X11
9 # Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
11 # Wireshark - Network traffic analyzer
12 # By Gerald Combs <gerald@wireshark.org>
13 # Copyright 1998 Gerald Combs
15 # SPDX-License-Identifier: GPL-2.0-or-later
18 use File::Spec;
20 my $srcdir = shift;
21 die "'$srcdir' is not a directory" unless -d $srcdir;
23 open(DECL, "> $srcdir/x11-declarations.h") || die;
24 open(REG, "> $srcdir/x11-register-info.h") || die;
26 my $script_name = File::Spec->abs2rel ($0, $srcdir);
28 sub add_generated_header {
29 my ($out) = @_;
31 print $out <<eot
32 /* Do not modify this file. */
33 /* It was automatically generated by $script_name. */
34 eot
37 # Add license text
38 print $out <<eot
40 * Copyright 2000, Christophe Tronche <ch.tronche[AT]computer.org>
42 * Wireshark - Network traffic analyzer
43 * By Gerald Combs <gerald[AT]wireshark.org>
44 * Copyright 1998 Gerald Combs
46 * SPDX-License-Identifier: GPL-2.0-or-later
49 eot
53 add_generated_header(DECL);
54 add_generated_header(REG);
56 $prefix = '';
57 $subfieldStringLength = 0;
59 while(<>) {
60 s/#.*$//go;
61 next if /^\s*$/o;
62 s/^(\s*)//o;
63 $subfield = $1;
65 if (length $subfield != $subfieldStringLength) {
66 if (!length $subfield) {
67 $prefix = '';
68 } elsif (length $subfield > $subfieldStringLength) {
69 $prefix .= "$lastAbbrev.";
70 } else {
71 $prefix =~ s/^(.*)\.[^\.]+\.$/$1./o;
73 $subfieldStringLength = length $subfield;
76 @fields = split /\s+/o ;
77 if ($fields[0] eq '#') {
79 # If the line begins with "#", treat it as a comment, by
80 # ignoring it.
82 # (We don't support comments at the end of a line; that would
83 # require some more pain in our simple parser.)
85 next;
87 $abbrev = shift @fields;
88 $type = shift @fields;
89 $lastAbbrev = $abbrev;
91 $field = $prefix.$abbrev;
93 if ($fields[0] =~ /^\d+$/o) {
95 # This is presumably a Boolean bitfield, and this is the number
96 # of bits in the parent field.
98 $fieldDisplay = shift @fields;
99 } else {
101 # The next token is the base for the field.
103 $fieldDisplay = "BASE_".shift @fields;
106 if ($fields[0] eq 'VALS') {
108 # It's an enumerated field, with the value_string table having a
109 # name based on the field's name.
111 shift @fields;
112 $fieldStrings = "VALS(${abbrev}_vals)";
113 $fieldStrings =~ s/-/_/go;
114 } elsif ($fields[0] =~ /^VALS\(/o) {
116 # It's an enumerated field, with a specified name for the
117 # value_string table.
119 $fieldStrings = shift @fields;
120 $fieldStrings =~ s/\)/_vals\)/o;
121 } else {
123 # It's not an enumerated field.
125 $fieldStrings = 'NULL';
128 if ($fields[0] =~ /^0x/) {
130 # The next token looks like a bitmask for a bitfield.
132 $mask = shift @fields;
133 } else {
134 $mask = 0;
137 $rest = join(' ', @fields);
138 $longName = uc $name;
139 $longName = $rest if ($rest);
140 # Don't allow empty blurbs
141 $longName = $longName eq "" ? "NULL" : "\"$longName\"";
143 $variable = $field;
144 $variable =~ s/-/_/go;
145 $variable =~ s/\./_/go;
147 print DECL "static int hf_x11_$variable;\n";
149 print REG <<END;
150 { &hf_x11_$variable, { "$abbrev", "x11.$field", FT_$type, $fieldDisplay, $fieldStrings, $mask, $longName, HFILL }},
155 # Editor modelines
157 # Local Variables:
158 # c-basic-offset: 4
159 # tab-width: 8
160 # indent-tabs-mode: nil
161 # End:
163 # ex: set shiftwidth=4 tabstop=8 expandtab:
164 # :indentSize=4:tabSize=8:noTabs=true: