]> mj.ucw.cz Git - pciids.git/blob - scripts/export.pl
84e2aab7e031cf2b5260f9f4756039c89b4a2d9f
[pciids.git] / scripts / export.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6         unshift @INC, ".";
7 }
8 use PciIds::Db;
9 use PciIds::DBQAny;
10
11 my $db = PciIds::DBQAny::new( connectDb(), {
12         'list' => 'SELECT id, name, note FROM locations WHERE id like "PC/%" OR id like "PD/%" ORDER BY id'
13 } );
14
15 my $lastInvalid = undef;
16
17 foreach( @{$db->query( 'list', [] )} ) {
18         my( $id, $name, $description ) = @{$_};
19         next if defined $lastInvalid and substr( $id, 0, length $lastInvalid ) eq $lastInvalid;
20         if( !defined $name || $name eq '' ) {
21                 $lastInvalid = $id;
22                 next;
23         }
24         $_ = $id;
25         my $prefix = ( /^PD\/..$/ ) ? 'C ' : '';
26         s/^P.\///;
27         s/[^\/]//g;
28         s/\//\t/g;
29         my $tabs = $_;
30         $id =~ s/.*\///;
31         $id =~ s/([0-9a-f]{4})([0-9a-f]{4})/$1 $2/;
32         print "$tabs$prefix$id  $name\n";
33         if( defined( $description ) && ( $description ne '' ) ) {
34                 chomp $description;
35                 $description =~ s/\n/\n$tabs#/g;
36                 print "$tabs# $description\n";
37         }
38 }
39
40 $db->commit();