[GRASS-dev] r.out.png giving files a .png extension

I prepared a patch for r.out.png (see below) that ensures the output file always has a ".png" extension (if the user supplied output file name already contains .png that is OK - if not r.out.png will now add it). I will commit it in a few days unless anyone gives a good reason why someone might need r.out.png to create PNG files that don't have a .png extension.

Paul

Index: r.out.png.c

RCS file: /home/grass/grassrepository/grass6/raster/r.out.png/r.out.png.c,v
retrieving revision 2.5
diff -u -r2.5 r.out.png.c
--- r.out.png.c 28 Oct 2006 20:33:33 -0000 2.5
+++ r.out.png.c 31 Oct 2006 18:04:21 -0000
@@ -50,7 +50,7 @@
      struct GModule *module;
      struct Option *rast, *png_file;
      struct Flag *bequiet;
- char *cellmap, *map, *p, ofile[1000];
+ char *cellmap, *map, *p, *basename = NULL, *ofile;
      char rastermap[1024];
      unsigned char *set, *ored, *ogrn, *oblu;
      CELL *cell_buf;
@@ -141,7 +141,7 @@

      if (strcmp(png_file->answer, "<rasterfilename>.png")) {
         if (strcmp(png_file->answer, "-"))
- strncpy(ofile, png_file->answer, 1000 * sizeof(char));
+ basename = G_store(png_file->answer);
         else
             do_stdout = 1;
      }
@@ -152,8 +152,15 @@
             if (p != map)
                 *p = '\0';
         }
- strncpy(ofile, map, 995 * sizeof(char));
- strcat(ofile, ".png");
+ basename = G_store(map);
+ }
+
+ if(basename)
+ {
+ G_basename(basename, "png");
+ ofile = G_malloc(strlen(basename) + 5);
+ sprintf(ofile, "%s.png", basename);
+ G_free(basename);
      }

      /*G_get_set_window (&w); *//* 10/99 MN: check for current region */
@@ -187,6 +194,8 @@
             fp = stdout;
         else if (NULL == (fp = fopen(ofile, "w")))
             G_fatal_error("Not able to open file for [%s]", ofile);
+ else
+ G_free(ofile);
      }

      png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,