Mercurial > hg > octave-nkf
changeset 5780:cbf717bf8150
[project @ 2006-04-27 20:02:30 by jwe]
author | jwe |
---|---|
date | Thu, 27 Apr 2006 20:03:48 +0000 |
parents | 12eeebfa7ead |
children | faafc2d98b8d |
files | liboctave/CSparse.cc src/ChangeLog src/defaults.cc src/defun-int.h src/defun.cc src/help.cc src/oct-stream.cc src/octave.cc src/sighandlers.cc src/symtab.cc src/symtab.h src/toplev.cc src/variables.cc src/variables.h |
diffstat | 14 files changed, 183 insertions(+), 216 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CSparse.cc +++ b/liboctave/CSparse.cc @@ -5823,7 +5823,7 @@ Ai, reinterpret_cast<const double *> (Ax), NULL, - reinterpret_cast<double *>, (&Xx[iidx]), + reinterpret_cast<double *> (&Xx[iidx]), NULL, reinterpret_cast<const double *> (Bz), NULL, Numeric,
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,8 +1,62 @@ +2006-04-27 John W. Eaton <jwe@octave.org> + + * variables.cc (Fexist): Fix doc string. + + * help.cc (simple_help): No need to handle built-in constants now. + * variables.cc (do_who): Likewise. + (symbol_exist): Likewise. + (link_to_builtin_or_function): Likewise. + + * symtab.cc (SYMBOL_DEF::type_as_string): Likewise. + (record::read_only_error): Likewise. + (SYMBOL_DEF::type): Likewise. + (record::variable_reference): Likewise. + (symbol_record::define_builtin_const): Delete function. + + * symtab.h (symbol_record::define_builtin_const): Delete decl. + (symbol_record::symbol_def::is_constant): Delete function. + (symbol_record::symbol_def::is_builtin_constant): Delete function. + (symbol_record::symbol_def::is_constant): Delete function. + (symbol_record::is_builtin_constant): Delete function. + (SYMTAB_ALL_TYPES): No need to handle builtin-constants now. + (symbol_record::TYPE): Remove BUILTIN_CONSTANT from enum. + (symbol_record): + + * defun.cc (install_builtin_constant): Delete function. + * defun-int.h (install_builtin_constant): Delete decl. + + * variables.cc (bind_builtin_constant): Delete function. + * variables.h (bind_builtin_constant): Delete decl. + + * defun-int.h (DEFCONST, DEFCONSTX, DEFCONST_INTERNAL, + DEFCONSTX_INTERNAL): Delete definitions. + + * sighandlers.cc (FSIG): New function to replace DEFCONST in + symbols_of_sighandlers. + + * octave.cc (intern_argv): Set octave_argv instead of calling + bind_builtin_variable here. + (Fargv, Fprogram_invocation_name, Fprogram_name): New functions to + replace DEFCONSTs in symbols_of_toplvev in toplev.cc. + (octave_program_invocation_name, octave_program_name): + New static variables. + (execute_command_line_file): Use unwind_protect_str to protect + octave_program_invocation_name, octave_program_name instead of + using a restore function. + (restore_program_name): Delete. + + * defaults.cc (FOCTAVE_HOME): New function to replace DEFCONST in + symbols_of_defaults. + 2006-04-27 David Bateman <dbateman@free.fr> * DLD-FUNCTIONS/regexp.cc (octregexp): Fix for infinite loop in regexp. Include news regexp arguments, and associated tests. +2006-04-26 John W. Eaton <jwe@octave.org> + + * oct-stream.cc: Also instantiate do_read functions for boolNDArray. + 2006-04-26 Bill Denney <denney@seas.upenn.edu> * pager.cc (Fterminal_size): Add list_in_columns to @seealso.
--- a/src/defaults.cc +++ b/src/defaults.cc @@ -734,13 +734,22 @@ A colon separated list of directories in which to search for image\n\ files.\n\ @end defvr"); +} - DEFCONST (OCTAVE_HOME, Voctave_home, - "-*- texinfo -*-\n\ -@defvr {Built-in Constant} OCTAVE_HOME\n\ -The name of the top-level Octave installation directory.\n\ -@end defvr"); +DEFUN (OCTAVE_HOME, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ +Return the name of the top-level Octave installation directory.\n\ +@end deftypefn") +{ + octave_value retval; + if (args.length () == 0) + retval = Voctave_home; + else + print_usage ("OCTAVE_HOME"); + + return retval; } DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, ,
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -54,10 +54,6 @@ const std::string& h); extern void -install_builtin_constant (const std::string& n, const octave_value& v, - bool p, const std::string& h); - -extern void install_dld_function (octave_dld_function::fcn f, const std::string& name, const octave_shlib& shl, const std::string& doc, bool is_text_fcn = false); @@ -116,20 +112,6 @@ #define DEFVAR(name, defn, chg_fcn, doc) \ DEFVAR_INTERNAL (#name, SBV_ ## name, defn, false, chg_fcn, doc) -// Define a builtin constant `name' (which may be redefined, but will -// retain its original value when cleared) and also an alias to it -// called `__name__' (which may not be redefined). - -#define DEFCONST(name, defn, doc) \ - DEFCONST_INTERNAL (name, defn, doc) - -// This one can be used when `name' cannot be used directly (if it is -// already defined as a macro). In that case, name is already a -// quoted string, and the name of the structure must to be passed too. - -#define DEFCONSTX(name, sname, defn, doc) \ - DEFCONSTX_INTERNAL (name, sname, defn, doc) - // MAKE_BUILTINS is defined to extract function names and related // information and create the *.df files that are eventually used to // create the builtins.cc file. @@ -177,16 +159,6 @@ XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ END_INSTALL_BUILTIN -#define DEFCONST_INTERNAL(name, defn, doc) \ - BEGIN_INSTALL_BUILTIN \ - XDEFCONST_INTERNAL(name, defn, doc) \ - END_INSTALL_BUILTIN - -#define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ - BEGIN_INSTALL_BUILTIN \ - XDEFCONST_INTERNAL(name, defn, doc) \ - END_INSTALL_BUILTIN - #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ d_c_map, c_c_map, lo, hi, \ ch_map_flag, can_ret_cmplx_for_real, doc) \ @@ -226,12 +198,6 @@ #define INSTALL_CONST(name, sname, defn, protect, doc) \ install_builtin_constant (name, octave_value (defn), protect, doc) -#define DEFCONST_INTERNAL(name, defn, doc) \ - INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); - -#define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ - INSTALL_CONST (name, sname, defn, false, doc); - // How mapper functions are actually installed. // FIXME -- Really want to avoid the following casts, since
--- a/src/defun.cc +++ b/src/defun.cc @@ -127,13 +127,6 @@ } void -install_builtin_constant (const std::string& name, const octave_value& val, - bool protect, const std::string& help) -{ - bind_builtin_constant (name, val, protect, false, help); -} - -void install_builtin_variable (const std::string& name, const octave_value& value, bool protect, bool eternal, symbol_record::change_function chg_fcn,
--- a/src/help.cc +++ b/src/help.cc @@ -518,8 +518,6 @@ // FIXME -- is this distinction needed? - LIST_SYMBOLS (symbol_record::BUILTIN_CONSTANT, "built-in constants"); - LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "built-in variables"); LIST_SYMBOLS (symbol_record::COMMAND, "commands");
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -3195,6 +3195,7 @@ // INSTANTIATE_DO_READ (floatNDArray); INSTANTIATE_DO_READ (NDArray); INSTANTIATE_DO_READ (charNDArray); +INSTANTIATE_DO_READ (boolNDArray); typedef octave_value (*read_fptr) (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, oct_mach_info::float_format ffmt, octave_idx_type&);
--- a/src/octave.cc +++ b/src/octave.cc @@ -88,6 +88,13 @@ // The command-line options. static string_vector octave_argv; +// The name used to invoke Octave. +static std::string +octave_program_invocation_name; + +// The last component of octave_program_invocation_name. +static std::string octave_program_name; + // TRUE means we read ~/.octaverc and ./.octaverc. // (--norc; --no-init-file; -f) static bool read_init_files = true; @@ -175,21 +182,15 @@ nargin_sr->define (argc-1); - Cell args; - if (argc > 1) { - Array<octave_value> tmp (argc-1); + octave_argv.resize (argc-1); // Skip program name in argv. int i = argc; while (--i > 0) - tmp(i-1) = octave_value (*(argv+i)); - - args = Cell (tmp, argc-1, 1); + octave_argv[i-1] = *(argv+i); } - - bind_builtin_constant ("argv", args, true, true); } static void @@ -354,15 +355,6 @@ } static void -restore_program_name (void *) -{ - bind_builtin_variable ("program_invocation_name", - octave_env::get_program_invocation_name ()); - - bind_builtin_variable ("program_name", octave_env::get_program_name ()); -} - -static void execute_command_line_file (const std::string& fname) { unwind_protect::begin_frame ("execute_command_line_file"); @@ -374,7 +366,8 @@ unwind_protect_str (curr_fcn_file_name); unwind_protect_str (curr_fcn_file_full_name); - unwind_protect::add (restore_program_name, 0); + unwind_protect_str (octave_program_invocation_name); + unwind_protect_str (octave_program_name); interactive = false; reading_script_file = true; @@ -383,14 +376,14 @@ curr_fcn_file_name = fname; curr_fcn_file_full_name = curr_fcn_file_name; - bind_builtin_variable ("program_invocation_name", curr_fcn_file_name); + octave_program_invocation_name = curr_fcn_file_name; size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars); std::string tmp = (pos != NPOS) ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; - bind_builtin_variable ("program_name", tmp); + octave_program_name = tmp; parse_and_execute (fname, false, "octave"); @@ -490,6 +483,9 @@ { octave_env::set_program_name (argv[0]); + octave_program_invocation_name = octave_env::get_program_invocation_name (); + octave_program_name = octave_env::get_program_name (); + // The order of these calls is important. The call to // install_defaults must come before install_builtins because // default variable values must be available for the variables to be @@ -746,6 +742,75 @@ return 0; } +DEFUN (argv, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} argv ()\n\ +Return the command line arguments passed to Octave. For example,\n\ +if you invoked Octave using the command\n\ +\n\ +@example\n\ +octave --no-line-editing --silent\n\ +@end example\n\ +\n\ +@noindent\n\ +@code{argv} would return a cell array of strings with the elements\n\ +@code{--no-line-editing} and @code{--silent}.\n\ +\n\ +If you write an executable Octave script, @code{argv} will return the\n\ +list of arguments passed to the script. @xref{Executable Octave Programs},\n\ +for an example of how to create an executable Octave script.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 0) + retval = Cell (octave_argv); + else + print_usage ("argv"); + + return retval; +} + +DEFUN (program_invocation_name, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} program_invocation_name ()\n\ +Return the name that was typed at the shell prompt to run Octave.\n\ +\n\ +If executing a script from the command line (e.g., @code{octave foo.m})\n\ +or using an executable Octave script, the program name is set to the\n\ +name of the script. @xref{Executable Octave Programs}, for an example of\n\ +how to create an executable Octave script.\n\ +@seealso{program_name}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 0) + retval = octave_program_invocation_name; + else + print_usage ("program_invocation_name"); + + return retval; +} + +DEFUN (program_name, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} program_name ()\n\ +Return the last component of of the value returned by\n\ +@code{program_invocation_name}.\n\ +@seealso{program_invocation_name}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 0) + retval = octave_program_name; + else + print_usage ("program_name"); + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -971,6 +971,26 @@ return retval; } +DEFUN (SIG, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} SIG ()\n\ +Return a structure containing Unix signal names and their defined values.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 0) + { + static Octave_map m = make_sig_struct (); + + retval = m; + } + else + print_usage ("SIG"); + + return retval; +} + static int debug_on_interrupt (void) { @@ -1025,12 +1045,6 @@ current variables the the file \"octave-core\" if it receives a\n\ terminate signal. The default value is 1.\n\ @end defvr"); - - DEFCONST (SIG, make_sig_struct (), - "-*- texinfo -*-\n\ -@defvr {Built-in Constant} SIG\n\ -Structure of Unix signal names and their defined values.\n\ -@end defvr"); } /*
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -82,8 +82,6 @@ retval = "built-in mapper function"; else if (is_user_function ()) retval = "user-defined function"; - else if (is_builtin_constant ()) - retval = "built-in constant"; else if (is_builtin_variable ()) retval = "built-in variable"; else if (is_builtin_function ()) @@ -132,9 +130,7 @@ defn->accept (tpc); } } - else if (is_user_variable () - || is_builtin_variable () - || is_builtin_constant ()) + else if (is_user_variable () || is_builtin_variable ()) { if (pr_type_info && ! quiet) os << name << " is a " << type_as_string () << "\n"; @@ -228,21 +224,6 @@ } bool -symbol_record::define_builtin_const (const octave_value& v) -{ - bool retval = false; - - if (! read_only_error ("redefine")) - { - definition->define (v, symbol_record::BUILTIN_CONSTANT); - - retval = true; - } - - return retval; -} - -bool symbol_record::define (octave_function *f, unsigned int sym_type) { bool retval = false; @@ -368,7 +349,7 @@ } } - if (is_function () || is_constant ()) + if (is_function ()) clear (); if (! is_defined ()) @@ -680,7 +661,7 @@ { if (is_read_only ()) { - if (is_variable () || is_constant ()) + if (is_variable ()) ::error ("can't %s read-only constant `%s'", action, nm.c_str ()); else if (is_function ()) ::error ("can't %s read-only function `%s'", action, nm.c_str ());
--- a/src/symtab.h +++ b/src/symtab.h @@ -75,8 +75,7 @@ COMMAND = 16, RAWCOMMAND = 32, MAPPER_FUNCTION = 64, - BUILTIN_VARIABLE = 128, - BUILTIN_CONSTANT = 256 + BUILTIN_VARIABLE = 128 }; private: @@ -94,9 +93,6 @@ ~symbol_def (void) { } - bool is_constant (void) const - { return (symbol_type & symbol_record::BUILTIN_CONSTANT); } - bool is_variable (void) const { return (symbol_type & symbol_record::USER_VARIABLE @@ -143,9 +139,6 @@ bool is_user_function (void) const { return (symbol_type & symbol_record::USER_FUNCTION); } - bool is_builtin_constant (void) const - { return (symbol_type & symbol_record::BUILTIN_CONSTANT); } - bool is_builtin_variable (void) const { return (symbol_type & symbol_record::BUILTIN_VARIABLE); } @@ -331,12 +324,6 @@ bool is_dld_function (void) const { return definition->is_dld_function (); } - bool is_constant (void) const - { return definition->is_constant (); } - - bool is_builtin_constant (void) const - { return definition->is_builtin_constant (); } - bool is_variable (void) const { return definition->is_variable (); } @@ -373,8 +360,6 @@ void define_builtin_var (const octave_value& v); - bool define_builtin_const (const octave_value& v); - bool define (octave_function *f, unsigned int sym_type); void document (const std::string& h) { definition->document (h); } @@ -511,8 +496,7 @@ | symbol_record::COMMAND \ | symbol_record::RAWCOMMAND \ | symbol_record::MAPPER_FUNCTION \ - | symbol_record::BUILTIN_VARIABLE \ - | symbol_record::BUILTIN_CONSTANT) + | symbol_record::BUILTIN_VARIABLE) #define SYMTAB_VARIABLES (symbol_record::USER_VARIABLE \ | symbol_record::BUILTIN_VARIABLE)
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -927,57 +927,6 @@ #endif -void -symbols_of_toplev (void) -{ - DEFCONST (argv, , - "-*- texinfo -*-\n\ -@defvr {Built-in Constant} argv\n\ -The command line arguments passed to Octave are available in this\n\ -variable. For example, if you invoked Octave using the command\n\ -\n\ -@example\n\ -octave --no-line-editing --silent\n\ -@end example\n\ -\n\ -@noindent\n\ -@code{argv} would be a cell array of strings with the elements\n\ -@code{--no-line-editing} and @code{--silent}.\n\ -\n\ -If you write an executable Octave script, @code{argv} will contain the\n\ -list of arguments passed to the script. @xref{Executable Octave Programs},\n\ -for an example of how to create an executable Octave script.\n\ -@end defvr"); - - DEFCONST (program_invocation_name, - octave_env::get_program_invocation_name (), - "-*- texinfo -*-\n\ -@defvr {Built-in Constant} program_invocation_name\n\ -@defvrx {Built-in Constant} program_name\n\ -When Octave starts, the value of the built-in variable\n\ -@code{program_invocation_name} is automatically set to the name that was\n\ -typed at the shell prompt to run Octave, and the value of\n\ -@code{program_name} is automatically set to the final component of\n\ -@code{program_invocation_name}. For example, if you typed\n\ -@samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ -@code{program_invocation_name} would have the value\n\ -@code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ -have the value @code{\"octave\"}.\n\ -\n\ -If executing a script from the command line (e.g., @code{octave foo.m})\n\ -or using an executable Octave script, the program name is set to the\n\ -name of the script. @xref{Executable Octave Programs}, for an example of\n\ -how to create an executable Octave script.\n\ -@end defvr"); - - DEFCONST (program_name, octave_env::get_program_name (), - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} program_name\n\ -See: program_invocation_name.\n\ -@end defvr"); - -} - /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/variables.cc +++ b/src/variables.cc @@ -805,10 +805,6 @@ { retval = 101; } - else if (var_ok && sr->is_builtin_constant ()) - { - retval = 102; - } } if (! retval @@ -913,7 +909,7 @@ appending @samp{.m}) is a function file in Octave's LOADPATH, 3 if the\n\ name is a @samp{.oct} file in Octave's LOADPATH, 5 if the name is a\n\ built-in function, 7 if the name is a directory, 101 if the name is\n\ -a built-in variable, 102 if the name is a built-in constant, or 103\n\ +a built-in variable, or 103\n\ if the name is a function not associated with a file (entered on\n\ the command line).\n\ \n\ @@ -1365,7 +1361,7 @@ // definition of the builtin variable of the same name. // Make the definition of the symbol record sr be the same as the -// definition of the builtin variable, constant, or function, or user +// definition of the builtin variable or function, or user // function of the same name, provided that the name has not been used // as a formal parameter. @@ -1388,7 +1384,6 @@ if (tmp_sym && (tmp_sym->is_builtin_variable () - || tmp_sym->is_builtin_constant () || tmp_sym->is_function ()) && ! tmp_sym->is_formal_parameter ()) sr->alias (tmp_sym); @@ -1538,7 +1533,6 @@ dim_vector dv (0, 0); - Array<symbol_record *> s1 (dv); Array<symbol_record *> s2 (dv); Array<symbol_record *> s3 (dv); Array<symbol_record *> s4 (dv); @@ -1548,9 +1542,6 @@ if (show_builtins) { - s1 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_CONSTANT, - SYMTAB_ALL_SCOPES); - s2 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); @@ -1576,7 +1567,6 @@ SYMTAB_GLOBAL_SCOPE); } - octave_idx_type s1_len = s1.length (); octave_idx_type s2_len = s2.length (); octave_idx_type s3_len = s3.length (); octave_idx_type s4_len = s4.length (); @@ -1585,14 +1575,12 @@ octave_idx_type s7_len = s7.length (); octave_idx_type symbols_len - = s1_len + s2_len + s3_len + s4_len + s5_len + s6_len + s7_len; + = s2_len + s3_len + s4_len + s5_len + s6_len + s7_len; Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); octave_idx_type k = 0; - symbols.insert (s1, k, 0); - k += s1_len; symbols.insert (s2, k, 0); k += s2_len; symbols.insert (s3, k, 0); @@ -1678,10 +1666,6 @@ if (show_builtins) { pad_after += fbi_sym_tab->maybe_list - ("*** built-in constants:", pats, octave_stdout, - show_verbose, symbol_record::BUILTIN_CONSTANT, SYMTAB_ALL_SCOPES); - - pad_after += fbi_sym_tab->maybe_list ("*** built-in variables:", pats, octave_stdout, show_verbose, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); @@ -1829,32 +1813,6 @@ } } -// Give a global constant a definition. This will insert the symbol -// in the global table if necessary. - -// How is this different than install_builtin_constant? Are both -// functions needed? - -void -bind_builtin_constant (const std::string& name, const octave_value& val, - bool protect, bool eternal, const std::string& help) -{ - symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); - sym_rec->unprotect (); - - std::string tmp_help = help.empty () ? sym_rec->help () : help; - - sym_rec->define_builtin_const (val); - - sym_rec->document (tmp_help); - - if (protect) - sym_rec->protect (); - - if (eternal) - sym_rec->make_eternal (); -} - // Give a global variable a definition. This will insert the symbol // in the global table if necessary.
--- a/src/variables.h +++ b/src/variables.h @@ -119,11 +119,6 @@ extern void bind_ans (const octave_value& val, bool print); extern void -bind_builtin_constant (const std::string&, const octave_value&, - bool protect = false, bool eternal = false, - const std::string& help = std::string ()); - -extern void bind_builtin_variable (const std::string&, const octave_value&, bool protect = false, bool eternal = false, symbol_record::change_function f = 0,