VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/ipxe/contrib/errdb/errdb.pl

最後變更 在這個檔案是 95666,由 vboxsync 提交於 2 年 前

Devices/PC/ipxe: scm fixes and export to OSE, bugref:10254

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.0 KB
 
1#!/usr/bin/perl -w
2
3=head1 NAME
4
5errdb.pl
6
7=head1 SYNOPSIS
8
9errdb.pl [options] ../../src/bin/errors
10
11Options:
12
13 -d,--database=db Specify path to errors.db
14 -h,--help Display brief help message
15 -v,--verbose Increase verbosity
16 -q,--quiet Decrease verbosity
17
18=cut
19
20use Getopt::Long;
21use Pod::Usage;
22use DBI;
23use strict;
24use warnings;
25
26# Parse command-line options
27my $verbosity = 0;
28my $errdb = "errors.db";
29Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
30GetOptions (
31 'database|d=s' => sub { shift; $errdb = shift; },
32 'verbose|v+' => sub { $verbosity++; },
33 'quiet|q+' => sub { $verbosity--; },
34 'help|h' => sub { pod2usage ( 1 ); },
35) or die "Could not parse command-line options\n";
36pod2usage ( 1 ) unless @ARGV >= 1;
37
38# Open database
39my $dbh = DBI->connect ( "dbi:SQLite:dbname=".$errdb, "", "",
40 { RaiseError => 1, PrintError => 0 } );
41$dbh->begin_work();
42
43# Create errors table if necessary
44eval {
45 $dbh->selectall_arrayref ( "SELECT * FROM errors LIMIT 1" );
46};
47if ( $@ ) {
48 print "Creating errors table\n" if $verbosity >= 1;
49 $dbh->do ( "CREATE TABLE errors (".
50 " errno char(8) NOT NULL,".
51 " description text NOT NULL,".
52 " PRIMARY KEY ( errno ) )" );
53}
54
55# Create xrefs table if necessary
56eval {
57 $dbh->selectall_arrayref ( "SELECT * FROM xrefs LIMIT 1" );
58};
59if ( $@ ) {
60 print "Creating xrefs table\n" if $verbosity >= 1;
61 $dbh->do ( "CREATE TABLE xrefs (".
62 " errno char(8) NOT NULL,".
63 " filename text NOT NULL,".
64 " line integer NOT NULL,".
65 " UNIQUE ( errno, filename, line ),".
66 " FOREIGN KEY ( errno ) REFERENCES errors ( errno ) )" );
67 $dbh->do ( "CREATE INDEX xrefs_errno ON xrefs ( errno )" );
68}
69
70# Parse input file(s)
71my $errors = {};
72my $xrefs = {};
73while ( <> ) {
74 chomp;
75 ( my $errno, my $filename, my $line, my $description ) = split ( /\t/ );
76 $errno = substr ( $errno, 0, 6 ) unless $errno =~ /^7f/;
77 $errors->{$errno} = $description;
78 $xrefs->{$errno} ||= {};
79 $xrefs->{$errno}->{$filename} ||= {};
80 $xrefs->{$errno}->{$filename}->{$line} ||= 1;
81}
82
83# Ensure all errors are present in database
84my $error_update =
85 $dbh->prepare ( "UPDATE errors SET description = ? WHERE errno = ?" );
86my $error_insert = $dbh->prepare ( "INSERT INTO errors VALUES ( ?, ? )" );
87while ( ( my $errno, my $description ) = each %$errors ) {
88 print "Error ".$errno." is \"".$description."\"\n" if $verbosity >= 2;
89 if ( $error_update->execute ( $description, $errno ) == 0 ) {
90 $error_insert->execute ( $errno, $description );
91 }
92}
93
94# Replace xrefs in database
95$dbh->do ( "DELETE FROM xrefs" );
96my $xref_insert = $dbh->prepare ( "INSERT INTO xrefs VALUES ( ?, ?, ? )" );
97while ( ( my $errno, my $xref_errno ) = each %$xrefs ) {
98 while ( ( my $filename, my $xref_filename ) = each %$xref_errno ) {
99 foreach my $line ( keys %$xref_filename ) {
100 print "Error ".$errno." is used at ".$filename." line ".$line."\n"
101 if $verbosity >= 2;
102 $xref_insert->execute ( $errno, $filename, $line );
103 }
104 }
105}
106
107# Close database
108$dbh->commit();
109$dbh->disconnect();
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette