# HG changeset patch # User jwe # Date 1128618733 0 # Node ID 2ff5363a16bd27db0e22b38375932058be50d014 # Parent d2df058c4319b119568adcda125c4fe58eb4089a [project @ 2005-10-06 17:12:12 by jwe] diff -r d2df058c4319 -r 2ff5363a16bd COPYING --- a/COPYING Wed Oct 05 07:54:51 2005 +0000 +++ b/COPYING Thu Oct 06 17:12:13 2005 +0000 @@ -2,7 +2,7 @@ Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -291,7 +291,7 @@ the "copyright" line and a pointer to where the full notice is found. - Copyright (C) 19yy + Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -305,7 +305,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. @@ -313,7 +313,7 @@ If the program is interactive, make it output a short notice like this when it starts in an interactive mode: - Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff -r d2df058c4319 -r 2ff5363a16bd src/ChangeLog --- a/src/ChangeLog Wed Oct 05 07:54:51 2005 +0000 +++ b/src/ChangeLog Thu Oct 06 17:12:13 2005 +0000 @@ -1,3 +1,14 @@ +2005-10-05 John W. Eaton + + * variables.cc (symbol_exist): Chekck for autoloaded functions. + + * parse.y (Fautoload): New function. + (autoloading, autoload_map): New static variables. + (load_fcn_from_file, frob_function): Handle autoloading. + (lookup_autoload): New function. + (get_help_from_file): New args, symbol_found and include_file_info. + Change all callers. + 2005-10-05 David Bateman * help.cc (try_info): format in command string for mingw. diff -r d2df058c4319 -r 2ff5363a16bd src/help.cc --- a/src/help.cc Wed Oct 05 07:54:51 2005 +0000 +++ b/src/help.cc Thu Oct 06 17:12:13 2005 +0000 @@ -849,21 +849,13 @@ { bool retval = false; - std::string file = fcn_file_in_path (nm); - - if (file.length () > 0) - { - symbol_found = true; - - std::string h = get_help_from_file (file); + std::string h = get_help_from_file (nm, symbol_found, true); - if (h.length () > 0) - { - os << nm << " is the file: " << file << "\n\n"; - display_help_text (os, h); - os << "\n"; - retval = true; - } + if (h.length () > 0) + { + display_help_text (os, h); + os << "\n"; + retval = true; } return retval; @@ -1715,7 +1707,10 @@ if (file_name == dirs[i] + tmp(0) || file_name == dirs[i] + tmp(1)) { - std::string h = get_help_from_file (file_name); + bool symbol_found; + + std::string h + = get_help_from_file (file_name, symbol_found); std::string s; if (first_sentence_only) diff -r d2df058c4319 -r 2ff5363a16bd src/parse.h --- a/src/parse.h Wed Oct 05 07:54:51 2005 +0000 +++ b/src/parse.h Thu Oct 06 17:12:13 2005 +0000 @@ -92,7 +92,11 @@ parse_and_execute (const std::string& s, bool verbose = false, const char *warn_for = 0); -extern std::string get_help_from_file (const std::string& f); +extern std::string +get_help_from_file (const std::string& nm, bool& symbol_found, + bool include_file_info = false); + +extern std::string lookup_autoload (const std::string& nm); extern bool load_fcn_from_file (const std::string& nm, bool exec_script); diff -r d2df058c4319 -r 2ff5363a16bd src/parse.y --- a/src/parse.y Wed Oct 05 07:54:51 2005 +0000 +++ b/src/parse.y Thu Oct 06 17:12:13 2005 +0000 @@ -39,6 +39,8 @@ #include #endif +#include + #include "Cell.h" #include "Matrix.h" #include "cmd-edit.h" @@ -146,6 +148,12 @@ // contain nested functions. std::string parent_function_name; +// TRUE means we are in the process of autoloading a function. +static bool autoloading = false; + +// List of autoloads (function -> file mapping). +static std::map autoload_map; + // Forward declarations for some functions defined at the bottom of // the file. @@ -2510,9 +2518,9 @@ // file. Matlab doesn't provide a diagnostic (it ignores the stated // name). - if (reading_fcn_file) + if (reading_fcn_file || autoloading) { - if (! lexer_flags.parsing_nested_function + if (! (lexer_flags.parsing_nested_function || autoloading) && curr_fcn_file_name != id_name) { if (Vwarn_function_name_clash) @@ -3167,13 +3175,18 @@ } std::string -get_help_from_file (const std::string& path) +get_help_from_file (const std::string& nm, bool& symbol_found, + bool include_file_info) { std::string retval; - if (! path.empty ()) + std::string file = fcn_file_in_path (nm); + + if (! file.empty ()) { - FILE *fptr = fopen (path.c_str (), "r"); + symbol_found = true; + + FILE *fptr = fopen (file.c_str (), "r"); if (fptr) { @@ -3181,6 +3194,9 @@ retval = gobble_leading_white_space (fptr, true, true, false); + if (! retval.empty () && include_file_info) + retval = nm + " is the file: " + file + "\n\n" + retval; + unwind_protect::run (); } } @@ -3355,9 +3371,19 @@ return script_file_executed; } +std::string +lookup_autoload (const std::string& nm) +{ + return + octave_env::make_absolute (Vload_path_dir_path.find (autoload_map[nm]), + octave_env::getcwd ()); +} + bool load_fcn_from_file (const std::string& nm, bool exec_script) { + unwind_protect::begin_frame ("load_fcn_from_file"); + bool script_file_executed = false; string_vector names (2); @@ -3374,12 +3400,23 @@ } else { - names[0] = nm + ".oct"; - names[1] = nm + ".m"; - - file - = octave_env::make_absolute (Vload_path_dir_path.find_first_of (names), - octave_env::getcwd ()); + file = lookup_autoload (nm); + + if (! file.empty ()) + { + unwind_protect_bool (autoloading); + + autoloading = true; + exec_script = true; + } + else + { + names[0] = nm + ".oct"; + names[1] = nm + ".m"; + + file = octave_env::make_absolute (Vload_path_dir_path.find_first_of (names), + octave_env::getcwd ()); + } } int len = file.length (); @@ -3393,22 +3430,28 @@ { // These are needed by yyparse. - unwind_protect::begin_frame ("load_fcn_from_file"); - unwind_protect_str (curr_fcn_file_name); unwind_protect_str (curr_fcn_file_full_name); curr_fcn_file_name = nm; curr_fcn_file_full_name = file; - script_file_executed = parse_fcn_file (file, exec_script); - - if (! (error_state || script_file_executed)) - force_link_to_function (nm); - - unwind_protect::run_frame ("load_fcn_from_file"); + script_file_executed = parse_fcn_file (file, exec_script, autoloading); + + if (! error_state) + { + if (autoloading) + { + script_file_executed = false; + force_link_to_function (nm); + } + else if (! script_file_executed) + force_link_to_function (nm); + } } + unwind_protect::run_frame ("load_fcn_from_file"); + return script_file_executed; } @@ -3418,6 +3461,29 @@ return load_fcn_from_file (sym_rec->name (), exec_script); } +DEFCMD (autoload, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} autoload (@var{function}, @var{file})\n\ +Define @var{function} to autoload from @var{file}.\n\ +@end deftypefn") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin == 2) + { + string_vector argv = args.make_argv ("autoload"); + + if (! error_state) + autoload_map[argv[1]] = argv[2]; + } + else + print_usage ("autoload"); + + return retval; +} + void source_file (const std::string file_name) { diff -r d2df058c4319 -r 2ff5363a16bd src/variables.cc --- a/src/variables.cc Wed Oct 05 07:54:51 2005 +0000 +++ b/src/variables.cc Thu Oct 06 17:12:13 2005 +0000 @@ -828,12 +828,17 @@ { if (! retval) { - string_vector names (2); - - names(0) = name + ".oct"; - names(1) = name + ".m"; - - std::string file_name = Vload_path_dir_path.find_first_of (names); + std::string file_name = lookup_autoload (name); + + if (file_name.empty ()) + { + string_vector names (2); + + names(0) = name + ".oct"; + names(1) = name + ".m"; + + file_name = Vload_path_dir_path.find_first_of (names); + } size_t len = file_name.length ();