Cloudy & Associates

Commit 7c6126e0 authored by Chatzikos, Marios's avatar Chatzikos, Marios
Browse files

Fix bug in BiblioToTeX.pm when no refs found

parent 81123151
......@@ -3,6 +3,8 @@
# TeX tables relevant to atomic data.
#
# Chatzikos, 2016-Jan-28
# Chatzikos, 2022-Apr-12
# Bugfix: In custom_to_json, protect against missing 'ref' key.
#
use warnings;
use strict;
......@@ -16,6 +18,7 @@ use Cwd;
use File::Basename;
use Text::BibTeX;
use URI::Escape;
use JSON;
# Immediately flush output
#
......@@ -242,51 +245,59 @@ sub custom_to_json
$$hash{$species}{$subhash_elm} ."\",\n";
}
$string .= ($tab x $ntabs) .'"ref" : {'."\n";
my @datatypes = sort keys $$hash{$species}{ref};
for( my $idt = 0; $idt < @datatypes; $idt++ )
if( not exists $$hash{$species}{ref} )
{
my $datatype = $datatypes[ $idt ];
$ntabs++;
$string .= ($tab x $ntabs) ."\"$datatype\" : [";
my $nrefs = @{ $$hash{$species}{ref}{$datatype} };
if( $nrefs > 0 )
# drop last comma
$string = substr( $string, 0, -2 ) ."\n";
}
else
{
$string .= ($tab x $ntabs) .'"ref" : {'."\n";
my @datatypes = sort keys $$hash{$species}{ref};
for( my $idt = 0; $idt < @datatypes; $idt++ )
{
$string .= "\n";
for( my $iref = 0; $iref < $nrefs; $iref++ )
my $datatype = $datatypes[ $idt ];
$ntabs++;
$string .= ($tab x $ntabs) ."\"$datatype\" : [";
my $nrefs = @{ $$hash{$species}{ref}{$datatype} };
if( $nrefs > 0 )
{
my $ref = $$hash{$species}{ref}{$datatype}[ $iref ];
$ntabs++;
$string .= ($tab x $ntabs) ."{\n";
$ntabs++;
my @keys = sort keys %$ref;
for( my $ikey = 0; $ikey < @keys; $ikey++ )
$string .= "\n";
for( my $iref = 0; $iref < $nrefs; $iref++ )
{
my $key = $keys[ $ikey ];
$string .= ($tab x $ntabs) ."\"$key\" : \"$$ref{$key}\"";
my $ref = $$hash{$species}{ref}{$datatype}[ $iref ];
$ntabs++;
$string .= ($tab x $ntabs) ."{\n";
$ntabs++;
my @keys = sort keys %$ref;
for( my $ikey = 0; $ikey < @keys; $ikey++ )
{
my $key = $keys[ $ikey ];
$string .= ($tab x $ntabs) ."\"$key\" : \"$$ref{$key}\"";
$string .= ","
if( $ikey != @keys-1 );
$string .= "\n";
}
$ntabs--;
$string .= ($tab x $ntabs) ."}";
$string .= ","
if( $ikey != @keys-1 );
if( $iref != $nrefs-1 );
$string .= "\n";
$ntabs--;
}
$ntabs--;
$string .= ($tab x $ntabs) ."}";
$string .= ","
if( $iref != $nrefs-1 );
$string .= "\n";
$ntabs--;
$string .= ($tab x $ntabs);
}
$string .= ($tab x $ntabs);
$string .= "]";
$string .= ","
if( $idt != @datatypes-1 );
$string .= "\n";
$ntabs--;
}
$string .= "]";
$string .= ","
if( $idt != @datatypes-1 );
$string .= "\n";
$string .= ($tab x $ntabs) ."}\n";
$ntabs--;
}
$string .= ($tab x $ntabs) ."}\n";
$ntabs--;
$string .= ($tab x $ntabs) ."}";
$string .= ","
if( $ispecies != @species-1 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment