Quellcode durchsuchen

displaylib: document D_save_command + update for d.erase

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47073 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa vor 14 Jahren
Ursprung
Commit
486c809559
1 geänderte Dateien mit 27 neuen und 4 gelöschten Zeilen
  1. 27 4
      lib/display/r_raster.c

+ 27 - 4
lib/display/r_raster.c

@@ -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;