From 053fa31bb23e7463e46c3645376904fa1f0b3a28 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 20 Dec 2012 17:37:59 +0000 Subject: [PATCH] Exit is better than abort. Also use a macro instead of integer to indicate failure. --- packages/CLPBN/horus/ElimGraph.cpp | 2 +- packages/CLPBN/horus/FactorGraph.cpp | 10 ++++----- packages/CLPBN/horus/HorusCli.cpp | 25 +++++++++++------------ packages/CLPBN/horus/HorusYap.cpp | 2 +- packages/CLPBN/horus/LiftedKc.cpp | 2 +- packages/CLPBN/horus/LiftedOperations.cpp | 2 +- packages/CLPBN/horus/Parfactor.cpp | 2 +- packages/CLPBN/horus/ParfactorList.cpp | 2 +- packages/CLPBN/horus/Util.cpp | 2 +- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/CLPBN/horus/ElimGraph.cpp b/packages/CLPBN/horus/ElimGraph.cpp index 48d360da8..c1b11f033 100644 --- a/packages/CLPBN/horus/ElimGraph.cpp +++ b/packages/CLPBN/horus/ElimGraph.cpp @@ -116,7 +116,7 @@ ElimGraph::exportToGraphViz ( out << " [shape=box3d]" << endl; } else { cout << "error: invalid variable id: " << highlightVarIds[i] << endl; - abort(); + exit (EXIT_FAILURE); } } for (size_t i = 0; i < nodes_.size(); i++) { diff --git a/packages/CLPBN/horus/FactorGraph.cpp b/packages/CLPBN/horus/FactorGraph.cpp index 5badec4ca..34640476d 100644 --- a/packages/CLPBN/horus/FactorGraph.cpp +++ b/packages/CLPBN/horus/FactorGraph.cpp @@ -38,14 +38,14 @@ FactorGraph::readFromUaiFormat (const char* fileName) std::ifstream is (fileName); if (!is.is_open()) { cerr << "error: cannot read from file " << fileName << endl; - abort(); + exit (EXIT_FAILURE); } ignoreLines (is); string line; getline (is, line); if (line != "MARKOV") { cerr << "error: the network must be a MARKOV network " << endl; - abort(); + exit (EXIT_FAILURE); } // read the number of vars ignoreLines (is); @@ -74,7 +74,7 @@ FactorGraph::readFromUaiFormat (const char* fileName) cerr << "error: invalid variable identifier `" << vid << "'" << endl; cerr << "identifiers must be between 0 and " << ranges.size() - 1 ; cerr << endl; - abort(); + exit (EXIT_FAILURE); } factorVarIds.back().push_back (vid); factorRanges.back().push_back (ranges[vid]); @@ -89,7 +89,7 @@ FactorGraph::readFromUaiFormat (const char* fileName) cerr << "error: invalid number of parameters for factor nÂș " << i ; cerr << ", expected: " << Util::sizeExpected (factorRanges[i]); cerr << ", given: " << nrParams << endl; - abort(); + exit (EXIT_FAILURE); } Params params (nrParams); for (unsigned j = 0; j < nrParams; j++) { @@ -111,7 +111,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName) std::ifstream is (fileName); if (!is.is_open()) { cerr << "error: cannot read from file " << fileName << endl; - abort(); + exit (EXIT_FAILURE); } ignoreLines (is); unsigned nrFactors; diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index 639b91739..54f229dfa 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -26,7 +26,7 @@ main (int argc, const char* argv[]) if (argc <= 1) { cerr << "error: no graphical model specified" << endl; cerr << USAGE << endl; - exit (0); + exit (EXIT_FAILURE); } int idx = readHorusFlags (argc, argv); FactorGraph fg; @@ -53,12 +53,12 @@ readHorusFlags (int argc, const char* argv[]) if (leftArg.empty()) { cerr << "error: missing left argument" << endl; cerr << USAGE << endl; - exit (0); + exit (EXIT_FAILURE); } if (rightArg.empty()) { cerr << "error: missing right argument" << endl; cerr << USAGE << endl; - exit (0); + exit (EXIT_FAILURE); } Util::setHorusFlag (leftArg, rightArg); } @@ -79,7 +79,7 @@ readFactorGraph (FactorGraph& fg, const char* s) } else { cerr << "error: the graphical model must be defined either " ; cerr << "in a UAI or libDAI file" << endl; - exit (0); + exit (EXIT_FAILURE); } } @@ -100,14 +100,14 @@ readQueryAndEvidence ( cerr << "error: `" << arg << "' " ; cerr << "is not a variable id" ; cerr << endl; - exit (0); + exit (EXIT_FAILURE); } VarId vid = Util::stringToUnsigned (arg); VarNode* queryVar = fg.getVarNode (vid); if (queryVar == false) { cerr << "error: unknow variable with id " ; cerr << "`" << vid << "'" << endl; - exit (0); + exit (EXIT_FAILURE); } queryIds.push_back (vid); } else { @@ -117,37 +117,36 @@ readQueryAndEvidence ( if (leftArg.empty()) { cerr << "error: missing left argument" << endl; cerr << USAGE << endl; - exit (0); + exit (EXIT_FAILURE); } if (Util::isInteger (leftArg) == false) { cerr << "error: `" << leftArg << "' " ; cerr << "is not a variable id" << endl ; - exit (0); - continue; + exit (EXIT_FAILURE); } VarId vid = Util::stringToUnsigned (leftArg); VarNode* observedVar = fg.getVarNode (vid); if (observedVar == false) { cerr << "error: unknow variable with id " ; cerr << "`" << vid << "'" << endl; - exit (0); + exit (EXIT_FAILURE); } if (rightArg.empty()) { cerr << "error: missing right argument" << endl; cerr << USAGE << endl; - exit (0); + exit (EXIT_FAILURE); } if (Util::isInteger (rightArg) == false) { cerr << "error: `" << rightArg << "' " ; cerr << "is not a state index" << endl ; - exit (0); + exit (EXIT_FAILURE); } unsigned stateIdx = Util::stringToUnsigned (rightArg); if (observedVar->isValidState (stateIdx) == false) { cerr << "error: `" << stateIdx << "' " ; cerr << "is not a valid state index for variable with id " ; cerr << "`" << vid << "'" << endl; - exit (0); + exit (EXIT_FAILURE); } observedVar->setEvidence (stateIdx); } diff --git a/packages/CLPBN/horus/HorusYap.cpp b/packages/CLPBN/horus/HorusYap.cpp index 504d17602..2e74e68a8 100644 --- a/packages/CLPBN/horus/HorusYap.cpp +++ b/packages/CLPBN/horus/HorusYap.cpp @@ -424,7 +424,7 @@ readParfactor (YAP_Term pfTerm) YAP_Term ti = YAP_ArgOfTerm (i, term); if (YAP_IsAtomTerm (ti) == false) { cerr << "error: constraint has free variables" << endl; - abort(); + exit (EXIT_FAILURE); } string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti))); tuple[i - 1] = LiftedUtils::getSymbol (name); diff --git a/packages/CLPBN/horus/LiftedKc.cpp b/packages/CLPBN/horus/LiftedKc.cpp index d9560f6df..e6c937c33 100644 --- a/packages/CLPBN/horus/LiftedKc.cpp +++ b/packages/CLPBN/horus/LiftedKc.cpp @@ -23,7 +23,7 @@ LiftedKc::solveQuery (const Grounds& query) circuit_ = new LiftedCircuit (lwcnf_); if (circuit_->isCompilationSucceeded() == false) { cerr << "error: compilation failed" << endl; - abort(); + exit (EXIT_FAILURE); } vector groups; Ranges ranges; diff --git a/packages/CLPBN/horus/LiftedOperations.cpp b/packages/CLPBN/horus/LiftedOperations.cpp index 03cafdee7..e6edfcb27 100644 --- a/packages/CLPBN/horus/LiftedOperations.cpp +++ b/packages/CLPBN/horus/LiftedOperations.cpp @@ -37,7 +37,7 @@ LiftedOperations::shatterAgainstQuery ( if (found == false) { cerr << "error: could not find a parfactor with ground " ; cerr << "`" << query[i] << "'" << endl; - exit (0); + exit (EXIT_FAILURE); } pfList.add (newPfs); } diff --git a/packages/CLPBN/horus/Parfactor.cpp b/packages/CLPBN/horus/Parfactor.cpp index 38a77892e..6ea8ada05 100644 --- a/packages/CLPBN/horus/Parfactor.cpp +++ b/packages/CLPBN/horus/Parfactor.cpp @@ -691,7 +691,7 @@ Parfactor::expandPotential ( if (newSize > params_.max_size()) { cerr << "error: an overflow occurred when performing expansion" ; cerr << endl; - abort(); + exit (EXIT_FAILURE); } Params backup = params_; diff --git a/packages/CLPBN/horus/ParfactorList.cpp b/packages/CLPBN/horus/ParfactorList.cpp index 7e829a6d0..41732ee0c 100644 --- a/packages/CLPBN/horus/ParfactorList.cpp +++ b/packages/CLPBN/horus/ParfactorList.cpp @@ -336,7 +336,7 @@ ParfactorList::shatterAgainstMySelf ( if (f1.isAtom()) { cerr << "error: a ground occurs twice in a parfactor" << endl; cerr << endl; - abort(); + exit (EXIT_FAILURE); } assert (g->constr()->empty() == false); ConstraintTree ctCopy (*g->constr()); diff --git a/packages/CLPBN/horus/Util.cpp b/packages/CLPBN/horus/Util.cpp index d3dbd588d..97c5907bd 100644 --- a/packages/CLPBN/horus/Util.cpp +++ b/packages/CLPBN/horus/Util.cpp @@ -54,7 +54,7 @@ stringToUnsigned (string str) ss >> val; if (val < 0) { cerr << "error: the readed number is negative" << endl; - abort(); + exit (EXIT_FAILURE); } return static_cast (val); }