MSWSP: add two more Property Sets
[wireshark-wip.git] / tools / usb-ptp-extract-models.pl
blob4f304f3e56888a4d1e7533283500265421f0e870
1 #!/usr/bin/perl -w
2 #
3 # USAGE: $0 </path/to/libgphoto2/camlibs/ptp2>
5 # $Id$
6 #
7 # USB PTP Dissector
8 # Extracts USB devices from libgphoto2
9 # This is then parsed by make-usb.py to make epan/dissectors/usb.c
11 # (c)2013 Max Baker <max@warped.org>
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 my $path = shift @ARGV || '.';
29 $re_hex = '0x[0-9a-f]+';
31 parse_file("$path/library.c",1);
32 parse_file("$path/music-players.h",0);
34 open (O,"> tools/usb-ptp-extract-models.txt") or die $!;
36 foreach my $vendor (sort {hex($a) <=> hex($b)} keys %devices) {
37 my $p = $devices{$vendor};
38 foreach my $product (sort {hex($a) <=> hex($b)} keys %$p) {
39 my $pd = $product; $pd =~ s/^0x//i;
40 my $v = $vendor; $v =~ s/^0x//i;
41 # { 0xeb1ae355, "KWorld DVB-T 355U Digital TV Dongle" },
42 #printf " { 0x%s%s, \"%s\" },\n",$v, $pd, $p->{$product};
44 printf O "%s%s %s\n", $v, $pd, $p->{$product};
48 close O or die $!;
50 exit;
52 sub parse_file {
53 my $file = shift;
54 my $detect = shift;
56 my $start = !$detect;
58 open (H,"<$file") or die "Could not find $file. $!";
59 while (<H>) {
60 chomp;
62 # Look for models[] line as start
63 if (/\bmodels\[\]/) {
64 $start = 1;
65 next;
68 # Look for }; as the end
69 $start = 0 if /^\s*};/;
71 next unless $start;
72 # Skip comment lines
74 # Remove comments
75 s,/\*.*\*/,,g;
77 s,^\s*,,;
78 s,\s*$,,;
80 # Skip blank lines
81 next if /^$/;
82 next if m,^\s*/?\*,;
84 my $line = $_;
86 my ($model, $vendor, $product, $manif);
88 # {"Nikon:DSC D90 (PTP mode)", 0x04b0, 0x0421, PTP_CAP|PTP_CAP_PREVIEW},
89 if($line =~ m/^\{
90 "([^"]+)",\s*
91 ($re_hex),\s*
92 ($re_hex),\s*
93 /xi) {
95 ($model, $vendor, $product) = ($1,$2,$3);
96 $model =~ s/:/ /;
97 $model =~ s/\(.*\)//;
99 # { "Creative", 0x041e, "ZEN X-Fi 3", 0x4169,
100 # { "TrekStor", 0x0402, "i.Beat Sweez FM", 0x0611,
101 if($line=~ m/^\{\s*
102 "([^"]+)",\s*
103 ($re_hex),\s*
104 "([^"]+)",\s*
105 ($re_hex),\s*
106 /xi) {
107 ($manif, $vendor, $model, $product) = ($1,$2,$3,$4);
108 $model = "$manif $model";
111 next unless defined $vendor;
113 $model =~ s/\s+/ /g;
114 $model =~ s/\s*$//;
116 #print "$vendor $product $model\n";
117 $devices{$vendor}->{$product}=$model;