From d6170f0d771ce86df57dc90c9c9ac4d6f8845c7d Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 21:06:24 +0200 Subject: Inkview: Put checking for valid files in separate function (bzr r15690.1.3) --- src/inkview.cpp | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 3cca34d6c..0358fe917 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -244,6 +244,29 @@ private: }; +/** get a list of valid SVG files from a list of strings */ +std::vector get_valid_files(std::vector filenames) +{ + std::vector valid_files; + + for(auto file : filenames) + { + if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { + g_printerr("File does not exist: %s\n", file.c_str()); + } else { + auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); + + if(doc) + { + /* Append to list */ + valid_files.push_back(file); + } + } + } + + return valid_files; +} + #ifdef WIN32 // minimal print handler (just prints the string to stdout) void g_print_no_convert(const gchar *buf) { fputs(buf, stdout); } @@ -285,23 +308,7 @@ int main (int argc, char **argv) exit(EXIT_FAILURE); } - std::vector valid_files; - - for(auto file : filenames) - { - if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { - g_printerr("File does not exist: %s\n", file.c_str()); - } else { - auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); - - if(doc) - { - /* Append to list */ - valid_files.push_back(file); - } - } - } - + std::vector valid_files = get_valid_files(filenames); if(valid_files.empty()) { return 1; /* none of the slides loadable */ } -- cgit v1.2.3