Improved handling of include paths in gmxcpp from Teemu
authorErik Lindahl <lindahl@cbr.su.se>
Mon, 30 Aug 2010 13:00:38 +0000 (15:00 +0200)
committerErik Lindahl <lindahl@cbr.su.se>
Mon, 30 Aug 2010 13:00:38 +0000 (15:00 +0200)
src/gmxlib/gmxcpp.c

index 0cb6fb7c5bc2c6835efd0aa41cb215bd5ea27c23..994c6e7265f31cdbdc40a6a022f03b264cfd3c59 100644 (file)
@@ -183,7 +183,7 @@ int cpp_open_file(const char *filenm,gmx_cpp_t *handle, char **cppopts)
 {
   gmx_cpp_t cpp;
   char *buf,*pdum;
-  char *ptr;
+  char *ptr, *ptr2;
   int i;
   unsigned int i1;
     
@@ -229,7 +229,7 @@ int cpp_open_file(const char *filenm,gmx_cpp_t *handle, char **cppopts)
     for (i = 0; i < nincl; ++i)
     {
       snew(buf, strlen(incl[i]) + strlen(filenm) + 2);
-      sprintf(buf, "%s%c%s", incl[i], DIR_SEPARATOR, filenm);
+      sprintf(buf, "%s/%s", incl[i], filenm);
       if (gmx_fexist(buf))
       {
           cpp->fn = buf;
@@ -251,8 +251,14 @@ int cpp_open_file(const char *filenm,gmx_cpp_t *handle, char **cppopts)
    * directory. Note that we - just as C - always use UNIX path separators
    * internally in include file names.
    */
-  ptr = strrchr(cpp->fn, '/');
-  if (!ptr)
+  ptr  = strrchr(cpp->fn, '/');
+  ptr2 = strrchr(cpp->fn, DIR_SEPARATOR);
+    
+  if (ptr == NULL || (ptr2 != NULL && ptr2 > ptr))
+  {
+      ptr = ptr2;
+  }
+  if(ptr==NULL)
   {
     cpp->path = NULL;
     cpp->cwd  = NULL;