Browse Source

parser: use new option rule to launch module dialog when there is at least one option in a group specified as required

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61351 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 10 years ago
parent
commit
a5e474e6cb
3 changed files with 21 additions and 1 deletions
  1. 2 1
      lib/gis/parser.c
  2. 18 0
      lib/gis/parser_dependencies.c
  3. 1 0
      lib/gis/parser_local_proto.h

+ 2 - 1
lib/gis/parser.c

@@ -419,7 +419,8 @@ int G_parser(int argc, char **argv)
 
     /* If there are NO arguments, go interactive */
 
-    if (argc < 2 && st->has_required && !st->no_interactive && isatty(0)) {
+    if (argc < 2 && (st->has_required || G__has_required_rule())
+        && !st->no_interactive && isatty(0)) {
 	module_gui_wx();
 	return -1;
     }

+ 18 - 0
lib/gis/parser_dependencies.c

@@ -372,3 +372,21 @@ void G__describe_option_rules(void)
 	}
     }
 }
+
+/*!
+   \brief Checks if there is any rule RULE_REQUIRED.
+
+   \return 1 if there is such rule
+   \return 0 if not
+ */
+int G__has_required_rule(void)
+{
+    size_t i;
+
+    for (i = 0; i < rules.count; i++) {
+	const struct rule *rule = &((const struct rule *) rules.data)[i];
+	if (rule->type == RULE_REQUIRED)
+	    return TRUE;
+    }
+    return FALSE;
+}

+ 1 - 0
lib/gis/parser_local_proto.h

@@ -56,6 +56,7 @@ void G__print_keywords(FILE *, void (*)(FILE *, const char *));
 
 void G__check_option_rules(void);
 void G__describe_option_rules(void);
+int G__has_required_rule(void);
 
 #endif