[GRASS-SVN] r44134 - in grass/branches/develbranch_6: include lib/gis raster/r.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 1 03:30:41 EDT 2010


Author: martinl
Date: 2010-11-01 00:30:41 -0700 (Mon, 01 Nov 2010)
New Revision: 44134

Removed:
   grass/branches/develbranch_6/lib/gis/color_print.c
Modified:
   grass/branches/develbranch_6/include/gisdefs.h
   grass/branches/develbranch_6/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())
(merge r44133 from trunk)


Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h	2010-11-01 07:23:49 UTC (rev 44133)
+++ grass/branches/develbranch_6/include/gisdefs.h	2010-11-01 07:30:41 UTC (rev 44134)
@@ -304,9 +304,6 @@
 /* color_org.c */
 int G__organize_colors(struct Colors *);
 
-/* color_print.c */
-int G_print_colors(const char *, const char *, FILE *);
-
 /* color_rand.c */
 int G_make_random_colors(struct Colors *, CELL, CELL);
 

Deleted: grass/branches/develbranch_6/lib/gis/color_print.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_print.c	2010-11-01 07:23:49 UTC (rev 44133)
+++ grass/branches/develbranch_6/lib/gis/color_print.c	2010-11-01 07:30:41 UTC (rev 44134)
@@ -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 G_print_colors(const char *name, const char *mapset, FILE *file)
-{
-    char element[512];
-    char xname[GNAME_MAX];
-        
-    strcpy(xname, name);
-    mapset = G_find_cell(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/branches/develbranch_6/raster/r.colors/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.colors/main.c	2010-11-01 07:23:49 UTC (rev 44133)
+++ grass/branches/develbranch_6/raster/r.colors/main.c	2010-11-01 07:30:41 UTC (rev 44134)
@@ -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.
@@ -33,6 +32,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];
@@ -47,6 +54,8 @@
     rules[nrules++] = G_store("grey.eq");
     rules[nrules++] = G_store("grey.log");
     rules[nrules++] = G_store("rules");
+
+    qsort(rules, nrules, sizeof(char *), cmp);
 }
 
 static char *rules_list(void)
@@ -138,7 +147,7 @@
 {
     int overwrite;
     int interactive;
-    int remove, print;
+    int remove;
     int have_colors;
     struct Colors colors, colors_tmp;
     struct Cell_stats statf;
@@ -152,8 +161,8 @@
     struct GModule *module;
     struct
     {
-	struct Flag *r, *w, *l, *g, *a, *e, *i, *q, *n, *p;
-    } flag;
+	struct Flag *r, *w, *l, *g, *a, *e, *i, *q, *n;
+   } flag;
     struct
     {
 	struct Option *map, *colr, *rast, *rules;
@@ -209,8 +218,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");
@@ -231,11 +239,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");
-
     flag.i = G_define_flag();
     flag.i->key = 'i';
     flag.i->description = _("Enter rules interactively");
@@ -263,7 +266,6 @@
     overwrite = !flag.w->answer;
     interactive = flag.i->answer;
     remove = flag.r->answer;
-    print = flag.p->answer;
     
     name = opt.map->answer;
 
@@ -274,8 +276,8 @@
     if (!name)
 	G_fatal_error(_("No raster map specified"));
 
-    if (!cmap && !style && !rules && !interactive && !remove && !print)
-	G_fatal_error(_("One of \"-i\", \"-p\" or \"-r\" or options \"color\", \"rast\" or \"rules\" must be specified!"));
+    if (!cmap && !style && !rules && !interactive && !remove)
+	G_fatal_error(_("One of \"-i\" or \"-r\" or options \"color\", \"rast\" or \"rules\" must be specified!"));
 
     if (interactive && (style || rules || cmap))
 	G_fatal_error(_("Interactive mode is incompatible with \"color\", \"rules\", and \"raster\" options"));
@@ -302,11 +304,6 @@
     if (mapset == NULL)
 	G_fatal_error(_("Raster map <%s> not found"), name);
 
-    if (print) {
-	G_print_colors(name, mapset, stdout);
-	return EXIT_SUCCESS;
-    }
-    
     if (remove) {
 	int stat = G_remove_colors(name, mapset);
 



More information about the grass-commit mailing list