Commit 36c31997 authored by Alexandre Julliard's avatar Alexandre Julliard

Default search path for an include file should be based on the path of

the parent source file, not the current directory.
parent e573caf8
......@@ -29,7 +29,7 @@ extern void wpp_add_cmdline_define( const char *value );
extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );
extern void wpp_set_pedantic( int on );
extern void wpp_add_include_path( const char *path );
extern char *wpp_find_include( const char *name, int search );
extern char *wpp_find_include( const char *name, const char *parent_name );
extern int wpp_parse( const char *input, FILE *output );
extern int wpp_parse_temp( const char *input, const char *output_base, char **output_name );
......
......@@ -1445,7 +1445,7 @@ void pp_do_include(char *fname, int type)
/* Undo the effect of the quotation */
fname[n-1] = '\0';
if((ppin = pp_open_include(fname+1, type, &newpath)) == NULL)
if((ppin = pp_open_include(fname+1, type ? pp_status.input : NULL, &newpath)) == NULL)
pperror("Unable to open include file %s", fname+1);
fname[n-1] = *fname; /* Redo the quotes */
......
......@@ -355,10 +355,11 @@ void wpp_add_include_path(const char *path)
free(cpy);
}
char *wpp_find_include(const char *name, int search)
char *wpp_find_include(const char *name, const char *parent_name)
{
char *cpy;
char *cptr;
char *path;
const char *ccptr;
int i, fd;
......@@ -380,20 +381,28 @@ char *wpp_find_include(const char *name, int search)
}
*cptr = '\0';
if(search)
if(parent_name)
{
/* Search current dir and then -I path */
fd = open( cpy, O_RDONLY );
/* Search directory of parent include and then -I path */
const char *p;
if ((p = strrchr( parent_name, '/' ))) p++;
else p = parent_name;
path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
memcpy( path, parent_name, p - parent_name );
strcpy( path + (p - parent_name), cpy );
fd = open( path, O_RDONLY );
if (fd != -1)
{
close( fd );
return cpy;
free( cpy );
return path;
}
free( path );
}
/* Search -I path */
for(i = 0; i < nincludepath; i++)
{
char *path;
path = pp_xmalloc(strlen(includepath[i]) + strlen(cpy) + 2);
strcpy(path, includepath[i]);
strcat(path, "/");
......@@ -411,12 +420,12 @@ char *wpp_find_include(const char *name, int search)
return NULL;
}
FILE *pp_open_include(const char *name, int search, char **newpath)
FILE *pp_open_include(const char *name, const char *parent_name, char **newpath)
{
char *path;
FILE *fp;
if (!(path = wpp_find_include( name, search ))) return NULL;
if (!(path = wpp_find_include( name, parent_name ))) return NULL;
fp = fopen(path, "rt");
if (fp)
......
......@@ -200,7 +200,7 @@ void pp_pop_define_state(void);
pp_entry_t *pp_add_define(char *def, char *text);
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
void pp_del_define(const char *name);
FILE *pp_open_include(const char *name, int search, char **newpath);
FILE *pp_open_include(const char *name, const char *parent_name, char **newpath);
void pp_push_if(pp_if_state_t s);
void pp_next_if_state(int);
pp_if_state_t pp_pop_if(void);
......
......@@ -417,7 +417,7 @@ int do_import(char *fname)
import->next = first_import;
first_import = import;
if (!(path = wpp_find_include( fname, 1 )))
if (!(path = wpp_find_include( fname, input_name )))
yyerror("Unable to open include file %s", fname);
import_stack[ptr].temp_name = temp_name;
......
......@@ -2311,7 +2311,7 @@ static raw_data_t *load_file(string_t *filename, language_t *lang)
if (codepage <= 0 && filename->type != str_char)
yyerror("Cannot convert filename to ASCII string");
name = convert_string( filename, str_char, codepage );
if (!(path = wpp_find_include(name->str.cstr, 1)))
if (!(path = wpp_find_include(name->str.cstr, input_name)))
yyerror("Cannot open file %s", name->str.cstr);
if (!(fp = fopen( path, "rb" )))
yyerror("Cannot open file %s", name->str.cstr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment