Sfoglia il codice sorgente

d.legend: run indent script

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68700 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 9 anni fa
parent
commit
41e2a7146e
5 ha cambiato i file con 1239 aggiunte e 1205 eliminazioni
  1. 836 802
      display/d.legend/draw.c
  2. 90 89
      display/d.legend/get_stats.c
  3. 196 191
      display/d.legend/histogram.c
  4. 17 17
      display/d.legend/local_proto.h
  5. 100 106
      display/d.legend/main.c

File diff suppressed because it is too large
+ 836 - 802
display/d.legend/draw.c


+ 90 - 89
display/d.legend/get_stats.c

@@ -7,18 +7,18 @@
 
 
 void run_stats(const char *mapname, int nsteps, const char *tempfile,
-	       int map_type)
+               int map_type)
 {
     char buf[32];
     const char *argv[12];
     int argc = 0;
 
     if (map_type == MAP_TYPE_RASTER2D) {
-	argv[argc++] = "r.stats";
-	argv[argc++] = "-r";
+        argv[argc++] = "r.stats";
+        argv[argc++] = "-r";
     }
     else
-	argv[argc++] = "r3.stats";
+        argv[argc++] = "r3.stats";
 
     argv[argc++] = "-c";
     argv[argc++] = mapname;
@@ -34,42 +34,43 @@ void run_stats(const char *mapname, int nsteps, const char *tempfile,
     argv[argc++] = NULL;
 
     if (G_vspawn_ex(argv[0], argv) != 0)
-	G_fatal_error("error running r.stats");
+        G_fatal_error("error running r.stats");
 }
 
 /* linked list of stats */
 void get_stats(const char *mapname, struct stat_list *dist_stats, int nsteps,
-	       int map_type)
+               int map_type)
 {
-    char buf[1024];		/* input buffer for reading stats */
+    char buf[1024];             /* input buffer for reading stats */
     int done = FALSE;
-    char *tempfile;		/* temp file name */
-    FILE *fd;			/* temp file pointer */
-/*
-    int is_fp;
-    struct FPRange fp_range;
-*/
-    long int cat;		/* a category value */
-    long int stat;		/* a category stat value */
+    char *tempfile;             /* temp file name */
+    FILE *fd;                   /* temp file pointer */
+
+    /*
+       int is_fp;
+       struct FPRange fp_range;
+     */
+    long int cat;               /* a category value */
+    long int stat;              /* a category stat value */
     struct stat_node *ptr = NULL;
     int first;
 
     /* write stats to a temp file */
     tempfile = G_tempfile();
-/*
-    is_fp = Rast_map_is_fp(mapname, "");
-    if (is_fp) {
-	if (Rast_read_fp_range(mapname, "", &fp_range) <= 0)
-	    G_fatal_error("Can't read frange file");
-    }
-*/
+    /*
+       is_fp = Rast_map_is_fp(mapname, "");
+       if (is_fp) {
+       if (Rast_read_fp_range(mapname, "", &fp_range) <= 0)
+       G_fatal_error("Can't read frange file");
+       }
+     */
     run_stats(mapname, nsteps, tempfile, map_type);
 
     /* open temp file and read the stats into a linked list */
     fd = fopen(tempfile, "r");
     if (fd == NULL) {
-	perror("opening r.stats output file");
-	G_fatal_error("unable to continue.");
+        perror("opening r.stats output file");
+        G_fatal_error("unable to continue.");
     }
     dist_stats->ptr = NULL;
     dist_stats->count = 0;
@@ -78,71 +79,71 @@ void get_stats(const char *mapname, struct stat_list *dist_stats, int nsteps,
     first = TRUE;
 
     while (!done) {
-	if (fgets(buf, sizeof(buf), fd) != NULL) {
-	    /* WARNING!!!!!!
-	     * this will be very wrong if type!=COUNT
-	     * since the stat prodcued by r.stats will be a floating point value
-	     * possibly less than 1 (shapiro)
-	     */
-	    if (sscanf(buf, "* %ld", &stat) == 1) {
-		dist_stats->null_stat = stat;
-/*
-		if (stat > dist_stats->maxstat && nodata)
-		    dist_stats->maxstat = stat;
-		if (stat < dist_stats->minstat && nodata)
-		    dist_stats->minstat = stat;
-		if (nodata)
-		    dist_stats->sumstat += stat;
-*/
-	    }
-	    else if (sscanf(buf, "%ld %ld", &cat, &stat) == 2) {
-		/* count stats */
-		dist_stats->count++;
-
-		/* sum stats */
-		dist_stats->sumstat += stat;
-
-		/* a max or a min stat? */
-		if (first) {
-		    dist_stats->maxstat = stat;
-		    dist_stats->minstat = stat;
-		    dist_stats->maxcat = cat;
-		    dist_stats->mincat = cat;
-		    first = FALSE;
-		}
-		if (stat > dist_stats->maxstat)
-		    dist_stats->maxstat = stat;
-		if (stat < dist_stats->minstat)
-		    dist_stats->minstat = stat;
-
-		/* a max or a min cat? */
-		if (cat > dist_stats->maxcat)
-		    dist_stats->maxcat = cat;
-		if (cat < dist_stats->mincat)
-		    dist_stats->mincat = cat;
-
-		/* put it in the list */
-		if (dist_stats->ptr == NULL) {
-		    /* first in list */
-		    dist_stats->ptr = (struct stat_node *)
-			G_malloc(sizeof(struct stat_node));
-		    dist_stats->ptr->cat = cat;
-		    dist_stats->ptr->stat = stat;
-		    dist_stats->ptr->next = NULL;
-		    ptr = dist_stats->ptr;
-		}
-		else {
-		    ptr->next = (struct stat_node *)
-			G_malloc(sizeof(struct stat_node));
-		    ptr->next->cat = cat;
-		    ptr->next->stat = stat;
-		    ptr->next->next = NULL;	/* mod: shapiro */
-		    ptr = ptr->next;
-		}
-	    }
-	}
-	else
-	    done = TRUE;
+        if (fgets(buf, sizeof(buf), fd) != NULL) {
+            /* WARNING!!!!!!
+             * this will be very wrong if type!=COUNT
+             * since the stat prodcued by r.stats will be a floating point value
+             * possibly less than 1 (shapiro)
+             */
+            if (sscanf(buf, "* %ld", &stat) == 1) {
+                dist_stats->null_stat = stat;
+                /*
+                   if (stat > dist_stats->maxstat && nodata)
+                   dist_stats->maxstat = stat;
+                   if (stat < dist_stats->minstat && nodata)
+                   dist_stats->minstat = stat;
+                   if (nodata)
+                   dist_stats->sumstat += stat;
+                 */
+            }
+            else if (sscanf(buf, "%ld %ld", &cat, &stat) == 2) {
+                /* count stats */
+                dist_stats->count++;
+
+                /* sum stats */
+                dist_stats->sumstat += stat;
+
+                /* a max or a min stat? */
+                if (first) {
+                    dist_stats->maxstat = stat;
+                    dist_stats->minstat = stat;
+                    dist_stats->maxcat = cat;
+                    dist_stats->mincat = cat;
+                    first = FALSE;
+                }
+                if (stat > dist_stats->maxstat)
+                    dist_stats->maxstat = stat;
+                if (stat < dist_stats->minstat)
+                    dist_stats->minstat = stat;
+
+                /* a max or a min cat? */
+                if (cat > dist_stats->maxcat)
+                    dist_stats->maxcat = cat;
+                if (cat < dist_stats->mincat)
+                    dist_stats->mincat = cat;
+
+                /* put it in the list */
+                if (dist_stats->ptr == NULL) {
+                    /* first in list */
+                    dist_stats->ptr = (struct stat_node *)
+                        G_malloc(sizeof(struct stat_node));
+                    dist_stats->ptr->cat = cat;
+                    dist_stats->ptr->stat = stat;
+                    dist_stats->ptr->next = NULL;
+                    ptr = dist_stats->ptr;
+                }
+                else {
+                    ptr->next = (struct stat_node *)
+                        G_malloc(sizeof(struct stat_node));
+                    ptr->next->cat = cat;
+                    ptr->next->stat = stat;
+                    ptr->next->next = NULL;     /* mod: shapiro */
+                    ptr = ptr->next;
+                }
+            }
+        }
+        else
+            done = TRUE;
     }
     fclose(fd);
     unlink(tempfile);

+ 196 - 191
display/d.legend/histogram.c

@@ -14,13 +14,13 @@
 #include "local_proto.h"
 
 double histogram(const char *map_name, int x0, int y0, int width,
-            int height, int color, int flip, int horiz, int map_type,
-            int is_fp, struct FPRange render_range, int drawh)
+                 int height, int color, int flip, int horiz, int map_type,
+                 int is_fp, struct FPRange render_range, int drawh)
 {
     int i, nsteps, ystep;
     long cell_count = 0;
     double max_width, width_mult, dx, max;
-    double dy, y0_adjust;	/* only needed for CELL maps */
+    double dy, y0_adjust;       /* only needed for CELL maps */
     struct stat_list dist_stats;
     struct stat_node *ptr;
     struct Range range;
@@ -31,12 +31,12 @@ double histogram(const char *map_name, int x0, int y0, int width,
     double crop_min_perc = 0.0, crop_max_perc = 1.0, pad_min_perc = 0.0;
 
     if (horiz) {
-	max_width = height * 1.75;
-	nsteps = width - 3;
+        max_width = height * 1.75;
+        nsteps = width - 3;
     }
     else {
-	max_width = width * 1.75;
-	nsteps = height - 3;
+        max_width = width * 1.75;
+        nsteps = height - 3;
     }
 
     /* reset return value max */
@@ -44,73 +44,77 @@ double histogram(const char *map_name, int x0, int y0, int width,
 
 
     if (render_range.first_time) {
-	/* user specified range, can be either larger
-	    or smaller than actual map's range */
-
-	if (is_fp) {
-	    Rast_read_fp_range(map_name, "", &fprange);
-	    Rast_get_fp_range_min_max(&fprange, &d_map_min, &d_map_max);
-	    map_min = (double)d_map_min;
-	    map_max = (double)d_map_max;
-	}
-	else {
-	    Rast_read_range(map_name, "", &range);
-	    Rast_get_range_min_max(&range, &c_map_min, &c_map_max);
-	    map_min = (double)c_map_min;
-	    map_max = (double)c_map_max;
-	}
-
-	map_range = map_max - map_min;
-	user_range = render_range.max - render_range.min;
-
-	if (horiz)
-	    nsteps = (int)(0.5 + (map_range * (width - 3) / user_range));
-	else
-	    nsteps = (int)(0.5 + (map_range * (height - 3) / user_range));
-
-	G_debug(1, "number of steps for r.stats = %d, height-3=%d  width-3=%d",
-		nsteps, height - 3, width - 3);
-
-	/* need to know the % of the MAP range where user range starts and stops.
-	 *   note that MAP range can be fully inside user range, in which case
-	 *   keep 0-100% aka 0,nsteps, i.e. the step number in the nsteps range */
-
-	if (render_range.min > map_min) {
-	   crop_min_perc = (render_range.min - map_min) / map_range;
-	   G_debug(3, "min: %.02f vs. %.02f (%.02f) ... %.02f%%",
-	   	   render_range.min, map_min, map_range, 100 * crop_min_perc);
-	}
-
-	if (render_range.max > map_max) {
-	    crop_max_perc = 1.0 - ((render_range.max - map_max) / user_range);
-	    G_debug(3, "max: %.02f vs. %.02f (%.02f) ... %.02f%%",
-		    map_max, render_range.max, map_range, 100 * crop_max_perc);
-	}
-
-	if (render_range.min < map_min) {
-	   pad_min_perc = (map_min - render_range.min) / user_range;
-	   G_debug(3, "Min: %.02f vs. %.02f (%.02f) ... %.02f%%",
-	   	   map_min, render_range.min, user_range, 100 * pad_min_perc);
-	}
+        /* user specified range, can be either larger
+           or smaller than actual map's range */
+
+        if (is_fp) {
+            Rast_read_fp_range(map_name, "", &fprange);
+            Rast_get_fp_range_min_max(&fprange, &d_map_min, &d_map_max);
+            map_min = (double)d_map_min;
+            map_max = (double)d_map_max;
+        }
+        else {
+            Rast_read_range(map_name, "", &range);
+            Rast_get_range_min_max(&range, &c_map_min, &c_map_max);
+            map_min = (double)c_map_min;
+            map_max = (double)c_map_max;
+        }
+
+        map_range = map_max - map_min;
+        user_range = render_range.max - render_range.min;
+
+        if (horiz)
+            nsteps = (int)(0.5 + (map_range * (width - 3) / user_range));
+        else
+            nsteps = (int)(0.5 + (map_range * (height - 3) / user_range));
+
+        G_debug(1,
+                "number of steps for r.stats = %d, height-3=%d  width-3=%d",
+                nsteps, height - 3, width - 3);
+
+        /* need to know the % of the MAP range where user range starts and stops.
+         *   note that MAP range can be fully inside user range, in which case
+         *   keep 0-100% aka 0,nsteps, i.e. the step number in the nsteps range */
+
+        if (render_range.min > map_min) {
+            crop_min_perc = (render_range.min - map_min) / map_range;
+            G_debug(3, "min: %.02f vs. %.02f (%.02f) ... %.02f%%",
+                    render_range.min, map_min, map_range,
+                    100 * crop_min_perc);
+        }
+
+        if (render_range.max > map_max) {
+            crop_max_perc = 1.0 - ((render_range.max - map_max) / user_range);
+            G_debug(3, "max: %.02f vs. %.02f (%.02f) ... %.02f%%",
+                    map_max, render_range.max, map_range,
+                    100 * crop_max_perc);
+        }
+
+        if (render_range.min < map_min) {
+            pad_min_perc = (map_min - render_range.min) / user_range;
+            G_debug(3, "Min: %.02f vs. %.02f (%.02f) ... %.02f%%",
+                    map_min, render_range.min, user_range,
+                    100 * pad_min_perc);
+        }
 
 #ifdef amplify_gain
-	/* proportion of nsteps to width, use as mult factor to boost the 1.75x
-	    when spread out over more nsteps than we are displaying */
-	G_debug(0, "max_width was: %.2f  (nsteps=%d)", max_width, nsteps);
+        /* proportion of nsteps to width, use as mult factor to boost the 1.75x
+           when spread out over more nsteps than we are displaying */
+        G_debug(0, "max_width was: %.2f  (nsteps=%d)", max_width, nsteps);
 
-	if (nsteps > ((horiz ? width : height) - 3.0))
-	    max_width *= nsteps / ((horiz ? width : height) - 3.0);
+        if (nsteps > ((horiz ? width : height) - 3.0))
+            max_width *= nsteps / ((horiz ? width : height) - 3.0);
 
-	G_debug(0, "max_width now: %.2f", max_width);
+        G_debug(0, "max_width now: %.2f", max_width);
 #endif
     }
 
 
     /* TODO */
     if (!is_fp && render_range.first_time) {
-	G_warning(_("Histogram constrained by range not yet implemented for "
-		  "categorical rasters"));
-	return max;
+        G_warning(_("Histogram constrained by range not yet implemented for "
+                    "categorical rasters"));
+        return max;
     }
 
 
@@ -121,145 +125,146 @@ double histogram(const char *map_name, int x0, int y0, int width,
     ptr = dist_stats.ptr;
 
     if (drawh) {
-    D_use_color(color);
-    D_begin();
+        D_use_color(color);
+        D_begin();
 
-    if (!is_fp) {
-	dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat);
+        if (!is_fp) {
+            dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat);
 
-	if (flip)
-	    dy *= -1;
+            if (flip)
+                dy *= -1;
 
-	if (dist_stats.mincat == 0)
-	    y0_adjust = dy;
-	else
-	    y0_adjust = 0;
+            if (dist_stats.mincat == 0)
+                y0_adjust = dy;
+            else
+                y0_adjust = 0;
 
-	if (!flip)  /* mmph */
-	    y0_adjust += 0.5;
-    }
+            if (!flip)          /* mmph */
+                y0_adjust += 0.5;
+        }
     }
 
 
-    G_debug(3, "mincat=%ld  maxcat=%ld", dist_stats.mincat, dist_stats.maxcat);
+    G_debug(3, "mincat=%ld  maxcat=%ld", dist_stats.mincat,
+            dist_stats.maxcat);
 
     for (i = dist_stats.mincat, ystep = 0; i <= dist_stats.maxcat; i++) {
-	if (!ptr)
-	    break;
-
-	/* jump out if user range cuts things shorter than the map's native range */
-	if ((horiz && ystep > width - 4) || (!horiz && ystep > height - 4))
-	    break;
-
-	/* jump out if user range goes beyond max of map data */
-	if (((double)ystep / ((horiz ? width : height) - 3.0)) > crop_max_perc)
-	    break;
-/* TODO	if (!is_fp && i > render_range.max)
-	    break;
-*/
-	/* haven't made it to the min of the user range yet */
-	if (((double)i / nsteps) < crop_min_perc) {
-	    continue;
-	}
-
-	/* now it's ok advance the plotter position */
-	ystep++;
-
-	/* if user range is below the minimum real map value, we need to pad out the space */
-	if (render_range.first_time && render_range.min < map_min) {
-	    if ( ((double)ystep / ((horiz ? width : height) - 3.0)) < pad_min_perc) {
-		i--;
-		continue;
-	    }
-	}
-
-	if (ptr->cat == i) {	/* AH-HA!! found the stat */
-	    cell_count = ptr->stat;
-
-	    if (ptr->next != NULL)
-		ptr = ptr->next;
-	}
-	else {			/* we have to look for the stat */
-
-	    /* loop until we find it, or pass where it should be */
-	    while (ptr->cat < i && ptr->next != NULL)
-		ptr = ptr->next;
-	    if (ptr->cat == i) {	/* AH-HA!! found the stat */
-		cell_count = ptr->stat;
-
-		if (ptr->next != NULL)
-		    ptr = ptr->next;
-	    }
-	    else		/* stat cannot be found */
-		G_debug(5, "No matching stat found, i=%d", i);
-	}
-
-	G_debug(5, "i=%d  ptr->cat=%ld  cell_count=%ld", i, ptr->cat, 
-		cell_count);
-
-	if (!cell_count)
-	    continue;
-
-	dx = cell_count * width_mult;
-
-    if (drawh){
-	if (is_fp) {
-	    if (horiz) {
-		if (flip)
-		    D_move_abs(x0 + width - ystep - 1, y0 - 1);
-		else
-		    D_move_abs(x0 + ystep + 1, y0 - 1);
-
-		D_cont_rel(0, -dx);
-	    }
-	    else {  /* vertical */
-		if (flip)
-		    D_move_abs(x0 - 1, y0 - 1 + height - ystep);
-		else
-		    D_move_abs(x0 - 1, y0 + 1 + ystep);
-
-		D_cont_rel(-dx, 0);
-	    }
-	}
-	else {	/* categorical */
-
-	    if (horiz) {
-		if (flip)
-		    D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy),
-			      y0 - 1,
-			      x0 + width + y0_adjust + 1 + (i * dy),
-			      y0 - 1 - dx);
-		else
-		    D_box_abs(x0 + y0_adjust + ((i - 1) * dy),
-			      y0 - 1,
-			      x0 - 1 + y0_adjust + (i * dy),
-			      y0 - 1 - dx);
-	    }
-	    else {  /* vertical */
-
-		if (flip)
-		    /* GRASS_EPSILON fudge around D_box_abs() weirdness + PNG driver */
-		    D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
-			      y0 + height + y0_adjust + ((i - 1) * dy),
-			      x0 - 1 - dx,
-			      y0 + height + y0_adjust + 1 + (i * dy));
-		else
-		    D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
-			      y0 + y0_adjust + ((i - 1) * dy),
-			      x0 - 1 - dx,
-			      y0 + y0_adjust - 1 + (i * dy));
-	    }
-	}
-    }
-    if (dx > max)
-        max = dx;
+        if (!ptr)
+            break;
+
+        /* jump out if user range cuts things shorter than the map's native range */
+        if ((horiz && ystep > width - 4) || (!horiz && ystep > height - 4))
+            break;
+
+        /* jump out if user range goes beyond max of map data */
+        if (((double)ystep / ((horiz ? width : height) - 3.0)) >
+            crop_max_perc)
+            break;
+        /* TODO if (!is_fp && i > render_range.max)
+           break;
+         */
+        /* haven't made it to the min of the user range yet */
+        if (((double)i / nsteps) < crop_min_perc) {
+            continue;
+        }
+
+        /* now it's ok advance the plotter position */
+        ystep++;
+
+        /* if user range is below the minimum real map value, we need to pad out the space */
+        if (render_range.first_time && render_range.min < map_min) {
+            if (((double)ystep / ((horiz ? width : height) - 3.0)) <
+                pad_min_perc) {
+                i--;
+                continue;
+            }
+        }
+
+        if (ptr->cat == i) {    /* AH-HA!! found the stat */
+            cell_count = ptr->stat;
+
+            if (ptr->next != NULL)
+                ptr = ptr->next;
+        }
+        else {                  /* we have to look for the stat */
+
+            /* loop until we find it, or pass where it should be */
+            while (ptr->cat < i && ptr->next != NULL)
+                ptr = ptr->next;
+            if (ptr->cat == i) {        /* AH-HA!! found the stat */
+                cell_count = ptr->stat;
+
+                if (ptr->next != NULL)
+                    ptr = ptr->next;
+            }
+            else                /* stat cannot be found */
+                G_debug(5, "No matching stat found, i=%d", i);
+        }
+
+        G_debug(5, "i=%d  ptr->cat=%ld  cell_count=%ld", i, ptr->cat,
+                cell_count);
+
+        if (!cell_count)
+            continue;
+
+        dx = cell_count * width_mult;
+
+        if (drawh) {
+            if (is_fp) {
+                if (horiz) {
+                    if (flip)
+                        D_move_abs(x0 + width - ystep - 1, y0 - 1);
+                    else
+                        D_move_abs(x0 + ystep + 1, y0 - 1);
+
+                    D_cont_rel(0, -dx);
+                }
+                else {          /* vertical */
+                    if (flip)
+                        D_move_abs(x0 - 1, y0 - 1 + height - ystep);
+                    else
+                        D_move_abs(x0 - 1, y0 + 1 + ystep);
+
+                    D_cont_rel(-dx, 0);
+                }
+            }
+            else {              /* categorical */
+
+                if (horiz) {
+                    if (flip)
+                        D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy),
+                                  y0 - 1,
+                                  x0 + width + y0_adjust + 1 + (i * dy),
+                                  y0 - 1 - dx);
+                    else
+                        D_box_abs(x0 + y0_adjust + ((i - 1) * dy),
+                                  y0 - 1,
+                                  x0 - 1 + y0_adjust + (i * dy), y0 - 1 - dx);
+                }
+                else {          /* vertical */
+
+                    if (flip)
+                        /* GRASS_EPSILON fudge around D_box_abs() weirdness + PNG driver */
+                        D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
+                                  y0 + height + y0_adjust + ((i - 1) * dy),
+                                  x0 - 1 - dx,
+                                  y0 + height + y0_adjust + 1 + (i * dy));
+                    else
+                        D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
+                                  y0 + y0_adjust + ((i - 1) * dy),
+                                  x0 - 1 - dx, y0 + y0_adjust - 1 + (i * dy));
+                }
+            }
+        }
+        if (dx > max)
+            max = dx;
     }
 
     if (drawh) {
-    D_close();
-    D_end();
-    D_stroke();
-}
+        D_close();
+        D_end();
+        D_stroke();
+    }
 
     return max;
 }

