|
@@ -173,10 +173,25 @@ void D_close_driver(void)
|
|
|
system(cmd);
|
|
|
}
|
|
|
|
|
|
+/*!
|
|
|
+ \brief Append command to the cmd file
|
|
|
+
|
|
|
+ Cmd file is created by d.mon by defining GRASS variable
|
|
|
+ MONITOR_<name>_CMDFILE, where <name> is 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
|
|
|
+*/
|
|
|
int D_save_command(const char *cmd)
|
|
|
{
|
|
|
const char *mon_name, *mon_cmd;
|
|
|
- char *env;
|
|
|
+ char *env, *flag;
|
|
|
FILE *fd;
|
|
|
|
|
|
G_debug(1, "D_save_command(): %s", cmd);
|
|
@@ -190,13 +205,21 @@ int D_save_command(const char *cmd)
|
|
|
mon_cmd = G__getenv(env);
|
|
|
if (!mon_cmd)
|
|
|
return 0;
|
|
|
-
|
|
|
- fd = fopen(mon_cmd, "a");
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
- fprintf(fd, "%s\n", cmd);
|
|
|
+
|
|
|
+ if (cmd)
|
|
|
+ fprintf(fd, "%s\n", cmd);
|
|
|
+
|
|
|
fclose(fd);
|
|
|
|
|
|
return 1;
|