From 6c6b3789c78670e75a72edf743d204ab056bd9e0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 12 Apr 2017 18:53:26 +0200 Subject: [PATCH] Make search_for_file (in ImageInput) available to the rest of the code. --- image_input.cpp | 19 ++++++++++++------- image_input.h | 8 ++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/image_input.cpp b/image_input.cpp index 5c9d796..92c58ec 100644 --- a/image_input.cpp +++ b/image_input.cpp @@ -37,8 +37,6 @@ struct SwsContext; using namespace std; -namespace { - string search_for_file(const string &filename) { // Look for the file in all theme_dirs until we find one; @@ -61,18 +59,25 @@ string search_for_file(const string &filename) for (const string &error : errors) { fprintf(stderr, "%s\n", error.c_str()); } - fprintf(stderr, "Couldn't find %s in any directory in --theme-dirs, exiting.\n", - filename.c_str()); - exit(1); + return ""; } -} // namespace +string search_for_file_or_die(const string &filename) +{ + string pathname = search_for_file(filename); + if (pathname.empty()) { + fprintf(stderr, "Couldn't find %s in any directory in --theme-dirs, exiting.\n", + filename.c_str()); + exit(1); + } + return pathname; +} ImageInput::ImageInput(const string &filename) : movit::FlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, 1280, 720), // Resolution will be overwritten. filename(filename), - pathname(search_for_file(filename)), + pathname(search_for_file_or_die(filename)), current_image(load_image(filename, pathname)) { if (current_image == nullptr) { // Could happen even though search_for_file() returned. diff --git a/image_input.h b/image_input.h index 02be497..f384264 100644 --- a/image_input.h +++ b/image_input.h @@ -46,4 +46,12 @@ private: static std::condition_variable threads_should_quit_modified; // Signals when threads_should_quit is set. }; +// Look for the file in all theme_dirs until we find one; +// that will be the permanent resolution of this file, whether +// it is actually valid or not. Returns an empty string on error. +std::string search_for_file(const std::string &filename); + +// Same, but exits on error. +std::string search_for_file_or_die(const std::string &filename); + #endif // !defined(_IMAGE_INPUT_H) -- 2.39.2