[GRASS-SVN] r47044 - grass/trunk/display/d.mon
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 7 05:48:54 EDT 2011
Author: martinl
Date: 2011-07-07 02:48:54 -0700 (Thu, 07 Jul 2011)
New Revision: 47044
Modified:
grass/trunk/display/d.mon/list.c
grass/trunk/display/d.mon/main.c
grass/trunk/display/d.mon/proto.h
grass/trunk/display/d.mon/start.c
Log:
d.mon: new flag `-c` to list command for selected monitor
Modified: grass/trunk/display/d.mon/list.c
===================================================================
--- grass/trunk/display/d.mon/list.c 2011-07-07 09:09:55 UTC (rev 47043)
+++ grass/trunk/display/d.mon/list.c 2011-07-07 09:48:54 UTC (rev 47044)
@@ -66,3 +66,26 @@
return TRUE;
}
+
+/* list related commands for given monitor */
+void list_cmd(const char *name, FILE *fd_out)
+{
+ char buf[1024];
+ char *cmd_name;
+ const char *cmd_value;
+ FILE *fd;
+
+ cmd_name = NULL;
+ G_asprintf(&cmd_name, "MONITOR_%s_CMDFILE", name);
+ cmd_value = G__getenv(cmd_name);
+ if (!cmd_value)
+ G_fatal_error(_("Command file not found"));
+
+ fd = fopen(cmd_value, "r");
+ if (!fd)
+ G_fatal_error(_("Unable to read command file"));
+
+ while (G_getl2(buf, sizeof(buf) - 1, fd) != 0) {
+ fprintf(fd_out, "%s\n", buf);
+ }
+}
Modified: grass/trunk/display/d.mon/main.c
===================================================================
--- grass/trunk/display/d.mon/main.c 2011-07-07 09:09:55 UTC (rev 47043)
+++ grass/trunk/display/d.mon/main.c 2011-07-07 09:48:54 UTC (rev 47044)
@@ -3,8 +3,8 @@
*
* MODULE: d.mon
* AUTHOR(S): Martin Landa <landa.martin gmail.com>
- * PURPOSE: Controls map displays
- * COPYRIGHT: (C) 2011 by the GRASS Development Team
+ * PURPOSE: Controls graphics monitors for CLI
+ * COPYRIGHT: (C) 2011 by Martin Landa, and the GRASS Development Team
*
* This program is free software under the GNU General
* Public License (>=v2). Read the file COPYING that
@@ -25,7 +25,8 @@
struct GModule *module;
struct Option *start_opt, *select_opt, *stop_opt, *output_opt,
*width_opt, *height_opt, *bgcolor_opt;
- struct Flag *list_flag, *selected_flag, *select_flag, *release_flag;
+ struct Flag *list_flag, *selected_flag, *select_flag, *release_flag,
+ *cmd_flag;
int nopts, ret;
const char *mon;
@@ -93,6 +94,11 @@
selected_flag->description = _("Print name of currently selected monitor and exit");
selected_flag->guisection = _("Print");
+ cmd_flag = G_define_flag();
+ cmd_flag->key = 'c';
+ cmd_flag->description = _("Print commands for currently selected monitor and exit");
+ cmd_flag->guisection = _("Print");
+
select_flag = G_define_flag();
select_flag->key = 's';
select_flag->description = _("Do not automatically select when starting");
@@ -106,21 +112,25 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- if (selected_flag->answer || release_flag->answer) {
+ if (selected_flag->answer || release_flag->answer || cmd_flag->answer) {
if (list_flag->answer)
G_warning(_("Flag -%c ignored"), list_flag->key);
mon = G__getenv("MONITOR");
- if (selected_flag->answer) {
- if (mon) {
+ if (mon) {
+ if (selected_flag->answer) {
G_message(_("Currently selected monitor:"));
fprintf(stdout, "%s\n", mon);
}
+ else if (cmd_flag->answer) {
+ G_message(_("List of commands for monitor <%s>:"), mon);
+ list_cmd(mon, stdout);
+ }
+ else if (mon) { /* release */
+ G_unsetenv("MONITOR");
+ G_verbose_message(_("Monitor <%s> released"), mon);
+ }
}
- else if (mon) {
- G_unsetenv("MONITOR");
- G_verbose_message(_("Monitor <%s> released"), mon);
- }
- if (!mon)
+ else
G_important_message(_("No monitor selected"));
exit(EXIT_SUCCESS);
Modified: grass/trunk/display/d.mon/proto.h
===================================================================
--- grass/trunk/display/d.mon/proto.h 2011-07-07 09:09:55 UTC (rev 47043)
+++ grass/trunk/display/d.mon/proto.h 2011-07-07 09:48:54 UTC (rev 47044)
@@ -11,3 +11,4 @@
void list_mon();
void print_list(FILE *);
int check_mon(const char *);
+void list_cmd(const char *, FILE *);
Modified: grass/trunk/display/d.mon/start.c
===================================================================
--- grass/trunk/display/d.mon/start.c 2011-07-07 09:09:55 UTC (rev 47043)
+++ grass/trunk/display/d.mon/start.c 2011-07-07 09:48:54 UTC (rev 47044)
@@ -8,7 +8,7 @@
static void start(const char *, const char *);
static void start_wx(const char *, const char *, const char *,
- const char *, const char *);
+ const char *, const char *, const char *);
/* start file-based monitor */
void start(const char *name, const char *output)
@@ -24,24 +24,19 @@
}
/* start wxGUI display monitor */
-void start_wx(const char *name, const char *tempfile, const char *env_value,
+void start_wx(const char *name, const char *tempfile,
+ const char *env_value, const char *cmd_value,
const char *width, const char *height)
{
char progname[GPATH_MAX];
- char *env_name, *map_value, *cmd_value;
+ char *env_name, *map_value;
env_name = NULL;
- G_asprintf(&env_name, "MONITOR_%s_CMDFILE", name);
- G_asprintf(&cmd_value, "%s.cmd", tempfile);
- G_setenv(env_name, cmd_value);
- close(creat(cmd_value, 0666));
-
G_asprintf(&env_name, "MONITOR_%s_MAPFILE", name);
G_asprintf(&map_value, "%s.ppm", tempfile);
G_setenv(env_name, map_value);
/* close(creat(map_value, 0666)); */
- G_debug(3, " cmdfile = %s", cmd_value);
G_debug(3, " mapfile = %s", map_value);
sprintf(progname, "%s/etc/gui/wxpython/gui_modules/mapdisp.py", G_gisbase());
@@ -53,7 +48,7 @@
const char *width, const char *height, const char *bgcolor)
{
const char *curr_mon;
- char *env_name, *env_value;
+ char *env_name, *env_value, *cmd_value;
char *tempfile, buf[1024];
int env_fd;
@@ -87,16 +82,24 @@
}
close(env_fd);
+ cmd_value = NULL;
+ G_asprintf(&env_name, "MONITOR_%s_CMDFILE", name);
+ G_asprintf(&cmd_value, "%s.cmd", tempfile);
+ G_setenv(env_name, cmd_value);
+ close(creat(cmd_value, 0666));
+
G_verbose_message(_("Staring monitor <%s> with env file '%s'"), name, env_value);
G_debug(1, "start: name=%s ", name);
G_debug(3, " envfile = %s", env_value);
-
+ G_debug(3, " cmdfile = %s", cmd_value);
+
if (select)
G_setenv("MONITOR", name);
if (strncmp(name, "wx", 2) == 0) /* use G_strncasecmp() instead */
- start_wx(name, tempfile, env_value, width, height);
+ start_wx(name, tempfile, env_value, cmd_value,
+ width, height);
else
start(name, output);
More information about the grass-commit
mailing list