[GRASS-SVN] r44133 - in grass/trunk: include lib/raster raster/r.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 1 03:23:49 EDT 2010


Author: martinl
Date: 2010-11-01 00:23:49 -0700 (Mon, 01 Nov 2010)
New Revision: 44133

Removed:
   grass/trunk/lib/raster/color_print.c
Modified:
   grass/trunk/include/rasterdefs.h
   grass/trunk/raster/r.colors/main.c
Log:
r.colors: remove `-p` (there is already r.colors.out)
          clean up raster library (no need for Rast_print_colors())


Modified: grass/trunk/include/rasterdefs.h
===================================================================
--- grass/trunk/include/rasterdefs.h	2010-10-31 17:38:43 UTC (rev 44132)
+++ grass/trunk/include/rasterdefs.h	2010-11-01 07:23:49 UTC (rev 44133)
@@ -174,9 +174,6 @@
 /* color_org.c */
 void Rast__organize_colors(struct Colors *);
 
-/* color_print.c */
-int Rast_print_colors(const char *, const char *, FILE *);
-
 /* color_rand.c */
 void Rast_make_random_colors(struct Colors *, CELL, CELL);
 

Deleted: grass/trunk/lib/raster/color_print.c
===================================================================
--- grass/trunk/lib/raster/color_print.c	2010-10-31 17:38:43 UTC (rev 44132)
+++ grass/trunk/lib/raster/color_print.c	2010-11-01 07:23:49 UTC (rev 44133)
@@ -1,70 +0,0 @@
-/*!
- * \file lib/gis/color_print.c
- *
- * \brief GIS Library - Print color table of raster map
- *
- * (C) 2010 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public License
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author Martin Landa <landa.martin gmail.com>
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <grass/gis.h>
-
-static int print_color_table(const char *, const char *, const char *, FILE *);
-
-/*!
-  \brief Print current color table of raster map to file
-
-  \param name name of raster map
-  \param mapset mapset of raster map
-  \param file file where to print color table
-
-  \return -1 on error (raster map not found)
-  \return -2 on error (reading color table failed)
-  \return 0 on success
-*/
-int Rast_print_colors(const char *name, const char *mapset, FILE *file)
-{
-    char element[512];
-    char xname[GNAME_MAX];
-        
-    strcpy(xname, name);
-    mapset = G_find_raster(xname, mapset);
-    if (!mapset)
-	return -1;
-    name = xname;
-    
-    /* first look for secondary color table in current mapset */
-    sprintf(element, "colr2/%s", mapset);
-    if (print_color_table(element, name, G_mapset(), file) < 0)
-	/* now look for the regular color table */
-	if (print_color_table("colr", name, mapset, file) < 0)
-	    return -2;
-    
-    return 0;
-}
-
-int print_color_table(const char *element, const char *name,
-		      const char *mapset, FILE *file)
-{
-    FILE *fd;
-    char buf[4096];
-    
-    fd = G_fopen_old(element, name, mapset);
-    if (!fd)
-	return -1;
-    
-    while(fgets(buf, sizeof(buf), fd)) {
-	fwrite(buf, strlen(buf), 1, file);
-    }
-    
-    fclose(fd);
-    
-    return 0;
-}

Modified: grass/trunk/raster/r.colors/main.c
===================================================================
--- grass/trunk/raster/r.colors/main.c	2010-10-31 17:38:43 UTC (rev 44132)
+++ grass/trunk/raster/r.colors/main.c	2010-11-01 07:23:49 UTC (rev 44133)
@@ -4,7 +4,6 @@
  *
  * AUTHOR(S):    Michael Shapiro - CERL
  *               David Johnson
- *               Print color table by Martin Landa <landa.martin gmail.com>
  *
  * PURPOSE:      Allows creation and/or modification of the color table
  *               for a raster map layer.
@@ -28,6 +27,14 @@
 static char **rules;
 static int nrules;
 
+static int cmp(const void *aa, const void *bb)
+{
+    char *const *a = (char *const *)aa;
+    char *const *b = (char *const *)bb;
+
+    return strcmp(*a, *b);
+}
+
 static void scan_rules(void)
 {
     char path[GPATH_MAX];
@@ -41,6 +48,8 @@
     rules[nrules++] = G_store("random");
     rules[nrules++] = G_store("grey.eq");
     rules[nrules++] = G_store("grey.log");
+
+    qsort(rules, nrules, sizeof(char *), cmp);
 }
 
 static char *rules_list(void)
@@ -131,7 +140,7 @@
 {
     int overwrite;
     int is_from_stdin;
-    int remove, print;
+    int remove;
     int have_colors;
     struct Colors colors, colors_tmp;
     struct Cell_stats statf;
@@ -145,7 +154,7 @@
     struct GModule *module;
     struct
     {
-	struct Flag *r, *w, *l, *g, *a, *e, *n, *p;
+	struct Flag *r, *w, *l, *g, *a, *e, *n;
     } flag;
     struct
     {
@@ -204,8 +213,7 @@
     flag.l = G_define_flag();
     flag.l->key = 'l';
     flag.l->description = _("List available rules then exit");
-    flag.l->guisection = _("Print");
-
+    
     flag.n = G_define_flag();
     flag.n->key = 'n';
     flag.n->description = _("Invert colors");
@@ -226,11 +234,6 @@
     flag.e->description = _("Histogram equalization");
     flag.e->guisection = _("Define");
 
-    flag.p = G_define_flag();
-    flag.p->key = 'p';
-    flag.p->description = _("Print current color table and exit");
-    flag.p->guisection = _("Print");
-    
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -241,7 +244,6 @@
 
     overwrite = !flag.w->answer;
     remove = flag.r->answer;
-    print = flag.p->answer;
     
     name = opt.map->answer;
     style = opt.colr->answer;
@@ -251,8 +253,8 @@
     if (!name)
 	G_fatal_error(_("No raster map specified"));
     
-    if (!cmap && !style && !rules && !remove && !print)
-	G_fatal_error(_("One of \"-r\", \"-p\" or options \"color\", \"raster\" or \"rules\" must be specified!"));
+    if (!cmap && !style && !rules && !remove)
+	G_fatal_error(_("One of \"-r\" or options \"color\", \"raster\" or \"rules\" must be specified!"));
 
     if (!!style + !!cmap + !!rules > 1)
 	G_fatal_error(_("\"color\", \"rules\", and \"raster\" options are mutually exclusive"));
@@ -268,11 +270,6 @@
     if (mapset == NULL)
 	G_fatal_error(_("Raster map <%s> not found"), name);
 
-    if (print) {
-	Rast_print_colors(name, mapset, stdout);
-	return EXIT_SUCCESS;
-    }
-    
     if (remove) {
 	int stat = Rast_remove_colors(name, mapset);
 



More information about the grass-commit mailing list