[GRASS-SVN] r44421 - in grass/trunk: general/g.mapset general/g.parser include lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 25 12:40:48 EST 2010


Author: glynn
Date: 2010-11-25 09:40:48 -0800 (Thu, 25 Nov 2010)
New Revision: 44421

Modified:
   grass/trunk/general/g.mapset/main.c
   grass/trunk/general/g.parser/main.c
   grass/trunk/include/gis.h
   grass/trunk/lib/gis/parser.c
   grass/trunk/lib/gis/parser_interface.c
   grass/trunk/lib/gis/parser_local_proto.h
   grass/trunk/lib/gis/parser_script.c
Log:
Add suppress_required field to flags


Modified: grass/trunk/general/g.mapset/main.c
===================================================================
--- grass/trunk/general/g.mapset/main.c	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/general/g.mapset/main.c	2010-11-25 17:40:48 UTC (rev 44421)
@@ -81,6 +81,7 @@
 
     f_list = G_define_flag();
     f_list->key = 'l';
+    f_list->suppress_required = 1;
     f_list->description = _("List available mapsets");
     f_list->guisection = _("Print");
     

Modified: grass/trunk/general/g.parser/main.c
===================================================================
--- grass/trunk/general/g.parser/main.c	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/general/g.parser/main.c	2010-11-25 17:40:48 UTC (rev 44421)
@@ -73,6 +73,20 @@
 #endif
 }
 
+static int parse_boolean(struct context *ctx, const char *arg)
+{
+    if (strcasecmp(arg, "yes") == 0)
+	return YES;
+
+    if (strcasecmp(arg, "no") == 0)
+	return NO;
+
+    fprintf(stderr, "Unknown boolean value \"%s\" at line %d\n",
+	    arg, ctx->line);
+
+    return NO;
+}
+
 static void parse_toplevel(struct context *ctx, const char *cmd)
 {
     if (strcasecmp(cmd, "module") == 0) {
@@ -136,6 +150,11 @@
 	return;
     }
 
+    if (strcasecmp(cmd, "suppress_required") == 0) {
+	ctx->flag->key = parse_boolean(ctx, arg);
+	return;
+    }
+
     if (strcasecmp(cmd, "answer") == 0) {
 	ctx->flag->answer = atoi(arg);
 	return;
@@ -182,20 +201,6 @@
     return TYPE_STRING;
 }
 
-static int parse_boolean(struct context *ctx, const char *arg)
-{
-    if (strcasecmp(arg, "yes") == 0)
-	return YES;
-
-    if (strcasecmp(arg, "no") == 0)
-	return NO;
-
-    fprintf(stderr, "Unknown boolean value \"%s\" at line %d\n",
-	    arg, ctx->line);
-
-    return NO;
-}
-
 static void parse_option(struct context *ctx, const char *cmd,
 			 const char *arg)
 {

Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/include/gis.h	2010-11-25 17:40:48 UTC (rev 44421)
@@ -349,6 +349,7 @@
 {
     char key;			/* Key char used on command line    */
     char answer;		/* Stores flag state: 0/1           */
+    char suppress_required;	/* Suppresses checking of required options */
     const char *label;		/* Optional short label, used in GUI as item label */
     const char *description;	/* String describing flag meaning   */
     const char *guisection;	/* GUI Layout guidance: ';' delimited heirarchical tree position */

Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/lib/gis/parser.c	2010-11-25 17:40:48 UTC (rev 44421)
@@ -555,7 +555,8 @@
 	error += check_opts();
 
     /* Make sure all required options are set */
-    error += check_required();
+    if (!st->suppress_required)
+	error += check_required();
     
     if (error) {
 	if (G_verbose() > G_verbose_min())
@@ -799,6 +800,8 @@
     while (flag) {
 	if (flag->key == f) {
 	    flag->answer = 1;
+	    if (flag->suppress_required)
+		st->suppress_required = 1;
 	    return (0);
 	}
 	flag = flag->next_flag;

Modified: grass/trunk/lib/gis/parser_interface.c
===================================================================
--- grass/trunk/lib/gis/parser_interface.c	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/lib/gis/parser_interface.c	2010-11-25 17:40:48 UTC (rev 44421)
@@ -294,6 +294,9 @@
 		fprintf(stdout, "\n\t\t</label>\n");
 	    }
 
+	    if (flag->suppress_required)
+		fprintf(stdout, "\t\t<suppress_required/>\n");
+
 	    if (flag->description) {
 		fprintf(stdout, "\t\t<description>\n\t\t\t");
 		print_escaped_for_xml(stdout, flag->description);

Modified: grass/trunk/lib/gis/parser_local_proto.h
===================================================================
--- grass/trunk/lib/gis/parser_local_proto.h	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/lib/gis/parser_local_proto.h	2010-11-25 17:40:48 UTC (rev 44421)
@@ -20,6 +20,7 @@
     int overwrite;
     int quiet;
     int has_required;
+    int suppress_required;
 
     struct GModule module_info;	/* general information on the corresponding module */
 

Modified: grass/trunk/lib/gis/parser_script.c
===================================================================
--- grass/trunk/lib/gis/parser_script.c	2010-11-25 17:26:26 UTC (rev 44420)
+++ grass/trunk/lib/gis/parser_script.c	2010-11-25 17:40:48 UTC (rev 44421)
@@ -69,6 +69,8 @@
 	for (flag = &st->first_flag; flag; flag = flag->next_flag) {
 	    fprintf(fp, "#%%flag\n");
 	    fprintf(fp, "#%% key: %c\n", flag->key);
+	    if (flag->suppress_required)
+		fprintf(fp, "#%% suppress_required: yes\n");
 	    if (flag->label)
 		fprintf(fp, "#%% label: %s\n", flag->label);
 	    if (flag->description)



More information about the grass-commit mailing list