6dea2ec25eb2e896aef0d7669c68b81f4d75b104
jcasper
  Fri Jan 8 16:07:06 2016 -0800
Updating relative path calculation to support root-level resource paths beginning with //

diff --git src/lib/filePath.c src/lib/filePath.c
index 68fe762..62b2030 100644
--- src/lib/filePath.c
+++ src/lib/filePath.c
@@ -123,49 +123,67 @@
  * files.  In this case the baseFile would be the current
  * source file, and the relPath would be from the include
  * statement.  The returned result could then be used to
  * open the include file. */
 {
 char dir[PATH_LEN];
 splitPath(baseFile, dir, NULL, NULL);
 int dirLen = strlen(dir);
 if (dirLen > 0 && dir[dirLen-1] == '/')
      dir[dirLen-1] = 0;
 return expandRelativePath(dir, relPath);
 }
 
 char *makeRelativePath(char *from, char *to)
 /* Calculate a relative path from one absolute directory/file to another.
- * Assumptions: both from and to are absolute paths beginning at "/", and
- * may be as small as only "/".  Filenames are okay, but all directory
- * names must end with a "/" to distinguish them from files.
+ * Assumptions: both from and to are canonicalized absolute paths beginning
+ * at "/" or "//".  Filenames are okay, but all directory names must end with
+ * a "/" to distinguish them from files.
  * e.g., /test/dir/ is a directory, but /test/dir is a file.
  */
 {
 int i, j, toCount, fromCount;
 char fromDir[PATH_LEN];
 char toDir[PATH_LEN], toFile[FILENAME_LEN], toExt[FILEEXT_LEN];
 char relPath [PATH_LEN] = "";
 char *fromDirList[PATH_LEN], *toDirList[PATH_LEN];
+boolean fromStartsDoubleSlash = FALSE, toStartsDoubleSlash = FALSE;
+
+if (startsWith("//", from) && from[2] != '/')
+    {
+    fromStartsDoubleSlash = TRUE;
+    from[1] = '_'; // prevent initial // from being misinterpreted
+    }
+if (startsWith("//", to) && to[2] != '/')
+    {
+    toStartsDoubleSlash = TRUE;
+    to[1] = '_'; // prevent initial // from being misinterpreted
+    }
 
 splitPath(from, fromDir, NULL, NULL);
 splitPath(to, toDir, toFile, toExt);
 
 fromCount = chopByChar(fromDir, '/', fromDirList, ArraySize(fromDirList));
 toCount   = chopByChar(toDir,   '/', toDirList,   ArraySize(toDirList));
 
-for (i=1; i < min(fromCount, toCount); i++)
+if (fromStartsDoubleSlash == TRUE)
+    fromDirList[1][0] = '/';
+if (toStartsDoubleSlash == TRUE)
+    toDirList[1][0] = '/';
+    
+
+for (i=1; i < min(fromCount-1, toCount-1); i++)
     {
     if (!sameString(fromDirList[i], toDirList[i]))
         break;
     }
 for (j=i; j < fromCount-1; j++)
     {
     safecat(relPath, sizeof relPath, "../");
     }
 for (j=i; j < toCount-1; j++)
     {
     safecat(relPath, sizeof relPath, toDirList[j]);
     safecat(relPath, sizeof relPath, "/");
     }
 
 safecat(relPath, sizeof relPath, toFile);