Sync to Wine-0_9:
[reactos.git] / reactos / tools / wpp / preproc.c
index e16176c..08c8fba 100644 (file)
@@ -354,10 +354,11 @@ void wpp_add_include_path(const char *path)
        free(cpy);
 }
 
-char *wpp_find_include(const char *name, int type)
+char *wpp_find_include(const char *name, const char *parent_name, int type)
 {
     char *cpy;
     char *cptr;
+    char *path;
     const char *ccptr;
     int i, fd;
 
@@ -379,15 +380,24 @@ char *wpp_find_include(const char *name, int type)
     }
     *cptr = '\0';
 
-    if(type == LOCAL_INCLUDE)
+    if(type == LOCAL_INCLUDE && 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 );
     }
 
     /* Skip all directories till the current include file for #include_next. */
@@ -416,7 +426,6 @@ char *wpp_find_include(const char *name, int type)
     /* Search -I path */
     for(; i < nincludepath; i++)
     {
-        char *path;
         path = pp_xmalloc(strlen(includepath[i]) + strlen(cpy) + 2);
         strcpy(path, includepath[i]);
         strcat(path, "/");
@@ -434,12 +443,12 @@ char *wpp_find_include(const char *name, int type)
     return NULL;
 }
 
-FILE *pp_open_include(const char *name, int type, char **newpath)
+FILE *pp_open_include(const char *name, const char *parent_name, char **newpath, int type)
 {
     char *path;
     FILE *fp;
 
-    if (!(path = wpp_find_include( name, type ))) return NULL;
+    if (!(path = wpp_find_include( name, parent_name, type ))) return NULL;
     fp = fopen(path, "rt");
 
     if (fp)