[GRASS-SVN] r47073 - grass/trunk/lib/display

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 9 10:06:44 EDT 2011


Author: martinl
Date: 2011-07-09 07:06:44 -0700 (Sat, 09 Jul 2011)
New Revision: 47073

Modified:
   grass/trunk/lib/display/r_raster.c
Log:
displaylib: document D_save_command + update for d.erase


Modified: grass/trunk/lib/display/r_raster.c
===================================================================
--- grass/trunk/lib/display/r_raster.c	2011-07-09 14:05:02 UTC (rev 47072)
+++ grass/trunk/lib/display/r_raster.c	2011-07-09 14:06:44 UTC (rev 47073)
@@ -173,10 +173,25 @@
 	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 @@
     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;



More information about the grass-commit mailing list