[GRASS-SVN] r59317 - in grass/trunk: include include/defs lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 24 12:38:32 PDT 2014


Author: martinl
Date: 2014-03-24 12:38:32 -0700 (Mon, 24 Mar 2014)
New Revision: 59317

Modified:
   grass/trunk/include/defs/gis.h
   grass/trunk/include/gis.h
   grass/trunk/lib/gis/home.c
Log:
libgis: introduce G_config_path(), fix CONFIG_DIR for winGRASS


Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h	2014-03-24 19:36:37 UTC (rev 59316)
+++ grass/trunk/include/defs/gis.h	2014-03-24 19:38:32 UTC (rev 59317)
@@ -318,6 +318,7 @@
 /* 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 *);

Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2014-03-24 19:36:37 UTC (rev 59316)
+++ grass/trunk/include/gis.h	2014-03-24 19:38:32 UTC (rev 59317)
@@ -96,7 +96,11 @@
 #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

Modified: grass/trunk/lib/gis/home.c
===================================================================
--- grass/trunk/lib/gis/home.c	2014-03-24 19:36:37 UTC (rev 59316)
+++ grass/trunk/lib/gis/home.c	2014-03-24 19:38:32 UTC (rev 59317)
@@ -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 @@
 }
 
 /*!
- * \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 @@
     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;
+    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);
 
-    sprintf(rcpath, "%s%c%s", G_home(), HOST_DIRSEP, RCDIR);
-
-#ifdef POSSIBILITY
+#if 0
     /* create it if it doesn't exist */
 #include <errno.h>
     int ret;
@@ -112,6 +118,7 @@
 	G_fatal_error(_("Failed to create directory [%s]"), rcpath);
 #endif
 
-    return G_store(rcpath);
+    G_initialize_done(&initialized_config);
+
+    return config_path;
 }
-#endif



More information about the grass-commit mailing list