[GRASS-SVN] r60944 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 24 07:35:57 PDT 2014
Author: hcho
Date: 2014-06-24 07:35:57 -0700 (Tue, 24 Jun 2014)
New Revision: 60944
Modified:
grass/trunk/lib/gis/parser.c
grass/trunk/lib/gis/parser_dependencies.c
Log:
libgis: G_parser() calls G__check_option_rules()
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2014-06-24 09:26:56 UTC (rev 60943)
+++ grass/trunk/lib/gis/parser.c 2014-06-24 14:35:57 UTC (rev 60944)
@@ -277,15 +277,30 @@
* - G_define_module()
* - G_define_flag()
* - G_define_option()
+ * - G_define_standard_flag()
* - G_define_standard_option()
* - G_disable_interactive()
+ * - G_option_exclusive()
+ * - G_option_required()
+ * - G_option_requires()
+ * - G_option_requires_all()
+ * - G_option_excludes()
+ * - G_option_collective()
*
* The usual order a module calls functions is:
*
* # G_gisinit()
* # G_define_module()
+ * # G_define_standard_flag()
+ * # G_define_standard_option()
* # G_define_flag()
* # G_define_option()
+ * # G_option_exclusive()
+ * # G_option_required()
+ * # G_option_requires()
+ * # G_option_requires_all()
+ * # G_option_excludes()
+ * # G_option_collective()
* # G_parser()
*
* \param argc number of arguments
@@ -560,6 +575,8 @@
if (!st->suppress_required)
check_required();
+ G__check_option_rules();
+
if (st->n_errors > 0) {
if (G_verbose() > -1) {
if (G_verbose() > G_verbose_min())
Modified: grass/trunk/lib/gis/parser_dependencies.c
===================================================================
--- grass/trunk/lib/gis/parser_dependencies.c 2014-06-24 09:26:56 UTC (rev 60943)
+++ grass/trunk/lib/gis/parser_dependencies.c 2014-06-24 14:35:57 UTC (rev 60944)
@@ -173,6 +173,12 @@
return s;
}
+static void append_error(const char *msg)
+{
+ st->error = G_realloc(st->error, sizeof(char *) * (st->n_errors + 1));
+ st->error[st->n_errors++] = G_store(msg);
+}
+
/* at most one option from a set */
void G_option_exclusive(void *first, ...)
{
@@ -184,9 +190,12 @@
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));
+ if (count_present(rule, 0) > 1) {
+ char *err;
+ G_asprintf(&err, _("Options %s are mutually exclusive"),
+ describe_rule(rule, 0, 0));
+ append_error(err);
+ }
}
/* at least one option from a set */
@@ -200,9 +209,12 @@
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));
+ if (count_present(rule, 0) < 1) {
+ char *err;
+ G_asprintf(&err, _("At least one of %s is required"),
+ describe_rule(rule, 0, 0));
+ append_error(err);
+ }
}
/* if the first option is present, at least one of the other
@@ -219,9 +231,12 @@
{
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, 1, 1));
+ if (count_present(rule, 1) < 1) {
+ char *err;
+ G_asprintf(&err, _("Option %s requires at least one of %s"),
+ get_name(rule->opts[0]), describe_rule(rule, 1, 1));
+ append_error(err);
+ }
}
/* if the first option is present, all the other options must also
@@ -238,9 +253,12 @@
{
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, 1, 0));
+ if (count_present(rule, 1) < rule->count - 1) {
+ char *err;
+ G_asprintf(&err, _("Option %s requires all of %s"),
+ get_name(rule->opts[0]), describe_rule(rule, 1, 0));
+ append_error(err);
+ }
}
/* if the first option is present, none of the other options may also
@@ -257,9 +275,12 @@
{
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 (count_present(rule, 1) > 0) {
+ char *err;
+ G_asprintf(&err, _("Option %s is mutually exclusive with all of %s"),
+ get_name(rule->opts[0]), describe_rule(rule, 1, 0));
+ append_error(err);
+ }
}
/* if any option is present, all the other options must also be present
@@ -275,9 +296,12 @@
static void check_collective(const struct rule *rule)
{
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));
+ if (count > 0 && count < rule->count) {
+ char *err;
+ G_asprintf(&err, _("Either all or none of %s must be given"),
+ describe_rule(rule, 0, 0));
+ append_error(err);
+ }
}
void G__check_option_rules(void)
More information about the grass-commit
mailing list