+ 17 - 17
display/d.legend/local_proto.h

@@ -3,9 +3,9 @@
 #define MAP_TYPE_RASTER2D 1
 #define MAP_TYPE_RASTER3D 2
 /* possibles for the future:
-#define MAP_TYPE_VECTOR 3
-#define MAP_TYPE_RULES 4
-*/
+   #define MAP_TYPE_VECTOR 3
+   #define MAP_TYPE_RULES 4
+ */
 
 struct stat_node
 {
@@ -30,25 +30,25 @@ struct stat_list
 
 /* histogram.c */
 double histogram(const char *, int, int, int, int, int, int, int, int,
-            int, struct FPRange, int);
+                 int, struct FPRange, int);
 
 /* get_stats.c */
 void get_stats(const char *, struct stat_list *, int, int);
 void run_stats(const char *, int, const char *, int);
 
 /* background.c */
-void background(const char *, int, int, int, int, int, int, int, int, int, int,
-                int, int, struct Categories, struct Colors, double, double, double,
-                double, int, int, double, double, double *, int, int, int, double,
-                double, const char *, double *, double, int, int, struct Option *,
-                struct Option *, struct Option *, struct Option *, struct Option *,
-                struct Option *, struct Flag *, struct Flag *);
+void background(const char *, int, int, int, int, int, int, int, int, int,
+                int, int, int, struct Categories, struct Colors, double,
+                double, double, double, int, int, double, double, double *,
+                int, int, int, double, double, const char *, double *, double,
+                int, int, struct Option *, struct Option *, struct Option *,
+                struct Option *, struct Option *, struct Option *,
+                struct Flag *, struct Flag *);
 
 /* draw.c */
