Hopefully clarify usage a bit to indicate multiple infile's can be specified to be...
[obnox/wireshark/wip.git] / doc / dfilter2pod.pl
1 #!/usr/bin/perl
2 #
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
6 #
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
11 #
12 # $Id$
13
14 use Getopt::Std;
15
16 %ftenum_names = (
17         'FT_NONE',              'No value',
18         'FT_PROTOCOL',          'Protocol',
19         'FT_BOOLEAN',           'Boolean',
20         'FT_UINT8',             'Unsigned 8-bit integer',
21         'FT_UINT16',            'Unsigned 16-bit integer',
22         'FT_UINT24',            'Unsigned 24-bit integer',
23         'FT_UINT32',            'Unsigned 32-bit integer',
24         'FT_UINT64',            'Unsigned 64-bit integer',
25         'FT_INT8',              'Signed 8-bit integer',
26         'FT_INT16',             'Signed 16-bit integer',
27         'FT_INT24',             'Signed 24-bit integer',
28         'FT_INT32',             'Signed 32-bit integer',
29         'FT_INT64',             'Signed 64-bit integer',
30         'FT_FLOAT',             'Single-precision floating point',
31         'FT_DOUBLE',            'Double-precision floating point',
32         'FT_ABSOLUTE_TIME',     'Date/Time stamp',
33         'FT_RELATIVE_TIME',     'Time duration',
34         'FT_STRING',            'String',
35         'FT_STRINGZ',           'NULL terminated string',
36         'FT_EBCDIC',            'EBCDIC string',
37         'FT_UINT_STRING',       'Length string pair',
38         'FT_ETHER',             '6-byte Hardware (MAC) Address',
39         'FT_BYTES',             'Byte array',
40         'FT_UINT_BYTES',        'Length byte array pair',
41         'FT_IPv4',              'IPv4 address',
42         'FT_IPv6',              'IPv6 address',
43         'FT_IPXNET',            'IPX network or server name',
44         'FT_FRAMENUM',          'Frame number',
45         'FT_PCRE',              'Perl Compatible Regular Expression',
46         'FT_GUID',              'Globally Unique Identifier',
47         'FT_OID',               'Object Identifier',
48 );
49
50 getopts('e');
51
52 if ($opt_e) {
53         $proto_abbrev{'Unable to generate filter documentation'} =
54                 'Please refer to http://www.wireshark.org/docs/dfref/';
55         printf STDERR "Creating empty filter list.\n";
56 } else {
57         # Read all the data into memory
58         while (<STDIN>) {
59                 next unless (/^([PF])/);
60         
61                 $record_type = $1;
62                 # Strip the line from its line-end sequence
63                 # chomp($_) won't work on Win32/CygWin as it leaves the '\r' character.
64                 $_ =~ s/[\r\n]//g;
65         
66                 # Store protocol information
67                 if ($record_type eq 'P') {
68                         ($junk, $name, $abbrev) = split(/\t+/, $_);
69                         $proto_abbrev{$name} = $abbrev;
70                 }
71                 # Store header field information
72                 else {
73                         ($junk, $name, $abbrev, $type, $parent, $blurb) =
74                                 split(/\t+/, $_);
75                         push(@{$field_abbrev{$parent}}, $abbrev);
76                         $field_info{$abbrev} = [ $name, $type, $blurb ];
77                 }
78         }
79 }
80
81 # if there was no input on stdin, bail out
82 if ($record_type ne 'P' and $record_type ne 'F' and !defined($opt_e)) {
83         exit;
84 }
85
86 $template = shift(@ARGV);
87
88 open(TEMPLATE, $template) || die "Can't open $template for reading: $!\n";
89
90 while (<TEMPLATE>) {
91         if (/=insert_dfilter_table/) {
92                 &create_dfilter_table;
93         }
94         else {
95                 print;
96         }
97 }
98
99 close(TEMPLATE) || die "Can't close $template: $!\n";
100
101 sub create_dfilter_table {
102
103         # Print each protocol
104         for $proto_name (sort keys %proto_abbrev) {
105
106                 print "=head2 $proto_name ($proto_abbrev{$proto_name})\n\n";
107
108                 # If this proto has children fields, print those
109                 if ($field_abbrev{$proto_abbrev{$proto_name}}) {
110
111                         for $field_abbrev (sort @{$field_abbrev{$proto_abbrev{$proto_name}}}) {
112                                 print "    $field_abbrev  ", $field_info{$field_abbrev}[0],"\n",
113                                       "        ", $ftenum_names{$field_info{$field_abbrev}[1]},
114                                    "\n";
115                                 print "        ", $field_info{$field_abbrev}[2], "\n"
116                                         if $field_info{$field_abbrev}[2];
117                                 print "\n";
118                         }
119                 }
120         }
121 }