Mercurial > hg > octave-avbm
changeset 9584:0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 28 Aug 2009 05:30:29 -0400 |
parents | 8dc1531e2149 |
children | 06b8b51dca48 |
files | src/ChangeLog src/genprops.awk src/graphics.cc src/octave.cc |
diffstat | 4 files changed, 41 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2009-08-28 John W. Eaton <jwe@octave.org> + + * graphics.cc (validate_property_name): Return full name of + matched property value. Issue warning if given property name is + abbreviated. + * genprops.awk: Use name returned by validate_property_name for + subsequent matching. + * octave.cc (maximum_braindamage): + Disable Octave:abbreviated-property-match warning. + 2009-08-27 John W. Eaton <jwe@octave.org> * graphics.cc (validate_property_name): New static function.
--- a/src/genprops.awk +++ b/src/genprops.awk @@ -430,11 +430,11 @@ if (base) printf ("void\nbase_properties::set (const caseless_str& pname, const std::string& cname, const octave_value& val)\n{\n") >> filename; else - printf ("void\n%s::properties::set (const caseless_str& pname, const octave_value& val)\n{\n", + printf ("void\n%s::properties::set (const caseless_str& pname_arg, const octave_value& val)\n{\n", class_name) >> filename; if (! base) - printf (" const std::set<std::string>& pnames = all_property_names ();\n\n validate_property_name (\"get\", pnames, pname);\n\n if (error_state)\n return;\n\n") >> filename; + printf (" const std::set<std::string>& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", pnames, pname_arg);\n\n if (error_state)\n return;\n\n") >> filename; first = 1; @@ -483,12 +483,12 @@ if (base) printf ("octave_value\nbase_properties::get (const caseless_str& pname) const\n{\n") >> filename; else - printf ("octave_value\n%s::properties::get (const caseless_str& pname) const\n{\n", + printf ("octave_value\n%s::properties::get (const caseless_str& pname_arg) const\n{\n", class_name) >> filename; printf (" octave_value retval;\n\n") >> filename; if (! base) - printf (" const std::set<std::string>& pnames = all_property_names ();\n\n validate_property_name (\"get\", pnames, pname);\n\n if (error_state)\n return retval;\n\n") >> filename; + printf (" const std::set<std::string>& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", pnames, pname_arg);\n\n if (error_state)\n return retval;\n\n") >> filename; for (i = 1; i<= idx; i++) { @@ -509,11 +509,11 @@ if (base) printf ("property\nbase_properties::get_property (const caseless_str& pname)\n{\n") >> filename; else - printf ("property\n%s::properties::get_property (const caseless_str& pname)\n{\n", + printf ("property\n%s::properties::get_property (const caseless_str& pname_arg)\n{\n", class_name) >> filename; if (! base) - printf (" const std::set<std::string>& pnames = all_property_names ();\n\n validate_property_name (\"get\", pnames, pname);\n\n if (error_state)\n return property ();\n\n") >> filename; + printf (" const std::set<std::string>& pnames = all_property_names ();\n\n caseless_str pname = validate_property_name (\"get\", pnames, pname_arg);\n\n if (error_state)\n return property ();\n\n") >> filename; for (i = 1; i<= idx; i++) {
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -61,7 +61,11 @@ error ("set: invalid value for %s property", pname.c_str ()); } -static void +// Check to see that PNAME matches just one of PNAMES uniquely. +// Return the full name of the match, or an empty caseless_str object +// if there is no match, or the match is ambiguous. + +static caseless_str validate_property_name (const std::string& who, const std::set<std::string>& pnames, const caseless_str& pname) @@ -73,7 +77,15 @@ p != pnames.end (); p++) { if (pname.compare (*p, len)) - matches.insert (*p); + { + if (len == p->length ()) + { + // Exact match. + return pname; + } + + matches.insert (*p); + } } size_t num_matches = matches.size (); @@ -95,13 +107,20 @@ error ("%s: ambiguous property name %s; possible matches:\n\n%s", who.c_str (), pname.c_str (), match_list.c_str ()); } - else if (num_matches == 1 && ! pname.compare (*(matches.begin ()))) + else if (num_matches == 1) { + // Exact match was handled above. + std::string possible_match = *(matches.begin ()); - error ("%s: instead of %s, did you mean %s?", - who.c_str (), pname.c_str (), possible_match.c_str ()); + warning_with_id ("Octave:abbreviated-property-match", + "%s: allowing %s to match %s", who.c_str (), + pname.c_str (), possible_match.c_str ()); + + return possible_match; } + + return caseless_str (); } static Matrix
--- a/src/octave.cc +++ b/src/octave.cc @@ -585,6 +585,7 @@ bind_internal_variable ("page_screen_output", false); bind_internal_variable ("print_empty_dimensions", false); + disable_warning ("Octave:abbreviated-property-match"); disable_warning ("Octave:fopen-file-in-path"); disable_warning ("Octave:function-name-clash"); disable_warning ("Octave:load-file-in-path");