Default search path for an include file should be based on the path of
the parent source file, not the current directory.
This commit is contained in:
parent
e573caf8f9
commit
36c3199782
|
@ -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_debug( int lex_debug, int parser_debug, int msg_debug );
|
||||||
extern void wpp_set_pedantic( int on );
|
extern void wpp_set_pedantic( int on );
|
||||||
extern void wpp_add_include_path( const char *path );
|
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( const char *input, FILE *output );
|
||||||
extern int wpp_parse_temp( const char *input, const char *output_base, char **output_name );
|
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 */
|
/* Undo the effect of the quotation */
|
||||||
fname[n-1] = '\0';
|
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);
|
pperror("Unable to open include file %s", fname+1);
|
||||||
|
|
||||||
fname[n-1] = *fname; /* Redo the quotes */
|
fname[n-1] = *fname; /* Redo the quotes */
|
||||||
|
|
|
@ -355,10 +355,11 @@ void wpp_add_include_path(const char *path)
|
||||||
free(cpy);
|
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 *cpy;
|
||||||
char *cptr;
|
char *cptr;
|
||||||
|
char *path;
|
||||||
const char *ccptr;
|
const char *ccptr;
|
||||||
int i, fd;
|
int i, fd;
|
||||||
|
|
||||||
|
@ -380,20 +381,28 @@ char *wpp_find_include(const char *name, int search)
|
||||||
}
|
}
|
||||||
*cptr = '\0';
|
*cptr = '\0';
|
||||||
|
|
||||||
if(search)
|
if(parent_name)
|
||||||
{
|
{
|
||||||
/* Search current dir and then -I path */
|
/* Search directory of parent include and then -I path */
|
||||||
fd = open( cpy, O_RDONLY );
|
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)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
close( fd );
|
close( fd );
|
||||||
return cpy;
|
free( cpy );
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
free( path );
|
||||||
}
|
}
|
||||||
/* Search -I path */
|
/* Search -I path */
|
||||||
for(i = 0; i < nincludepath; i++)
|
for(i = 0; i < nincludepath; i++)
|
||||||
{
|
{
|
||||||
char *path;
|
|
||||||
path = pp_xmalloc(strlen(includepath[i]) + strlen(cpy) + 2);
|
path = pp_xmalloc(strlen(includepath[i]) + strlen(cpy) + 2);
|
||||||
strcpy(path, includepath[i]);
|
strcpy(path, includepath[i]);
|
||||||
strcat(path, "/");
|
strcat(path, "/");
|
||||||
|
@ -411,12 +420,12 @@ char *wpp_find_include(const char *name, int search)
|
||||||
return NULL;
|
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;
|
char *path;
|
||||||
FILE *fp;
|
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");
|
fp = fopen(path, "rt");
|
||||||
|
|
||||||
if (fp)
|
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_define(char *def, char *text);
|
||||||
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
|
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
|
||||||
void pp_del_define(const char *name);
|
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_push_if(pp_if_state_t s);
|
||||||
void pp_next_if_state(int);
|
void pp_next_if_state(int);
|
||||||
pp_if_state_t pp_pop_if(void);
|
pp_if_state_t pp_pop_if(void);
|
||||||
|
|
|
@ -417,7 +417,7 @@ int do_import(char *fname)
|
||||||
import->next = first_import;
|
import->next = first_import;
|
||||||
first_import = 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);
|
yyerror("Unable to open include file %s", fname);
|
||||||
|
|
||||||
import_stack[ptr].temp_name = temp_name;
|
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)
|
if (codepage <= 0 && filename->type != str_char)
|
||||||
yyerror("Cannot convert filename to ASCII string");
|
yyerror("Cannot convert filename to ASCII string");
|
||||||
name = convert_string( filename, str_char, codepage );
|
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);
|
yyerror("Cannot open file %s", name->str.cstr);
|
||||||
if (!(fp = fopen( path, "rb" )))
|
if (!(fp = fopen( path, "rb" )))
|
||||||
yyerror("Cannot open file %s", name->str.cstr);
|
yyerror("Cannot open file %s", name->str.cstr);
|
||||||
|
|
Loading…
Reference in New Issue