From 371b89e155b76f4fa8466dec16f3bb8004802069 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 28 Apr 2012 09:34:21 +0200 Subject: fix paths when working with command line (Bug #695120 , patch by Patrick Monnerat) (bzr r11299) --- src/extension/system.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index ebad0c050..cf78cd2b8 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -69,6 +69,26 @@ static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementatio SPDocument *open(Extension *key, gchar const *filename) { Input *imod = NULL; + int relpath; + gchar * curdir; + + // Convert to absolute pathname to tolerate chdir(). + relpath = *filename != '/'; +#ifdef WIN32 + relpath &= *filename != '\\' && !(isalpha(*filename) && filename[1] == ':'); +#endif + + if (relpath) { +#ifndef WIN32 + curdir = getcwd(NULL, 0); +#else + curdir = _getcwd(NULL, 0); +#endif + + filename = g_build_filename(curdir, filename, NULL); + free(curdir); + } + if (key == NULL) { gpointer parray[2]; parray[0] = (gpointer)filename; @@ -108,6 +128,9 @@ SPDocument *open(Extension *key, gchar const *filename) } if (!imod->prefs(filename)) { + if (relpath){ + free((void *) filename); + } return NULL; } @@ -129,6 +152,9 @@ SPDocument *open(Extension *key, gchar const *filename) imod->set_gui(true); } + if (relpath){ + free((void *) filename); + } return doc; } -- cgit v1.2.3 From 8b6b45cf07aa5abff73aaa765f79f480b9f9de5e Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 28 Apr 2012 11:24:18 +0200 Subject: C++ify syntax a bit (bzr r11300) --- src/extension/system.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index cf78cd2b8..476499385 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -68,17 +68,14 @@ static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementatio */ SPDocument *open(Extension *key, gchar const *filename) { - Input *imod = NULL; - int relpath; - gchar * curdir; - // Convert to absolute pathname to tolerate chdir(). - relpath = *filename != '/'; + bool relpath = (filename[0] != '/'); #ifdef WIN32 - relpath &= *filename != '\\' && !(isalpha(*filename) && filename[1] == ':'); + relpath &= (filename[0] != '\\') && !(isalpha(filename[0]) && (filename[1] == ':')); #endif if (relpath) { + gchar * curdir = NULL; #ifndef WIN32 curdir = getcwd(NULL, 0); #else @@ -88,7 +85,9 @@ SPDocument *open(Extension *key, gchar const *filename) filename = g_build_filename(curdir, filename, NULL); free(curdir); } - + + Input *imod = NULL; + if (key == NULL) { gpointer parray[2]; parray[0] = (gpointer)filename; -- cgit v1.2.3