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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 14 12:34:25 PDT 2014


Author: huhabla
Date: 2014-09-14 12:34:25 -0700 (Sun, 14 Sep 2014)
New Revision: 61956

Modified:
   grass/trunk/include/defs/gis.h
   grass/trunk/lib/gis/env.c
Log:
libgis: Added support to force the reading of VAR and gisrc files at runtime and tests. Discussed in ticket #2408.

Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h	2014-09-14 19:24:02 UTC (rev 61955)
+++ grass/trunk/include/defs/gis.h	2014-09-14 19:34:25 UTC (rev 61956)
@@ -221,6 +221,8 @@
 int G_get_gisrc_mode(void);
 void G_create_alt_env(void);
 void G_switch_env(void);
+void G__read_mapset_env(void);
+void G__read_gisrc_env(void);
 
 /* error.c */
 jmp_buf *G_fatal_longjmp(int);

Modified: grass/trunk/lib/gis/env.c
===================================================================
--- grass/trunk/lib/gis/env.c	2014-09-14 19:24:02 UTC (rev 61955)
+++ grass/trunk/lib/gis/env.c	2014-09-14 19:34:25 UTC (rev 61956)
@@ -47,6 +47,8 @@
 static int unset_env(const char *, int);
 static const char *get_env(const char *, int);
 static void write_env(int);
+static void parse_env(FILE *, int);
+static void force_read_env(int);
 static FILE *open_env(const char *, int);
 
 /*!
@@ -84,21 +86,41 @@
     read_env(G_VAR_MAPSET);
 }
 
-static int read_env(int loc)
+/*!
+ * \brief Force to read the mapset environment file VAR
+ * 
+ * The mapset specific VAR file of the mapset set with G_setenv()
+ * will be read into memory, ignoring if it was readed before. 
+ * Existing values will be overwritten, new values appended.
+ * 
+ * \return
+ */ 
+void G__read_mapset_env(void)
 {
+    force_read_env(G_VAR_MAPSET);
+}
+
+/*!
+ * \brief Force to read the GISRC environment file
+ * 
+ * The GISRC file 
+ * will be read into memory, ignoring if it was readed before. 
+ * Existing values will be overwritten, new values appended.
+ * 
+ * \return
+ */ 
+void G__read_gisrc_env(void)
+{
+    force_read_env(G_VAR_GISRC);
+}
+
+static void parse_env(FILE *fd, int loc)
+{    
     char buf[200];
     char *name;
     char *value;
-    FILE *fd;
 
-    if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
-	return 0;		/* don't use file for GISRC */
-
-    if (G_is_initialized(&st->init[loc]))
-	return 1;
-
-    if ((fd = open_env("r", loc))) {
-	while (G_getl2(buf, sizeof buf, fd)) {
+    while (G_getl2(buf, sizeof buf, fd)) {
 	    for (name = value = buf; *value; value++)
 		if (*value == ':')
 		    break;
@@ -111,14 +133,43 @@
 	    if (*name && *value)
 		set_env(name, value, loc);
 	}
+}
 
-	fclose(fd);
+static int read_env(int loc)
+{
+
+    FILE *fd;
+
+    if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
+	return 0;		/* don't use file for GISRC */
+
+    if (G_is_initialized(&st->init[loc]))
+	return 1;
+
+    if ((fd = open_env("r", loc))) {
+        parse_env(fd, loc);
+        fclose(fd);
     }
 
     G_initialize_done(&st->init[loc]);
     return 0;
 }
 
+/*!
+ * \brief Force the reading or the GISRC or MAPSET/VAR files
+ * and overwrite/append the specified variables
+ * 
+ */ 
+static void force_read_env(int loc)
+{
+    FILE *fd;
+    if ((fd = open_env("r", loc))) {
+        parse_env(fd, loc);
+        fclose(fd);
+    }
+}
+
+
 static int set_env(const char *name, const char *value, int loc)
 {
     int n;



More information about the grass-commit mailing list