Skip to content

Commit

Permalink
r.distance: sort -s/-r => sort=
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60564 15284696-431f-4ddb-bdfa-cd5b030d7da7
  • Loading branch information
HuidaeCho committed May 28, 2014
1 parent 4d93d1a commit 3646ead
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions raster/r.distance/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* PURPOSE: Locates the closest points between objects in two
* raster maps.
*
* COPYRIGHT: (C) 2003 by the GRASS Development Team
* COPYRIGHT: (C) 2003-2014 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
Expand All @@ -18,14 +18,15 @@

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "defs.h"
#include <grass/gis.h>
#include <grass/glocale.h>

void parse(int argc, char *argv[], struct Parms *parms)
{
struct Option *maps, *fs;
struct Flag *labels, *overlap, *null, *sort, *revsort;
struct Option *maps, *fs, *sort;
struct Flag *labels, *overlap, *null;
const char *name, *mapset;

maps = G_define_standard_option(G_OPT_R_MAPS);
Expand All @@ -35,6 +36,19 @@ void parse(int argc, char *argv[], struct Parms *parms)
fs = G_define_standard_option(G_OPT_F_SEP);
fs->answer = ":"; /* colon is default output fs */

sort = G_define_option();
sort->key = "sort";
sort->type = TYPE_STRING;
sort->required = NO;
sort->multiple = NO;
sort->label = _("Sort output by distance");
sort->description = _("Default: sorted by categories");
sort->options = "asc,desc";
G_asprintf((char **)&(sort->descriptions),
"asc;%s;desc;%s",
_("Sort by distance in ascending order"),
_("Sort by distance in descending order"));

labels = G_define_flag();
labels->key = 'l';
labels->description = _("Include category labels in the output");
Expand All @@ -48,21 +62,9 @@ void parse(int argc, char *argv[], struct Parms *parms)
null->key = 'n';
null->description = _("Report null objects as *");

sort = G_define_flag();
sort->key = 's';
sort->description = _("Sort by distance in ascending order");

revsort = G_define_flag();
revsort->key = 'r';
revsort->description = _("Sort by distance in descending order");

if (G_parser(argc, argv))
exit(EXIT_FAILURE);

if (sort->answer && revsort->answer)
G_fatal_error(_("-%c and -%c are mutually exclusive"),
sort->key, revsort->key);

name = parms->map1.name = maps->answers[0];
mapset = parms->map1.mapset = G_find_raster2(name, "");
if (mapset == NULL)
Expand All @@ -85,5 +87,8 @@ void parse(int argc, char *argv[], struct Parms *parms)
parms->fs = fs->answer;
parms->overlap = overlap->answer ? 1 : 0;
parms->null = null->answer ? 1 : 0;
parms->sort = sort->answer ? 1 : (revsort->answer ? 2 : 0);
if (sort->answer)
parms->sort = strcmp(sort->answer, "asc") == 0 ? 1 : 2;
else
parms->sort = 0;
}

0 comments on commit 3646ead

Please sign in to comment.