From 6be3ccd951033a3dfc2ea461b5eafa4293130df0 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavier.robin@unibas.ch> Date: Tue, 23 Jul 2024 14:28:03 +0200 Subject: [PATCH] fix: exit with error code if nothing was read --- modules/conop/src/chemdict_tool.cc | 5 +++++ modules/io/src/mol/chemdict_parser.cc | 1 + modules/io/src/mol/chemdict_parser.hh | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/conop/src/chemdict_tool.cc b/modules/conop/src/chemdict_tool.cc index 89499b698..9ca3729ca 100644 --- a/modules/conop/src/chemdict_tool.cc +++ b/modules/conop/src/chemdict_tool.cc @@ -116,6 +116,11 @@ int main(int argc, char const *argv[]) compound_lib.reset(); cdp.SetCompoundLib(in_mem_lib); cdp.Parse(); + if (cdp.GetImportedCount() == 0) + { + std::cout << "No compound imported from " << argv[2] << std::endl; + return 1; + } in_mem_lib->SetChemLibInfo(); conop::CompoundLibPtr copy = in_mem_lib->Copy(argv[3]); if (! copy) { diff --git a/modules/io/src/mol/chemdict_parser.cc b/modules/io/src/mol/chemdict_parser.cc index 3f97a49b5..f1b2610ad 100644 --- a/modules/io/src/mol/chemdict_parser.cc +++ b/modules/io/src/mol/chemdict_parser.cc @@ -215,6 +215,7 @@ void ChemdictParser::OnEndData() } } lib_->AddCompound(compound_); + ++imported_count_; } } } diff --git a/modules/io/src/mol/chemdict_parser.hh b/modules/io/src/mol/chemdict_parser.hh index 46a83ec3b..fe4981c11 100644 --- a/modules/io/src/mol/chemdict_parser.hh +++ b/modules/io/src/mol/chemdict_parser.hh @@ -44,7 +44,8 @@ public: bool ignore_reserved=false, bool ignore_obsolete=false): StarParser(stream), compound_(new conop::Compound("UNK")), last_(0), loop_type_(DONT_KNOW), dialect_(dialect), - ignore_reserved_(ignore_reserved), ignore_obsolete_(ignore_obsolete) + ignore_reserved_(ignore_reserved), ignore_obsolete_(ignore_obsolete), + imported_count_(0) { this->InitTypeMap(); this->InitPDBXTypeMap(); @@ -65,6 +66,12 @@ public: { lib_=lib; } + + /// \brief Get the number of compounds that were successfully parsed + int GetImportedCount() + { + return imported_count_; + } private: void InitTypeMap(); void InitPDBXTypeMap(); @@ -98,6 +105,7 @@ private: conop::Compound::Dialect dialect_; bool ignore_reserved_; bool ignore_obsolete_; + int imported_count_; }; -- GitLab