# HG changeset patch # User John W. Eaton # Date 1251451829 14400 # Node ID 0fcbfddaa87fc8c4adc9a82b84f8032adc6075a5 # Parent 8dc1531e214922d9d49b63b1d1dd8e62c549a253 allow abbreviated graphics property names to match, with optional warning diff -r 8dc1531e2149 -r 0fcbfddaa87f src/ChangeLog --- a/src/ChangeLog Thu Aug 27 15:49:51 2009 -0400 +++ b/src/ChangeLog Fri Aug 28 05:30:29 2009 -0400 @@ -1,3 +1,13 @@ +2009-08-28 John W. Eaton + + * 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 * graphics.cc (validate_property_name): New static function. diff -r 8dc1531e2149 -r 0fcbfddaa87f src/genprops.awk --- a/src/genprops.awk Thu Aug 27 15:49:51 2009 -0400 +++ b/src/genprops.awk Fri Aug 28 05:30:29 2009 -0400 @@ -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& 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& 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& 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& 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& 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& 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++) { diff -r 8dc1531e2149 -r 0fcbfddaa87f src/graphics.cc --- a/src/graphics.cc Thu Aug 27 15:49:51 2009 -0400 +++ b/src/graphics.cc Fri Aug 28 05:30:29 2009 -0400 @@ -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& 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 diff -r 8dc1531e2149 -r 0fcbfddaa87f src/octave.cc --- a/src/octave.cc Thu Aug 27 15:49:51 2009 -0400 +++ b/src/octave.cc Fri Aug 28 05:30:29 2009 -0400 @@ -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");