[PATCH] Search for include files relative to the current files path first.

This patch add the current files path to the start of the list used
when search for include files.
This commit is contained in:
Cary R 2007-08-17 18:36:11 -07:00 committed by Stephen Williams
parent ca924639a8
commit d08817aec1
2 changed files with 20 additions and 55 deletions

View File

@ -763,10 +763,22 @@ static void do_include()
fprintf(depend_file, "%s\n", istack->path);
}
} else {
unsigned idx = 0;
unsigned idx, start = 0;
char path[4096];
char *cp;
/* Add the current path to the start of the include_dir list. */
strcpy(path, istack->path);
cp = strrchr(path, '/');
if (cp == 0) start = 1; /* A base file so already in [1] */
else *cp = '\0';
/* We do not need a strdup here since the path is read before
* it is overridden. If the search order is changed add a
* strdup here and a free before the include_dir[0] = 0 below.
*/
include_dir[0] = path;
standby->file = 0;
for (idx = 0 ; idx < include_cnt ; idx += 1) {
char path[4096];
for (idx = start ; idx < include_cnt ; idx += 1) {
sprintf(path, "%s/%s", include_dir[idx], standby->path);
standby->file = fopen(path, "r");
if (standby->file) {
@ -776,6 +788,7 @@ static void do_include()
break;
}
}
include_dir[0] = 0;
}
if (standby->file == 0) {

View File

@ -220,9 +220,10 @@ int main(int argc, char*argv[])
define_macro("unconnected_drive", "`unconnected_drive", 1);
define_macro("uselib", "`uselib", 1);
include_dir = malloc(sizeof(char*));
include_dir[0] = strdup(".");
include_cnt = 1;
include_cnt = 2;
include_dir = malloc(include_cnt*sizeof(char*));
include_dir[0] = 0; /* 0 is reserved for the current files path. */
include_dir[1] = strdup(".");
while ((opt=getopt(argc, argv, "F:f:K:Lo:v")) != EOF) switch (opt) {
@ -333,52 +334,3 @@ int main(int argc, char*argv[])
return error_count;
}
/*
* $Log: main.c,v $
* Revision 1.23 2006/10/02 18:16:18 steve
* Save dep_path because arg space is overrun.
*
* Revision 1.22 2006/07/26 00:11:40 steve
* Pass depfiles through temp defines file.
*
* Revision 1.21 2006/07/26 00:02:48 steve
* Pass defines and includes through temp file.
*
* Revision 1.20 2004/09/10 00:15:45 steve
* Remove bad casts.
*
* Revision 1.19 2004/09/05 21:29:08 steve
* Better type safety.
*
* Revision 1.18 2004/02/15 18:03:30 steve
* Cleanup of warnings.
*
* Revision 1.17 2003/09/26 02:08:31 steve
* Detect missing endif markers.
*
* Revision 1.16 2002/08/12 01:35:02 steve
* conditional ident string using autoconfig.
*
* Revision 1.15 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.14 2001/11/21 02:59:27 steve
* Remove diag print.
*
* Revision 1.13 2001/11/21 02:20:35 steve
* Pass list of file to ivlpp via temporary file.
*
* Revision 1.12 2001/09/15 18:27:04 steve
* Make configure detect malloc.h
*
* Revision 1.11 2001/07/25 03:10:50 steve
* Create a config.h.in file to hold all the config
* junk, and support gcc 3.0. (Stephan Boettcher)
*
* Revision 1.10 2001/06/23 18:41:02 steve
* Include stdlib.h
*
* Revision 1.9 2001/05/20 18:08:07 steve
* local declares if the header is missing.
*/