Cloudy & Associates
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cloudy
cloudy
Commits
7c6126e0
Commit
7c6126e0
authored
Apr 12, 2022
by
Chatzikos, Marios
Browse files
Fix bug in BiblioToTeX.pm when no refs found
parent
81123151
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/BiblioToTeX.pm
View file @
7c6126e0
...
...
@@ -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
(
$i
key
!=
@key
s
-
1
);
if
(
$i
ref
!=
$nref
s
-
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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment