From 814731e7a894b2ce17695c60a0b15b2a3202511a Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Thu, 1 Jun 2017 09:28:12 +0700 Subject: improve open .yaml error message and exit with error Fixed bugs: - https://launchpad.net/bugs/1692707 (bzr r15700.1.1) --- src/main-cmdlinexact.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index fc9e84dc4..2806e5b5f 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -293,9 +293,11 @@ parseVerbsYAMLFile(gchar const *yaml_filename) FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { - printf("Failed to open file!\n"); + printf("Failed to open file %s\n", yaml_filename); fflush(stdout); - return verbs_list; + + // exit with error + exit(1); } yaml_parser_t parser; -- cgit v1.2.3 From 6b20733af3ca815d12168948ff6d7f3737d17541 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sat, 3 Jun 2017 13:41:49 +0700 Subject: fix crash in XFileOpen Fixed bugs: - https://launchpad.net/bugs/1692699 (bzr r15700.1.2) --- src/main-cmdlinexact.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 2806e5b5f..676bf7b44 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -120,6 +120,7 @@ void xFileOpen( const Glib::ustring &uri ) std::string exeption_mgs = e.what(); printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); fflush(stdout); + return; } // Set viewBox if it doesn't exist -- cgit v1.2.3 From 454c66cd88665d3e9e7374e134e2215fbc8c2d38 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sat, 3 Jun 2017 14:05:27 +0700 Subject: check if file exist Fixed bugs: - https://launchpad.net/bugs/1692699 (bzr r15700.1.3) --- src/main-cmdlinexact.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 676bf7b44..000ad6fec 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") @@ -98,6 +98,11 @@ std::vector vectorFromString(const std::string &csv) void xFileOpen( const Glib::ustring &uri ) { + if (!Inkscape::IO::file_test(uri.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) { + printf("document is not exists: %s\n", uri.c_str()); + return; + } + if (s_verbose) { printf("open %s\n", uri.c_str()); fflush(stdout); @@ -120,7 +125,6 @@ void xFileOpen( const Glib::ustring &uri ) std::string exeption_mgs = e.what(); printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); fflush(stdout); - return; } // Set viewBox if it doesn't exist -- cgit v1.2.3 From 387d4eccb3a10dbda4a15e152fdea20525d934f7 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sat, 3 Jun 2017 14:59:36 +0700 Subject: handle svg documents relative to .yaml path Fixed bugs: - https://launchpad.net/bugs/1692701 (bzr r15700.1.4) --- src/main-cmdlinexact.cpp | 57 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 000ad6fec..9e7231194 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -48,6 +48,7 @@ namespace { bool s_verbose = false; +Glib::ustring s_yaml_filename(""); bool createDirForFilename( const std::string &filename ) { @@ -96,15 +97,33 @@ std::vector vectorFromString(const std::string &csv) return result; } +Glib::ustring getDocumentPathRelatedYaml( const Glib::ustring &uri ) +{ + if (g_path_is_absolute (uri.c_str())) + return uri; + + gchar *yaml_dirname = g_path_get_dirname(s_yaml_filename.c_str()); + gchar *document_path = g_build_filename(yaml_dirname, uri.c_str(), NULL); + + Glib::ustring result(document_path); + + g_free(document_path); + g_free(yaml_dirname); + + return result; +} + void xFileOpen( const Glib::ustring &uri ) { - if (!Inkscape::IO::file_test(uri.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) { - printf("document is not exists: %s\n", uri.c_str()); + Glib::ustring document_filename = getDocumentPathRelatedYaml(uri); + + if (!Inkscape::IO::file_test(document_filename.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) { + printf("document is not exists: %s\n", document_filename.c_str()); return; } if (s_verbose) { - printf("open %s\n", uri.c_str()); + printf("open %s\n", document_filename.c_str()); fflush(stdout); } @@ -119,11 +138,11 @@ void xFileOpen( const Glib::ustring &uri ) SPDocument *doc = NULL; Inkscape::Extension::Extension *key = NULL; try { - doc = Inkscape::Extension::open(key, uri.c_str()); + doc = Inkscape::Extension::open(key, document_filename.c_str()); } catch (std::exception &e) { doc = NULL; std::string exeption_mgs = e.what(); - printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); + printf("Error: open %s:%s\n",document_filename.c_str(), exeption_mgs.c_str() ); fflush(stdout); } @@ -162,31 +181,33 @@ void xFileOpen( const Glib::ustring &uri ) void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { + Glib::ustring document_filename = getDocumentPathRelatedYaml(uri); SPDocument *doc = context.getDocument(); if (s_verbose) { - printf("save as %s\n", uri.c_str()); + printf("save as %s\n", document_filename.c_str()); fflush(stdout); } - if( createDirForFilename( uri )) { + if( createDirForFilename( document_filename )) { Inkscape::Extension::save( Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), - doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + doc, document_filename.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); if (s_verbose) { - printf("save done: %s\n", uri.c_str() ); + printf("save done: %s\n", document_filename.c_str() ); fflush(stdout); } } else { - printf("can't create dirs for filename %s\n", uri.c_str() ); + printf("can't create dirs for filename %s\n", document_filename.c_str() ); fflush(stdout); } } void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { + Glib::ustring document_filename = getDocumentPathRelatedYaml(uri); if (s_verbose) { - printf("export png %s\n", uri.c_str()); + printf("export png %s\n", document_filename.c_str()); fflush(stdout); } @@ -209,27 +230,27 @@ void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustrin SPNamedView *nv = desktop->getNamedView(); - ExportResult status = sp_export_png_file(doc, uri.c_str(), + ExportResult status = sp_export_png_file(doc, document_filename.c_str(), Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, nv->pagecolor, 0, 0, TRUE); } -void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &element_name ) { if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } if (s_verbose) { - printf("select element: %s\n", uri.c_str()); + printf("select element: %s\n", element_name.c_str()); fflush(stdout); } SPDocument * doc = context.getDocument(); - SPObject * obj = doc->getObjectById(uri); + SPObject * obj = doc->getObjectById(element_name); if (obj == NULL) { - printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); + printf(_("Unable to find node ID: '%s'\n"), element_name.c_str()); fflush(stdout); return; } @@ -238,7 +259,7 @@ void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustrin selection->add(obj); if (s_verbose) { - printf("select done %s\n", uri.c_str()); + printf("select done %s\n", element_name.c_str()); fflush(stdout); } } @@ -444,6 +465,8 @@ parseVerbsYAMLFile(gchar const *yaml_filename) void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { + s_yaml_filename = Glib::ustring(yaml_filename); + verbs_list_t verbs_list = parseVerbsYAMLFile(yaml_filename); typedef std::map undo_labels_map_t; -- cgit v1.2.3 From de3945431b7222ed127ed59cdae8990640b79170 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sat, 3 Jun 2017 20:40:10 +0700 Subject: abort Inkscape if XFileOpen command fails Fixed bugs: - https://launchpad.net/bugs/1695606 (bzr r15700.1.5) --- src/main-cmdlinexact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 9e7231194..9827378b2 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -119,7 +119,7 @@ void xFileOpen( const Glib::ustring &uri ) if (!Inkscape::IO::file_test(document_filename.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) { printf("document is not exists: %s\n", document_filename.c_str()); - return; + exit(1); } if (s_verbose) { -- cgit v1.2.3 From 745324f2e65dec6eeec16585f5d5ca639179ded3 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sat, 3 Jun 2017 20:50:01 +0700 Subject: minor fixes Fixed bugs: - https://launchpad.net/bugs/1692699 (bzr r15700.1.6) --- src/main-cmdlinexact.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 9827378b2..4da138f0c 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -118,7 +118,7 @@ void xFileOpen( const Glib::ustring &uri ) Glib::ustring document_filename = getDocumentPathRelatedYaml(uri); if (!Inkscape::IO::file_test(document_filename.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) { - printf("document is not exists: %s\n", document_filename.c_str()); + printf("SVG document does not exist: %s\n", document_filename.c_str()); exit(1); } @@ -319,7 +319,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { - printf("Failed to open file %s\n", yaml_filename); + printf("Failed to read from file %s\n", yaml_filename); fflush(stdout); // exit with error -- cgit v1.2.3 From 16e2b8d276eec85a7fc138e66f438caf6acf0929 Mon Sep 17 00:00:00 2001 From: "dmitry.zhulanov@gmail.com" <> Date: Sun, 4 Jun 2017 21:21:43 +0700 Subject: replace fopen with g_fopen Fixed bugs: - https://launchpad.net/bugs/1695629 (bzr r15700.1.7) --- src/main-cmdlinexact.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 4da138f0c..eca402ab3 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -29,6 +29,7 @@ #include "extension/system.h" #include "file.h" #include +#include #include "sp-root.h" #include "document-undo.h" #include "util/units.h" @@ -317,7 +318,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) { verbs_list_t verbs_list; - FILE *fh = fopen(yaml_filename, "r"); + FILE *fh = g_fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to read from file %s\n", yaml_filename); fflush(stdout); -- cgit v1.2.3