Relocate path names when searching for files.
[pspp-builds.git] / src / data / file-name.c
index c6f91b56a961c1567cf7b9a4822f8c4d5899088d..e9411b65d950d444ee07dbfd155bdaeb982d1351 100644 (file)
@@ -138,6 +138,7 @@ fn_search_path (const char *base_name, const char *path_)
       if (!ds_is_empty (&file) && !ISSLASH (ds_last (&file)))
        ds_put_char (&file, '/');
       ds_put_cstr (&file, base_name);
+      ds_relocate (&file);
 
       /* Check whether file exists. */
       if (fn_exists (ds_cstr (&file)))
@@ -411,7 +412,7 @@ fn_get_identity (const char *file_name)
   identity->device = 0;
   identity->inode = 0;
   identity->name = xstrdup (ok ? cname : file_name);
-  str_lowercase (identity->file_name);
+  str_lowercase (identity->name);
 #endif /* Windows */
 
   return identity;
@@ -452,3 +453,45 @@ fn_hash_identity (const struct file_identity *identity)
     hash ^= hsh_hash_string (identity->name);
   return hash;
 }
+
+
+
+#ifdef WINDOWS32
+
+/* Apparently windoze users like to see output dumped into their home directory,
+   not the current directory (!) */
+const char *
+default_output_path (void)
+{
+  static const char *home_dir = NULL;
+
+  /* Windows NT defines HOMEDRIVE and HOMEPATH.  But give preference
+     to HOME, because the user can change HOME.  */
+  if (home_dir == NULL)
+    {
+      const char *home_drive = getenv ("HOMEDRIVE");
+      const char *home_path = getenv ("HOMEPATH");
+
+      if (home_drive != NULL && home_path != NULL)
+       home_dir = xasprintf ("%s%s%c",
+                             home_drive, home_path, DIRECTORY_SEPARATOR);
+      else
+       home_dir = "c:/users/default/"; /* poor default */
+    }
+  return home_dir;
+}
+
+#else
+
+/* ... whereas the rest of the world just likes it to be
+   put "here" for easy access. */
+const char *
+default_output_path (void)
+{
+  static char current_dir[]  = "";
+
+  return current_dir;
+}
+
+#endif
+