[GRASS-SVN] r60914 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 21 10:35:41 PDT 2014


Author: glynn
Date: 2014-06-21 10:35:41 -0700 (Sat, 21 Jun 2014)
New Revision: 60914

Modified:
   grass/trunk/lib/gis/parser_dependencies.c
Log:
Add G_option_excludes()
Fix rule descriptiosn (don't list first option twice)
Formatting (80-column limit)


Modified: grass/trunk/lib/gis/parser_dependencies.c
===================================================================
--- grass/trunk/lib/gis/parser_dependencies.c	2014-06-21 09:34:04 UTC (rev 60913)
+++ grass/trunk/lib/gis/parser_dependencies.c	2014-06-21 17:35:41 UTC (rev 60914)
@@ -25,6 +25,7 @@
     RULE_REQUIRED,
     RULE_REQUIRES,
     RULE_REQUIRES_ALL,
+    RULE_EXCLUDES,
     RULE_COLLECTIVE
 };
 
@@ -145,7 +146,8 @@
     return count;
 }
 
-static const char *describe_rule(const struct rule *rule, int start, int disjunction)
+static const char *describe_rule(const struct rule *rule, int start,
+				 int disjunction)
 {
     char *s = get_name(rule->opts[start]);
     int i;
@@ -183,7 +185,8 @@
 static void check_exclusive(const struct rule *rule)
 {
     if (count_present(rule, 0) > 1)
-	G_fatal_error(_("Options %s are mutually exclusive"), describe_rule(rule, 0, 0));
+	G_fatal_error(_("Options %s are mutually exclusive"),
+		      describe_rule(rule, 0, 0));
 }
 
 /* at least one option from a set */
@@ -198,7 +201,8 @@
 static void check_required(const struct rule *rule)
 {
     if (count_present(rule, 0) < 1)
-	G_fatal_error(_("At least one of %s is required"), describe_rule(rule, 0, 0));
+	G_fatal_error(_("At least one of %s is required"),
+		      describe_rule(rule, 0, 0));
 }
 
 /* if the first option is present, at least one of the other
@@ -216,7 +220,8 @@
     if (!is_present(rule->opts[0]))
 	return;
     if (count_present(rule, 1) < 1)
-	G_fatal_error(_("Option %s requires at least one of %s"), get_name(rule->opts[0]), describe_rule(rule, 0, 1));
+	G_fatal_error(_("Option %s requires at least one of %s"),
+		      get_name(rule->opts[0]), describe_rule(rule, 1, 1));
 }
 
 /* if the first option is present, all the other options must also
@@ -234,9 +239,29 @@
     if (!is_present(rule->opts[0]))
 	return;
     if (count_present(rule, 1) < rule->count - 1)
-	G_fatal_error(_("Option %s requires all of %s"), get_name(rule->opts[0]), describe_rule(rule, 0, 0));
+	G_fatal_error(_("Option %s requires all of %s"),
+		      get_name(rule->opts[0]), describe_rule(rule, 1, 0));
 }
 
+/* if the first option is present, none of the other options may also
+   be present. */
+void G_option_excludes(void *first, ...)
+{
+    va_list ap;
+    va_start(ap, first);
+    make_rule(RULE_EXCLUDES, first, ap);
+    va_end(ap);
+}
+
+static void check_excludes(const struct rule *rule)
+{
+    if (!is_present(rule->opts[0]))
+	return;
+    if (count_present(rule, 1) > 0)
+	G_fatal_error(_("Option %s is mutually exclusive with all of %s"),
+		      get_name(rule->opts[0]), describe_rule(rule, 1, 0));
+}
+
 /* if any option is present, all the other options must also be present
    all or nothing from a set */
 void G_option_collective(void *first, ...)
@@ -251,7 +276,8 @@
 {
     int count = count_present(rule, 0);
     if (count > 0 && count < rule->count)
-	G_fatal_error(_("Either all or none of %s must be given"), describe_rule(rule, 0, 0));
+	G_fatal_error(_("Either all or none of %s must be given"),
+		      describe_rule(rule, 0, 0));
 }
 
 void G__check_option_rules(void)
@@ -273,11 +299,15 @@
 	case RULE_REQUIRES_ALL:
 	    check_requires_all(rule);
 	    break;
+	case RULE_EXCLUDES:
+	    check_excludes(rule);
+	    break;
 	case RULE_COLLECTIVE:
 	    check_collective(rule);
 	    break;
 	default:
-	    G_fatal_error(_("Internal error: invalid rule type: %d"), rule->type);
+	    G_fatal_error(_("Internal error: invalid rule type: %d"),
+			  rule->type);
 	    break;
 	}
     }
@@ -297,16 +327,23 @@
 	    fprintf(stderr, "Required: %s", describe_rule(rule, 0, 1));
 	    break;
 	case RULE_REQUIRES:
-	    fprintf(stderr, "Requires: %s => %s", get_name(rule->opts[0]), describe_rule(rule, 1, 1));
+	    fprintf(stderr, "Requires: %s => %s", get_name(rule->opts[0]),
+		    describe_rule(rule, 1, 1));
 	    break;
 	case RULE_REQUIRES_ALL:
-	    fprintf(stderr, "Requires: %s => %s", get_name(rule->opts[0]), describe_rule(rule, 1, 0));
+	    fprintf(stderr, "Requires: %s => %s", get_name(rule->opts[0]),
+		    describe_rule(rule, 1, 0));
 	    break;
+	case RULE_EXCLUDES:
+	    fprintf(stderr, "Excludes: %s => %s", get_name(rule->opts[0]),
+		    describe_rule(rule, 1, 0));
+	    break;
 	case RULE_COLLECTIVE:
 	    fprintf(stderr, "Collective: %s", describe_rule(rule, 0, 0));
 	    break;
 	default:
-	    G_fatal_error(_("Internal error: invalid rule type: %d"), rule->type);
+	    G_fatal_error(_("Internal error: invalid rule type: %d"),
+			  rule->type);
 	    break;
 	}
     }



More information about the grass-commit mailing list