Browse Source

Convert MONITOR_*_*FILE variable names to upper case (trunk, https://trac.osgeo.org/grass/changeset/60203 + https://trac.osgeo.org/grass/changeset/60204)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@61436 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 10 years ago
parent
commit
0fc454e252

+ 5 - 3
display/d.mon/list.c

@@ -25,7 +25,9 @@ void list_mon(char ***list, int *n)
 		strcmp(tokens[2], "ENVFILE") != 0)
 		strcmp(tokens[2], "ENVFILE") != 0)
 		continue;
 		continue;
 	    *list = G_realloc(*list, (*n + 1) * sizeof(char *));
 	    *list = G_realloc(*list, (*n + 1) * sizeof(char *));
-	    (*list)[*n] = G_store(tokens[1]);
+	    /* GRASS variable names are upper case, but monitor names are lower
+	     * case. */
+	    (*list)[*n] = G_store_lower(tokens[1]);
 	    (*n)++;
 	    (*n)++;
 	    G_free_tokens(tokens);
 	    G_free_tokens(tokens);
 	    tokens = NULL;
 	    tokens = NULL;
@@ -59,7 +61,7 @@ int check_mon(const char *name)
     const char *str;
     const char *str;
     
     
     env_name = NULL;
     env_name = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", G_store_upper(name));
     str = G__getenv(env_name);
     str = G__getenv(env_name);
     if (!str)
     if (!str)
 	return FALSE;
 	return FALSE;
@@ -76,7 +78,7 @@ void list_cmd(const char *name, FILE *fd_out)
     FILE *fd;
     FILE *fd;
 
 
     cmd_name = NULL;
     cmd_name = NULL;
-    G_asprintf(&cmd_name, "MONITOR_%s_CMDFILE", name);
+    G_asprintf(&cmd_name, "MONITOR_%s_CMDFILE", G_store_upper(name));
     cmd_value = G__getenv(cmd_name);
     cmd_value = G__getenv(cmd_name);
     if (!cmd_value)
     if (!cmd_value)
 	G_fatal_error(_("Command file not found"));
 	G_fatal_error(_("Command file not found"));

+ 14 - 5
display/d.mon/start.c

