welding in a virtual unix root for windoze
[feisty_meow.git] / nucleus / library / filesystem / filename.cpp
index 81ca6f02f69d7abd04724e4877110f3e05ad4bdd..ba72084e997a929723c4ba7c9fa6358bd83da41d 100644 (file)
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#ifdef __UNIX__
+#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
   #include <unistd.h>
-#endif
-#ifdef __WIN32__
+#else
   #include <io.h>
 #endif
 
@@ -191,13 +190,22 @@ void filename::canonicalize()
   // on windows, we want to translate away from any cygwin or msys format into a more palatable
   // version that the rest of windows understands.
   // first, cygwin...
-  const astring CYGDRIVE_PATH = astring(astring(DEFAULT_SEPARATOR, 1) + "cygdrive"
-      + astring(DEFAULT_SEPARATOR, 1));
+//hmmm: make these into statics!
+  const astring CYGDRIVE_SENTINEL = "cygdrive";
+  const astring CYGDRIVE_PATH = astring(astring(DEFAULT_SEPARATOR, 1)
+      + CYGDRIVE_SENTINEL + astring(DEFAULT_SEPARATOR, 1));
+
   // must be at least as long as the string we're looking for, plus a drive letter afterwards.
-  if ( (length() > CYGDRIVE_PATH.length() + 1) && begins(CYGDRIVE_PATH) ) {
+  if ( (length() >= CYGDRIVE_PATH.length() + 1)
+      && separator(get(0))
+      && separator(get(CYGDRIVE_PATH.length() - 1))
+      && compare(CYGDRIVE_SENTINEL, 1, 
+          0, CYGDRIVE_SENTINEL.length(), true) ) {
     zap(0, CYGDRIVE_PATH.length() - 1);  // whack the cygdrive portion plus two slashes.
     insert(1, ":");  // add a colon after the imputed drive letter.
-LOG(astring("turned cygdrive string into: ") + *this);
+//LOG(astring("turned cygdrive path string into: ") + *this);
+  } else {
+//LOG(astring("path didn't match so left as: ") + *this);
   }
   // now we convert msys...
   if ( (length() >= 2) && (get(0) == DEFAULT_SEPARATOR)
@@ -216,9 +224,23 @@ LOG(astring("turned cygdrive string into: ") + *this);
       // then only on the near defunct windows platform.
       zap(0, 0);  // take off initial slash.
       insert(1, ":");  // add the obligatory colon.
-LOG(astring("turned msys string into: ") + *this);
+//LOG(astring("turned msys string into: ") + *this);
     }
   } 
+
+  // if no specialized path specifications were seen, and we have a unix style path
+  // here, then there will be trouble when we pass that to windows.
+//if first character is a slash, and second char is alphanumeric, then we check...
+//can we find a cygwin root dir stored in our config stuff?
+//  maybe in the build version file?  ugh, yuck.
+//  what about in generated files, created at build time?  --> yes, nice option.
+//
+//hmmm: we need the capability to re-create the config file that tells us
+// where cyg root is, but how can we, aside from guessing at where to find
+// cygwin (c:/cygwin c:/cygwin64 etc).
+//
+//hmmm: 
+
 #endif
 
   // we don't crop the last separator if the name's too small.  for msdos