-void draw(const char *, int, int, int, int, int, int, int, int, int, int, int, int,
-          struct Categories, struct Colors, double, double, double, double, int, int,
-          double, double, double *, int, int, int, double, double ,const char *,
-          double *, double, int, int, struct Option *, struct Option *, struct Option *,
-          struct Option *, struct Option *, struct Option *, struct Flag *,
-          struct Flag *, int);
-
+void draw(const char *, int, int, int, int, int, int, int, int, int, int, int,
+          int, struct Categories, struct Colors, double, double, double,
+          double, int, int, double, double, double *, int, int, int, double,
+          double, const char *, double *, double, int, int, struct Option *,
+          struct Option *, struct Option *, struct Option *, struct Option *,
+          struct Option *, struct Flag *, struct Flag *, int);

+ 100 - 106
display/d.legend/main.c

@@ -51,11 +51,12 @@ int main(int argc, char **argv)
     struct Colors colors;
     struct GModule *module;
     struct Option *opt_rast2d, *opt_rast3d, *opt_color, *opt_lines,
-		  *opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range,
-          *opt_font, *opt_path, *opt_charset, *opt_fontsize, *opt_title,
-          *opt_ticks, *opt_tstep, *opt_brdcolor, *opt_bgcolor, *opt_tit_fontsize;
+        *opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range,
+        *opt_font, *opt_path, *opt_charset, *opt_fontsize, *opt_title,
+        *opt_ticks, *opt_tstep, *opt_brdcolor, *opt_bgcolor,
+        *opt_tit_fontsize;
     struct Flag *hidestr, *hidenum, *hidenodata, *smooth, *flipit, *histo,
