[GRASS-SVN] r42150 - grass/branches/develbranch_6/general/g.message

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 8 07:34:28 EDT 2010


Author: martinl
Date: 2010-05-08 07:34:28 -0400 (Sat, 08 May 2010)
New Revision: 42150

Modified:
   grass/branches/develbranch_6/general/g.message/main.c
Log:
g.message: flag for progress info message
(merge r42147 from trunk)


Modified: grass/branches/develbranch_6/general/g.message/main.c
===================================================================
--- grass/branches/develbranch_6/general/g.message/main.c	2010-05-08 11:33:29 UTC (rev 42149)
+++ grass/branches/develbranch_6/general/g.message/main.c	2010-05-08 11:34:28 UTC (rev 42150)
@@ -4,10 +4,11 @@
  * MODULE:       g.message 
  * AUTHOR(S):    Jachym Cepicky - jachym AT les-ejk cz
  *               Hamish Bowman - hamish_b AT yahoo com
+ *               Martin Landa - landa.martin AT gmail.com
  * PURPOSE:      Provides a means of reporting the contents of GRASS
  *               projection information files and creating
  *               new projection information files.
- * COPYRIGHT:    (C) 2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2007,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
@@ -21,7 +22,7 @@
 
 int main(int argc, char *argv[])
 {
-    struct Flag *warning, *fatal, *debug_flag, *verbose, *important;
+    struct Flag *warning, *fatal, *percent, *debug_flag, *verbose, *important;
     struct Option *message, *debug_opt;
     struct GModule *module;
     int debug_level;
@@ -30,83 +31,95 @@
 
     module = G_define_module();
     module->keywords = _("general");
+    G_add_keyword(_("scripts"));
     module->label =
-	_("Prints a message, warning, or fatal error the GRASS way.");
+	_("Prints a message, warning, progress info, or fatal error in the GRASS way.");
     module->description =
 	_("This module should be used in scripts for messages served to user.");
 
     warning = G_define_flag();
     warning->key = 'w';
-    warning->guisection = "Input";
-    warning->description = _("Print message as GRASS warning");
+    warning->guisection = _("Type");
+    warning->description = _("Print message as warning");
 
     fatal = G_define_flag();
     fatal->key = 'e';
-    fatal->guisection = "Input";
-    fatal->description = _("Print message as GRASS fatal error");
+    fatal->guisection = _("Type");
+    fatal->description = _("Print message as fatal error");
 
     debug_flag = G_define_flag();
     debug_flag->key = 'd';
-    debug_flag->guisection = "Input";
-    debug_flag->description = _("Print message as GRASS debug message");
+    debug_flag->guisection = _("Type");
+    debug_flag->description = _("Print message as debug message");
 
+    percent = G_define_flag();
+    percent->key = 'p';
+    percent->guisection = _("Type");
+    percent->description = _("Print message as progress info");
+
     important = G_define_flag();
     important->key = 'i';
-    important->guisection = "Input";
-    important->description = _("Print message in all but full quiet mode");
+    important->guisection = _("Level");
+    important->description = _("Don't print message in quiet mode");
 
     verbose = G_define_flag();
     verbose->key = 'v';
-    verbose->guisection = "Input";
-    verbose->description = _("Print message only if in verbose mode");
+    verbose->guisection = _("Level");
+    verbose->description = _("Print message only in verbose mode");
 
     message = G_define_option();
     message->key = "message";
     message->type = TYPE_STRING;
     message->key_desc = "string";
     message->required = YES;
-    message->guisection = "Input";
     message->description = _("Text of the message to be printed");
 
     debug_opt = G_define_option();
     debug_opt->key = "debug";
     debug_opt->type = TYPE_INTEGER;
     debug_opt->required = NO;
-    debug_opt->guisection = "Input";
+    debug_opt->guisection = _("Level");
     debug_opt->answer = "1";
     debug_opt->options = "0-5";
     debug_opt->description = _("Level to use for debug messages");
 
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
 
     if (fatal->answer + warning->answer + debug_flag->answer +
 	verbose->answer > 1)
-	G_fatal_error(_("Select only one message level."));
+	G_fatal_error(_("Select only one message level"));
 
     debug_level = atoi(debug_opt->answer);
-
-
-    if (fatal->answer)
+    
+    if (fatal->answer) {
 	G_fatal_error(message->answer);
-
-    else if (warning->answer)
+    }
+    else if (warning->answer) {
 	G_warning(message->answer);
-
-    else if (debug_flag->answer)
+    }
+    else if (percent->answer) {
+	int i, n, s;
+	i = n = s = -1;
+	sscanf(message->answer, "%d %d %d", &i, &n, &s);
+	if (s == -1) 
+	    G_fatal_error(_("Unable to parse input message"));
+	G_percent(i, n, s);
+	fprintf(stderr, "\n");
+    }
+    else if (debug_flag->answer) {
 	G_debug(debug_level, message->answer);
-
-    else if (verbose->answer)
+    }
+    else if (verbose->answer) {
 	G_verbose_message(message->answer);
-
-    else if (important->answer)
+    }
+    else if (important->answer) {
 	G_important_message(message->answer);
-
-    else
+    }
+    else {
 	G_message(message->answer);
+    }
 
-
     exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list