Mercurial > octave-nkf
diff src/variables.cc @ 4207:fa3482b34599
[project @ 2002-12-03 18:22:05 by jwe]
author | jwe |
---|---|
date | Tue, 03 Dec 2002 18:22:51 +0000 |
parents | 8734ba917fea |
children | e96f52432059 |
line wrap: on
line diff
--- a/src/variables.cc Fri Nov 29 20:13:01 2002 +0000 +++ b/src/variables.cc Tue Dec 03 18:22:51 2002 +0000 @@ -27,6 +27,7 @@ #include <cstdio> #include <cstring> +#include <set> #include <string> #include "file-stat.h" @@ -103,11 +104,108 @@ // Is this a text-style function? +static std::set <std::string> text_function_set; + +static inline bool +is_marked_as_text_function (const std::string& s) +{ + return text_function_set.find (s) != text_function_set.end (); +} + +static inline void +mark_as_text_function (const std::string& s) +{ + text_function_set.insert (s); +} + +static inline void +unmark_text_function (const std::string& s) +{ + text_function_set.erase (s); + + symbol_record *sr = fbi_sym_tab->lookup (s); + + if (sr) + sr->unmark_text_function (); +} + +DEFUN_TEXT (mark_as_text_function, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mark_as_text_function (@var{name})\n\ +Enter @var{name} into the list of text functions\n\ +@end deftypefn") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin > 0) + { + int argc = nargin + 1; + + string_vector argv = args.make_argv ("mark_as_text_function"); + + if (! error_state) + { + for (int i = 1; i < argc; i++) + mark_as_text_function (argv[i]); + } + } + else + print_usage ("mark_as_text_function"); + + return retval; +} + +DEFUN_TEXT (unmark_text_function, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} mark_as_text_function (@var{name})\n\ +Enter @var{name} into the list of text functions\n\ +@end deftypefn") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin > 0) + { + int argc = nargin + 1; + + string_vector argv = args.make_argv ("unmark_text_function"); + + if (! error_state) + { + for (int i = 1; i < argc; i++) + unmark_text_function (argv[i]); + } + } + else + print_usage ("unmark_text_function"); + + return retval; +} + bool is_text_function_name (const std::string& s) { + bool retval = false; + symbol_record *sr = fbi_sym_tab->lookup (s); - return (sr && sr->is_text_function ()); + + if (sr) + { + if (sr->is_text_function ()) + retval = true; + else if (is_marked_as_text_function (s)) + { + sr->mark_as_text_function (); + retval = true; + } + } + else + retval = is_marked_as_text_function (s); + + return retval; } // Is this a built-in function?