Witness: fix compiler warnings
[wireshark-wip.git] / docbook / dfilter2xml.pl
blobed0ee4810b8b0dcd70588de7a48ffd3a3cfd2bb9
1 #!/usr/bin/perl
3 # Reads the display filter keyword dump produced by 'tshark -G' and
4 # formats it for a pod document. The pod document is then used to
5 # make a manpage
7 # STDIN is the wireshark glossary
8 # arg1 is the pod template file. The =insert_dfilter_table token
9 # will be replaced by the pod-formatted glossary
10 # STDOUT is the output
12 # Gilbert Ramirez <gram [AT] alumni.rice.edu>
14 # $Id$
16 # Wireshark - Network traffic analyzer
17 # By Gerald Combs <gerald@wireshark.org>
18 # Copyright 1998 Gerald Combs
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License
22 # as published by the Free Software Foundation; either version 2
23 # of the License, or (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write to the Free Software
32 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 %ftenum_names = (
35 'FT_NONE', 'No value',
36 'FT_PROTOCOL', 'Protocol',
37 'FT_BOOLEAN', 'Boolean',
38 'FT_UINT8', 'Unsigned 8-bit integer',
39 'FT_UINT16', 'Unsigned 16-bit integer',
40 'FT_UINT24', 'Unsigned 24-bit integer',
41 'FT_UINT32', 'Unsigned 32-bit integer',
42 'FT_UINT64', 'Unsigned 64-bit integer',
43 'FT_INT8', 'Signed 8-bit integer',
44 'FT_INT16', 'Signed 16-bit integer',
45 'FT_INT24', 'Signed 24-bit integer',
46 'FT_INT32', 'Signed 32-bit integer',
47 'FT_INT64', 'Signed 64-bit integer',
48 'FT_FLOAT', 'Single-precision floating point',
49 'FT_DOUBLE', 'Double-precision floating point',
50 'FT_ABSOLUTE_TIME', 'Date/Time stamp',
51 'FT_RELATIVE_TIME', 'Time duration',
52 'FT_STRING', 'String',
53 'FT_STRINGZ', 'NULL terminated string',
54 'FT_EBCDIC', 'EBCDIC string',
55 'FT_UINT_STRING', 'Length string pair',
56 'FT_ETHER', '6-byte Hardware (MAC) Address',
57 'FT_BYTES', 'Byte array',
58 'FT_UINT_BYTES', 'Length byte array pair',
59 'FT_IPv4', 'IPv4 address',
60 'FT_IPv6', 'IPv6 address',
61 'FT_IPXNET', 'IPX network or server name',
62 'FT_FRAMENUM', 'Frame number',
63 'FT_PCRE', 'Perl Compatible Regular Expression',
64 'FT_GUID', 'Globally Unique Identifier',
65 'FT_OID', 'Object Identifier',
66 'FT_REL_OID', 'Relative Object Identifier',
69 # Read all the data into memory
70 while (<STDIN>) {
71 next unless (/^([PF])/);
73 $record_type = $1;
74 # Strip the line from its line-end sequence
75 # chomp($_) won't work on Win32/CygWin as it leaves the '\r' character.
76 $_ =~ s/[\r\n]//g;
77 $_ =~ s/\&/\&amp\;/g;
78 $_ =~ s/\>/\&gt;/g;
79 $_ =~ s/\</\&lt\;/g;
81 # Store protocol information
82 if ($record_type eq 'P') {
83 ($junk, $name, $abbrev) = split(/\t+/, $_);
84 $proto_abbrev{$name} = $abbrev;
86 # Store header field information
87 else {
88 ($junk, $name, $abbrev, $type, $parent, $blurb) =
89 split(/\t+/, $_);
90 push(@{$field_abbrev{$parent}}, $abbrev);
91 $field_info{$abbrev} = [ $name, $type, $blurb ];
95 # if there was no input on stdin, bail out
96 if ($record_type ne 'P' and $record_type ne 'F') {
97 exit;
100 $template = shift(@ARGV);
102 open(TEMPLATE, $template) || die "Can't open $template for reading: $!\n";
104 while (<TEMPLATE>) {
105 if (/=insert_dfilter_table/) {
106 &create_dfilter_table;
108 else {
109 print;
113 close(TEMPLATE) || die "Can't close $template: $!\n";
115 sub create_dfilter_table {
117 print "<appendix id=\"AppFiltFields\"><title>Wireshark Display Filter Fields</title>\n";
118 $pn_counter = 1;
120 # Print each protocol
121 for $proto_name (sort keys %proto_abbrev) {
123 $ns_proto_name = $proto_name;
124 $ns_proto_name =~ s/\s//g;
125 $ns_proto_name =~ s/\)//g;
126 $ns_proto_name =~ s/\(//g;
127 $ns_proto_name =~ s/_//g;
128 $ns_proto_name =~ s/\+/plus/g;
129 $ns_proto_name =~ s/\//slash/g;
130 $ns_proto_name =~ s/,/comma/g;
131 $ns_proto_name =~ s/:/colon/g;
132 $ns_proto_name =~ s/'/apos/g;
134 # The maximum token name length is apparently 44 characters.
135 # That's what NAMELEN is defined as in docbook 4.1, at least.
137 if (length ($ns_proto_name) > 41) { # "SID" and "TID" are prepended below
138 $ns_proto_name = sprintf ("%s%04d", substr($ns_proto_name, 0,
139 37), $pn_counter);
140 $pn_counter++;
143 print "<section id=\"SID$ns_proto_name\"><title>$proto_name ($proto_abbrev{$proto_name})</title>\n\n";
145 print "<table id=\"TID$ns_proto_name\"><title>$proto_name ($proto_abbrev{$proto_name})</title>\n";
146 print "<tgroup cols=\"4\">\n";
147 # print "<colspec colnum=\"1\" colwidth=\"80pt\">\n";
148 # print "<colspec colnum=\"2\" colwidth=\"80pt\"\n>";
149 print "<thead>\n <row>\n ";
150 print "<entry>Field</>\n <entry>Field Name</>\n <entry>Type</>\n <entry>Description</>\n\n";
152 print " </row>\n</thead>\n<tbody>\n";
154 # If this proto has children fields, print those
155 if ($field_abbrev{$proto_abbrev{$proto_name}}) {
157 for $field_abbrev (sort @{$field_abbrev{$proto_abbrev{$proto_name}}}) {
159 print " <row>\n";
160 print " <entry>$field_abbrev</entry>\n";
161 print " <entry>", $field_info{$field_abbrev}[0], "</entry>\n";
162 print " <entry>", $ftenum_names{$field_info{$field_abbrev}[1]}, "</entry>\n";
163 print " <entry>", $field_info{$field_abbrev}[2], "</>\n";
164 print " </row>\n\n";
169 else {
171 print " <row>\n <entry></entry>\n <entry></entry>\n <entry></entry><entry></entry>\n";
172 print " </row>\n";
176 print "</tbody></tgroup></table>\n";
177 print "</section>\n\n";
181 print "</appendix>\n";