瀏覽代碼

libgis: introduce G_config_path(), fix CONFIG_DIR for winGRASS

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59317 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年之前
父節點
當前提交
95efb2a033
共有 3 個文件被更改,包括 32 次插入20 次删除
  1. 1 0
      include/defs/gis.h
  2. 4 0
      include/gis.h
  3. 27 20
      lib/gis/home.c

+ 1 - 0
include/defs/gis.h

@@ -318,6 +318,7 @@ void G__call_error_handlers(void);
 /* home.c */
 const char *G_home(void);
 const char *G__home(void);
+const char *G_config_path(void);
 
 /* ilist.c */
 void G_init_ilist(struct ilist *);

+ 4 - 0
include/gis.h

@@ -96,7 +96,11 @@ static const char *GRASS_copyright __attribute__ ((unused))
 #define PROJECTION_FILE "PROJ_INFO"
 #define UNIT_FILE       "PROJ_UNITS"
 
+#ifdef __MINGW32__
+#define CONFIG_DIR "GRASS7"
+#else
 #define CONFIG_DIR ".grass7"
+#endif
 
 /* define PI and friends */
 #undef M_PI

+ 27 - 20
lib/gis/home.c

@@ -1,9 +1,9 @@
 /*!
  * \file gis/home.c
  *
- * \brief GIS Library - Get user's home directory.
+ * \brief GIS Library - Get user's home or config directory.
  *
- * (C) 2001-2009 by the GRASS Development Team
+ * (C) 2001-2014 by the GRASS Development Team
  *
  * This program is free software under the GNU General Public License
  * (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -22,6 +22,8 @@
  * Returns a pointer to a string which is the full path name of the
  * user's home directory.
  *
+ * Calls G_fatal_error() on failure.
+ *
  * \return pointer to string
  * \return NULL on error
  */
@@ -38,7 +40,7 @@ const char *G_home(void)
 }
 
 /*!
- * \brief Get user's home directory
+ * \brief Get user's home directory (internal use only)
  *
  * Returns a pointer to a string which is the full path name of the
  * user's home directory.
@@ -78,32 +80,36 @@ const char *G__home(void)
     return home;
 }
 
-
-#ifdef TODO
-#include <stdio.h>
-#define RCDIR ".grass7"
-
 /*!
- * \brief Get user's .grass/ config path directory
+ * \brief Get user's config path directory
  *
  * Returns a pointer to a string which is the full path name of the
- * user's .grass/ config directory in their home directory.
+ * user's GRASS config directory in their home directory.
  *
  * The path is not guaranteed to exist.
-(should it be?  see possible TODO below)
+ *
+ * \todo should it be? see possible TODO below
  *
  * \return pointer to string
  * \return NULL on error
  */
-const char *G_rc_path(void)
+const char *G_config_path(void)
 {
-/* choose better name for fn? */
-/* HB: making a complete bollocks of this, but to express the idea... */
-    const char *rcpath = 0;
-
-    sprintf(rcpath, "%s%c%s", G_home(), HOST_DIRSEP, RCDIR);
+    static int initialized_config;
+    static const char *config_path = 0;
+    char buf[GPATH_MAX];
+    
+    if (G_is_initialized(&initialized_config))
+        return config_path;
+    
+#ifdef __MINGW32__
+    sprintf(buf, "%s%c%s", getenv("APPDATA"), HOST_DIRSEP, CONFIG_DIR);
+#else    
+    sprintf(buf, "%s%c%s", G_home(), HOST_DIRSEP, CONFIG_DIR);
+#endif
+    config_path = G_store(buf);
 
-#ifdef POSSIBILITY
+#if 0
     /* create it if it doesn't exist */
 #include <errno.h>
     int ret;
@@ -112,6 +118,7 @@ const char *G_rc_path(void)
 	G_fatal_error(_("Failed to create directory [%s]"), rcpath);
 #endif
 
-    return G_store(rcpath);
+    G_initialize_done(&initialized_config);
+
+    return config_path;
 }
-#endif