[GRASS-SVN] r32756 - in grass/trunk: display/d.colorlist
display/d.erase display/d.fontlist display/d.info
display/d.measure display/d.what.rast display/d.what.vect
display/d.where display/d.zoom general/g.gisenv general/g.gui
general/g.mkfontcap general/g.setproj general/g.tempfile
general/g.version imagery/i.maxlik lib/gis ps/ps.map
raster/r.rescale.eq vector/v.what
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 14 04:22:53 EDT 2008
Author: glynn
Date: 2008-08-14 04:22:52 -0400 (Thu, 14 Aug 2008)
New Revision: 32756
Modified:
grass/trunk/display/d.colorlist/main.c
grass/trunk/display/d.erase/main.c
grass/trunk/display/d.fontlist/main.c
grass/trunk/display/d.info/main.c
grass/trunk/display/d.measure/main.c
grass/trunk/display/d.measure/msurements.c
grass/trunk/display/d.what.rast/main.c
grass/trunk/display/d.what.vect/main.c
grass/trunk/display/d.where/main.c
grass/trunk/display/d.zoom/main.c
grass/trunk/general/g.gisenv/main.c
grass/trunk/general/g.gui/main.c
grass/trunk/general/g.mkfontcap/main.c
grass/trunk/general/g.setproj/main.c
grass/trunk/general/g.tempfile/main.c
grass/trunk/general/g.version/main.c
grass/trunk/imagery/i.maxlik/main.c
grass/trunk/lib/gis/parser.c
grass/trunk/ps/ps.map/main.c
grass/trunk/raster/r.rescale.eq/main.c
grass/trunk/vector/v.what/main.c
Log:
Make G_parser() only invoke UI if module has required arguments
No need for "if (argc > 1 && G_parser(argc, argv))"
Modified: grass/trunk/display/d.colorlist/main.c
===================================================================
--- grass/trunk/display/d.colorlist/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.colorlist/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -45,11 +45,9 @@
sep->description = "character for separation of list items";
sep->answer = ",";
- G_disable_interactive();
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
- if (argc > 1 && G_parser(argc, argv))
- exit(1);
-
colorlist = G_store(D_color_list());
/* if separator is different from ",", escape this character */
@@ -60,5 +58,5 @@
}
fprintf(stdout, "%s\n", colorlist);
- return (0);
+ return 0;
}
Modified: grass/trunk/display/d.erase/main.c
===================================================================
--- grass/trunk/display/d.erase/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.erase/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -44,7 +44,7 @@
eraseframe->key = 'f';
eraseframe->description = _("Remove all frames and erase the screen");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(1);
if (R_open_driver() != 0)
Modified: grass/trunk/display/d.fontlist/main.c
===================================================================
--- grass/trunk/display/d.fontlist/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.fontlist/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -46,7 +46,7 @@
flagL->key = 'L';
flagL->description = _("List fonts verbosely");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (R_open_driver() != 0)
Modified: grass/trunk/display/d.info/main.c
===================================================================
--- grass/trunk/display/d.info/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.info/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -59,7 +59,7 @@
cflag->key = 'c';
cflag->description = _("Display number of colors");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (!rflag->answer && !dflag->answer && !cflag->answer &&
Modified: grass/trunk/display/d.measure/main.c
===================================================================
--- grass/trunk/display/d.measure/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.measure/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -78,7 +78,7 @@
parm.k->key = 'k';
parm.k->description = _("Output in kilometers as well");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (R_open_driver() != 0)
Modified: grass/trunk/display/d.measure/msurements.c
===================================================================
--- grass/trunk/display/d.measure/msurements.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.measure/msurements.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -18,7 +18,7 @@
int cur_screen_x, cur_screen_y;
int screen_x, screen_y;
struct Cell_head window;
- int t, b, l, r;
+ double t, b, l, r;
nalloc = 128;
x = (double *)G_calloc(nalloc, sizeof(double));
Modified: grass/trunk/display/d.what.rast/main.c
===================================================================
--- grass/trunk/display/d.what.rast/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.what.rast/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -30,7 +30,7 @@
int main(int argc, char **argv)
{
struct Cell_head window;
- int t, b, l, r;
+ double t, b, l, r;
int i, j;
int width, mwidth;
struct Flag *once, *terse, *colrow;
@@ -80,7 +80,7 @@
colrow->description =
_("Print out col/row for the entire map in grid resolution of the region");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/display/d.what.vect/main.c
===================================================================
--- grass/trunk/display/d.what.vect/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.what.vect/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -46,7 +46,7 @@
struct Flag *once, *terse, *txt, *topo_flag, *edit_flag;
struct Option *opt1;
struct GModule *module;
- char *mapset, *openvect();
+ char *mapset;
char *str;
int i, j, level, width = 0, mwidth = 0;
@@ -91,7 +91,7 @@
edit_flag->key = 'e';
edit_flag->description = _("Open form in edit mode");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (opt1->answers && opt1->answers[0])
Modified: grass/trunk/display/d.where/main.c
===================================================================
--- grass/trunk/display/d.where/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.where/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -82,7 +82,7 @@
/* if (G_parser(argc,argv)) */
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (latlong->answer && wgs84->answer)
@@ -162,7 +162,7 @@
}
}
else
- fp = NULL;
+ fp = stdin;
if (R_open_driver() != 0)
G_fatal_error(_("No graphics device selected"));
Modified: grass/trunk/display/d.zoom/main.c
===================================================================
--- grass/trunk/display/d.zoom/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/display/d.zoom/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -113,7 +113,7 @@
last->key = 'r';
last->description = _("Return to previous zoom");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if ((full->answer + pan->answer + hand->answer) > 1)
Modified: grass/trunk/general/g.gisenv/main.c
===================================================================
--- grass/trunk/general/g.gisenv/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.gisenv/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -25,9 +25,9 @@
int main(int argc, char *argv[])
{
int n, store;
- int tty;
char *name, *value, *ptr;
struct Option *get, *set, *store_opt;
+ struct Flag *flag_s, *flag_n;
struct GModule *module;
G_set_program_name(argv[0]);
@@ -60,15 +60,34 @@
store_opt->description = _("Where GRASS variable is stored");
store_opt->required = NO;
- if (argc > 1 && G_parser(argc, argv) < 0)
+ flag_s = G_define_flag();
+ flag_s->key = 's';
+ flag_s->description = _("Use shell syntax (for \"eval\")");
+
+ flag_n = G_define_flag();
+ flag_n->key = 'n';
+ flag_n->description = _("Don't Use shell syntax");
+
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ if (flag_s->answer && flag_n->answer)
+ G_fatal_error(_("-s and -n are mutually exclusive"));
+
/* Print or optionally set environment variables */
if (!get->answer && !set->answer) {
- tty = isatty(1);
for (n = 0; (name = G__env_name(n)); n++) {
+ int quote;
+
+ if (flag_s->answer)
+ quote = 1;
+ else if (flag_n->answer)
+ quote = 0;
+ else
+ quote = !isatty(fileno(stdout));
+
if ((value = G__getenv(name))) {
- if (tty)
+ if (!quote)
fprintf(stdout, "%s=%s\n", name, value);
else
fprintf(stdout, "%s='%s';\n", name, value);
Modified: grass/trunk/general/g.gui/main.c
===================================================================
--- grass/trunk/general/g.gui/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.gui/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -63,7 +63,7 @@
oneoff->key = 'u';
oneoff->description = _("Update default GUI setting");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/general/g.mkfontcap/main.c
===================================================================
--- grass/trunk/general/g.mkfontcap/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.mkfontcap/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -90,7 +90,7 @@
"Comma-separated list of extra directories to scan for "
"Freetype-compatible fonts as well as the defaults (see documentation)";
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (!tostdout->answer) {
Modified: grass/trunk/general/g.setproj/main.c
===================================================================
--- grass/trunk/general/g.setproj/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.setproj/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -79,7 +79,7 @@
module->description =
_("Interactively reset the location's projection settings.");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/general/g.tempfile/main.c
===================================================================
--- grass/trunk/general/g.tempfile/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.tempfile/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -45,7 +45,7 @@
G_disable_interactive();
if (G_parser(argc, argv))
- exit(1);
+ exit(EXIT_FAILURE);
if (sscanf(pid->answer, "%d", &p) != 1) {
G_usage();
Modified: grass/trunk/general/g.version/main.c
===================================================================
--- grass/trunk/general/g.version/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/general/g.version/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -42,7 +42,7 @@
build->key = 'b';
build->description = _("Print the GRASS build information");
- if (argc > 1 && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/imagery/i.maxlik/main.c
===================================================================
--- grass/trunk/imagery/i.maxlik/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/imagery/i.maxlik/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -88,8 +88,6 @@
flag.quiet->key = 'q';
flag.quiet->description = _("Run quietly");
- G_disable_interactive();
-
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/lib/gis/parser.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -90,10 +90,11 @@
#define KEYLENGTH 64
static int interactive_ok = 1;
-static int n_opts = 0;
-static int n_flags = 0;
-static int overwrite = 0;
-static int quiet = 0;
+static int n_opts;
+static int n_flags;
+static int overwrite;
+static int quiet;
+static int has_required;
static struct Flag first_flag; /* First flag in a linked list */
static struct Flag *current_flag; /* Pointer for traversing list */
@@ -723,6 +724,9 @@
opt = &first_option;
while (opt != NULL) {
+ if (opt->required)
+ has_required = 1;
+
/* Parse options */
if (opt->options) {
int cnt = 0;
@@ -803,11 +807,11 @@
/* If there are NO arguments, go interactive */
- if (argc < 2 && interactive_ok && isatty(0)) {
+ if (argc < 2 && has_required && interactive_ok && isatty(0)) {
G_gui();
return -1;
}
- else if (argc < 2 && isatty(0)) {
+ else if (argc < 2 && has_required && isatty(0)) {
G_usage();
return -1;
}
Modified: grass/trunk/ps/ps.map/main.c
===================================================================
--- grass/trunk/ps/ps.map/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/ps/ps.map/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -158,10 +158,8 @@
copies->description = _("Number of copies to print");
copies->required = NO;
- if (!isatty(0))
- G_disable_interactive();
if (G_parser(argc, argv))
- usage(0);
+ exit(EXIT_FAILURE);
/* Print papers */
if (pflag->answer) {
@@ -277,7 +275,8 @@
else {
G_message(_("\nERROR: Required parameter <%s> not set:\n (%s).\n"),
output_file->key, output_file->description);
- usage(1);
+ G_usage();
+ exit(EXIT_FAILURE);
}
/* get current mapset */
@@ -753,10 +752,3 @@
exit(EXIT_SUCCESS);
}
-
-int usage(int full)
-{
- if (full)
- G_usage();
- exit(EXIT_FAILURE);
-}
Modified: grass/trunk/raster/r.rescale.eq/main.c
===================================================================
--- grass/trunk/raster/r.rescale.eq/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/raster/r.rescale.eq/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -87,7 +87,6 @@
parm.title->required = NO;
parm.title->description = _("Title for new raster map");
- G_disable_interactive();
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass/trunk/vector/v.what/main.c
===================================================================
--- grass/trunk/vector/v.what/main.c 2008-08-14 08:15:13 UTC (rev 32755)
+++ grass/trunk/vector/v.what/main.c 2008-08-14 08:22:52 UTC (rev 32756)
@@ -84,7 +84,7 @@
printattributes->key = 'a';
printattributes->description = _("Print attribute information");
- if ((argc > 1 || !vect) && G_parser(argc, argv))
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
if (opt1->answers && opt1->answers[0])
More information about the grass-commit
mailing list