|
@@ -2,6 +2,7 @@
|
|
|
#include <string.h>
|
|
|
#include <grass/gis.h>
|
|
|
#include <grass/spawn.h>
|
|
|
+#include <grass/display.h>
|
|
|
#include <grass/glocale.h>
|
|
|
|
|
|
#include "proto.h"
|
|
@@ -9,16 +10,43 @@
|
|
|
static void start(const char *, const char *);
|
|
|
static void start_wx(const char *, const char *, const char *,
|
|
|
const char *, int, int);
|
|
|
+static void error_handler(void *);
|
|
|
|
|
|
/* start file-based monitor */
|
|
|
void start(const char *name, const char *output)
|
|
|
{
|
|
|
char *env_name, output_path[GPATH_MAX];
|
|
|
+ const char *output_name;
|
|
|
|
|
|
- if (!output)
|
|
|
- return;
|
|
|
+ /* stop monitor on failure */
|
|
|
+ G_add_error_handler(error_handler, (char *)name);
|
|
|
+
|
|
|
+ if (!output) {
|
|
|
+ if (D_open_driver() != 0)
|
|
|
+ G_fatal_error(_("No graphics device selected. "
|
|
|
+ "Use d.mon to select graphics device."));
|
|
|
+ output_name = D_get_file();
|
|
|
+ if (!output_name)
|
|
|
+ return;
|
|
|
+ if (access(output_name, F_OK) == 0) {
|
|
|
+ if (G_get_overwrite()) {
|
|
|
+ G_warning(_("File '%s' already exists and will be overwritten"), output_name);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ D_close_driver();
|
|
|
+ G_fatal_error(_("option <%s>: <%s> exists."),
|
|
|
+ "output", output_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ D_close_driver(); /* must be called after check because this
|
|
|
+ * function produces default map file */
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ output_name = output;
|
|
|
+ }
|
|
|
|
|
|
- if (!strchr(output, HOST_DIRSEP)) { /* relative path */
|
|
|
+
|
|
|
+ if (!strchr(output_name, HOST_DIRSEP)) { /* relative path */
|
|
|
char *ptr;
|
|
|
|
|
|
if (!getcwd(output_path, GPATH_MAX))
|
|
@@ -28,13 +56,13 @@ void start(const char *name, const char *output)
|
|
|
*(ptr++) = HOST_DIRSEP;
|
|
|
*(ptr) = '\0';
|
|
|
}
|
|
|
- strcat(output_path, output);
|
|
|
+ strcat(output_path, output_name);
|
|
|
G_message(_("Output file: %s"), output_path);
|
|
|
}
|
|
|
else {
|
|
|
- strcpy(output_path, output); /* already full path */
|
|
|
+ strcpy(output_path, output_name); /* already full path */
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
env_name = NULL;
|
|
|
G_asprintf(&env_name, "MONITOR_%s_MAPFILE", G_store_upper(name));
|
|
|
G_setenv(env_name, output_path);
|
|
@@ -157,3 +185,9 @@ int start_mon(const char *name, const char *output, int select,
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+void error_handler(void *p)
|
|
|
+{
|
|
|
+ const char *name = (const char *) p;
|
|
|
+ stop_mon(name);
|
|
|
+}
|