@@ -13,13 +13,16 @@ static void start_wx(const char *, const char *, const char *,
 /* start file-based monitor */
 /* start file-based monitor */
 void start(const char *name, const char *output)
 void start(const char *name, const char *output)
 {
 {
+    char *u_name;
     char *env_name;
     char *env_name;
 
 
     if (!output)
     if (!output)
 	return;
 	return;
-    
+
+    u_name = G_store_upper(name);
+
     env_name = NULL;
     env_name = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_MAPFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_MAPFILE", u_name);
     G_setenv(env_name, output);
     G_setenv(env_name, output);
 }
 }
 
 
@@ -28,11 +31,14 @@ void start_wx(const char *name, const char *tempfile,
 	      const char *env_value, const char *cmd_value,
 	      const char *env_value, const char *cmd_value,
 	      int width, int height)
 	      int width, int height)
 {
 {
+    char *u_name;
     char progname[GPATH_MAX];
     char progname[GPATH_MAX];
     char *env_name, *map_value, str_width[1024], str_height[1024];
     char *env_name, *map_value, str_width[1024], str_height[1024];
 
 
+    u_name = G_store_upper(name);
+
     env_name = NULL;
     env_name = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_MAPFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_MAPFILE", u_name);
     G_asprintf(&map_value, "%s.ppm", tempfile);
     G_asprintf(&map_value, "%s.ppm", tempfile);
     G_setenv(env_name, map_value);
     G_setenv(env_name, map_value);
     /* close(creat(map_value, 0666)); */
     /* close(creat(map_value, 0666)); */
@@ -59,6 +65,7 @@ int start_mon(const char *name, const char *output, int select,
 	      int truecolor)
 	      int truecolor)
 {
 {
     const char *curr_mon;
     const char *curr_mon;
+    char *u_name;
     char *env_name, *env_value, *cmd_value;
     char *env_name, *env_value, *cmd_value;
     char *tempfile, buf[1024];
     char *tempfile, buf[1024];
     int env_fd;
     int env_fd;
@@ -69,8 +76,10 @@ int start_mon(const char *name, const char *output, int select,
     
     
     tempfile = G_tempfile();
     tempfile = G_tempfile();
 
 
+    u_name = G_store_upper(name);
+
     env_name = env_value = NULL;
     env_name = env_value = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", u_name);
     G_asprintf(&env_value, "%s.env", tempfile);
     G_asprintf(&env_value, "%s.env", tempfile);
     G_setenv(env_name, env_value);
     G_setenv(env_name, env_value);
     env_fd = creat(env_value, 0666);
     env_fd = creat(env_value, 0666);
@@ -101,7 +110,7 @@ int start_mon(const char *name, const char *output, int select,
     close(env_fd);
     close(env_fd);
 
 
     cmd_value = NULL;
     cmd_value = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_CMDFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_CMDFILE", u_name);
     G_asprintf(&cmd_value, "%s.cmd", tempfile);
     G_asprintf(&cmd_value, "%s.cmd", tempfile);
     G_setenv(env_name, cmd_value);
     G_setenv(env_name, cmd_value);
     close(creat(cmd_value, 0666));
     close(creat(cmd_value, 0666));

+ 14 - 6
display/d.mon/stop.c

@@ -26,11 +26,14 @@ int stop_mon(const char *name)
 
 
 int stop(const char *name)
 int stop(const char *name)
 {
 {
+    char *u_name;
     char *env_name;
     char *env_name;
     const char *env_file;
     const char *env_file;
-    
+
+    u_name = G_store_upper(name);
+
     env_name = NULL;
     env_name = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
+    G_asprintf(&env_name, "MONITOR_%s_ENVFILE", u_name);
     
     
     env_file = G__getenv(env_name);
     env_file = G__getenv(env_name);
     if (!env_file)
     if (!env_file)
@@ -43,11 +46,14 @@ int stop(const char *name)
 
 
 int stop_wx(const char *name)
 int stop_wx(const char *name)
 {
 {
+    char *u_name;
     char *env_name;
     char *env_name;
     const char *pid;
     const char *pid;
-    
+
+    u_name = G_store_upper(name);
+
     env_name = NULL;
     env_name = NULL;
-    G_asprintf(&env_name, "MONITOR_%s_PID", name);
+    G_asprintf(&env_name, "MONITOR_%s_PID", u_name);
     
     
     pid = G__getenv(env_name);
     pid = G__getenv(env_name);
     if (!pid) {
     if (!pid) {
@@ -71,11 +77,13 @@ int stop_wx(const char *name)
 void clean_env(const char *name)
 void clean_env(const char *name)
 {
 {
     int i;
     int i;
+    char *u_name;
     const char *env_prefix = "MONITOR_";
     const char *env_prefix = "MONITOR_";
     const char *env;
     const char *env;
     int env_prefix_len;
     int env_prefix_len;
     char **tokens;
     char **tokens;
-    
+
+    u_name = G_store_upper(name);
     env_prefix_len = strlen(env_prefix);
     env_prefix_len = strlen(env_prefix);
     
     
     tokens = NULL;
     tokens = NULL;
@@ -85,7 +93,7 @@ void clean_env(const char *name)
 	
 	
 	tokens = G_tokenize(env, "_");
 	tokens = G_tokenize(env, "_");
 	if (G_number_of_tokens(tokens) != 3 ||
 	if (G_number_of_tokens(tokens) != 3 ||
-	    strcmp(tokens[1], name) != 0)
+	    strcmp(tokens[1], u_name) != 0)
 	    continue;
 	    continue;
 	G_unsetenv(env);
 	G_unsetenv(env);
 	i--; /* env has been removed for the list */
 	i--; /* env has been removed for the list */

+ 2 - 2
gui/wxpython/mapdisp/main.py

@@ -420,7 +420,7 @@ if __name__ == "__main__":
     grass.verbose(_("Starting map display <%s>...") % (monName))
     grass.verbose(_("Starting map display <%s>...") % (monName))
 
 
     RunCommand('g.gisenv',
     RunCommand('g.gisenv',
-               set = 'MONITOR_%s_PID=%d' % (monName, os.getpid()))
+               set = 'MONITOR_%s_PID=%d' % (monName.upper(), os.getpid()))
     
     
     gmMap = MapApp(0)
     gmMap = MapApp(0)
     # set title
     # set title
@@ -432,7 +432,7 @@ if __name__ == "__main__":
 
 
     # clean up GRASS env variables
     # clean up GRASS env variables
     env = grass.gisenv()
     env = grass.gisenv()
-    env_name = 'MONITOR_%s' % monName
+    env_name = 'MONITOR_%s' % monName.upper()
     for key in env.keys():
     for key in env.keys():
         if key.find(env_name) == 0:
         if key.find(env_name) == 0:
             RunCommand('g.gisenv',
             RunCommand('g.gisenv',

+ 2 - 0
include/defs/gis.h

@@ -612,6 +612,8 @@ int G_snprintf(char *, size_t, const char *, ...)
 int G_strcasecmp(const char *, const char *);
 int G_strcasecmp(const char *, const char *);
 int G_strncasecmp(const char *, const char *, int);
 int G_strncasecmp(const char *, const char *, int);
 char *G_store(const char *);
 char *G_store(const char *);
+char *G_store_upper(const char *);
+char *G_store_lower(const char *);
 char *G_strchg(char *, char, char);
 char *G_strchg(char *, char, char);
 char *G_str_replace(const char *, const char *, const char *);
 char *G_str_replace(const char *, const char *, const char *);
 void G_strip(char *);
 void G_strip(char *);

+ 13 - 5
lib/display/r_raster.c

@@ -112,12 +112,16 @@ int D_open_driver(void)
     } else if (m) {
     } else if (m) {
 	char *env;
 	char *env;
 	const char *v;
 	const char *v;
+	char *u_m;
 	
 	
 	if (p)
 	if (p)
 	    G_warning(_("%s variable defined, %s ignored"),
 	    G_warning(_("%s variable defined, %s ignored"),
 		      "MONITOR", "GRASS_RENDER_IMMEDIATE");
 		      "MONITOR", "GRASS_RENDER_IMMEDIATE");
+	/* GRASS variable names should be upper case. */
+	u_m = G_store_upper(m);
+
 	env = NULL;
 	env = NULL;
-	G_asprintf(&env, "MONITOR_%s_MAPFILE", m);
+	G_asprintf(&env, "MONITOR_%s_MAPFILE", u_m);
 	v = G__getenv(env);
 	v = G__getenv(env);
 	p = m;
 	p = m;
 
 
@@ -128,7 +132,7 @@ int D_open_driver(void)
 		G_putenv("GRASS_PNGFILE", v);
 		G_putenv("GRASS_PNGFILE", v);
 	}
 	}
 	
 	
-	G_asprintf(&env, "MONITOR_%s_ENVFILE", m);
+	G_asprintf(&env, "MONITOR_%s_ENVFILE", u_m);
 	v = G__getenv(env);
 	v = G__getenv(env);
 	if (v) 
 	if (v) 
 	    read_env_file(v);
 	    read_env_file(v);
@@ -177,7 +181,8 @@ void D_close_driver(void)
   \brief Append command to the cmd file
   \brief Append command to the cmd file
 
 
   Cmd file is created by d.mon by defining GRASS variable
   Cmd file is created by d.mon by defining GRASS variable
-  \c MONITOR_<name>_CMDFILE, where \c \<name\> is name of the monitor.
+  \c MONITOR_<name>_CMDFILE, where \c \<name\> is the upper case name of
+  the monitor.
 
 
   Command string is usually generated by G_recreate_command(), NULL is
   Command string is usually generated by G_recreate_command(), NULL is
   used to clean up list of commands (see d.erase command).
   used to clean up list of commands (see d.erase command).
@@ -191,7 +196,7 @@ void D_close_driver(void)
 int D_save_command(const char *cmd)
 int D_save_command(const char *cmd)
 {
 {
     const char *mon_name, *mon_cmd;
     const char *mon_name, *mon_cmd;
-    char *env, *flag;
+    char *env, *flag, *u_mon_name;
     FILE *fd;
     FILE *fd;
 
 
     G_debug(1, "D_save_command(): %s", cmd);
     G_debug(1, "D_save_command(): %s", cmd);
@@ -203,8 +208,11 @@ int D_save_command(const char *cmd)
 	 getenv("GRASS_RENDER_IMMEDIATE")))
 	 getenv("GRASS_RENDER_IMMEDIATE")))
 	return 0;
 	return 0;
 
 
+    /* GRASS variable names should be upper case. */
+    u_mon_name = G_store_upper(mon_name);
+
     env = NULL;
     env = NULL;
-    G_asprintf(&env, "MONITOR_%s_CMDFILE", mon_name);
+    G_asprintf(&env, "MONITOR_%s_CMDFILE", u_mon_name);
     mon_cmd = G__getenv(env);
     mon_cmd = G__getenv(env);
     if (!mon_cmd)
     if (!mon_cmd)
 	return 0;
 	return 0;

+ 48 - 0
lib/gis/strings.c

@@ -100,6 +100,54 @@ char *G_store(const char *s)
 }
 }
 
 
 /*!
 /*!
+  \brief Copy string to allocated memory and convert copied string
+  to upper case
+  
+  This routine allocates enough memory to hold the string <b>s</b>,
+  copies <em>s</em> to the allocated memory, and returns a pointer
+  to the allocated memory.
+  
+  If <em>s</em> is NULL then empty string is returned.
+  
+  \param s string
+ 
+  \return pointer to newly allocated upper case string
+*/
+char *G_store_upper(const char *s)
+{
+    char *u_s;
+
+    u_s = G_store(s);
+    G_str_to_upper(u_s);
+
+    return u_s;
+}
+
+/*!
+  \brief Copy string to allocated memory and convert copied string
+  to lower case
+  
+  This routine allocates enough memory to hold the string <b>s</b>,
+  copies <em>s</em> to the allocated memory, and returns a pointer
+  to the allocated memory.
+  
+  If <em>s</em> is NULL then empty string is returned.
+  
+  \param s string
+ 
+  \return pointer to newly allocated lower case string
+*/
+char *G_store_lower(const char *s)
+{
+    char *l_s;
+
+    l_s = G_store(s);
+    G_str_to_lower(l_s);
+
+    return l_s;
+}
+
+/*!
   \brief Replace all occurencies of character in string bug with new
   \brief Replace all occurencies of character in string bug with new
   
   
   \param[in,out] bug base string
   \param[in,out] bug base string

+ 1 - 1
scripts/d.out.file/d.out.file.py

@@ -44,7 +44,7 @@ def main():
     options, flags = gcore.parser()
     options, flags = gcore.parser()
     gisenv = gcore.gisenv()
     gisenv = gcore.gisenv()
     if 'MONITOR' in gisenv:
     if 'MONITOR' in gisenv:
-        cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'])]
+        cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
         dout_cmd = 'd.out.file'
         dout_cmd = 'd.out.file'
         for param, val in options.iteritems():
         for param, val in options.iteritems():
             if val:
             if val:

+ 1 - 1
scripts/d.redraw/d.redraw.py

@@ -39,7 +39,7 @@ def main():
     if not mon:
     if not mon:
         grass.fatal(_("No monitor selected. Run `d.mon` to select monitor."))
         grass.fatal(_("No monitor selected. Run `d.mon` to select monitor."))
     
     
-    monCmd = env.get('MONITOR_%s_CMDFILE' % mon)
+    monCmd = env.get('MONITOR_%s_CMDFILE' % mon.upper())
     if not monCmd:
     if not monCmd:
         grass.fatal(_("No cmd file found for monitor <%s>") % mon)
         grass.fatal(_("No cmd file found for monitor <%s>") % mon)