-            *showtick, *showbg;
+        *showtick, *showbg;
     double X0, X1, Y0, Y1;
     int flip, UserRange;
     double UserRangeMin, UserRangeMax, UserRangeTemp;
@@ -76,8 +77,8 @@ int main(int argc, char **argv)
     G_add_keyword(_("cartography"));
     G_add_keyword(_("legend"));
     module->description =
-	_("Displays a legend for a 2D or 3D raster map in the active frame "
-	  "of the graphics monitor.");
+        _("Displays a legend for a 2D or 3D raster map in the active frame "
+          "of the graphics monitor.");
 
     opt_rast2d = G_define_standard_option(G_OPT_R_MAP);
     opt_rast2d->key = "raster";
@@ -111,7 +112,7 @@ int main(int argc, char **argv)
     opt_lines->answer = "0";
     opt_lines->options = "0-1000";
     opt_lines->description =
-	_("Number of text lines (useful for truncating long legends)");
+        _("Number of text lines (useful for truncating long legends)");
     opt_lines->guisection = _("Advanced");
 
     opt_thin = G_define_option();
@@ -121,7 +122,7 @@ int main(int argc, char **argv)
     opt_thin->answer = "1";
     opt_thin->options = "1-1000";
     opt_thin->description =
-	_("Thinning factor (thin=10 gives cats 0,10,20...)");
+        _("Thinning factor (thin=10 gives cats 0,10,20...)");
     opt_thin->guisection = _("Advanced");
 
     opt_labelnum = G_define_option();
