From bf3cd16f27f93c57ae10349dcfcca85cc3e2c44f Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 17 Dec 2014 20:09:01 +0000 Subject: [PATCH] Updated to preferentially search the local directory for dependencies Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1222 --- wmake/src/wmkdep.l | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l index c9e1d8e67d..cf0be5e02c 100644 --- a/wmake/src/wmkdep.l +++ b/wmake/src/wmkdep.l @@ -132,6 +132,16 @@ char* depFile = NULL; /* Set of files already visited */ struct HashEntry* visitedFiles[HASH_TABLE_SIZE]; +/* Buffer pointer stack counter */ +int currentBuffer = 0; + +/* Buffer pointer stack */ +YY_BUFFER_STATE buffers[FILE_STACK_SIZE]; + +/* Directory paths for the loaded files */ +const char* bufferPaths[FILE_STACK_SIZE]; + + int main(int argc, char* argv[]) { char *basePos, *dotPos; @@ -224,6 +234,9 @@ int main(int argc, char* argv[]) printf("%s: \\\n", depFile); free(objectFile); + /* Initialize buffer path for currentBuffer */ + bufferPaths[currentBuffer] = NULL; + nextFile(sourceFile); yylex(); @@ -242,10 +255,6 @@ int main(int argc, char* argv[]) } -int currentBuffer = 0; /* Buffer pointer stack counter */ -YY_BUFFER_STATE buffers[FILE_STACK_SIZE]; /* Buffer pointer stack */ - - /* * Add a directory name to the file name */ @@ -290,6 +299,28 @@ void nextFile(const char* fileName) /* Pointer to new file which is set if the file is successfully opened */ FILE* newyyin = NULL; + /* Check if the file has same path as the file in the current buffer */ + if (bufferPaths[currentBuffer] != NULL) + { + char* pathName = addDirectoryName(bufferPaths[currentBuffer], fileName); + + if ((newyyin = fopen(pathName, "r"))) + { + printf("%s \\\n", pathName); + + buffers[currentBuffer++] = YY_CURRENT_BUFFER; + bufferPaths[currentBuffer] = bufferPaths[currentBuffer-1]; + + yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE)); + + free(pathName); + + return; + } + + free(pathName); + } + if (!(newyyin = fopen(fileName, "r"))) { int d; @@ -300,7 +331,10 @@ void nextFile(const char* fileName) if ((newyyin = fopen(pathName, "r"))) { printf("%s \\\n", pathName); + buffers[currentBuffer++] = YY_CURRENT_BUFFER; + bufferPaths[currentBuffer] = directories[d]; + yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE)); free(pathName); @@ -342,6 +376,8 @@ void nextFile(const char* fileName) fflush(stdout); buffers[currentBuffer++] = YY_CURRENT_BUFFER; + bufferPaths[currentBuffer] = NULL; + yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE)); } }