From e72fe71056ccc26e75233d8ec5c4e90b9d685136 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Tue, 11 Nov 2003 20:18:13 +0000 Subject: [PATCH] Enhancement. %include now adds path where files are found to search path during processing. (The C preprocessor seems to do the same). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5298 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Preprocessor/cpp.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/SWIG/Source/Preprocessor/cpp.c b/SWIG/Source/Preprocessor/cpp.c index fdbd33205..dcef77d68 100644 --- a/SWIG/Source/Preprocessor/cpp.c +++ b/SWIG/Source/Preprocessor/cpp.c @@ -1314,7 +1314,8 @@ Preprocessor_parse(String *s) } else if (Cmp(id,"line") == 0) { } else if (Cmp(id,"include") == 0) { if (((include_all) || (import_all)) && (allow)) { - DOH *s1, *s2, *fn; + String *s1, *s2, *fn; + char *dirname; Seek(value,0,SEEK_SET); fn = get_filename(value); s1 = cpp_include(fn); @@ -1323,9 +1324,20 @@ Preprocessor_parse(String *s) Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file()); else if (import_all) Printf(ns,"%%importfile \"%s\" [\n", Swig_last_file()); + + /* See if the filename has a directory component */ + dirname = Swig_file_dirname(Swig_last_file); + if (!strlen(dirname)) dirname = 0; + if (dirname) { + dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ + Swig_push_directory(dirname); + } s2 = Preprocessor_parse(s1); addline(ns,s2,allow); Printf(ns,"\n]\n"); + if (dirname) { + Swig_pop_directory(); + } Delete(s2); } Delete(s1); @@ -1429,6 +1441,7 @@ Preprocessor_parse(String *s) fn = get_filename(s); s1 = cpp_include(fn); if (s1) { + char *dirname; add_chunk(ns,chunk,allow); copy_location(s,chunk); Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file()); @@ -1436,7 +1449,16 @@ Preprocessor_parse(String *s) Preprocessor_define("WRAPEXTERN 1", 0); Preprocessor_define("SWIGIMPORT 1", 0); } + dirname = Swig_file_dirname(Swig_last_file()); + if (!strlen(dirname)) dirname = 0; + if (dirname) { + dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ + Swig_push_directory(dirname); + } s2 = Preprocessor_parse(s1); + if (dirname) { + Swig_pop_directory(); + } if ((Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) { Preprocessor_undef("SWIGIMPORT"); Preprocessor_undef("WRAPEXTERN");