@@ -130,15 +131,14 @@ int main(int argc, char **argv)
     opt_labelnum->answer = "5";
     opt_labelnum->options = "2-100";
     opt_labelnum->description =
-	_("Number of text labels for smooth gradient legend");
+        _("Number of text labels for smooth gradient legend");
     opt_labelnum->guisection = _("Gradient");
 
     opt_ticks = G_define_option();
     opt_ticks->key = "label_values";
     opt_ticks->type = TYPE_DOUBLE;
     opt_ticks->required = NO;
-    opt_ticks->description =
-    _("Specific values to draw ticks");
+    opt_ticks->description = _("Specific values to draw ticks");
     opt_ticks->required = NO;
     opt_ticks->multiple = YES;
     opt_ticks->guisection = _("Gradient");
@@ -147,8 +147,7 @@ int main(int argc, char **argv)
     opt_tstep->key = "label_step";
     opt_tstep->type = TYPE_DOUBLE;
     opt_tstep->required = NO;
-    opt_tstep->description =
-    _("Display label every step");
+    opt_tstep->description = _("Display label every step");
     opt_tstep->required = NO;
     opt_tstep->guisection = _("Gradient");
 
@@ -156,31 +155,31 @@ int main(int argc, char **argv)
     opt_at = G_define_option();
     opt_at->key = "at";
     opt_at->key_desc = "bottom,top,left,right";
