From bug-request at octave dot org Wed Jan 11 08:14:25 2006 Subject: Patch for autoload fixes [Was: lookfor: Texinfo formatting filter exited abnormally] From: David Bateman To: Keith Goodman Cc: octave bug mailing list Date: Wed, 11 Jan 2006 15:10:00 +0100 This is a multi-part message in MIME format. --------------010400040201000706070003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Keith, I'm not sure why texinfo is returning an error, but the fact that cumsum is not found is that lookfor at the moment only looks for the string in the first sentence or body of the help and not the function name. As I was last night looking at dealing with the simple_help, line completion and lookfor issues of autoloaded functions, I actually fixed the issue that cumsum isn't found with the attached patch. It doesn't address the texinfo issue as I don't see it and don't understand why you got this issue. Regards David 2006-01-11 David Bateman * help.cc (make_name_list): Add autoload functions to list of available completions. (simple_help): Add autoloaded functions to functions listed (Flookfor): Check for string match in the keyword/function, etc name. Also use look for string match in help of autoloaded functions * parse.y (string_vector autoloaded_functions (void)): New function to list all autloaded functions. (string_vector reverse_lookup_autoload (const std::string& nm)): Reverse lookup function to match file to autoloaded functions. * parse.h (autoloaded_functions, reverse_lookup_autoload): Declaration. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary --------------010400040201000706070003 Content-Type: text/plain; name="patch.autoload-20060111" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.autoload-20060111" *** ./src/help.cc.orig3 2006-01-11 10:33:44.642739745 +0100 --- ./src/help.cc 2006-01-11 11:58:05.520064329 +0100 *************** *** 407,413 **** string_vector ffl = octave_fcn_file_name_cache::list_no_suffix (); int ffl_len = ffl.length (); ! int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len; string_vector list (total_len); --- 407,416 ---- string_vector ffl = octave_fcn_file_name_cache::list_no_suffix (); int ffl_len = ffl.length (); ! string_vector afl = autoloaded_functions (); ! int afl_len = afl.length (); ! ! int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len + afl_len; string_vector list (total_len); *************** *** 433,438 **** --- 436,444 ---- for (i = 0; i < ffl_len; i++) list[j++] = ffl[i]; + for (i = 0; i < afl_len; i++) + list[j++] = afl[i]; + return list; } *************** *** 542,547 **** --- 548,564 ---- names.list_in_columns (octave_stdout); } } + + string_vector autoloaded = autoloaded_functions (); + + if (! autoloaded.empty ()) + { + octave_stdout << "\n*** autoloaded functions:\n\n"; + + autoloaded.qsort (); + + autoloaded.list_in_columns (octave_stdout); + } } static int *************** *** 1571,1585 **** std::string name = ptr->name; std::string h = ptr->help; ! std::string s; ! if (first_sentence_only) ! s = first_help_sentence (h); ! else ! s = h; ! ! transform (s.begin (), s.end (), s.begin (), tolower); ! ! if (s.length () > 0 && s.find (txt) != NPOS) { if (nargout) { --- 1588,1594 ---- std::string name = ptr->name; std::string h = ptr->help; ! if (name.find (txt) != NPOS) { if (nargout) { *************** *** 1589,1594 **** --- 1598,1625 ---- else print_lookfor (name, first_help_sentence (h)); } + else + { + std::string s; + + if (first_sentence_only) + s = first_help_sentence (h); + else + s = h; + + transform (s.begin (), s.end (), s.begin (), tolower); + + if (s.length () > 0 && s.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (name); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (name, first_help_sentence (h)); + } + } OCTAVE_QUIT; *************** *** 1601,1615 **** std::string name = ptr->name; std::string h = ptr->help; ! std::string s; ! if (first_sentence_only) ! s = first_help_sentence (h); ! else ! s = h; ! ! transform (s.begin (), s.end (), s.begin (), tolower); ! ! if (s.length () > 0 && s.find (txt) != NPOS) { if (nargout) { --- 1632,1638 ---- std::string name = ptr->name; std::string h = ptr->help; ! if (name.find (txt) != NPOS) { if (nargout) { *************** *** 1619,1624 **** --- 1642,1668 ---- else print_lookfor (name, first_help_sentence (h)); } + else + { + std::string s; + if (first_sentence_only) + s = first_help_sentence (h); + else + s = h; + + transform (s.begin (), s.end (), s.begin (), tolower); + + if (s.length () > 0 && s.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (name); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (name, first_help_sentence (h)); + } + } OCTAVE_QUIT; *************** *** 1639,1653 **** if (sr && sr->is_defined ()) { std::string h = sr->help (); - std::string s; - if (first_sentence_only) - s = first_help_sentence (h); - else - s = h; - - transform (s.begin (), s.end (), s.begin (), tolower); ! if (s.length () > 0 && s.find (txt) != NPOS) { if (nargout) { --- 1683,1690 ---- if (sr && sr->is_defined ()) { std::string h = sr->help (); ! if (name.find (txt) != NPOS) { if (nargout) { *************** *** 1657,1662 **** --- 1694,1721 ---- else print_lookfor (name, first_help_sentence (h)); } + else + { + std::string s; + + if (first_sentence_only) + s = first_help_sentence (h); + else + s = h; + + transform (s.begin (), s.end (), s.begin (), tolower); + + if (s.length () > 0 && s.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (name); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (name, first_help_sentence (h)); + } + } } } *************** *** 1697,1703 **** std::string file_name = Vload_path_dir_path.find_first_of (tmp); - if (file_name == dirs[i] + tmp(0) || file_name == dirs[i] + tmp(1)) { --- 1756,1761 ---- *************** *** 1706,1720 **** std::string h = get_help_from_file (file_name, symbol_found); ! std::string s; ! if (first_sentence_only) ! s = first_help_sentence (h); ! else ! s = h; ! ! transform (s.begin (), s.end (), s.begin (), tolower); ! ! if (s.length () > 0 && s.find (txt) != NPOS) { if (nargout) { --- 1764,1770 ---- std::string h = get_help_from_file (file_name, symbol_found); ! if (name.find (txt) != NPOS) { if (nargout) { *************** *** 1724,1736 **** else print_lookfor (name, first_help_sentence (h)); } } } } } } - if (nargout != 0) { retval (1) = ret[1]; --- 1774,1869 ---- else print_lookfor (name, first_help_sentence (h)); } + else + { + std::string s; + if (first_sentence_only) + s = first_help_sentence (h); + else + s = h; + + transform (s.begin (), s.end (), s.begin (), tolower); + + if (s.length () > 0 && s.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (name); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (name, first_help_sentence (h)); + } + } + } + } + + // Check if this function has autoloaded functions attached to it + string_vector autoload_fcns = reverse_lookup_autoload (names(j)); + + if (! autoload_fcns.empty ()) + { + for (int k = 0; k < names.length (); k++) + { + std::string aname = autoload_fcns (k); + + // Check if already in symbol table + sr = fbi_sym_tab->lookup (aname); + + if (!sr) + { + // Check if this version is first in the path + std::string file_name = + Vload_path_dir_path.find_first_of (names(j)); + + if (file_name == dirs[i] + names(j)) + { + bool symbol_found; + + std::string h + = get_help_from_file (aname, symbol_found); + + if (aname.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (aname); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (aname, first_help_sentence (h)); + } + else + { + std::string s; + if (first_sentence_only) + s = first_help_sentence (h); + else + s = h; + + transform (s.begin (), s.end (), s.begin (), + tolower); + + if (s.length () > 0 && s.find (txt) != NPOS) + { + if (nargout) + { + ret[0].append (name); + ret[1].append (first_help_sentence (h)); + } + else + print_lookfor (name, + first_help_sentence (h)); + } + } + } + } } } } } } if (nargout != 0) { retval (1) = ret[1]; *** ./src/parse.h.orig3 2006-01-11 10:35:05.758547100 +0100 --- ./src/parse.h 2006-01-11 11:37:48.461995557 +0100 *************** *** 98,103 **** --- 98,107 ---- extern std::string lookup_autoload (const std::string& nm); + extern string_vector autoloaded_functions (void); + + extern string_vector reverse_lookup_autoload (const std::string& nm); + extern bool load_fcn_from_file (const std::string& nm, bool exec_script); *** ./src/parse.y.orig3 2006-01-11 10:35:13.696133561 +0100 --- ./src/parse.y 2006-01-11 11:52:58.107329150 +0100 *************** *** 3379,3384 **** --- 3379,3412 ---- octave_env::getcwd ()); } + string_vector + autoloaded_functions (void) + { + string_vector names (autoload_map.size()); + + octave_idx_type i = 0; + std::map::const_iterator p; + for (p = std::map::iterator (autoload_map.begin ()); + p != std::map::iterator (autoload_map.end ()); p++) + names[i++] = p->first; + + return names; + } + + string_vector + reverse_lookup_autoload (const std::string& nm) + { + string_vector names; + + std::map::const_iterator p; + for (p = std::map::iterator (autoload_map.begin ()); + p != std::map::iterator (autoload_map.end ()); p++) + if (nm == p->second) + names.append (p->first); + + return names; + } + bool load_fcn_from_file (const std::string& nm, bool exec_script) { --------------010400040201000706070003-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------