# HG changeset patch # User David Bateman # Date 1222183905 14400 # Node ID 10b63c4fd4138010b71abcaa7acc330de49d5f03 # Parent de8b07e95d1b96a20f815b0825799d625fe8ec53 Add -file option to who/whos diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2008-09-23 David Bateman + + * variables.cc (static octave_value do_who (int, const string_vector&, + bool, bool, std::string): Add final message argument and simple + treatment of the "-file" option. + 2008-09-22 David Bateman * debug.cc (static octave_user_code * get_user_code diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -1631,7 +1631,7 @@ static octave_value do_who (int argc, const string_vector& argv, bool return_list, - bool verbose = false) + bool verbose = false, std::string msg = std::string ()) { octave_value retval; @@ -1644,7 +1644,48 @@ for (i = 1; i < argc; i++) { if (argv[i] == "-file") - error ("%s: `-file' option not implemented", my_name.c_str ()); + { + // FIXME. This is an inefficient manner to implement this as the + // variables are loaded in to a temporary context and then treated. + // It would be better to refecat symbol_info_list to not store the + // symbol records and then use it in load-save.cc (do_load) to + // implement this option there so that the variables are never + // stored at all. + if (i == argc - 1) + error ("whos: -file argument must be followed by a file name"); + else + { + std::string nm = argv [i + 1]; + + symbol_table::scope_id tmp_scope = symbol_table::alloc_scope (); + + unwind_protect::begin_frame ("do_who_file"); + + symbol_table::push_scope (tmp_scope); + symbol_table::push_context (); + octave_call_stack::push (0); + + unwind_protect::add (octave_call_stack::unwind_pop, 0); + + unwind_protect::add (symbol_table::clear_variables); + + feval ("load", octave_value (nm), 0); + + if (! error_state) + { + std::string newmsg = std::string ("Variables in the file ") + + nm + ":\n\n"; + + retval = do_who (i, argv, return_list, verbose, newmsg); + } + + unwind_protect::run_frame ("do_who_file"); + + symbol_table::erase_scope (tmp_scope); + } + + return retval; + } else if (argv[i] == "-regexp") have_regexp = true; else if (argv[i] == "global") @@ -1763,10 +1804,13 @@ } else if (! (symbol_stats.empty () && symbol_names.empty ())) { - if (global_only) - octave_stdout << "Global variables:\n\n"; + if (msg.length () == 0) + if (global_only) + octave_stdout << "Global variables:\n\n"; + else + octave_stdout << "Variables in the current scope:\n\n"; else - octave_stdout << "Variables in the current scope:\n\n"; + octave_stdout << msg; if (verbose) symbol_stats.display (octave_stdout); @@ -1798,6 +1842,9 @@ The patterns are considered as regular expressions and will be used\n\ for matching the variables to display. The same pattern syntax as for\n\ the @code{regexp} function is used.\n\ +@item -file\n\ +The following argument is treated as a filename, and the variables that\n\ +are found within this file are listed.\n\ @end table\n\ \n\ Valid patterns are the same as described for the @code{clear} command\n\