-    opt_at->type = TYPE_DOUBLE;  /* needs to be TYPE_DOUBLE to get past options check */
+    opt_at->type = TYPE_DOUBLE; /* needs to be TYPE_DOUBLE to get past options check */
     opt_at->required = NO;
     opt_at->options = "0-100";
     opt_at->label =
-	_("Size and placement as percentage of screen coordinates "
-	  "(0,0 is lower left)");
+        _("Size and placement as percentage of screen coordinates "
+          "(0,0 is lower left)");
     opt_at->description = opt_at->key_desc;
     opt_at->answer = NULL;
 
     opt_use = G_define_option();
     opt_use->key = "use";
-    opt_use->type = TYPE_DOUBLE;  /* string as it is fed through the parser? */
+    opt_use->type = TYPE_DOUBLE;        /* string as it is fed through the parser? */
     opt_use->required = NO;
     opt_use->description =
-	_("List of discrete category numbers/values for legend");
+        _("List of discrete category numbers/values for legend");
     opt_use->multiple = YES;
     opt_use->guisection = _("Subset");
 
     opt_range = G_define_option();
     opt_range->key = "range";
     opt_range->key_desc = "min,max";
-    opt_range->type = TYPE_DOUBLE;  /* should it be type_double or _string ?? */
+    opt_range->type = TYPE_DOUBLE;      /* should it be type_double or _string ?? */
     opt_range->required = NO;
     opt_range->description =
-	_("Use a subset of the map range for the legend (min,max)");
+        _("Use a subset of the map range for the legend (min,max)");
     opt_range->guisection = _("Subset");
 
     opt_color = G_define_standard_option(G_OPT_C);
@@ -215,7 +214,7 @@ int main(int argc, char **argv)
     opt_charset->type = TYPE_STRING;
     opt_charset->required = NO;
     opt_charset->description =
-	_("Text encoding (only applicable to TrueType fonts)");
+        _("Text encoding (only applicable to TrueType fonts)");
     opt_charset->guisection = _("Font settings");
 
     opt_brdcolor = G_define_standard_option(G_OPT_CN);
@@ -278,15 +277,15 @@ int main(int argc, char **argv)
 
     /* Check command line */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
     if (opt_rast2d->answer) {
-	map_name = opt_rast2d->answer;
-	maptype = MAP_TYPE_RASTER2D;
+        map_name = opt_rast2d->answer;
+        maptype = MAP_TYPE_RASTER2D;
     }
     else {
-	map_name = opt_rast3d->answer;
-	maptype = MAP_TYPE_RASTER3D;
+        map_name = opt_rast3d->answer;
+        maptype = MAP_TYPE_RASTER3D;
     }
 
     if (opt_title->answer)
