File: btcheck

package info (click to toggle)
libtext-bibtex-perl 0.91-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,528 kB
  • sloc: ansic: 10,706; perl: 1,991; makefile: 9
file content (31 lines) | stat: -rwxr-xr-x 829 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl -w

#
# btcheck
#
# Check the syntax and structure of a single BibTeX database file.
# Currently hardcoded to use the "Bib" structure, which implements
# exactly the structure of BibTeX 0.99.
#
# $Id$
#

use strict;
use Text::BibTeX (':metatypes');

my ($filename, $structure, $bibfile, $entry, %seen_key);
die "usage: btcheck file [structure]\n" unless @ARGV == 1 || @ARGV == 2;
($filename, $structure) = @ARGV;
$structure ||= 'Bib';

$bibfile =  Text::BibTeX::File->new( $filename) or die "$filename: $!\n";
$bibfile->set_structure ($structure);

while ($entry =  Text::BibTeX::Entry->new( $bibfile)) 
{
   next unless $entry->parse_ok and $entry->metatype == BTE_REGULAR;
   my $key = $entry->key;
   $entry->warn ("repeated entry key \"$key\"") if $seen_key{$key};
   $seen_key{$key} = 1;
   $entry->check;
}