sub ReadBibData{ # print "ReadBibData\n===\n${$_[0]}\n==========\n"; my $abc = ${$_[0]}; $abc =~ s/(\{|\}|\(|\)|=|,)/;;$1;;/g; $abc =~ s/\\;;\{;;/\\\{/g; $abc =~ s/\\;;\};;/\\\}/g; $abc =~ s/\s+/ /g; while ($abc =~ s/;;;;/;;/g) {}; my @tokens = split(/;;/, $abc); my %rec; my @fields; my $i = 0; while (($i < @tokens)&&($rec{name} eq '')) { $tokens[$i] =~ s/^\s//; $tokens[$i] =~ s/\s$//; $tokens[$i] =~ tr/a-z/A-Z/; if ((($tokens[$i] eq '@ARTICLE') or ($tokens[$i] eq '@MISC')) and (($tokens[$i+1] eq '(') or ($tokens[$i+1] eq '{'))) { $i += 2; $tokens[$i] =~ s/^\s+//; $tokens[$i] =~ s/\s+$//; $rec{name} = $tokens[$i]; # print $tokens[$i], "\n"; $ARTICLE{$tokens[$i]} = \%rec; push @ARTICLE, $tokens[$i]; while ($tokens[$i+1] eq ',') { $i += 2; $tokens[$i] =~ s/^\s+//; $tokens[$i] =~ s/\s+$//; my $name = $tokens[$i]; my $value = ''; if ($tokens[$i+1] eq '=') { $i += 2; if ($tokens[$i] eq ' ') {$i++}; $tokens[$i] =~ s/^\s//; $value = $tokens[$i]; my $count = 0; if ($tokens[$i] eq '{') {$count++}; while ($count > 0) { $i++; $value .= $tokens[$i]; if ($tokens[$i] eq '{') {$count++}; if ($tokens[$i] eq '(') {$count++}; if ($tokens[$i] eq '}') {$count--}; if ($tokens[$i] eq ')') {$count--}; } } $value =~ s/\s$//; if ($value =~ /^\{(.*)\}$/) {$value = $1}; $name =~ tr/a-z/A-Z/; $rec{$name} = $value; push @fields, $name; # print " $name = {$value}\n"; }; }; $i++; }; (\%rec, \@fields); } sub ProcessBibData{ my %rec = %{$_[0]}; my ($author, @author, @_author); my $authnr = 0; for $author (split(/\s+and\s+/, $rec{AUTHOR})) { $authnr++; $author =~ s/^\s+//; $author =~ s/\s+$//; if ($author =~ /^([\w\s\{\}\\\'\.]+)\s([\w\{\}\\\'\.]+)$/) { # print "AUTHOR: $author,\n"; $author = "$2, $1"; }; $author =~ s/^\s+//; $author =~ s/\s+$//; $rec{'author'.$authnr} = $author; my $aa = $author; $aa =~ s/\\c\{/\{/g; $aa =~ tr/\{\}//d; $aa =~ s/\\[\.\']//g; $aa =~ s/\\Pla//g; $aa =~ s/\\Ple//g; $aa =~ tr/\\//d; push @{$AUTHOR{$aa}}, \%rec; my ($surname, $given) = split(/,\s+/, $author); push @author, "$given $surname"; ($surname, $given) = split(/,\s+/, $aa); push @_author, "$surname, $given"; $rec{'author'.$authnr.'alt'} = "$given $surname"; }; $rec{'authornbr'} = "$authnr"; $rec{AUTHORalt} = join(', ', @author); $rec{author} = join(';', @_author); $rec{TITLE} =~ s/\{|\}|\\tt //g; $rec{TITLE} =~ s/\\_/_/g; # my $title = $rec{TITLE}; # $title =~ s/\{|\}//g; # $TITLE{$title} = \%rec; my ($name, $rest) = split('\.', $rec{name}); $name =~ tr/A-Z/a-z/; $rec{article} = $name; $rec{VOLUME} = 'MML' unless $rec{VOLUME}; $rec{NUMBER} = '{\bf 1}' unless $rec{NUMBER}; # if ($rec{VOLUME} eq 'MML') {print "MML: $rec{name}\n"}; # print join("\n", %rec), "\n"; my $secnbr = 0; my $key; for $key (keys %rec) { if ($key =~ /^SECTION(\d+)$/) { if ($secnbr < $1) {$secnbr = $1}; } } $rec{sectionnbr} = $secnbr; \%rec; } sub GetBibData{ my $article = $_[0]; $article =~ tr/A-Z/a-z/; # ZLE bo &ReadBibData jako argument powinna miec wskazanie na tresc biba &ProcessBibData(&ReadBibData($megrez_cvsroot.'/bnt/'.$article.'.bib')); } sub GetBibDataByLarlist{ my $larfile = $_[0]; my $bibpath = $_[1]; open(LAR, $larfile); my @artlist = ; close(LAR); chomp @artlist; my %bibs; foreach my $article (@artlist) { $article =~ tr/A-Z/a-z/; open(BIB, $bibpath.'/'.$article.'.bib'); local $/; undef $/; my $content = ; close(BIB); $bibs{$article} = &ProcessBibData(&ReadBibData(\$content)); # print "$bibs{$article}->{'authornbr'}, $bibs{$article}->{'author1'}\n".join('; ', %{$bibs{$article}})."\n$content\n=======================\n"; } \%bibs; } sub AuthorListByLarlist{ my $larfile = $_[0]; my $bibpath = $_[1]; my $bibs = &GetBibDataByLarlist($larfile, $bibpath); my %authors; foreach my $art (keys %$bibs) { for(my $i = 1; $i <= $bibs->{$art}->{'authornbr'}; $i++) { my $author = $bibs->{$art}->{'author'.$i}; $authors{$author} = [] unless $authors{$author}; push @{$authors{$author}}, $art; } } \%authors; } %NUMERALS = (1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth', 6 => 'sixth'); sub unTeX_string{ my $aa = $_[0]; $aa =~ s/\\c\{/\{/g; $aa =~ tr/\{\}//d; $aa =~ s/\\[\.\']//g; $aa =~ s/\\Pla//g; $aa =~ s/\\Ple//g; $aa =~ tr/\\//d; $aa; } %convert = ( 'name' => 'art_name', 'title' => 'art_title', 'note' => 'art_title_note', 'note1' => 'note[1]', 'note2' => 'note[2]', 'note3' => 'note[3]', 'note4' => 'note[4]', 'section1' => 'section[1]', 'section2' => 'section[2]', 'section3' => 'section[3]', 'section4' => 'section[4]', 'section5' => 'section[5]', 'section6' => 'section[6]', 'section7' => 'section[7]', 'section8' => 'section[8]', 'section9' => 'section[9]', 'section10' => 'section[10]', 'section11' => 'section[11]', 'section12' => 'section[12]', 'section13' => 'section[13]', 'section14' => 'section[14]', 'section15' => 'section[15]', 'year' => 'year', 'month' => 'month', 'day' => 'day', 'summary' => 'summary', 'address1' => 'affiliation[1]', 'address2' => 'affiliation[2]', 'address3' => 'affiliation[3]', 'address4' => 'affiliation[4]', );