added the -I- option and %include <file>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6249 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-09-17 05:55:43 +00:00
commit 7cc6470fe6
4 changed files with 100 additions and 31 deletions

View file

@ -59,6 +59,7 @@ static const char *usage1 = (const char*)"\
-Fmicrosoft - Display error/warning messages in Microsoft format\n\ -Fmicrosoft - Display error/warning messages in Microsoft format\n\
-help - This output\n\ -help - This output\n\
-I<dir> - Look for SWIG files in <dir>\n\ -I<dir> - Look for SWIG files in <dir>\n\
-I- - Don't search the current directory\n\
-ignoremissing - Ignore missing include files\n\ -ignoremissing - Ignore missing include files\n\
-importall - Follow all #include statements as imports\n\ -importall - Follow all #include statements as imports\n\
-includeall - Follow all #include statements\n\ -includeall - Follow all #include statements\n\
@ -343,7 +344,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Get options // Get options
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i]) { if (argv[i]) {
if (strncmp(argv[i],"-I",2) == 0) { if (strncmp(argv[i],"-I-",3) == 0) {
// Don't push/pop directories
Swig_set_push_dir(0);
Swig_mark_arg(i);
} else if (strncmp(argv[i],"-I",2) == 0) {
// Add a new directory search path // Add a new directory search path
includefiles[includecount++] = Swig_copy_string(argv[i]+2); includefiles[includecount++] = Swig_copy_string(argv[i]+2);
Swig_mark_arg(i); Swig_mark_arg(i);
@ -633,12 +638,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SWIG_exit (EXIT_FAILURE); SWIG_exit (EXIT_FAILURE);
} }
fclose(df); fclose(df);
Printf(fs,"%%include \"swig.swg\"\n"); Printf(fs,"%%include <swig.swg>\n");
if (allkw) { if (allkw) {
Printf(fs,"%%include \"allkw.swg\"\n"); Printf(fs,"%%include <allkw.swg>\n");
} }
if (lang_config) { if (lang_config) {
Printf(fs,"\n%%include \"%s\"\n", lang_config); Printf(fs,"\n%%include <%s>\n", lang_config);
} }
Printf(fs,"%%include \"%s\"\n", Swig_last_file()); Printf(fs,"%%include \"%s\"\n", Swig_last_file());
for (i = 0; i < Len(libfiles); i++) { for (i = 0; i < Len(libfiles); i++) {

View file

@ -77,9 +77,9 @@ copy_location(DOH *s1, DOH *s2) {
Setline(s2,Getline(s1)); Setline(s2,Getline(s1));
} }
static String *cpp_include(String_or_char *fn) { static String *cpp_include(String_or_char *fn, int sysfile) {
String *s; String *s;
s = Swig_include(fn); s = sysfile ? Swig_include_sys(fn) : Swig_include(fn);
if (s && single_include) { if (s && single_include) {
String *file = Getfile(s); String *file = Getfile(s);
if (Getattr(included_files,file)) { if (Getattr(included_files,file)) {
@ -484,7 +484,7 @@ find_args(String *s)
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static String * static String *
get_filename(String *str) { get_filename(String *str, int* sysfile) {
String *fn; String *fn;
int c; int c;
@ -492,9 +492,11 @@ get_filename(String *str) {
fn = NewString(""); fn = NewString("");
copy_location(str,fn); copy_location(str,fn);
c = Getc(str); c = Getc(str);
*sysfile = 0;
if (c == '\"') { if (c == '\"') {
while (((c = Getc(str)) != EOF) && (c != '\"')) Putc(c,fn); while (((c = Getc(str)) != EOF) && (c != '\"')) Putc(c,fn);
} else if (c == '<') { } else if (c == '<') {
*sysfile = 1;
while (((c = Getc(str)) != EOF) && (c != '>')) Putc(c,fn); while (((c = Getc(str)) != EOF) && (c != '>')) Putc(c,fn);
} else { } else {
Putc(c,fn); Putc(c,fn);
@ -1363,10 +1365,10 @@ Preprocessor_parse(String *s)
} else if (Cmp(id,"include") == 0) { } else if (Cmp(id,"include") == 0) {
if (((include_all) || (import_all)) && (allow)) { if (((include_all) || (import_all)) && (allow)) {
String *s1, *s2, *fn; String *s1, *s2, *fn;
char *dirname; char *dirname; int sysfile = 0;
Seek(value,0,SEEK_SET); Seek(value,0,SEEK_SET);
fn = get_filename(value); fn = get_filename(value, &sysfile);
s1 = cpp_include(fn); s1 = cpp_include(fn, sysfile);
if (s1) { if (s1) {
if (include_all) if (include_all)
Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file()); Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file());
@ -1375,7 +1377,7 @@ Preprocessor_parse(String *s)
/* See if the filename has a directory component */ /* See if the filename has a directory component */
dirname = Swig_file_dirname(Swig_last_file()); dirname = Swig_file_dirname(Swig_last_file());
if (!strlen(dirname)) dirname = 0; if (sysfile || !strlen(dirname)) dirname = 0;
if (dirname) { if (dirname) {
dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */
Swig_push_directory(dirname); Swig_push_directory(dirname);
@ -1478,7 +1480,7 @@ Preprocessor_parse(String *s)
if ((Cmp(decl,"%include") == 0) || (Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) { if ((Cmp(decl,"%include") == 0) || (Cmp(decl,"%import") == 0) || (Cmp(decl,"%extern") == 0)) {
/* Got some kind of file inclusion directive */ /* Got some kind of file inclusion directive */
if (allow) { if (allow) {
DOH *s1, *s2, *fn, *opt; DOH *s1, *s2, *fn, *opt; int sysfile = 0;
if (Cmp(decl,"%extern") == 0) { if (Cmp(decl,"%extern") == 0) {
Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n"); Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n");
@ -1486,8 +1488,8 @@ Preprocessor_parse(String *s)
Printf(decl,"%%import"); Printf(decl,"%%import");
} }
opt = get_options(s); opt = get_options(s);
fn = get_filename(s); fn = get_filename(s, &sysfile);
s1 = cpp_include(fn); s1 = cpp_include(fn, sysfile);
if (s1) { if (s1) {
char *dirname; char *dirname;
add_chunk(ns,chunk,allow); add_chunk(ns,chunk,allow);
@ -1498,7 +1500,7 @@ Preprocessor_parse(String *s)
Preprocessor_define("SWIGIMPORT 1", 0); Preprocessor_define("SWIGIMPORT 1", 0);
} }
dirname = Swig_file_dirname(Swig_last_file()); dirname = Swig_file_dirname(Swig_last_file());
if (!strlen(dirname)) dirname = 0; if (sysfile || !strlen(dirname)) dirname = 0;
if (dirname) { if (dirname) {
dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */
Swig_push_directory(dirname); Swig_push_directory(dirname);

View file

@ -21,6 +21,17 @@ static List *directories = 0; /* List of include directories */
static String *lastpath = 0; /* Last file that was included */ static String *lastpath = 0; /* Last file that was included */
static String *swiglib = 0; /* Location of SWIG library */ static String *swiglib = 0; /* Location of SWIG library */
static String *lang_config = 0; /* Language configuration file */ static String *lang_config = 0; /* Language configuration file */
static int dopush = 1; /* Whether to push directories */
/* This functions determine whether to push/pop dirs in the preprocessor */
void Swig_set_push_dir(int push) {
dopush = push;
}
int Swig_get_push_dir(void) {
return dopush;
}
/* This function sets the name of the configuration file */ /* This function sets the name of the configuration file */
@ -59,15 +70,17 @@ Swig_swiglib_get() {
void void
Swig_add_directory(const String_or_char *dirname) { Swig_add_directory(const String_or_char *dirname) {
String *dir = 0;
if (!directories) directories = NewList(); if (!directories) directories = NewList();
assert(directories); assert(directories);
if (!DohIsString(dirname)) { dir = NewString((char *) dirname);
dirname = NewString((char *) dirname); assert(dir);
assert(dirname); Setattr(dir,"sysdir","1");
} Append(directories, dir);
Append(directories, dirname);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_push_directory() * Swig_push_directory()
* *
@ -77,6 +90,7 @@ Swig_add_directory(const String_or_char *dirname) {
void void
Swig_push_directory(const String_or_char *dirname) { Swig_push_directory(const String_or_char *dirname) {
if (!Swig_get_push_dir()) return;
if (!directories) directories = NewList(); if (!directories) directories = NewList();
assert(directories); assert(directories);
if (!DohIsString(dirname)) { if (!DohIsString(dirname)) {
@ -95,6 +109,7 @@ Swig_push_directory(const String_or_char *dirname) {
void void
Swig_pop_directory() { Swig_pop_directory() {
if (!Swig_get_push_dir()) return;
if (!directories) return; if (!directories) return;
Delitem(directories,0); Delitem(directories,0);
} }
@ -117,13 +132,14 @@ Swig_last_file() {
* Returns a list of the current search paths. * Returns a list of the current search paths.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
List * static List *
Swig_search_path() { Swig_search_path_any(int syspath) {
String *filename; String *filename;
String *dirname; String *dirname;
List *slist; List *slist, *llist;
int i; int i;
llist = 0;
slist = NewList(); slist = NewList();
assert(slist); assert(slist);
filename = NewString(""); filename = NewString("");
@ -133,25 +149,50 @@ Swig_search_path() {
#else #else
Printf(filename,".%s", SWIG_FILE_DELIMETER); Printf(filename,".%s", SWIG_FILE_DELIMETER);
#endif #endif
if (syspath) {
llist = NewList();
assert(slist);
Append(llist,filename);
} else {
Append(slist,filename); Append(slist,filename);
}
for (i = 0; i < Len(directories); i++) { for (i = 0; i < Len(directories); i++) {
dirname = Getitem(directories,i); dirname = Getitem(directories,i);
filename = NewString(""); filename = NewString("");
assert(filename); assert(filename);
Printf(filename, "%s%s", dirname, SWIG_FILE_DELIMETER); Printf(filename, "%s%s", dirname, SWIG_FILE_DELIMETER);
if (syspath && !Getattr(dirname,"sysdir")) {
Append(llist,filename);
} else {
Append(slist,filename); Append(slist,filename);
} }
}
if (syspath) {
for (i = 0; i < Len(llist); i++) {
Append(slist,Getitem(llist,i));
}
Delete(llist);
}
return slist; return slist;
} }
List *
Swig_search_path() {
return Swig_search_path_any(0);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_open() * Swig_open()
* *
* Looks for a file and open it. Returns an open FILE * on success. * Looks for a file and open it. Returns an open FILE * on success.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
FILE * static FILE *
Swig_open(const String_or_char *name) { Swig_open_any(const String_or_char *name, int sysfile) {
FILE *f; FILE *f;
String *filename; String *filename;
List *spath = 0; List *spath = 0;
@ -166,7 +207,7 @@ Swig_open(const String_or_char *name) {
assert(filename); assert(filename);
f = fopen(Char(filename),"r"); f = fopen(Char(filename),"r");
if (!f) { if (!f) {
spath = Swig_search_path(); spath = Swig_search_path_any(sysfile);
for (i = 0; i < Len(spath); i++) { for (i = 0; i < Len(spath); i++) {
Clear(filename); Clear(filename);
Printf(filename,"%s%s", Getitem(spath,i), cname); Printf(filename,"%s%s", Getitem(spath,i), cname);
@ -187,6 +228,13 @@ Swig_open(const String_or_char *name) {
return f; return f;
} }
FILE *
Swig_open(const String_or_char *name) {
return Swig_open_any(name, 0);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_read_file() * Swig_read_file()
* *
@ -212,12 +260,12 @@ Swig_read_file(FILE *f) {
* Opens a file and returns it as a string. * Opens a file and returns it as a string.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
String * static String *
Swig_include(const String_or_char *name) { Swig_include_any(const String_or_char *name, int sysfile) {
FILE *f; FILE *f;
String *str; String *str;
f = Swig_open(name); f = Swig_open_any(name, sysfile);
if (!f) return 0; if (!f) return 0;
str = Swig_read_file(f); str = Swig_read_file(f);
fclose(f); fclose(f);
@ -227,6 +275,17 @@ Swig_include(const String_or_char *name) {
return str; return str;
} }
String *
Swig_include(const String_or_char *name) {
return Swig_include_any(name, 0);
}
String *
Swig_include_sys(const String_or_char *name) {
return Swig_include_any(name, 1);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Swig_insert_file() * Swig_insert_file()
* *

View file

@ -99,9 +99,12 @@ extern List *Swig_search_path();
extern FILE *Swig_open(const String_or_char *name); extern FILE *Swig_open(const String_or_char *name);
extern String *Swig_read_file(FILE *f); extern String *Swig_read_file(FILE *f);
extern String *Swig_include(const String_or_char *name); extern String *Swig_include(const String_or_char *name);
extern String *Swig_include_sys(const String_or_char *name);
extern int Swig_insert_file(const String_or_char *name, File *outfile); extern int Swig_insert_file(const String_or_char *name, File *outfile);
extern void Swig_set_config_file(const String_or_char *filename); extern void Swig_set_config_file(const String_or_char *filename);
extern String *Swig_get_config_file(void); extern String *Swig_get_config_file(void);
extern void Swig_set_push_dir(int dopush);
extern int Swig_get_push_dir(void);
extern void Swig_swiglib_set(const String_or_char *); extern void Swig_swiglib_set(const String_or_char *);
extern String *Swig_swiglib_get(); extern String *Swig_swiglib_get();
extern void Swig_register_filebyname(const String_or_char *filename, File *outfile); extern void Swig_register_filebyname(const String_or_char *filename, File *outfile);