diff options
| author | fishsoupisgood <github@madingley.org> | 2019-04-29 01:17:54 +0100 | 
|---|---|---|
| committer | fishsoupisgood <github@madingley.org> | 2019-05-27 03:43:43 +0100 | 
| commit | 3f2546b2ef55b661fd8dd69682b38992225e86f6 (patch) | |
| tree | 65ca85f13617aee1dce474596800950f266a456c /roms/ipxe/contrib/errdb | |
| download | qemu-master.tar.gz qemu-master.tar.bz2 qemu-master.zip | |
Diffstat (limited to 'roms/ipxe/contrib/errdb')
| -rw-r--r-- | roms/ipxe/contrib/errdb/.gitignore | 1 | ||||
| -rwxr-xr-x | roms/ipxe/contrib/errdb/errdb.pl | 109 | 
2 files changed, 110 insertions, 0 deletions
| diff --git a/roms/ipxe/contrib/errdb/.gitignore b/roms/ipxe/contrib/errdb/.gitignore new file mode 100644 index 00000000..95bf5c3c --- /dev/null +++ b/roms/ipxe/contrib/errdb/.gitignore @@ -0,0 +1 @@ +errors.db diff --git a/roms/ipxe/contrib/errdb/errdb.pl b/roms/ipxe/contrib/errdb/errdb.pl new file mode 100755 index 00000000..6423d834 --- /dev/null +++ b/roms/ipxe/contrib/errdb/errdb.pl @@ -0,0 +1,109 @@ +#!/usr/bin/perl -w + +=head1 NAME + +errdb.pl + +=head1 SYNOPSIS + +errdb.pl [options] ../../src/bin/errors + +Options: + +    -d,--database=db	Specify path to errors.db +    -h,--help		Display brief help message +    -v,--verbose	Increase verbosity +    -q,--quiet		Decrease verbosity + +=cut + +use Getopt::Long; +use Pod::Usage; +use DBI; +use strict; +use warnings; + +# Parse command-line options +my $verbosity = 0; +my $errdb = "errors.db"; +Getopt::Long::Configure ( 'bundling', 'auto_abbrev' ); +GetOptions ( +  'database|d=s' => sub { shift; $errdb = shift; }, +  'verbose|v+' => sub { $verbosity++; }, +  'quiet|q+' => sub { $verbosity--; }, +  'help|h' => sub { pod2usage ( 1 ); }, +) or die "Could not parse command-line options\n"; +pod2usage ( 1 ) unless @ARGV >= 1; + +# Open database +my $dbh = DBI->connect ( "dbi:SQLite:dbname=".$errdb, "", "", +			 { RaiseError => 1, PrintError => 0 } ); +$dbh->begin_work(); + +# Create errors table if necessary +eval { +  $dbh->selectall_arrayref ( "SELECT * FROM errors LIMIT 1" ); +}; +if ( $@ ) { +  print "Creating errors table\n" if $verbosity >= 1; +  $dbh->do ( "CREATE TABLE errors (". +	     " errno char(8) NOT NULL,". +	     " description text NOT NULL,". +	     " PRIMARY KEY ( errno ) )" ); +} + +# Create xrefs table if necessary +eval { +  $dbh->selectall_arrayref ( "SELECT * FROM xrefs LIMIT 1" ); +}; +if ( $@ ) { +  print "Creating xrefs table\n" if $verbosity >= 1; +  $dbh->do ( "CREATE TABLE xrefs (". +	     " errno char(8) NOT NULL,". +	     " filename text NOT NULL,". +	     " line integer NOT NULL,". +	     " UNIQUE ( errno, filename, line ),". +	     " FOREIGN KEY ( errno ) REFERENCES errors ( errno ) )" ); +  $dbh->do ( "CREATE INDEX xrefs_errno ON xrefs ( errno )" ); +} + +# Parse input file(s) +my $errors = {}; +my $xrefs = {}; +while ( <> ) { +  chomp; +  ( my $errno, my $filename, my $line, my $description ) = split ( /\t/ ); +  $errno = substr ( $errno, 0, 6 ) unless $errno =~ /^7f/; +  $errors->{$errno} = $description; +  $xrefs->{$errno} ||= {}; +  $xrefs->{$errno}->{$filename} ||= {}; +  $xrefs->{$errno}->{$filename}->{$line} ||= 1; +} + +# Ensure all errors are present in database +my $error_update = +    $dbh->prepare ( "UPDATE errors SET description = ? WHERE errno = ?" ); +my $error_insert = $dbh->prepare ( "INSERT INTO errors VALUES ( ?, ? )" ); +while ( ( my $errno, my $description ) = each %$errors ) { +  print "Error ".$errno." is \"".$description."\"\n" if $verbosity >= 2; +  if ( $error_update->execute ( $description, $errno ) == 0 ) { +    $error_insert->execute ( $errno, $description ); +  } +} + +# Replace xrefs in database +$dbh->do ( "DELETE FROM xrefs" ); +my $xref_insert = $dbh->prepare ( "INSERT INTO xrefs VALUES ( ?, ?, ? )" ); +while ( ( my $errno, my $xref_errno ) = each %$xrefs ) { +  while ( ( my $filename, my $xref_filename ) = each %$xref_errno ) { +    foreach my $line ( keys %$xref_filename ) { +      print "Error ".$errno." is used at ".$filename." line ".$line."\n" +	  if $verbosity >= 2; +      $xref_insert->execute ( $errno, $filename, $line ); +    } +  } +} + +# Close database +$dbh->commit(); +$dbh->disconnect(); | 
