]> mj.ucw.cz Git - pciids.git/blob - scripts/export.pl
Fix export comments
[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         if( defined( $description ) && ( $description ne '' ) ) {
33                 chomp $description;
34                 $description =~ s/\n/\n# /g;
35                 print "# $description\n";
36         }
37         print "$tabs$prefix$id  $name\n";
38 }
39
40 $db->commit();