# HG changeset patch # User jwe # Date 1045170184 0 # Node ID 05973ead74eb801b5357c2aaef10bf5d7bb3eb45 # Parent 115bffcecfd3f92f26af804b1ec048fad1db8d9a [project @ 2003-02-13 21:03:04 by jwe] diff -r 115bffcecfd3 -r 05973ead74eb src/ChangeLog --- a/src/ChangeLog Thu Feb 13 05:52:16 2003 +0000 +++ b/src/ChangeLog Thu Feb 13 21:03:04 2003 +0000 @@ -1,3 +1,12 @@ +2003-02-13 Paul Kienzle + + * variables.cc (Fmlock, Fmunlock, Fmislocked): New functions. + + * variables.cc (mlock, munlock, mislocked): New functions. + * variables.h: Provide decls. + + * symtab.h (symbol_record::unmark_static): New function. + 2003-02-12 John W. Eaton * error.cc (reset_error_handler): New function. diff -r 115bffcecfd3 -r 05973ead74eb src/symtab.h --- a/src/symtab.h Thu Feb 13 05:52:16 2003 +0000 +++ b/src/symtab.h Thu Feb 13 21:03:04 2003 +0000 @@ -323,6 +323,7 @@ void mark_as_static (void); bool is_static (void) const { return tagged_static; } + void unmark_static (void) { tagged_static = false; } int rows (void) const { return definition->rows (); } int columns (void) const { return definition->columns (); } diff -r 115bffcecfd3 -r 05973ead74eb src/variables.cc --- a/src/variables.cc Thu Feb 13 05:52:16 2003 +0000 +++ b/src/variables.cc Thu Feb 13 21:03:04 2003 +0000 @@ -1290,6 +1290,131 @@ sr->document (help); } +void +mlock (const std::string& nm) +{ + symbol_record *sr = fbi_sym_tab->lookup (nm, true); + + if (sr) + sr->mark_as_static (); +} + +void +munlock (const std::string& nm) +{ + symbol_record *sr = fbi_sym_tab->lookup (nm); + + if (sr && sr->is_static ()) + sr->unmark_static (); + else + error ("munlock: %s is not locked", nm.c_str ()); +} + +bool +mislocked (const std::string& nm) +{ + symbol_record *sr = fbi_sym_tab->lookup (nm); + + return (sr && sr->is_static ()); +} + +DEFCMD (mlock, args, , + "-*- texinfo -*-\n\ +@deftypefnx {Built-in Function} {} mlock (@var{name})\n\ +Lock the named function into memory. If no function is named\n\ +then lock in the current function.\n\ +@end deftypefn\n\ +@seealso{munlock, mislocked, and persistent}") +{ + octave_value_list retval; + + if (args.length () == 1) + { + std::string name = args(0).string_value (); + + if (! error_state) + mlock (name); + else + error ("mlock: expecting argument to be a function name"); + } + else if (args.length () == 0) + { + if (curr_function) + mlock (curr_function->function_name ()); + else + error ("mlock: invalid use outside a function"); + } + else + print_usage ("mlock"); + + return retval; +} + +DEFCMD (munlock, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} munlock (@var{fcn})\n\ +Unlock the named function. If no function is named\n\ +then unlock the current function.\n\ +@end deftypefn\n\ +@seealso{mlock, mislocked, and persistent}") +{ + octave_value_list retval; + + if (args.length() == 1) + { + std::string name = args(0).string_value (); + + if (! error_state) + munlock (name); + else + error ("munlock: expecting argument to be a function name"); + } + else if (args.length () == 0) + { + if (curr_function) + mlock (curr_function->function_name ()); + else + error ("munlock: invalid use outside a function"); + } + else + print_usage ("munlock"); + + return retval; +} + + +DEFCMD (mislocked, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mislocked (@var{fcn})\n\ +Return true if the named function is locked. If no function is named\n\ +then return true if the current function is locked.\n\ +@end deftypefn\n\ +@seealso{mlock, munlock, and persistent}") +{ + octave_value retval; + + if (args.length() == 1) + { + std::string name = args(0).string_value (); + + if (! error_state) + retval = mislocked (name); + else + error ("mislocked: expecting argument to be a function name"); + } + else if (args.length () == 0) + { + if (curr_function) + retval = mislocked (curr_function->function_name ()); + else + error ("mislocked: invalid use outside a function"); + } + else + print_usage ("mislocked"); + + return retval; +} + // Deleting names from the symbol tables. static inline bool diff -r 115bffcecfd3 -r 05973ead74eb src/variables.h --- a/src/variables.h Thu Feb 13 05:52:16 2003 +0000 +++ b/src/variables.h Thu Feb 13 21:03:04 2003 +0000 @@ -71,6 +71,10 @@ extern bool looks_like_struct (const std::string& text); +extern int +symbol_exist (const std::string& name, + const std::string& type = std::string ()); + extern bool lookup (symbol_record *s, bool exec_script = true); extern symbol_record * @@ -106,9 +110,9 @@ symbol_record::change_function f = 0, const std::string& help = std::string ()); -extern int -symbol_exist (const std::string& name, - const std::string& type = std::string ()); +extern void mlock (const std::string&); +extern void munlock (const std::string&); +extern bool mislocked (const std::string&); // Symbol table for symbols at the top level. extern symbol_table *top_level_sym_tab;