nexmon – Blame information for rev 1

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