[GRASS-SVN] r67000 - grass/trunk/raster/r.mapcalc

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 1 13:53:43 PST 2015


Author: glynn
Date: 2015-12-01 13:53:43 -0800 (Tue, 01 Dec 2015)
New Revision: 67000

Modified:
   grass/trunk/raster/r.mapcalc/evaluate.c
   grass/trunk/raster/r.mapcalc/main.c
   grass/trunk/raster/r.mapcalc/map.c
   grass/trunk/raster/r.mapcalc/map3.c
   grass/trunk/raster/r.mapcalc/mapcalc.h
Log:
Add -l (list maps) flag (issue #2592)


Modified: grass/trunk/raster/r.mapcalc/evaluate.c
===================================================================
--- grass/trunk/raster/r.mapcalc/evaluate.c	2015-12-01 20:22:20 UTC (rev 66999)
+++ grass/trunk/raster/r.mapcalc/evaluate.c	2015-12-01 21:53:43 UTC (rev 67000)
@@ -362,4 +362,34 @@
     G_unset_error_routine();
 }
 
+void describe_maps(FILE *fp, expr_list *ee)
+{
+    expr_list *l;
+
+    fprintf(fp, "output=");
+
+    for (l = ee; l; l = l->next) {
+	expression *e = l->exp;
+	const char *var;
+
+	if (e->type != expr_type_binding && e->type != expr_type_function)
+	    G_fatal_error("internal error: execute: invalid type: %d",
+			  e->type);
+
+	initialize(e);
+
+	if (e->type != expr_type_binding)
+	    continue;
+
+	var = e->data.bind.var;
+        fprintf(fp, "%s%s", l != ee ? "," : "", var);
+    }
+
+    fprintf(fp, "\n");
+
+    fprintf(fp, "input=");
+    list_maps(fp, ",");
+    fprintf(fp, "\n");
+}
+
 /****************************************************************************/

Modified: grass/trunk/raster/r.mapcalc/main.c
===================================================================
--- grass/trunk/raster/r.mapcalc/main.c	2015-12-01 20:22:20 UTC (rev 66999)
+++ grass/trunk/raster/r.mapcalc/main.c	2015-12-01 21:53:43 UTC (rev 67000)
@@ -106,7 +106,7 @@
 {
     struct GModule *module;
     struct Option *expr, *file, *seed;
-    struct Flag *random;
+    struct Flag *random, *describe;
     int all_ok;
 
     G_gisinit(argv[0]);
@@ -140,6 +140,10 @@
     random->key = 's';
     random->description = _("Generate random seed (result is non-deterministic)");
 
+    describe = G_define_flag();
+    describe->key = 'l';
+    describe->description = _("List input and output maps");
+
     if (argc == 1)
     {
 	char **p = G_malloc(3 * sizeof(char *));
@@ -186,6 +190,11 @@
 	G_debug(3, "Generated random seed (-s): %ld", seed_value);
     }
 
+    if (describe->answer) {
+        describe_maps(stdout, result);
+        return EXIT_SUCCESS;
+    }
+
     pre_exec();
     execute(result);
     post_exec();

Modified: grass/trunk/raster/r.mapcalc/map.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map.c	2015-12-01 20:22:20 UTC (rev 66999)
+++ grass/trunk/raster/r.mapcalc/map.c	2015-12-01 21:53:43 UTC (rev 67000)
@@ -651,6 +651,16 @@
 #endif
 }
 
+void list_maps(FILE *fp, const char *sep)
+{
+    int i;
+
+    for (i = 0; i < num_maps; i++) {
+        const struct map *m = &maps[i];
+        fprintf(fp, "%s%s@%s", i ? sep : "", m->name, m->mapset);
+    }
+}
+
 /****************************************************************************/
 
 int check_output_map(const char *name)

Modified: grass/trunk/raster/r.mapcalc/map3.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map3.c	2015-12-01 20:22:20 UTC (rev 66999)
+++ grass/trunk/raster/r.mapcalc/map3.c	2015-12-01 21:53:43 UTC (rev 67000)
@@ -575,6 +575,16 @@
     num_maps = 0;
 }
 
+void list_maps(FILE *fp, const char *sep)
+{
+    int i;
+
+    for (i = 0; i < num_maps; i++) {
+        const struct map *m = &maps[i];
+        fprintf(fp, "%s%s@%s", i ? sep : "", m->name, m->mapset);
+    }
+}
+
 /****************************************************************************/
 
 int check_output_map(const char *name)

Modified: grass/trunk/raster/r.mapcalc/mapcalc.h
===================================================================
--- grass/trunk/raster/r.mapcalc/mapcalc.h	2015-12-01 20:22:20 UTC (rev 66999)
+++ grass/trunk/raster/r.mapcalc/mapcalc.h	2015-12-01 21:53:43 UTC (rev 67000)
@@ -38,6 +38,7 @@
 /* evaluate.c */
 
 extern void execute(expr_list *);
+extern void describe_maps(FILE *, expr_list *);
 
 /* map.c/map3.c */
 
@@ -49,6 +50,7 @@
 extern void get_map_row(int idx, int mod, int depth, int row, int col,
 			void *buf, int res_type);
 extern void close_maps(void);
+extern void list_maps(FILE *, const char *);
 
 extern int check_output_map(const char *name);
 extern int open_output_map(const char *name, int res_type);



More information about the grass-commit mailing list