[GRASS-SVN] r64401 - grass/trunk/lib/display
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 2 08:21:49 PST 2015
Author: martinl
Date: 2015-02-02 08:21:49 -0800 (Mon, 02 Feb 2015)
New Revision: 64401
Modified:
grass/trunk/lib/display/r_raster.c
Log:
libdisplay: implement GRASS_RENDER_COMMAND
prepare D_save_command() for removal
(work in progress)
Modified: grass/trunk/lib/display/r_raster.c
===================================================================
--- grass/trunk/lib/display/r_raster.c 2015-02-02 15:18:01 UTC (rev 64400)
+++ grass/trunk/lib/display/r_raster.c 2015-02-02 16:21:49 UTC (rev 64401)
@@ -3,7 +3,7 @@
\brief Display Library - Raster graphics subroutines
- (C) 2001-2014 by the GRASS Development Team
+ (C) 2001-2015 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.
@@ -24,6 +24,7 @@
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/display.h>
+#include <grass/spawn.h>
#include "driver.h"
@@ -34,8 +35,6 @@
extern const struct driver *Cairo_Driver(void);
#endif
-static int read_env_file(const char *);
-
static struct {
double t, b, l, r;
} screen;
@@ -71,79 +70,64 @@
COM_Get_window(&screen.t, &screen.b, &screen.l, &screen.r);
}
-int read_env_file(const char *path)
-{
- FILE *fd;
- char buf[1024];
- char **token;
-
- G_debug(1, "read_env_file(): %s", path);
-
- fd = fopen(path, "r");
- if (!fd)
- return -1;
-
- token = NULL;
- while (G_getl2(buf, sizeof(buf) - 1, fd) != 0) {
- token = G_tokenize(buf, "=");
- if (G_number_of_tokens(token) != 2)
- continue;
- G_debug(3, "\tread_env_file(): %s=%s", token[0], token[1]);
- G_putenv(token[0], token[1]);
- G_free_tokens(token);
- token = NULL;
- }
-
- return 0;
-}
-
/*!
\brief Open display driver
Default display driver is Cairo, if not available PNG is used.
\return 0 on success
- \return 1 no monitor defined
*/
int D_open_driver(void)
{
- const char *p, *m;
+ const char *p, *c, *m;
const struct driver *drv;
G_debug(1, "D_open_driver():");
p = getenv("GRASS_RENDER_IMMEDIATE");
+ c = getenv("GRASS_RENDER_COMMAND");
m = G_getenv_nofatal("MONITOR");
- if (m && G_strncasecmp(m, "wx", 2) == 0) {
- /* wx monitors always use GRASS_RENDER_IMMEDIATE. */
- p = NULL; /* use default display driver */
- }
- else if (m) {
- char *env;
- const char *v;
- char *u_m;
-
- if (p)
- G_warning(_("%s variable defined, %s ignored"),
- "MONITOR", "GRASS_RENDER_IMMEDIATE");
- /* GRASS variable names should be upper case. */
- u_m = G_store_upper(m);
+ if (!p && (m || c)) {
+ char *cmd;
+ char progname[GPATH_MAX];
- env = NULL;
- G_asprintf(&env, "MONITOR_%s_MAPFILE", u_m);
- v = G_getenv_nofatal(env);
- p = m;
-
- if (v)
- G_putenv("GRASS_RENDER_FILE", v);
+ cmd = G_recreate_command();
- G_asprintf(&env, "MONITOR_%s_ENVFILE", u_m);
- v = G_getenv_nofatal(env);
- if (v)
- read_env_file(v);
+ if (c && m) {
+ G_warning(_("Both %s and %s are defined. "
+ "%s will be ignored."),
+ "GRASS_RENDER_COMMAND", "MONITOR",
+ "MONITOR");
+ m = NULL;
+ }
+
+ if (c)
+ sprintf(progname, "%s", c);
+ else { /* monitors managed by d.mon -> call default renderer */
+ char element[GPATH_MAX];
+
+ G_temp_element(element);
+ strcat(element, "/");
+ strcat(element, "MONITORS");
+ strcat(element, "/");
+ strcat(element, m);
+ G_file_name(progname, element, "render.py", G_mapset());
+ }
+
+ /* assuming Python script here (could be extended in the future) */
+ G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
+ cmd, NULL);
+
+ G_free(cmd);
+
+ /* force exiting GRASS command, leave rendering on
+ * GRASS_RENDER_COMMAND program */
+ exit(0);
}
- else if (!p)
- G_fatal_error(_("Neither %s (managed by d.mon command) nor %s (used for direct rendering) defined"),
+
+ if (!p)
+ G_fatal_error(_("Neither %s (managed by d.mon command) nor %s "
+ "(used for direct rendering) defined"),
"MONITOR", "GRASS_RENDER_IMMEDIATE");
if (p && G_strcasecmp(p, "default") == 0)
@@ -186,62 +170,13 @@
}
/*!
- \brief Append command to the cmd file
+ \brief Append command to the cmd file (unused)
- Cmd file is created by d.mon by defining GRASS variable
- \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
- used to clean up list of commands (see d.erase command).
-
- \param cmd string buffer with command or NULL
-
- \return 0 no monitor selected
- \return -1 on error
- \return 1 on success
+ \todo To be removed
*/
int D_save_command(const char *cmd)
{
- const char *mon_name, *mon_cmd;
- char *env, *flag, *u_mon_name;
- FILE *fd;
-
- G_debug(1, "D_save_command(): %s", cmd);
-
- mon_name = G_getenv_nofatal("MONITOR");
- if (!mon_name || /* if no monitor selected */
- /* or wx monitor selected and display commands called by the monitor */
- (G_strncasecmp(mon_name, "wx", 2) == 0 &&
- getenv("GRASS_RENDER_IMMEDIATE")))
- return 0;
-
- /* GRASS variable names should be upper case. */
- u_mon_name = G_store_upper(mon_name);
-
- env = NULL;
- G_asprintf(&env, "MONITOR_%s_CMDFILE", u_mon_name);
- mon_cmd = G_getenv_nofatal(env);
- if (!mon_cmd)
- return 0;
-
- if (cmd)
- flag = "a";
- else
- flag = "w";
-
- fd = fopen(mon_cmd, flag);
- if (!fd) {
- G_warning(_("Unable to open file '%s'"), mon_cmd);
- return -1;
- }
-
- if (cmd)
- fprintf(fd, "%s\n", cmd);
-
- fclose(fd);
-
- return 1;
+ return 0;
}
/*!
More information about the grass-commit
mailing list