diff --git a/src/libwrapper.cpp b/src/libwrapper.cpp index 1544b18..b852e7f 100644 --- a/src/libwrapper.cpp +++ b/src/libwrapper.cpp @@ -316,10 +316,10 @@ private: }; } -bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force) +search_result Library::process_phrase(const char *loc_str, IReadLine &io, bool force) { if (nullptr == loc_str) - return true; + return SEARCH_SUCCESS; std::string query; @@ -330,6 +330,7 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force) gsize bytes_read; gsize bytes_written; glib::Error err; + search_result rval = SEARCH_SUCCESS; glib::CharStr str; if (!utf8_input_) str.reset(g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, get_addr(err))); @@ -339,11 +340,11 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force) if (nullptr == get_impl(str)) { fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str); fprintf(stderr, "%s\n", err->message); - return false; + return SEARCH_FAILURE; } if (str[0] == '\0') - return true; + return SEARCH_SUCCESS; TSearchResultList res_list; @@ -443,10 +444,11 @@ bool Library::process_phrase(const char *loc_str, IReadLine &io, bool force) loc_str = utf8_to_locale_ign_err(get_impl(str)); if (!json_) printf(_("Nothing similar to %s, sorry :(\n"), utf8_output_ ? get_impl(str) : loc_str.c_str()); + rval = SEARCH_NO_RESULT; } if (json_) { fputs("]\n", stdout); } - return true; + return rval; } diff --git a/src/libwrapper.hpp b/src/libwrapper.hpp index 31783b6..154161b 100644 --- a/src/libwrapper.hpp +++ b/src/libwrapper.hpp @@ -23,6 +23,13 @@ struct TSearchResult { typedef std::vector TSearchResultList; +//possible return values for Library.process_phase() +enum search_result { + SEARCH_SUCCESS = 0, + SEARCH_FAILURE, + SEARCH_NO_RESULT +}; + //this class is wrapper around Dicts class for easy use //of it class Library : public Libs @@ -38,7 +45,7 @@ public: setFuzzy(!no_fuzzy); } - bool process_phrase(const char *loc_str, IReadLine &io, bool force = false); + search_result process_phrase(const char *loc_str, IReadLine &io, bool force = false); private: bool utf8_input_; diff --git a/src/sdcv.cpp b/src/sdcv.cpp index 0c75eb1..6ffcc1c 100644 --- a/src/sdcv.cpp +++ b/src/sdcv.cpp @@ -207,15 +207,16 @@ int main(int argc, char *argv[]) try { std::unique_ptr io(create_readline_object()); if (optind < argc) { + search_result rval = SEARCH_SUCCESS; for (int i = optind; i < argc; ++i) - if (!lib.process_phrase(argv[i], *io, non_interactive)) { - return EXIT_FAILURE; + if ((rval = lib.process_phrase(argv[i], *io, non_interactive)) != SEARCH_SUCCESS) { + return rval; } } else if (!non_interactive) { std::string phrase; while (io->read(_("Enter word or phrase: "), phrase)) { - if (!lib.process_phrase(phrase.c_str(), *io)) + if (lib.process_phrase(phrase.c_str(), *io) == SEARCH_FAILURE) return EXIT_FAILURE; phrase.clear(); }