comparison src/variables.cc @ 8131:10b63c4fd413

Add -file option to who/whos
author David Bateman <dbateman@free.fr>
date Tue, 23 Sep 2008 11:31:45 -0400
parents 16ab78b816bc
children b93ac0586e4b
comparison
equal deleted inserted replaced
8130:de8b07e95d1b 8131:10b63c4fd413
1629 1629
1630 }; 1630 };
1631 1631
1632 static octave_value 1632 static octave_value
1633 do_who (int argc, const string_vector& argv, bool return_list, 1633 do_who (int argc, const string_vector& argv, bool return_list,
1634 bool verbose = false) 1634 bool verbose = false, std::string msg = std::string ())
1635 { 1635 {
1636 octave_value retval; 1636 octave_value retval;
1637 1637
1638 std::string my_name = argv[0]; 1638 std::string my_name = argv[0];
1639 1639
1642 1642
1643 int i; 1643 int i;
1644 for (i = 1; i < argc; i++) 1644 for (i = 1; i < argc; i++)
1645 { 1645 {
1646 if (argv[i] == "-file") 1646 if (argv[i] == "-file")
1647 error ("%s: `-file' option not implemented", my_name.c_str ()); 1647 {
1648 // FIXME. This is an inefficient manner to implement this as the
1649 // variables are loaded in to a temporary context and then treated.
1650 // It would be better to refecat symbol_info_list to not store the
1651 // symbol records and then use it in load-save.cc (do_load) to
1652 // implement this option there so that the variables are never
1653 // stored at all.
1654 if (i == argc - 1)
1655 error ("whos: -file argument must be followed by a file name");
1656 else
1657 {
1658 std::string nm = argv [i + 1];
1659
1660 symbol_table::scope_id tmp_scope = symbol_table::alloc_scope ();
1661
1662 unwind_protect::begin_frame ("do_who_file");
1663
1664 symbol_table::push_scope (tmp_scope);
1665 symbol_table::push_context ();
1666 octave_call_stack::push (0);
1667
1668 unwind_protect::add (octave_call_stack::unwind_pop, 0);
1669
1670 unwind_protect::add (symbol_table::clear_variables);
1671
1672 feval ("load", octave_value (nm), 0);
1673
1674 if (! error_state)
1675 {
1676 std::string newmsg = std::string ("Variables in the file ") +
1677 nm + ":\n\n";
1678
1679 retval = do_who (i, argv, return_list, verbose, newmsg);
1680 }
1681
1682 unwind_protect::run_frame ("do_who_file");
1683
1684 symbol_table::erase_scope (tmp_scope);
1685 }
1686
1687 return retval;
1688 }
1648 else if (argv[i] == "-regexp") 1689 else if (argv[i] == "-regexp")
1649 have_regexp = true; 1690 have_regexp = true;
1650 else if (argv[i] == "global") 1691 else if (argv[i] == "global")
1651 global_only = true; 1692 global_only = true;
1652 else if (argv[i][0] == '-') 1693 else if (argv[i][0] == '-')
1761 else 1802 else
1762 retval = Cell (string_vector (symbol_names)); 1803 retval = Cell (string_vector (symbol_names));
1763 } 1804 }
1764 else if (! (symbol_stats.empty () && symbol_names.empty ())) 1805 else if (! (symbol_stats.empty () && symbol_names.empty ()))
1765 { 1806 {
1766 if (global_only) 1807 if (msg.length () == 0)
1767 octave_stdout << "Global variables:\n\n"; 1808 if (global_only)
1768 else 1809 octave_stdout << "Global variables:\n\n";
1769 octave_stdout << "Variables in the current scope:\n\n"; 1810 else
1811 octave_stdout << "Variables in the current scope:\n\n";
1812 else
1813 octave_stdout << msg;
1770 1814
1771 if (verbose) 1815 if (verbose)
1772 symbol_stats.display (octave_stdout); 1816 symbol_stats.display (octave_stdout);
1773 else 1817 else
1774 { 1818 {
1796 List the variables in the global scope rather than the current scope.\n\ 1840 List the variables in the global scope rather than the current scope.\n\
1797 @item -regexp\n\ 1841 @item -regexp\n\
1798 The patterns are considered as regular expressions and will be used\n\ 1842 The patterns are considered as regular expressions and will be used\n\
1799 for matching the variables to display. The same pattern syntax as for\n\ 1843 for matching the variables to display. The same pattern syntax as for\n\
1800 the @code{regexp} function is used.\n\ 1844 the @code{regexp} function is used.\n\
1845 @item -file\n\
1846 The following argument is treated as a filename, and the variables that\n\
1847 are found within this file are listed.\n\
1801 @end table\n\ 1848 @end table\n\
1802 \n\ 1849 \n\
1803 Valid patterns are the same as described for the @code{clear} command\n\ 1850 Valid patterns are the same as described for the @code{clear} command\n\
1804 above. If no patterns are supplied, all symbols from the given category\n\ 1851 above. If no patterns are supplied, all symbols from the given category\n\
1805 are listed. By default, only user defined functions and variables\n\ 1852 are listed. By default, only user defined functions and variables\n\