@@ -294,7 +293,7 @@ int main(int argc, char **argv)
     else
         title = "";
 
-    hide_catstr = hidestr->answer;	/* note hide_catstr gets changed and re-read below */
+    hide_catstr = hidestr->answer;      /* note hide_catstr gets changed and re-read below */
     hide_catnum = hidenum->answer;
     show_ticks = showtick->answer;
     hide_nodata = hidenodata->answer;
@@ -302,7 +301,7 @@ int main(int argc, char **argv)
     flip = flipit->answer;
     show_bg = showbg->answer;
 
-    if (showtick->answer){
+    if (showtick->answer) {
         label_indent = 12;
     }
     else
@@ -311,17 +310,17 @@ int main(int argc, char **argv)
     color = D_parse_color(opt_color->answer, TRUE);
 
     if (opt_lines->answer != NULL)
-	sscanf(opt_lines->answer, "%d", &lines);
+        sscanf(opt_lines->answer, "%d", &lines);
 
     thin = 1;
     if (opt_thin->answer != NULL)
-	sscanf(opt_thin->answer, "%d", &thin);
+        sscanf(opt_thin->answer, "%d", &thin);
     if (!thin)
-	thin = 1;
+        thin = 1;
 
     if (opt_labelnum->answer != NULL)
-	sscanf(opt_labelnum->answer, "%d", &steps);
-    
+        sscanf(opt_labelnum->answer, "%d", &steps);
+
     if ((opt_tstep->answer) || (opt_ticks->answer))
         steps = 0;
 
@@ -330,8 +329,8 @@ int main(int argc, char **argv)
 
     ticksCount = 0;
     if (opt_ticks->answer != NULL) {
-        tick_values = (double *)G_calloc(100+1, sizeof(double));
-        for (i = 0; i < 100; i++)   /* fill with dummy values */
+        tick_values = (double *)G_calloc(100 + 1, sizeof(double));
+        for (i = 0; i < 100; i++)       /* fill with dummy values */
             tick_values[i] = 1.0 * (i + 1);
         tick_values[i] = 0;
 
@@ -341,57 +340,57 @@ int main(int argc, char **argv)
     }
 
     catlistCount = 0;
-    if (opt_use->answer != NULL) {	/* should this be answerS ? */
-	use_catlist = TRUE;
+    if (opt_use->answer != NULL) {      /* should this be answerS ? */
+        use_catlist = TRUE;
 
-	catlist = (double *)G_calloc(100 + 1, sizeof(double));
-	for (i = 0; i < 100; i++)	/* fill with dummy values */
-	    catlist[i] = 1.0 * (i + 1);
-	catlist[i] = 0;
+        catlist = (double *)G_calloc(100 + 1, sizeof(double));
+        for (i = 0; i < 100; i++)       /* fill with dummy values */
+            catlist[i] = 1.0 * (i + 1);
+        catlist[i] = 0;
 
-	for (i = 0; (opt_use->answers[i] != NULL) && i < 100; i++)
-	    catlist[i] = atof(opt_use->answers[i]);
+        for (i = 0; (opt_use->answers[i] != NULL) && i < 100; i++)
+            catlist[i] = atof(opt_use->answers[i]);
 
-	catlistCount = i;
+        catlistCount = i;
     }
     else
-	use_catlist = FALSE;
+        use_catlist = FALSE;
 
 
     UserRange = FALSE;
-    if (opt_range->answer != NULL) {	/* should this be answerS ? */
-	sscanf(opt_range->answers[0], "%lf", &UserRangeMin);
-	sscanf(opt_range->answers[1], "%lf", &UserRangeMax);
-	UserRange = TRUE;
-	if (UserRangeMin > UserRangeMax) {
-	    UserRangeTemp = UserRangeMax;
-	    UserRangeMax = UserRangeMin;
-	    UserRangeMin = UserRangeTemp;
-	    flip = !flip;
-	}
+    if (opt_range->answer != NULL) {    /* should this be answerS ? */
+        sscanf(opt_range->answers[0], "%lf", &UserRangeMin);
+        sscanf(opt_range->answers[1], "%lf", &UserRangeMax);
+        UserRange = TRUE;
+        if (UserRangeMin > UserRangeMax) {
+            UserRangeTemp = UserRangeMax;
+            UserRangeMax = UserRangeMin;
+            UserRangeMin = UserRangeTemp;
+            flip = !flip;
+        }
     }
 
     if (maptype == MAP_TYPE_RASTER2D) {
-	if (Rast_read_colors(map_name, "", &colors) == -1)
-	    G_fatal_error(_("Color file for <%s> not available"), map_name);
+        if (Rast_read_colors(map_name, "", &colors) == -1)
+            G_fatal_error(_("Color file for <%s> not available"), map_name);
+
+        fp = Rast_map_is_fp(map_name, "");
 
-	fp = Rast_map_is_fp(map_name, "");
- 
-	Rast_read_cats(map_name, "", &cats);
+        Rast_read_cats(map_name, "", &cats);
     }
     else {
-	if (Rast3d_read_colors(map_name, "", &colors) == -1)
-	    G_fatal_error(_("Color file for <%s> not available"), map_name);
+        if (Rast3d_read_colors(map_name, "", &colors) == -1)
+            G_fatal_error(_("Color file for <%s> not available"), map_name);
 
-	fp = TRUE;  /* currently raster 3D is always floating point */
+        fp = TRUE;              /* currently raster 3D is always floating point */
 
-	Rast3d_read_cats(map_name, "", &cats);
+        Rast3d_read_cats(map_name, "", &cats);
     }
 
     if (fp && !use_catlist) {
-	do_smooth = TRUE;
-	/* fprintf(stderr, "FP map found - switching gradient legend on\n"); */
-	flip = !flip;
+        do_smooth = TRUE;
+        /* fprintf(stderr, "FP map found - switching gradient legend on\n"); */
+        flip = !flip;
     }
 
     D_open_driver();
@@ -401,17 +400,17 @@ int main(int argc, char **argv)
     colorbg = D_parse_color(opt_bgcolor->answer, TRUE);
 
     if (opt_font->answer)
-	D_font(opt_font->answer);
+        D_font(opt_font->answer);
     else if (opt_path->answer)
-	D_font(opt_path->answer);
+        D_font(opt_path->answer);
 
     if (opt_fontsize->answer != NULL)
-	fontsize = atof(opt_fontsize->answer);
+        fontsize = atof(opt_fontsize->answer);
     else
-	fontsize = 12; /* dummy placeholder, should never be called */
+        fontsize = 12;          /* dummy placeholder, should never be called */
 
     if (opt_charset->answer)
-	D_encoding(opt_charset->answer);
+        D_encoding(opt_charset->answer);
 
     if (opt_tit_fontsize->answer != NULL)
         tit_fontsize = atof(opt_tit_fontsize->answer);
@@ -419,44 +418,39 @@ int main(int argc, char **argv)
         tit_fontsize = 0;
 
     if (opt_at->answer != NULL) {
-	sscanf(opt_at->answers[0], "%lf", &Y1);
-	sscanf(opt_at->answers[1], "%lf", &Y0);
-	sscanf(opt_at->answers[2], "%lf", &X0);
-	sscanf(opt_at->answers[3], "%lf", &X1);
+        sscanf(opt_at->answers[0], "%lf", &Y1);
+        sscanf(opt_at->answers[1], "%lf", &Y0);
+        sscanf(opt_at->answers[2], "%lf", &X0);
+        sscanf(opt_at->answers[3], "%lf", &X1);
     }
-    else {			/* default */
-	Y1 = 12;
-	Y0 = 88;
-	X0 = 3;
-	X1 = 7;
-
-	if (histo->answer) {
-	    X0 += 5;
-	    X1 += 5;
-	}
+    else {                      /* default */
+        Y1 = 12;
+        Y0 = 88;
+        X0 = 3;
+        X1 = 7;
+
+        if (histo->answer) {
+            X0 += 5;
+            X1 += 5;
+        }
     }
-//    if (show_bg)
-//        background(map_name, maptype, color, thin, lines, steps, fp, label_indent, hide_catnum,
-//                   hide_catstr, show_ticks, hide_nodata, do_smooth, cats, colors, X0,
-//                   X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax, catlist, catlistCount,
-//                   use_catlist, ticksCount, fontsize, tit_fontsize, title, tick_values, t_step,
-//                   colorb, colorbg, opt_use, opt_at, opt_fontsize, opt_ticks, opt_tstep, opt_range,
-//                   histo, hidestr);
 
     if (show_bg)
-        draw(map_name, maptype, color, thin, lines, steps, fp, label_indent, hide_catnum,
-             hide_catstr, show_ticks, hide_nodata, do_smooth, cats, colors, X0,
-             X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax, catlist, catlistCount,
-             use_catlist, ticksCount, fontsize, tit_fontsize, title, tick_values, t_step, colorb,
-             colorbg, opt_use, opt_at, opt_fontsize, opt_ticks, opt_tstep, opt_range, histo, hidestr,
-             0);
-
-    draw(map_name, maptype, color, thin, lines, steps, fp, label_indent, hide_catnum,
-         hide_catstr, show_ticks, hide_nodata, do_smooth, cats, colors, X0,
-         X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax, catlist, catlistCount,
-         use_catlist, ticksCount, fontsize, tit_fontsize, title, tick_values, t_step, colorb,
-         colorbg, opt_use, opt_at, opt_fontsize, opt_ticks, opt_tstep, opt_range, histo, hidestr,
-         1);
+        draw(map_name, maptype, color, thin, lines, steps, fp, label_indent,
+             hide_catnum, hide_catstr, show_ticks, hide_nodata, do_smooth,
+             cats, colors, X0, X1, Y0, Y1, flip, UserRange, UserRangeMin,
+             UserRangeMax, catlist, catlistCount, use_catlist, ticksCount,
+             fontsize, tit_fontsize, title, tick_values, t_step, colorb,
+             colorbg, opt_use, opt_at, opt_fontsize, opt_ticks, opt_tstep,
+             opt_range, histo, hidestr, 0);
+
+    draw(map_name, maptype, color, thin, lines, steps, fp, label_indent,
+         hide_catnum, hide_catstr, show_ticks, hide_nodata, do_smooth, cats,
+         colors, X0, X1, Y0, Y1, flip, UserRange, UserRangeMin, UserRangeMax,
+         catlist, catlistCount, use_catlist, ticksCount, fontsize,
+         tit_fontsize, title, tick_values, t_step, colorb, colorbg, opt_use,
+         opt_at, opt_fontsize, opt_ticks, opt_tstep, opt_range, histo,
+         hidestr, 1);
 
     D_close_driver();