===================================================================
@@ -1069,6 +1069,38 @@
decoded->errors = 0;
}
+static void
+candidates_to_string (char *s, const auto_vec <const char *> *candidates)
+{
+ int i;
+ const char *candidate;
+ char *p = s;
+ FOR_EACH_VEC_ELT (*candidates, i, candidate)
+ {
+ gcc_assert (candidate);
+ size_t arglen = strlen (candidate);
+ memcpy (p, candidate, arglen);
+ p[arglen] = ' ';
+ p += arglen + 1;
+ }
+ p[-1] = 0;
+}
+
+void
+unrecognized_argument_hint (location_t loc, const char *opt, const char *arg,
+ const auto_vec <const char*> &candidates,
+ size_t total_len)
+{
+ char *s = XALLOCAVEC (char, total_len);
+ candidates_to_string (s, &candidates);
+ const char *hint = find_closest_string (arg, &candidates);
+ if (hint)
+ inform (loc, "valid arguments to %qs are: %s; did you mean %qs?",
+ opt, s, hint);
+ else
+ inform (loc, "valid arguments to %qs are: %s", opt, s);
+}
+
/* Perform diagnostics for read_cmdline_option and control_warning_option
functions. Returns true if an error has been diagnosed.
LOC and LANG_MASK arguments like in read_cmdline_option.
@@ -1107,40 +1139,22 @@
if (errors & CL_ERR_ENUM_ARG)
{
const struct cl_enum *e = &cl_enums[option->var_enum];
- unsigned int i;
- size_t len;
- char *s, *p;
-
if (e->unknown_error)
error_at (loc, e->unknown_error, arg);
else
- error_at (loc, "unrecognized argument in option %qs", opt);
+ error_at (loc, "argument %qs to %qs not recognized", arg, opt);
- len = 0;
- for (i = 0; e->values[i].arg != NULL; i++)
- len += strlen (e->values[i].arg) + 1;
-
+ size_t len = 0;
+ unsigned int i;
auto_vec <const char *> candidates;
- s = XALLOCAVEC (char, len);
- p = s;
for (i = 0; e->values[i].arg != NULL; i++)
{
if (!enum_arg_ok_for_language (&e->values[i], lang_mask))
- continue;
- size_t arglen = strlen (e->values[i].arg);
- memcpy (p, e->values[i].arg, arglen);
- p[arglen] = ' ';
- p += arglen + 1;
+ continue;
+ len += strlen (e->values[i].arg) + 1;
candidates.safe_push (e->values[i].arg);
}
- p[-1] = 0;
- const char *hint = find_closest_string (arg, &candidates);
- if (hint)
- inform (loc, "valid arguments to %qs are: %s; did you mean %qs?",
- option->opt_text, s, hint);
- else
- inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
-
+ unrecognized_argument_hint (loc, opt, arg, candidates, len);
return true;
}