From 9a94969fdd6f3abaee1c6b3154b8d2067b1ba739 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 24 Dec 2008 13:19:55 +0000 Subject: [PATCH] fix input filename containing a path on windows git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11000 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/main.cxx | 2 +- Source/Swig/include.c | 6 +----- Source/Swig/misc.c | 15 +++++++++++++++ Source/Swig/swig.h | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index a41191bb9..008ce5126 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -1002,7 +1002,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (lang_config) { Printf(fs, "\n%%include <%s>\n", lang_config); } - Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", input_file, Swig_last_file()); + Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(NewString(input_file)), Swig_last_file()); for (i = 0; i < Len(libfiles); i++) { Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i)); } diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 73cb6551e..cf105c787 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -183,12 +183,8 @@ static FILE *Swig_open_file(const String_or_char *name, int sysfile, int use_inc Delete(spath); } if (f) { -#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ - Replaceall(filename, "\\\\", "\\"); /* remove double '\' in case any already present */ - Replaceall(filename, "\\", "\\\\"); -#endif Delete(lastpath); - lastpath = Copy(filename); + lastpath = Swig_filename_escape(filename); } Delete(filename); return f; diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index ae3129fde..dca9774ab 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -117,6 +117,21 @@ String *Swig_strip_c_comments(const String *s) { } +/* ----------------------------------------------------------------------------- + * Swig_filename_escape() + * + * Escapes backslashes in filename - for Windows + * ----------------------------------------------------------------------------- */ + +String *Swig_filename_escape(String *filename) { + String *adjusted_filename = Copy(filename); +#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ + Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */ + Replaceall(adjusted_filename, "\\", "\\\\"); +#endif + return adjusted_filename; +} + /* ----------------------------------------------------------------------------- * Swig_string_escape() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 451de86c4..16966a516 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -286,6 +286,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern const char *Swig_package_version(void); extern void Swig_banner(File *f); extern String *Swig_strip_c_comments(const String *s); + extern String *Swig_filename_escape(String *filename); extern String *Swig_string_escape(String *s); extern String *Swig_string_mangle(const String *s); extern void Swig_scopename_split(String *s, String **prefix, String **last);