Mercurial > hg > octave-terminal
changeset 5794:1138ced03f14
[project @ 2006-05-08 20:23:04 by jwe]
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -4,8 +4,9 @@ * Previous versions of Octave had a number of built-in variables to control warnings (for example, warn_divide_by_zero). These variables have been replaced by warning identifiers that are used - with the warning function to control the state of warnings. Now, - instead of writing + with the warning function to control the state of warnings. + + For example, instead of writing warn_divide_by_zero = false; @@ -44,4 +45,20 @@ help warning_ids + * All built-in variables have been converted to functions. This + change simplifies the interpreter and allows a consistent + interface to internal variables for user-defined packages and the + core functions distributed with Octave. In most cases, code that + simply accesses internal variables does not need to change. Code + that sets internal variables will change. For example, instead of + writing + + PS1 = ">> "; + + you will need to write + + PS1 (">> "); + + + See NEWS.2 for old news.
--- a/liboctave/sparse-dmsolve.cc +++ b/liboctave/sparse-dmsolve.cc @@ -24,9 +24,10 @@ #endif - +// FIXME -- liboctave should not be including files from the src directory. #include "ov-re-sparse.h" #include "ov-cx-sparse.h" + #include "MArray2.h" #include "MSparse.h" #include "SparseQR.h"
--- a/scripts/miscellaneous/doc.m +++ b/scripts/miscellaneous/doc.m @@ -59,19 +59,19 @@ ## Determine if a file called doc.info exist in the same ## directory as the function. - info_file = fullfile (info_dir, "doc.info"); + info_file_name = fullfile (info_dir, "doc.info"); - if (! isstruct (stat (info_file))) - info_file = INFO_FILE; + if (! isstruct (stat (info_file_name))) + info_file_name = info_file (); endif cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s", - INFO_PROGRAM, info_dir, info_file, fname); + info_program (), info_dir, info_file_name, fname); status = system (cmd); if (status == 127) - warning ("unable to find info program `%s'", INFO_PROGRAM); + warning ("unable to find info program `%s'", info_program ()); endif if (nargout > 0)
--- a/scripts/miscellaneous/dump_prefs.m +++ b/scripts/miscellaneous/dump_prefs.m @@ -42,8 +42,6 @@ "EDITOR"; "EXEC_PATH"; "IMAGEPATH"; - "INFO_FILE"; - "INFO_PROGRAM"; "LOADPATH"; "PAGER"; "PS1"; @@ -68,6 +66,9 @@ "history_file"; "history_size"; "ignore_function_time_stamp"; + "info_file"; + "info_program"; + "makeinfo_program"; "max_recursion_depth"; "output_max_field_width"; "output_precision";
--- a/scripts/miscellaneous/warning_ids.m +++ b/scripts/miscellaneous/warning_ids.m @@ -122,6 +122,10 @@ ## printed for implicit conversions of complex numbers to real numbers. ## By default, the @code{Octave:imag-to-real} warning is disabled. ## +## @item Octave:matlab-incompatible +## Print warnings for Octave language features that may cause +## compatibility problems with Matlab. +## ## @item Octave:missing-semicolon ## If the @code{Octave:missing-semicolon} warning is enabled, Octave ## will warn when statements in function definitions don't end in @@ -175,6 +179,14 @@ ## indices outside the current bounds. By default, the ## @code{Octave:resize-on-range-error} warning is disabled. ## +## @item Octave:separator-insert +## Print warning if commas or semicolons might be inserted +## automatically in literal matrices. +## +## @item Octave:single-quote-string +## Print warning if a signle quote character is used to introduce a +## string constant. +## ## @item Octave:str-to-num ## If the @code{Octave:str-to-num} warning is enabled, a warning is printed ## for implicit conversions of strings to their numeric ASCII equivalents.
--- a/scripts/plot/print.m +++ b/scripts/plot/print.m @@ -71,6 +71,8 @@ ## Portable network graphics ## @item pbm ## PBMplus +## @item emf +## Microsoft Enhanced Metafile ## @end table ## ## Other devices are supported by "convert" from ImageMagick. Type
--- a/scripts/startup/main-rcfile +++ b/scripts/startup/main-rcfile @@ -3,21 +3,6 @@ ## This file should contain any commands that should be executed each ## time Octave starts for every user at this site. -## Default state for warnings is "on", but most people will want to -## have these disabled. - -warning ("off", "Octave:array-to-scalar"); -warning ("off", "Octave:array-to-vector"); -warning ("off", "Octave:empty-list-elements"); -warning ("off", "Octave:fortran-indexing"); -warning ("off", "Octave:imag-to-real"); -warning ("off", "Octave:missing-semicolon"); -warning ("off", "Octave:neg-dim-as-zero"); -warning ("off", "Octave:resize-on-range-error"); -warning ("off", "Octave:str-to-num"); -warning ("off", "Octave:string-concat"); -warning ("off", "Octave:variable-switch-label"); - ## Configure readline using the file inputrc in the Octave startup ## directory.
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,199 @@ +2006-05-08 John W. Eaton <jwe@octave.org> + + * load-save.cc: No need to handle built-in variables. + * help.cc (simple_help): No need to handle built-in variables. + + * variables.cc (is_builtin_variable, builtin_string_variable, + builtin_real_scalar_variable, builtin_any_variable): + Delete functions. + (Fexist, Fdocument, do_who, Fwho, link_to_builtin_or_function): + No need to handle built-in variables. + * variables.h (is_builtin_variable, builtin_string_variable, + builtin_real_scalar_variable, builtin_any_variable): Delete decls. + + * symtab.h (symbol_record::symbol_def::is_builtin_variable, + symbol_record::is_builtin_variable): Delete. + (symbol_record::TYPE): Remove BUILTIN_VARIABLE from enum. + (symbol_record::symbol_def::is_variable, SYMTAB_ALL_TYPES, + SYMTAB_VARIABLES): No need to handle built-in variables now. + (symbol_record::define_builtin_variable, + symbol_record::link_to_builtin_variable): Delete decls. + * symtab.cc (record::define, SYMBOL_DEF::type, + SYMBOL_DEF::type_as_string): No need to handle built-in variables. + (symbol_record::define_builtin_variable): Delete. + (symbol_record::variable_reference): No need to attemp to link to + built-in variable. + + * utils.cc (check_preference, warn_old_style_preference): Delete. + * utils.h (check_preference): Delete decl. + + * defun-int.h: Delete all DEFVAR macros. + + * Makefile.in, mkbuiltins: No need for VAR_FILES. + + * parse.y (current_script_file_name): Delete all uses. + (clear_current_script_file_name): Delete function. + + * variables.cc (symbols_of_variables): Delete DEFVAR and function. + (bind_ans): Lookup ans in curr_sym_tab, not fbi_sym_tab. + SR is no longer static, so we insert value in local scope. + + * defun.cc (bind_builtin_variable): Delete function. + * defun-int.h: Delete decl. + + * defaults.cc (fftw_wisdom_program): Rename from fftw_wisdom_prog. + Change all uses. + (VDEFAULT_LOADPATH): Rename from Vdefault_load_path. Change all uses. + (VLOADPATH): Rename from Vload_path. Change all uses. + (VDEFAULT_EXECPATH): Rename from Vdefault_exec_path. Change all uses. + (VEXECPATH): Rename from Vexec_path. Change all uses. + (VEDITOR): Rename from Veditor. Change all uses. + (Ffftw_wisdom_program, FDEFAULT_LOADPATH, FLOADPATH, + FDEFAULT_EXEC_PATH, FEXEC_PATH, FEDITOR, FIMAGEPATH): New functions. + (fftw_wisdom_program, default_load_path, loadpath, + default_exec_path, exec_path, editor, image_path): Delete functions. + (symbols_of_defaults): Delete DEFVARs and function. + + * pr-output.cc (set_output_prec_and_fw): Set Voutput_precision and + Voutput_max_field_width directly instad of calling + bind_builtin_variable. + + * octave.cc (octave_main, maximum_braindamage): + Call bind_internal_variable instead of bind_builtin_variable. + + * pager.cc (Fmore): Set Vpage_screen_output directly instead of + calling bind_builtin_variable. + + * error.cc (Fwarning): Set Vdebug_on_warning directly instead of + calling bind_builtin_variable. + + * error.cc (initialize_warning_options): Now static. + (disable_warning, initialize_default_warning_state): New functions. + + * error.h (initialize_warning_options): Delete decl. + (initialize_default_warning_state): Provide decl. + * octave.cc (octave_main): Call initialize_default_warning_state + instead initialize_warning_options. + + * lex.l (warn_matlab_incompatible, warn_separator_insert, + warn_single_quote_string): Delete functions. + (symbols_of_lex): Delete DEFVARS. + (Vwarn_matlab_incompatible, Vwarn_separator_insert, + Vwarn_single_quote_string): Delete variables. + (maybe_warn_separator_insert, gripe_single_quote_string, + gripe_matlab_incompatible): Call warning_with_id instead of warning. + + * variables.h (SET_NONEMPTY_INTERNAL_STRING_VARIABLE, + SET_INTERNAL_VARIABLE_WITH_LIMITS): New macros. + + * ls-oct-ascii.cc (Fsave_precision): New function. + (save_precision): Delete function. + (symbols_of_ls_oct_ascii): Delete DEFVAR and function. + + * oct-hist.cc (initialize_history): New function. + * oct-hist.h: Provide decl. + * octave.cc (octave_main): Call initialize_history instead of + command_history::read. + + * oct-hist.cc (Fhistory_size, Fhistory_file, + Fhistory_timestamp_format_string, Fsaving_history): New functions. + (history_size, history_file, history_timestamp_format_string, + saving_history): Delete functions. + (symbols_of_oct_hist): Delete DEFVARs and function. + + * pt-mat.cc (Fstring_fill_char): New function. + (string_fill_char): Delete function. + (symbols_of_pt_mat): Delete DEFVAR and function. + + * variables.cc (Fignore_function_time_stamp, ans): New functions. + (ignore_function_time_stamp): Delete function. + (symbols_of_variables): Delete DEFVARs and function. + + * oct-procbuf.cc: (Vkluge_procbuf_delay): Delete variable. + (octave_procbuf::open): Never delay after fork. + (kluge_procbuf_delay): Delete function. + (symbols_of_oct_procbuf): Delete DEFVAR and function. + + * dirfns.cc (Fconfirm_recursive_rmdir): New function. + (confirm_recursive_rmdir): Delete function. + (symbols_of_dirfns): Delete DEFVAR and function. + + * error.cc (initialize_warning_options): Now extern. + Rename from init_warning_options. + * error.h: Provide decl. + * octave.cc (octave_main): Call it here. + + * error.cc (Fbeep_on_error, Fdebug_on_error, Fdebug_on_warning): + New functions. + (beep_on_error, debug_on_error, debug_on_warning): Delete Functions. + (symbols_of_error): Delete DEFVARs and function. + + * help.cc (Finfo_file, Finfo_program, Fmakeinfo_program, + Fsuppress_verbose_help_message): New function. + (info_file, info_program, makeinfo_program, + suppress_verbose_help_message): Delete function. + (symbols_of_help): Delete DEFVARs and function. + (Vinfo_program): Rename from Vinfo_prog. Change all uses. + + * input.cc (FPS1, FPS2, FPS4, Fcompletion_append_char, + Fecho_executing_commands): New functions. + (ps1, ps2, ps4, completion_append_char, echo_executing_commands): + Delete functions. + (symbols_of_input): Delete DEFVARs and function. + (VPS1, VPS2, VPS4): Rename from Vps1, Vps2, Vps4. Change all uses. + (Fecho): Set Vecho_executing_commands directly. + + * load-save.cc (crash_dumps_octave_core, Fdefault_save_options, + Foctave_core_file_limit, Foctave_core_file_name, + Foctave_core_file_options, Fsave_header_format_string): + New functions. + (crash_dumps_octave_core, default_save_options, + octave_core_file_limit, octave_core_file_name, + octave_core_file_options, save_header_format_string): + Delete functions. + (symbols_of_load_save): Delete DEFVARs and function. + + * ov-base.cc (Fprint_answer_id_name, Fsilent_functions): New functions. + (print_answer_id_name, silent_functions): Delete functions. + (symbols_of_ov_base): Delete DEFVARs and function. + + * ov-usr-fcn.cc (Fmax_recursion_depth): New function. + (max_recursion_depth): Delete function. + (symbols_of_ov_usr_fcn): Delete DEFVAR for max_recursion_depth. + Delete function. + + * pager.cc (Fpage_output_immediately, Fpage_screen_output, FPAGER): + New functions. + (page_output_immediately, page_screen_output, pager_binary): + Delete functions. + (symbols_of_pager): Delete DEFVARs and function. + (VPAGER): Rename from Vpager_binary. Change all uses. + + * pr-output.cc (Ffixed_point_format, Fprint_empty_dimensions, + Fsplit_long_rows, Foutput_max_field_width, Foutput_precision, + Fstruct_levels_to_print): New functions. + (fixed_point_format, print_empty_dimensions, split_long_rows, + output_max_field_width, output_precision, struct_levels_to_print): + Delete functions. + (symbols_of_pr_output): Delete DEFVARs and function. + + * pt-assign.cc (Fprint_rhs_assign_val): New function. + (print_rhs_assign_val): Delete function. + (symbols_of_pt_assign): Delete DEFVAR. Delete function. + + * sighandlers.cc (Fdebug_on_interrupt, Fsighup_dumps_octave_core, + Fsigterm_dumps_octave_core): New functions. + (debug_on_interrupt, sighup_dumps_octave_core, + sigterm_dumps_octave_core): Delete functions. + (symbols_of_sighanlders): Delete DEFVARs. Delete function. + + * symtab.cc (Vdebug_symtab_lookups): Now bool. + (Fdebug_symtab_lookups, Fwhos_line_format, + Fvariables_can_hide_functions): New functions. + (debug_symtab_lookups, whos_line_format, + variables_can_hide_functions): Delete functions. + (symbols_of_symtab): Delete DEFVARs and function. + 2006-05-04 David Bateman <dbateman@free.fr> * DLD-FUNCTIONS/sqqr (Fdmperm): Allow compilation with versions @@ -217,7 +413,6 @@ * 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. @@ -231,7 +426,6 @@ (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.
--- a/src/DLD-FUNCTIONS/__gnuplot_raw__.l +++ b/src/DLD-FUNCTIONS/__gnuplot_raw__.l @@ -1464,25 +1464,24 @@ // User-callable functions // ----------------------- -DEFUN_DLD (automatic_replot, args, , +DEFUN_DLD (automatic_replot, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} automatic_replot ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} automatic_replot (@var{new_val})\n\ Query or set the current automatic replot state. Although it is fairly\n\ inefficient, especially for large plots, automatic replotting is enabled\n\ by default for compatibility with Matlab.\n\ -\n\ -When setting the state, @var{new_val}\n\ @end deftypefn") { return SET_INTERNAL_VARIABLE (automatic_replot); } -DEFUN_DLD (gnuplot_binary, args, , +DEFUN_DLD (gnuplot_binary, args, nargout, "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} gnuplot_binary\n\ -The name of the program invoked by the plot command. The default value\n\ -is @code{\"gnuplot\"}. @xref{Installation}.\n\ +@deftypefn {Loadable Function} {@var{val} =} gnuplot_binary ()\n\ +@deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_binary (@var{new_val})\n\ +Query or set the name of the program invoked by the plot command.\n\ +The default value @code{\"gnuplot\"}. @xref{Installation}.\n\ @end deftypefn") { octave_value retval = SET_INTERNAL_VARIABLE (gnuplot_binary); @@ -1493,7 +1492,7 @@ return retval; } -DEFUN_DLD (gnuplot_command_plot, args, , +DEFUN_DLD (gnuplot_command_plot, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} = } gnuplot_command_plot ()\n\ @deftypefnx {Loadable Function} {@var{old_val} = } gnuplot_command_plot (@var{new_val})\n\ @@ -1502,7 +1501,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_plot); } -DEFUN_DLD (gnuplot_command_replot, args, , +DEFUN_DLD (gnuplot_command_replot, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_replot ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_replot (@var{new_val})\n\ @@ -1511,7 +1510,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_replot); } -DEFUN_DLD (gnuplot_command_splot, args, , +DEFUN_DLD (gnuplot_command_splot, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_splot ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_splot (@var{new_val})\n\ @@ -1520,7 +1519,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_splot); } -DEFUN_DLD (gnuplot_command_using, args, , +DEFUN_DLD (gnuplot_command_using, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_using ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_using (@var{new_val})\n\ @@ -1529,7 +1528,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_using); } -DEFUN_DLD (gnuplot_command_with, args, , +DEFUN_DLD (gnuplot_command_with, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_with ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_with (@var{new_val})\n\ @@ -1538,7 +1537,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_with); } -DEFUN_DLD (gnuplot_command_axes, args, , +DEFUN_DLD (gnuplot_command_axes, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_axes ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_axes (@var{new_val})\n\ @@ -1547,7 +1546,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_axes); } -DEFUN_DLD (gnuplot_command_title, args, , +DEFUN_DLD (gnuplot_command_title, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_title ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_title (@var{new_val})\n\ @@ -1556,7 +1555,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_title); } -DEFUN_DLD (gnuplot_command_end, args, , +DEFUN_DLD (gnuplot_command_end, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_end ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_end (@var{new_val})\n\ @@ -1565,7 +1564,7 @@ return SET_INTERNAL_VARIABLE (gnuplot_command_end); } -DEFUN_DLD (gnuplot_use_title_option, args, , +DEFUN_DLD (gnuplot_use_title_option, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{val} =} gnuplot_use_title_option ()\n\ @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_use_title_option (@var{new_val})\n\
--- a/src/DLD-FUNCTIONS/fftw_wisdom.cc +++ b/src/DLD-FUNCTIONS/fftw_wisdom.cc @@ -160,7 +160,7 @@ } std::ostringstream cmd_buf; - cmd_buf << Vfftw_wisdom_prog << " -n -o \"" << name << "\""; + cmd_buf << Vfftw_wisdom_program << " -n -o \"" << name << "\""; for (octave_idx_type k = 0; k < m.rows (); k++) { @@ -197,8 +197,7 @@ fclose (ifile); } else - error ("fftw_wisdom: error running %s", Vfftw_wisdom_prog.c_str ()); - + error ("fftw_wisdom: error running %s", Vfftw_wisdom_program.c_str ()); } #else
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -223,15 +223,7 @@ DEF_1 := $(patsubst %.l, %.df, $(DEF_2)) DEF_FILES := $(patsubst %.cc, %.df, $(DEF_1)) $(DLD_DEF_FILES) -DEFVAR_PATTERN = "^[ \t]*DEF(VAR|CONS(T|TX))[ \t]*\\(" - -VAR_4 := $(addprefix $(srcdir)/, $(SOURCES)) -VAR_3 := $(notdir $(shell egrep -l $(DEFVAR_PATTERN) $(VAR_4))) -VAR_2 := $(patsubst %.y, %.df, $(VAR_3)) -VAR_1 := $(patsubst %.l, %.df, $(VAR_2)) -VAR_FILES := $(patsubst %.cc, %.df, $(VAR_1)) - -DOC_FILES := $(sort $(DEF_FILES) $(VAR_FILES)) +DOC_FILES := $(sort $(DEF_FILES)) OCTAVE_LFLAGS = -L$(TOPDIR)/liboctave -L$(TOPDIR)/libcruft \ -L$(TOPDIR)/src $(RLD_FLAG) @@ -341,10 +333,8 @@ builtins.cc: $(DEF_FILES) mkbuiltins @echo making $@ @echo DEF_FILES = $(DEF_FILES) - @echo VAR_FILES = $(VAR_FILES) @echo $(DEF_FILES) > def-files - @echo $(VAR_FILES) > var-files - @$(srcdir)/mkbuiltins def-files var-files > $@-t + @$(srcdir)/mkbuiltins def-files > $@-t @$(top_srcdir)/move-if-change $@-t $@ PKG_ADD: $(DLD_DEF_FILES) @@ -475,7 +465,7 @@ rm -f liboctinterp.$(SHLEXT_VER) liboctinterp.$(SHLEXT) rm -f $(OBJECTS) $(MAKEDEPS) $(DOC_FILES) $(OCT_FILES) rm -f $(PICOBJ) $(DLD_PICOBJ) stmp-pic gendoc$(EXEEXT) - rm -f builtins.cc ops.cc defaults.h oct-conf.h def-files var-files + rm -f builtins.cc ops.cc defaults.h oct-conf.h def-files rm -f PKG_ADD -rmdir pic .PHONY: clean
--- a/src/defaults.cc +++ b/src/defaults.cc @@ -71,32 +71,32 @@ // The default path that will be searched for programs that we // execute (in addition to the user-specified --exec-path). -static std::string Vdefault_exec_path; +static std::string VDEFAULT_EXEC_PATH; // The path that will be searched for programs that we execute. // (--exec-path path) -std::string Vexec_path; +static std::string VEXEC_PATH; // Load path specified on command line. // (--path path; -p path) -static std::string Vload_path; +static std::string VLOADPATH; // The default load path with OCTAVE_HOME appropriately substituted. -static std::string Vdefault_load_path; +static std::string VDEFAULT_LOADPATH; // And the cached directory path corresponding to Vload_path. dir_path Vload_path_dir_path; // Name of the editor to be invoked by the edit_history command. -std::string Veditor; +std::string VEDITOR; -std::string Vimagepath; +static std::string VIMAGEPATH; std::string Vlocal_site_defaults_file; std::string Vsite_defaults_file; // Name of the FFTW wisdom program. -std::string Vfftw_wisdom_prog; +std::string Vfftw_wisdom_program; // Each element of A and B should be directory names. For each // element of A not in the list B, execute SCRIPT_FILE in that @@ -156,7 +156,7 @@ { string_vector old_dirs = Vload_path_dir_path.all_directories (); - Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); + Vload_path_dir_path = dir_path (VLOADPATH, VDEFAULT_LOADPATH); string_vector new_dirs = Vload_path_dir_path.all_directories (); @@ -263,7 +263,7 @@ static void set_default_default_exec_path (void) { - Vdefault_exec_path + VDEFAULT_EXEC_PATH = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str + Vlocal_arch_lib_dir + dir_path::path_sep_str + Varch_lib_dir + dir_path::path_sep_str @@ -281,22 +281,22 @@ if (! shell_path.empty ()) { - Vexec_path = dir_path::path_sep_str; - Vexec_path.append (shell_path); + VEXEC_PATH = dir_path::path_sep_str; + VEXEC_PATH.append (shell_path); } } else - Vexec_path = std::string (octave_exec_path); + VEXEC_PATH = std::string (octave_exec_path); } static void set_default_path (void) { - Vdefault_load_path = subst_octave_home (OCTAVE_FCNFILEPATH); + VDEFAULT_LOADPATH = subst_octave_home (OCTAVE_FCNFILEPATH); std::string oct_path = octave_env::getenv ("OCTAVE_PATH"); - Vload_path = oct_path.empty () ? dir_path::path_sep_str : oct_path; + VLOADPATH = oct_path.empty () ? dir_path::path_sep_str : oct_path; update_load_path_dir_path (); } @@ -317,9 +317,9 @@ std::string oct_info_prog = octave_env::getenv ("OCTAVE_INFO_PROGRAM"); if (oct_info_prog.empty ()) - Vinfo_prog = "info"; + Vinfo_program = "info"; else - Vinfo_prog = std::string (oct_info_prog); + Vinfo_program = std::string (oct_info_prog); } static void @@ -328,20 +328,20 @@ std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_FFTW_WISDOM_PROGRAM"); if (oct_wisdom_prog.empty ()) - Vfftw_wisdom_prog = "fftw-wisdom"; + Vfftw_wisdom_program = "fftw-wisdom"; else - Vfftw_wisdom_prog = std::string (oct_wisdom_prog); + Vfftw_wisdom_program = std::string (oct_wisdom_prog); } static void set_default_editor (void) { - Veditor = "emacs"; + VEDITOR = "emacs"; std::string env_editor = octave_env::getenv ("EDITOR"); if (! env_editor.empty ()) - Veditor = env_editor; + VEDITOR = env_editor; } static void @@ -381,14 +381,14 @@ { if (dir_path::is_path_sep (pathstring[0])) { - retval = Vdefault_load_path; + retval = VDEFAULT_LOADPATH; retval.append (pathstring); } else retval = pathstring; if (dir_path::is_path_sep (pathstring[pathstring.length () - 1])) - retval.append (Vdefault_load_path); + retval.append (VDEFAULT_LOADPATH); size_t pos = 0; do @@ -396,7 +396,7 @@ pos = retval.find (dir_path::path_sep_str + dir_path::path_sep_str); if (pos != NPOS) - retval.insert (pos+1, Vdefault_load_path); + retval.insert (pos+1, VDEFAULT_LOADPATH); } while (pos != NPOS); } @@ -461,256 +461,134 @@ return retval; } -static int -editor (void) +DEFUN (EDITOR, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} EDITOR ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} EDITOR (@var{new_val})\n\ +Query or set the internal variable that specifies the editor to\n\ +use with the @code{edit_history} command. If the environment\n\ +variable @code{EDITOR} is set when Octave starts, its\n\ +value is used as the default. Otherwise, @code{EDITOR} is set to\n\ +@code{\"emacs\"}.\n\ +@seealso{edit_history}\n\ +@end deftypefn") { - int status = 0; - - std::string s = builtin_string_variable ("EDITOR"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("EDITOR"); - status = -1; - } - else - Veditor = s; - - return status; + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); } -static int -exec_path (void) +static void +update_exec_path (void) { - int status = 0; - - std::string s = builtin_string_variable ("EXEC_PATH"); + std::string path; - if (s.empty ()) - { - gripe_invalid_value_specified ("EXEC_PATH"); - status = -1; - } - else - { - Vexec_path = s; - - std::string path; + int eplen = VEXEC_PATH.length (); - int eplen = Vexec_path.length (); - - if (eplen > 0) - { - bool prepend = (Vexec_path[0] == ':'); - bool append = (eplen > 1 && Vexec_path[eplen-1] == ':'); + if (eplen > 0) + { + bool prepend = (VEXEC_PATH[0] == ':'); + bool append = (eplen > 1 && VEXEC_PATH[eplen-1] == ':'); - if (prepend) - { - path = Vdefault_exec_path + Vexec_path; - } - else - { - path = Vexec_path; - - if (append) - path.append (Vdefault_exec_path); - } + if (prepend) + { + path = VDEFAULT_EXEC_PATH + VEXEC_PATH; } else - path = Vdefault_exec_path; - - octave_env::putenv ("PATH", path); - } - - return status; -} - -static int -fftw_wisdom_prog (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("FFTW_WISDOM_PROGRAM"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("FFTW_WISDOM_PROGRAM"); - status = -1; - } - else - Vfftw_wisdom_prog = s; - - return status; -} + { + path = VEXEC_PATH; -static int -default_exec_path (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("DEFAULT_EXEC_PATH"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("DEFAULT_EXEC_PATH"); - status = -1; - } - else - { - Vdefault_exec_path = s; - - // Now also update PATH in environment. - exec_path (); - } - - return status; -} - -static int -imagepath (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("IMAGEPATH"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("IMAGEPATH"); - status = -1; + if (append) + path.append (VDEFAULT_EXEC_PATH); + } } else - Vimagepath = s; - - return status; -} - -static int -loadpath (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("LOADPATH"); + path = VDEFAULT_EXEC_PATH; - if (s.empty ()) - { - gripe_invalid_value_specified ("LOADPATH"); - status = -1; - } - else if (Vload_path != s) - { - // I'm not sure whether this causes more problems that it - // solves... - // if (! (s[0] == ':' || s[s.length () - 1] == ':' - // || s.find (dir_path::path_sep_str + - // dir_path::path_sep_str) != NPOS)) - // warning ("LOADPATH will ignore default load path"); - - Vload_path = s; - - // By resetting the last prompt time variable, we will force - // checks for out of date symbols even if the change to LOADPATH - // and subsequent function calls happen between prompts. - - // FIXME -- maybe we should rename - // Vlast_prompt_time_stamp since the new usage doesn't really - // fit with the current name? - - Vlast_prompt_time.stamp (); - - update_load_path_dir_path (); - } - - return status; + octave_env::putenv ("PATH", path); } -static int -default_load_path (void) +DEFUN (EXEC_PATH, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\ +Query or set the internal variable that specifies a colon separated\n\ +list of directories to search when executing external programs.\n\ +Its initial value is taken from the environment variable\n\ +@code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ +value can be overridden by the command line argument\n\ +@code{--exec-path PATH}. Any leading, trailing, or doubled colon in\n\ +the value of @code{EXEC_PATH} are replaced by by the value of\n\ +@code{DEFAULT_EXEC_PATH}.\n\ +@seealso{DEFAULT_EXEC_PATH}\n\ +@end deftypefn") { - int status = 0; - - std::string s = builtin_string_variable ("DEFAULT_LOADPATH"); + std::string saved_exec_path = VEXEC_PATH; - if (s.empty ()) - { - gripe_invalid_value_specified ("DEFAULT_LOADPATH"); - status = -1; - } - else - { - Vdefault_load_path = s; + octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); - update_load_path_dir_path (); - } + if (VEXEC_PATH != saved_exec_path) + update_exec_path (); - return status; + return retval; } -void -symbols_of_defaults (void) -{ - DEFVAR (EDITOR, Veditor, editor, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} EDITOR\n\ -A string naming the editor to use with the @code{edit_history} command.\n\ -If the environment variable @code{EDITOR} is set when Octave starts, its\n\ -value is used as the default. Otherwise, @code{EDITOR} is set to\n\ -@code{\"emacs\"}.\n\ -@end defvr"); - - DEFVAR (FFTW_WISDOM_PROGRAM, Vfftw_wisdom_prog, fftw_wisdom_prog, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} FFTW_WISDOM_PROGRAM\n\ -A string naming the FFTW wisdom program to use to create wisdom data\n\ -to accelerate Fourier transforms. If the environment variable\n\ -@code{OCTAVE_WISDOM_PROGRAM} is set when Octave starts, its value is used\n\ -as the default. Otherwise, @code{WISDOM_PROGRAM} is set to\n\ -@code{\"fftw-wisdom\"}.\n\ -@end defvr"); - - DEFVAR (EXEC_PATH, Vexec_path, exec_path, +DEFUN (fftw_wisdom_program, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} EXEC_PATH\n\ -The variable @code{EXEC_PATH} is a colon separated list of directories\n\ -to search when executing external programs. Its initial value is taken from\n\ -the environment variable @code{OCTAVE_EXEC_PATH} (if it exists) or\n\ -@code{PATH}, but that value can be overridden by the command line\n\ -argument @code{--exec-path PATH}, or by setting the value of\n\ -@code{EXEC_PATH} in a startup script. If the value of @code{EXEC_PATH}\n\ -begins (ends) with a colon, the directories\n\ -\n\ -@example\n\ -@group\n\ -@var{octave-home}/libexec/octave/site/exec/@var{arch}\n\ -@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}\n\ -@end group\n\ -@end example\n\ -\n\ -@noindent\n\ -are prepended (appended) to @code{EXEC_PATH}, where @var{octave-home}\n\ -is the top-level directory where all of Octave is installed\n\ -(the default value is @file{@value{OCTAVEHOME}}). If you don't specify\n\ -a value for @code{EXEC_PATH} explicitly, these special directories are\n\ -prepended to your shell path.\n\ -@end defvr"); +@deftypefn {Built-in Function} {@var{val} =} FFTW_WISDOM_PROGRAM ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} FFTW_WISDOM_PROGRAM (@var{new_val})\n\ +Query or set the internal variable that specifies the FFTW wisdom\n\ +program to use to create wisdom data to accelerate Fourier transforms.\n\ +If the environment variable @code{OCTAVE_WISDOM_PROGRAM} is set when\n\ +Octave starts, its value is used as the default. Otherwise,\n\ +@code{WISDOM_PROGRAM} is set to @code{\"fftw-wisdom\"}.\n\ +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); +} - DEFVAR (DEFAULT_EXEC_PATH, Vdefault_exec_path, default_exec_path, +DEFUN (DEFAULT_EXEC_PATH, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} DEFAULT_EXEC_PATH\n\ -A colon separated list of directories in which to search when executing\n\ +@deftypefn {Built-in Function} {@var{val} =} DEFAULT_EXEC_PATH ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} DEFAULT_EXEC_PATH (@var{new_val})\n\ +Query or set the internal variable that specifies a colon separated\n\ +list of directories in which to search when executing\n\ external programs. The value of this variable is automatically\n\ substituted for leading, trailing, or doubled colons that appear in the\n\ built-in variable @code{EXEC_PATH}.\n\ -@end defvr"); +@seealso{EXEC_PATH}\n\ +@end deftypefn") +{ + std::string saved_default_exec_path = VDEFAULT_EXEC_PATH; + + octave_value retval + = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (DEFAULT_EXEC_PATH); + + if (VDEFAULT_EXEC_PATH != saved_default_exec_path) + update_exec_path (); + + return retval; +} - DEFVAR (LOADPATH, Vload_path, loadpath, +DEFUN (IMAGEPATH, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} IMAGEPATH ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} IMAGEPATH (@var{new_val})\n\ +Query or set the internal variable that specifies a colon separated\n\ +list of directories in which to search for image files.\n\ +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGEPATH); +} + +DEFUN (LOADPATH, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} LOADPATH\n\ -A colon separated list of directories in which to search for function\n\ +@deftypefn {Built-in Function} {@var{val} =} LOADPATH ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} LOADPATH (@var{new_val})\n\ +Query or set the internal variable that specifies a colon separated\n\ +list of directories in which to search for function\n\ files. @xref{Functions and Scripts}. The value of @code{LOADPATH}\n\ overrides the environment variable @code{OCTAVE_PATH}. @xref{Installation}.\n\ \n\ -@code{LOADPATH} is now handled in the same way as @TeX{} handles\n\ -@code{TEXINPUTS}. Leading, trailing, or doubled colons that appear in\n\ +Leading, trailing, or doubled colons that appear in\n\ @code{LOADPATH} are replaced by the value of @code{DEFAULT_LOADPATH}.\n\ The default value of @code{LOADPATH} is @code{\"\n" SEPCHAR_STR @@ -731,25 +609,53 @@ \n\ @xref{Organization of Functions}, for a description of the function file\n\ directories that are distributed with Octave.\n\ -@end defvr"); +@seealso{DEFAULT_LOADPATH}\n\ +@end deftypefn") +{ + std::string saved_loadpath = VLOADPATH; + + octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (LOADPATH); - DEFVAR (DEFAULT_LOADPATH, Vdefault_load_path, default_load_path, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} DEFAULT_LOADPATH\n\ -A colon separated list of directories in which to search for function\n\ -files. The value of this variable is automatically substituted for\n\ -leading, trailing, or doubled colons that appear in the built-in\n\ -variable @code{LOADPATH}.\n\ -@end defvr"); - - DEFVAR (IMAGEPATH, OCTAVE_IMAGEPATH, imagepath, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} IMAGEPATH\n\ -A colon separated list of directories in which to search for image\n\ -files.\n\ -@end defvr"); + if (VLOADPATH != saved_loadpath) + { + // By resetting the last prompt time variable, we will force + // checks for out of date symbols even if the change to LOADPATH + // and subsequent function calls happen between prompts. + + // FIXME -- maybe we should rename + // Vlast_prompt_time_stamp since the new usage doesn't really + // fit with the current name? + + Vlast_prompt_time.stamp (); + + update_load_path_dir_path (); + } + + return retval; } +DEFUN (DEFAULT_LOADPATH, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} DEFAULT_LOADPATH ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} DEFAULT_LOADPATH (@var{new_val})\n\ +Query or set the internal variable that specifies the colon separated\n\ +list of directories in which to search for function files. The value\n\ +of this variable is automatically substituted for leading, trailing,\n\ +or doubled colons that appear in the internal @code{loadpath} variable.\n\ +@seealso{LOADPATH}\n\ +@end deftypefn") +{ + std::string saved_default_loadpath = VDEFAULT_LOADPATH; + + octave_value retval + = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (DEFAULT_LOADPATH); + + if (VDEFAULT_LOADPATH != saved_default_loadpath) + update_load_path_dir_path (); + + return retval; +} + DEFUN (OCTAVE_HOME, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\
--- a/src/defaults.h.in +++ b/src/defaults.h.in @@ -185,23 +185,17 @@ extern std::string Vfcn_file_dir; extern std::string Voct_file_dir; -// The path that will be searched for programs that we execute. -// (--exec-path path) -extern std::string Vexec_path; - // And the cached directory path corresponding to Vload_path. extern dir_path Vload_path_dir_path; // Name of the editor to be invoked by the edit_history command. -extern std::string Veditor; - -extern std::string Vimagepath; +extern std::string VEDITOR; extern std::string Vlocal_site_defaults_file; extern std::string Vsite_defaults_file; // Name of the FFTW wisdom program. -extern std::string Vfftw_wisdom_prog; +extern std::string Vfftw_wisdom_program; extern void execute_default_pkg_add_files (void);
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -48,12 +48,6 @@ bool can_hide_function = true); extern void -install_builtin_variable (const std::string& n, const octave_value& v, - bool p, bool e, - symbol_record::change_function chg_fcn, - 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); @@ -90,28 +84,6 @@ return error_state ? false : true; \ } -// Define a builtin variable. -// -// name is the name of the variable, unquoted. -// -// defn is the initial value for the variable. -// -// protect is a flag that says whether it should be possible to give -// the variable a new value. -// -// eternal is a flag that says whether it should be possible to -// clear the variable. Most builtin variables are eternal, and -// cannot be cleared. -// -// chg_fcn is a pointer to a function that should be called whenever -// this variable is given a new value. It can be 0 if there is no -// function to call. See also the code in user-prefs.cc. -// -// doc is the simple help text for this variable. - -#define DEFVAR(name, defn, chg_fcn, doc) \ - DEFVAR_INTERNAL (#name, SBV_ ## name, defn, false, chg_fcn, 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. @@ -154,11 +126,6 @@ XDEFALIAS_INTERNAL(alias, name) \ END_INSTALL_BUILTIN -#define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ - BEGIN_INSTALL_BUILTIN \ - XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, 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) \ @@ -187,17 +154,6 @@ #define DEFALIAS_INTERNAL(alias, name) -// How builtin variables are actually installed. - -#define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ - install_builtin_variable (name, octave_value (defn), protect, \ - (chg_fcn != 0), chg_fcn, doc) - -// How builtin variables are actually installed. - -#define INSTALL_CONST(name, sname, defn, protect, doc) \ - install_builtin_constant (name, octave_value (defn), protect, 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,15 +127,6 @@ } void -install_builtin_variable (const std::string& name, const octave_value& value, - bool protect, bool eternal, - symbol_record::change_function chg_fcn, - const std::string& doc) -{ - bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); -} - -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)
--- a/src/defun.h +++ b/src/defun.h @@ -48,7 +48,7 @@ // 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 internal name of the function must be passed -// too (the convetion is to use a prefix of "F", so "foo" becomes "Ffoo"). +// too (the convention is to use a prefix of "F", so "foo" becomes "Ffoo"). #define DEFUNX(name, fname, args_name, nargout_name, doc) \ DEFUNX_INTERNAL (name, fname, args_name, nargout_name, false, doc)
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -715,24 +715,15 @@ return retval; } -static int -confirm_recursive_rmdir (void) +DEFUN (confirm_recursive_rmdir, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave\n\ +will ask for confirmation before recursively removing a directory tree.\n\ +@end deftypefn") { - Vconfirm_recursive_rmdir = check_preference ("confirm_recursive_rmdir"); - - return 0; -} - -void -symbols_of_dirfns (void) -{ - DEFVAR (confirm_recursive_rmdir, true, confirm_recursive_rmdir, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} confirm_recursive_rmdir\n\ -If the value of @code{confirm_recursive_rmdir} is nonzero, Octave\n\ -will ask for confirmation before recursively removing a directory tree.\n\ -The default value is 1.\n\ -@end defvr"); + return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); } /*
--- a/src/error.cc +++ b/src/error.cc @@ -48,16 +48,16 @@ // TRUE means that Octave will try to beep obnoxiously before printing // error messages. -static bool Vbeep_on_error; +static bool Vbeep_on_error = false; // TRUE means that Octave will try to enter the debugger when an error // is encountered. This will also inhibit printing of the normal // traceback message (you will only see the top-level error message). -static bool Vdebug_on_error; +static bool Vdebug_on_error = false; // TRUE means that Octave will try to enter the debugger when a warning // is encountered. -static bool Vdebug_on_warning; +static bool Vdebug_on_warning = false; // TRUE means that Octave will try to display a stack trace when a // warning is encountered. @@ -129,7 +129,7 @@ } static void -init_warning_options (const std::string& state = "on") +initialize_warning_options (const std::string& state) { warning_options.clear (); @@ -859,7 +859,7 @@ { if (arg1 != "error") { - bind_builtin_variable ("debug_on_warning", arg1 == "on"); + Vdebug_on_warning = (arg1 == "on"); done = true; } } @@ -885,7 +885,7 @@ arg2 = Vlast_warning_id; if (arg2 == "all") - init_warning_options (arg1); + initialize_warning_options (arg1); else { Cell ident = warning_options.contents ("identifier"); @@ -1076,6 +1076,40 @@ return retval; } +static void +disable_warning (const std::string& id) +{ + octave_value_list args; + + args(1) = id; + args(0) = "off"; + + Fwarning (args, 0); +} + +void +initialize_default_warning_state (void) +{ + initialize_warning_options ("on"); + + // Most people will want to have the following disabled. + + disable_warning ("Octave:array-to-scalar"); + disable_warning ("Octave:array-to-vector"); + disable_warning ("Octave:empty-list-elements"); + disable_warning ("Octave:fortran-indexing"); + disable_warning ("Octave:imag-to-real"); + disable_warning ("Octave:matlab-incompatible"); + disable_warning ("Octave:missing-semicolon"); + disable_warning ("Octave:neg-dim-as-zero"); + disable_warning ("Octave:resize-on-range-error"); + disable_warning ("Octave:separator-insert"); + disable_warning ("Octave:single-quote-string"); + disable_warning ("Octave:str-to-num"); + disable_warning ("Octave:string-concat"); + disable_warning ("Octave:variable-switch-label"); +} + DEFUN (lasterr, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lasterr (@var{msg}, @var{msgid})\n\ @@ -1199,59 +1233,39 @@ return retval; } -static int -beep_on_error (void) -{ - Vbeep_on_error = check_preference ("beep_on_error"); - - return 0; -} - -static int -debug_on_error (void) +DEFUN (beep_on_error, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} beep_on_error ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will try\n\ +to ring the terminal bell before printing an error message.\n\ +@end deftypefn") { - Vdebug_on_error = check_preference ("debug_on_error"); - - return 0; -} - -static int -debug_on_warning (void) -{ - Vdebug_on_warning = check_preference ("debug_on_warning"); - - return 0; + return SET_INTERNAL_VARIABLE (beep_on_error); } -void -symbols_of_error (void) -{ - init_warning_options (); - - DEFVAR (beep_on_error, false, beep_on_error, +DEFUN (debug_on_error, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} beep_on_error\n\ -If the value of @code{beep_on_error} is nonzero, Octave will try\n\ -to ring your terminal's bell before printing an error message. The\n\ -default value is 0.\n\ -@end defvr"); - - DEFVAR (debug_on_error, false, debug_on_error, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} debug_on_error\n\ -If the value of @code{debug_on_error} is nonzero, Octave will try\n\ +@deftypefn {Built-in Function} {@var{val} =} debug_on_error ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will try\n\ to enter the debugger when an error is encountered. This will also\n\ inhibit printing of the normal traceback message (you will only see\n\ -the top-level error message). The default value is 0.\n\ -@end defvr"); +the top-level error message).\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (debug_on_error); +} - DEFVAR (debug_on_warning, false, debug_on_warning, +DEFUN (debug_on_warning, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} debug_on_warning\n\ -If the value of @code{debug_on_warning} is nonzero, Octave will try\n\ -to enter the debugger when a warning is encountered. The default\n\ -value is 0.\n\ -@end defvr"); +@deftypefn {Built-in Function} {@var{val} =} debug_on_warning ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will try\n\ +to enter the debugger when a warning is encountered.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (debug_on_warning); } /*
--- a/src/error.h +++ b/src/error.h @@ -60,6 +60,8 @@ // Helper function for print_usage defined in defun.cc. extern void defun_usage_message (const std::string& msg); +extern void initialize_default_warning_state (void); + // Current error state. extern int error_state;
--- a/src/help.cc +++ b/src/help.cc @@ -75,14 +75,14 @@ // Name of the info reader we'd like to use. // (--info-program program) -std::string Vinfo_prog; +std::string Vinfo_program; // Name of the makeinfo program to run. -static std::string Vmakeinfo_prog = "makeinfo"; +static std::string Vmakeinfo_program = "makeinfo"; // If TRUE, don't print additional help message in help and usage // functions. -static bool Vsuppress_verbose_help_message; +static bool Vsuppress_verbose_help_message = false; // FIXME -- maybe this should use string instead of char*. @@ -452,8 +452,8 @@ { if (! Vsuppress_verbose_help_message) os << "\ -Additional help for built-in functions, operators, and variables\n\ -is available in the on-line version of the manual. Use the command\n\ +Additional help for built-in functions and operators is\n\ +available in the on-line version of the manual. Use the command\n\ `doc <topic>' to search the manual index.\n\ \n\ Help and information about Octave is also available on the WWW\n\ @@ -518,8 +518,6 @@ // FIXME -- is this distinction needed? - LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "built-in variables"); - LIST_SYMBOLS (symbol_record::COMMAND, "commands"); LIST_SYMBOLS (symbol_record::MAPPER_FUNCTION, "mapper functions"); @@ -646,7 +644,7 @@ std::ostringstream buf; buf << "sed -e 's/^[#%][#%]* *//' -e 's/^ *@/@/' | " - << "\"" << Vmakeinfo_prog << "\"" + << "\"" << Vmakeinfo_program << "\"" << " -D \"VERSION " << OCTAVE_VERSION << "\"" << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" @@ -878,10 +876,10 @@ Octave's @code{help} command can be used to print brief usage-style\n\ messages, or to display information directly from an on-line version of\n\ the printed manual, using the GNU Info browser. If invoked without any\n\ -arguments, @code{help} prints a list of all the available operators,\n\ -functions, and built-in variables. If the first argument is @code{-i},\n\ -the @code{help} command searches the index of the on-line version of\n\ -this manual for the given topics.\n\ +arguments, @code{help} prints a list of all the available operators\n\ +and functions. If the first argument is @code{-i}, the @code{help}\n\ +command searches the index of the on-line version of this manual for\n\ +the given topics.\n\ \n\ For example, the command @kbd{help help} prints a short message\n\ describing the @code{help} command, and @kbd{help -i help} starts the\n\ @@ -1848,110 +1846,62 @@ return retval; } -static int -info_file (void) +DEFUN (info_file, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ +Query or set the internal variable that specifies the name of the\n\ +Octave info file. The default value is\n\ +@code{\"@var{octave-home}/info/octave.info\"}, in\n\ +which @var{octave-home} is the directory where all of Octave is installed.\n\ +@seealso{info_program, doc, help, makeinfo_program}\n\ +@end deftypefn") { - int status = 0; - - std::string s = builtin_string_variable ("INFO_FILE"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("INFO_FILE"); - status = -1; - } - else - Vinfo_file = s; - - return status; -} - -static int -info_prog (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("INFO_PROGRAM"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("INFO_PROGRAM"); - status = -1; - } - else - Vinfo_prog = s; - - return status; + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); } -static int -makeinfo_prog (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("MAKEINFO_PROGRAM"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("MAKEINFO_PROGRAM"); - status = -1; - } - else - Vmakeinfo_prog = s; - - return status; -} - -static int -suppress_verbose_help_message (void) -{ - Vsuppress_verbose_help_message - = check_preference ("suppress_verbose_help_message"); - - return 0; -} - -void -symbols_of_help (void) -{ - DEFVAR (INFO_FILE, Vinfo_file, info_file, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} INFO_FILE\n\ -The variable @code{INFO_FILE} names the location of the Octave info file.\n\ -The default value is @code{\"@var{octave-home}/info/octave.info\"}, in\n\ -which @var{octave-home} is the directory where all of Octave is installed.\n\ -@end defvr"); - - DEFVAR (INFO_PROGRAM, Vinfo_prog, info_prog, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} INFO_PROGRAM\n\ -The variable @code{INFO_PROGRAM} names the info program to run. Its\n\ -default initial value is\n\ +DEFUN (info_program, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ +Query or set the internal variable that specifies the name of the\n\ +info program to run. The default initial value is\n\ @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ in which @var{octave-home} is the directory where all of Octave is\n\ installed, @var{version} is the Octave version number, and @var{arch}\n\ is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ default initial value may be overridden by the environment variable\n\ @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ -@code{--info-program NAME}, or by setting the value of\n\ -@code{INFO_PROGRAM} in a startup script\n\ -@end defvr"); +@code{--info-program NAME}.\n\ +@seealso{info_file, doc, help, makeinfo_program}\n\ +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); +} - DEFVAR (MAKEINFO_PROGRAM, Vmakeinfo_prog, makeinfo_prog, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} MAKEINFO_PROGRAM\n\ -The variable @code{MAKEINFO_PROGRAM} names the makeinfo program that\n\ -Octave runs to format help text that contains Texinfo markup commands.\n\ -Its default initial value is @code{\"makeinfo\"}.\n\ -@end defvr"); +DEFUN (makeinfo_program, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ +Query or set the internal variable that specifies the name of the\n\ +makeinfo program that Octave runs to format help text containing\n\ +Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ +@seealso{info_file, info_program, doc, help}\n\ +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); +} - DEFVAR (suppress_verbose_help_message, false, suppress_verbose_help_message, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} suppress_verbose_help_message\n\ -If the value of @code{suppress_verbose_help_message} is nonzero, Octave\n\ -will not add additional help information to the end of the output from\n\ +DEFUN (suppress_verbose_help_message, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ +Query or set the internal vaiable that controls whether Octave\n\ +will add additional help information to the end of the output from\n\ the @code{help} command and usage messages for built-in commands.\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); } /*
--- a/src/help.h +++ b/src/help.h @@ -43,7 +43,7 @@ // Name of the info reader we'd like to use. // (--info-program program) -extern std::string Vinfo_prog; +extern std::string Vinfo_program; #endif
--- a/src/input.cc +++ b/src/input.cc @@ -72,13 +72,13 @@ #include "variables.h" // Primary prompt string. -static std::string Vps1; +static std::string VPS1 = "\\s:\\#> "; // Secondary prompt string. -static std::string Vps2; +static std::string VPS2 = "> "; // String printed before echoed input (enabled by --echo-input). -std::string Vps4; +std::string VPS4 = "+ "; // Echo commands as they are executed? // @@ -87,13 +87,13 @@ // 4 ==> echo commands read from command line // // more than one state can be active at once. -int Vecho_executing_commands; +int Vecho_executing_commands = ECHO_OFF; // The time we last printed a prompt. octave_time Vlast_prompt_time; // Character to append after successful command-line completion attempts. -static char Vcompletion_append_char; +static char Vcompletion_append_char = ' '; // Global pointer for eval(). std::string current_eval_string; @@ -151,12 +151,12 @@ if (forced_interactive) { if (promptflag > 0) - octave_stdout << command_editor::decode_prompt_string (Vps1); + octave_stdout << command_editor::decode_prompt_string (VPS1); else - octave_stdout << command_editor::decode_prompt_string (Vps2); + octave_stdout << command_editor::decode_prompt_string (VPS2); } else - octave_stdout << command_editor::decode_prompt_string (Vps4); + octave_stdout << command_editor::decode_prompt_string (VPS4); if (! input_string.empty ()) { @@ -217,7 +217,7 @@ if ((interactive || forced_interactive) && (! (reading_fcn_file || reading_script_file))) { - std::string ps = (promptflag > 0) ? Vps1 : Vps2; + std::string ps = (promptflag > 0) ? VPS1 : VPS2; std::string prompt = command_editor::decode_prompt_string (ps); @@ -898,9 +898,9 @@ { if ((Vecho_executing_commands & ECHO_SCRIPTS) || (Vecho_executing_commands & ECHO_FUNCTIONS)) - bind_builtin_variable ("echo_executing_commands", ECHO_OFF); + Vecho_executing_commands = ECHO_OFF; else - bind_builtin_variable ("echo_executing_commands", ECHO_SCRIPTS); + Vecho_executing_commands = ECHO_SCRIPTS; } break; @@ -909,9 +909,9 @@ std::string arg = argv[1]; if (arg == "on") - bind_builtin_variable ("echo_executing_commands", ECHO_SCRIPTS); + Vecho_executing_commands = ECHO_SCRIPTS; else if (arg == "off") - bind_builtin_variable ("echo_executing_commands", ECHO_OFF); + Vecho_executing_commands = ECHO_OFF; else print_usage ("echo"); } @@ -924,10 +924,10 @@ if (arg == "on" && argv[2] == "all") { int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); - bind_builtin_variable ("echo_executing_commands", tmp); + Vecho_executing_commands = tmp; } else if (arg == "off" && argv[2] == "all") - bind_builtin_variable ("echo_executing_commands", ECHO_OFF); + Vecho_executing_commands = ECHO_OFF; else print_usage ("echo"); } @@ -1125,82 +1125,15 @@ return retval; } -static int -ps1 (void) -{ - int status = 0; - - Vps1 = builtin_string_variable ("PS1"); - - return status; -} - -static int -ps2 (void) -{ - int status = 0; - - Vps2 = builtin_string_variable ("PS2"); - - return status; -} - -static int -ps4 (void) -{ - int status = 0; - - Vps4 = builtin_string_variable ("PS4"); - - return status; -} - -static int -completion_append_char (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("completion_append_char"); - - switch (s.length ()) - { - case 1: - Vcompletion_append_char = s[0]; - break; - - case 0: - Vcompletion_append_char = '\0'; - break; - - default: - warning ("completion_append_char must be a single character"); - status = -1; - break; - } - - return status; -} - -static int -echo_executing_commands (void) -{ - Vecho_executing_commands = check_preference ("echo_executing_commands"); - - return 0; -} - -void -symbols_of_input (void) -{ - DEFVAR (PS1, "\\s:\\#> ", ps1, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} PS1\n\ -The primary prompt string. When executing interactively, Octave\n\ -displays the primary prompt @code{PS1} when it is ready to read a\n\ -command.\n\ +DEFUN (PS1, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} PS1 ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\ +Query or set the primary prompt string. When executing interactively,\n\ +Octave displays the primary prompt when it is ready to read a command.\n\ \n\ -The default value of @code{PS1} is @code{\"\\s:\\#> \"}. To change it, use a\n\ -command like\n\ +The default value of the primary prompt string is @code{\"\\s:\\#> \"}.\n\ +To change it, use a command like\n\ \n\ @example\n\ octave:13> PS1 = \"\\\\u@@\\\\H> \"\n\ @@ -1209,42 +1142,63 @@ @noindent\n\ which will result in the prompt @samp{boris@@kremvax> } for the user\n\ @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two\n\ -backslashes are required to enter a backslash into a string.\n\ +backslashes are required to enter a backslash into a double-quoted\n\ +character string.\n\ @xref{Strings}.\n\ -@end defvr"); +@seealso{PS1, PS2}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (PS1); +} - DEFVAR (PS2, "> ", ps2, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} PS2\n\ -The secondary prompt string, which is printed when Octave is\n\ -expecting additional input to complete a command. For example, when\n\ -defining a function over several lines, Octave will print the value of\n\ -@code{PS1} at the beginning of each line after the first. The default\n\ -value of @code{PS2} is @code{\"> \"}.\n\ -@end defvr"); +DEFUN (PS2, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} PS2 ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\ +Query or set the secondary prompt string. The secondary prompt is\n\ +printed when Octave is expecting additional input to complete a\n\ +command. For example, if you are typing a for loop that spans several\n\ +lines, Octave will print the secondary prompt at the beginning of\n\ +each line after the first. The default value of the secondary prompt\n\ +string is @code{\"> \"}.\n\ +@seealso{PS1, PS4}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (PS2); +} - DEFVAR (PS4, "+ ", ps4, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} PS4\n\ -If Octave is invoked with the @code{--echo-commands} option, the value of\n\ -@code{PS4} is printed before each line of input that is echoed. The\n\ -default value of @code{PS4} is @code{\"+ \"}. @xref{Invoking Octave}, for\n\ +DEFUN (PS4, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} PS4 ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\ +Query or set the character string used to prefix output produced\n\ +when echoing commands when @code{echo_executing_commands} is enabled.\n\ +The default value is @code{\"+ \"}. @xref{Invoking Octave}, for\n\ a description of @code{--echo-commands}.\n\ -@end defvr"); +@seealso{echo_executing_commands, PS1, PS2}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (PS4); +} - DEFVAR (completion_append_char, " ", completion_append_char, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} completion_append_char\n\ -The value of @code{completion_append_char} is used as the character to\n\ -append to successful command-line completion attempts. The default\n\ +DEFUN (completion_append_char, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} completion_append_char ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\ +Query or set the internal character variable that is appended to\n\ +successful command-line completion attempts. The default\n\ value is @code{\" \"} (a single space).\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (completion_append_char); +} - DEFVAR (echo_executing_commands, ECHO_OFF, echo_executing_commands, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} echo_executing_commands\n\ -This variable may also be used to control the echo state. It may be\n\ -the sum of the following values:\n\ +DEFUN (echo_executing_commands, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} echo_executing_commands ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\ +Query or set the internal variable that controls the echo state.\n\ +It may be the sum of the following values:\n\ \n\ @table @asis\n\ @item 1\n\ @@ -1262,7 +1216,9 @@ \n\ The value of @code{echo_executing_commands} is set by the @kbd{echo}\n\ command and the command line option @code{--echo-input}.\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (echo_executing_commands); } /*
--- a/src/input.h +++ b/src/input.h @@ -92,7 +92,7 @@ extern octave_value do_keyboard (const octave_value_list& args = octave_value_list ()); -extern std::string Vps4; +extern std::string VPS4; enum echo_state {
--- a/src/lex.l +++ b/src/lex.l @@ -232,12 +232,6 @@ static bracket_brace_paren_nesting_level nesting_level; -static bool Vwarn_matlab_incompatible = false; - -static bool Vwarn_separator_insert = false; - -static bool Vwarn_single_quote_string = false; - static unsigned int Vtoken_count = 0; // Forward declarations for functions defined at the bottom of this @@ -2481,15 +2475,14 @@ { std::string nm = curr_fcn_file_full_name; - if (Vwarn_separator_insert) - { - if (nm.empty ()) - warning ("potential auto-insertion of `%c' near line %d", - sep, input_line_number); - else - warning ("potential auto-insertion of `%c' near line %d of file %s", - sep, input_line_number, nm.c_str ()); - } + if (nm.empty ()) + warning_with_id ("Octave:separator-insert", + "potential auto-insertion of `%c' near line %d", + sep, input_line_number); + else + warning_with_id ("Octave:separator-insert", + "potential auto-insertion of `%c' near line %d of file %s", + sep, input_line_number, nm.c_str ()); } static void @@ -2497,22 +2490,22 @@ { std::string nm = curr_fcn_file_full_name; - if (Vwarn_single_quote_string) - { - if (nm.empty ()) - warning ("single quote delimited string near line %d", - input_line_number); - else - warning ("single quote delimited string near line %d of file %s", - input_line_number, nm.c_str ()); - } + if (nm.empty ()) + warning_with_id ("Octave:single-quote-string", + "single quote delimited string near line %d", + input_line_number); + else + warning_with_id ("Octave:single-quote-string", + "single quote delimited string near line %d of file %s", + input_line_number, nm.c_str ()); } static void gripe_matlab_incompatible (const std::string& msg) { - if (Vwarn_matlab_incompatible) - warning ("potential Matlab compatibility problem: %s", msg.c_str ()); + warning_with_id ("Octave:matlab-incompatible", + "potential Matlab compatibility problem: %s", + msg.c_str ()); } static void @@ -2547,55 +2540,6 @@ return octave_value (Vtoken_count); } -static int -warn_matlab_incompatible (void) -{ - Vwarn_matlab_incompatible = check_preference ("warn_matlab_incompatible"); - - return 0; -} - -static int -warn_separator_insert (void) -{ - Vwarn_separator_insert = check_preference ("warn_separator_insert"); - - return 0; -} - -static int -warn_single_quote_string (void) -{ - Vwarn_single_quote_string = check_preference ("warn_single_quote_string"); - - return 0; -} - -void -symbols_of_lex (void) -{ - DEFVAR (warn_matlab_incompatible, false, warn_matlab_incompatible, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} warn_matlab_incompatible\n\ -Print warnings for Octave language features that may cause\n\ -compatibility problems with Matlab.\n\ -@end defvr"); - - DEFVAR (warn_separator_insert, false, warn_separator_insert, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} warn_separator_insert\n\ -Print warning if commas or semicolons might be inserted\n\ -automatically in literal matrices.\n\ -@end defvr"); - - DEFVAR (warn_single_quote_string, false, warn_single_quote_string, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} warn_single_quote_string\n\ -Print warning if a signle quote character is used to introduce a\n\ -string constant.\n\ -@end defvr"); -} - /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -86,26 +86,38 @@ #endif // Write octave-core file if Octave crashes or is killed by a signal. -static bool Vcrash_dumps_octave_core; +static bool Vcrash_dumps_octave_core = true; // The maximum amount of memory (in kilobytes) that we will attempt to // write to the Octave core file. -static double Voctave_core_file_limit; +static double Voctave_core_file_limit = -1.0; // The name of the Octave core file. -static std::string Voctave_core_file_name; +static std::string Voctave_core_file_name = "octave-core"; // The default output format. May be one of "binary", "text", // "mat-binary", or "hdf5". -static std::string Vdefault_save_options; +static std::string Vdefault_save_options = "-text"; // The output format for Octave core files. -static std::string Voctave_core_file_options; +static std::string Voctave_core_file_options = "-binary"; + +static std::string +default_save_header_format (void) +{ + return + std::string ("# Created by Octave " OCTAVE_VERSION + ", %a %b %d %H:%M:%S %Y %Z <") + + octave_env::get_user_name () + + std::string ("@") + + octave_env::get_host_name () + + std::string (">"); +} // The format string for the comment line at the top of text-format // save files. Passed to strftime. Should begin with `#' and contain // no newline characters. -static std::string Vsave_header_format_string; +static std::string Vsave_header_format_string = default_save_header_format (); static void gripe_file_open (const std::string& fcn, const std::string& file) @@ -1046,11 +1058,10 @@ } // Save variables with names matching PATTERN on stream OS in the -// format specified by FMT. If SAVE_BUILTINS is TRUE, also save -// builtin variables with names that match PATTERN. +// format specified by FMT. static int -save_vars (std::ostream& os, const std::string& pattern, bool save_builtins, +save_vars (std::ostream& os, const std::string& pattern, load_save_format fmt, bool save_as_floats) { Array<symbol_record *> vars = curr_sym_tab->glob @@ -1068,32 +1079,13 @@ break; } - if (! error_state && save_builtins) - { - vars = fbi_sym_tab->glob - (pattern, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); - - int count = vars.length (); - - saved += count; - - for (int i = 0; i < count; i++) - { - do_save (os, vars(i), fmt, save_as_floats, infnan_warned); - - if (error_state) - break; - } - } - return saved; } static int parse_save_options (const string_vector &argv, int argc, load_save_format &format, bool &append, - bool &save_as_floats, bool &save_builtins, - bool &use_zlib, int start_arg) + bool &save_as_floats, bool &use_zlib, int start_arg) { int i; for (i = start_arg; i < argc; i++) @@ -1159,10 +1151,6 @@ error ("save: octave executable was not linked with HDF5 library"); #endif /* ! HAVE_HDF5 */ } - else if (argv[i] == "-save-builtins") - { - save_builtins = true; - } #ifdef HAVE_ZLIB else if (argv[i] == "-zip" || argv[i] == "-z") { @@ -1179,7 +1167,7 @@ static int parse_save_options (const std::string &arg, load_save_format &format, bool &append, bool &save_as_floats, - bool &save_builtins, bool &use_zlib, int start_arg) + bool &use_zlib, int start_arg) { std::istringstream is (arg); std::string str; @@ -1194,7 +1182,7 @@ } return parse_save_options (argv, argc, format, append, save_as_floats, - save_builtins, use_zlib, start_arg); + use_zlib, start_arg); } void @@ -1281,7 +1269,7 @@ static void save_vars (const string_vector& argv, int argv_idx, int argc, - std::ostream& os, bool save_builtins, load_save_format fmt, + std::ostream& os, load_save_format fmt, bool save_as_floats, bool write_header_info) { if (write_header_info) @@ -1289,13 +1277,13 @@ if (argv_idx == argc) { - save_vars (os, "*", save_builtins, fmt, save_as_floats); + save_vars (os, "*", fmt, save_as_floats); } else { for (int i = argv_idx; i < argc; i++) { - if (! save_vars (os, argv[i], save_builtins, fmt, save_as_floats)) + if (! save_vars (os, argv[i], fmt, save_as_floats)) { warning ("save: no such variable `%s'", argv[i].c_str ()); } @@ -1369,17 +1357,14 @@ load_save_format format = LS_BINARY; - bool save_builtins = false; - bool save_as_floats = false; bool append = false; bool use_zlib = false; - // Note save_builtins is ignored parse_save_options (Voctave_core_file_options, format, append, - save_as_floats, save_builtins, use_zlib, 0); + save_as_floats, use_zlib, 0); std::ios::openmode mode = std::ios::out; @@ -1461,8 +1446,8 @@ output to your terminal. If no variable names are listed, Octave saves\n\ all the variables in the current scope. Valid options for the\n\ @code{save} command are listed in the following table. Options that\n\ -modify the output format override the format specified by the built-in\n\ -variable @code{default_save_options}.\n\ +modify the output format override the format specified by\n\ +@code{default_save_options}.\n\ \n\ If save is invoked using the functional form\n\ \n\ @@ -1526,10 +1511,6 @@ You should use this format only if you know that all the\n\ values to be saved can be represented in single precision.\n\ \n\ -@item -save-builtins\n\ -Force Octave to save the values of built-in variables too. By default,\n\ -Octave does not save built-in variables.\n\ -\n\ @item -zip\n\ @itemx -z\n\ Use the gzip algorithm to compress the file. This works equally on files that\n\ @@ -1587,8 +1568,6 @@ // Here is where we would get the default save format if it were // stored in a user preference variable. - bool save_builtins = false; - bool save_as_floats = false; load_save_format format = LS_ASCII; @@ -1602,14 +1581,14 @@ // Get user file format parse_save_options (argv, argc, user_file_format, dummy, - dummy, dummy, dummy, 1); + dummy, dummy, 1); if (user_file_format == LS_UNKNOWN) parse_save_options (Vdefault_save_options, format, append, save_as_floats, - save_builtins, use_zlib, 0); + use_zlib, 0); int i = parse_save_options (argv, argc, format, append, save_as_floats, - save_builtins, use_zlib, 1); + use_zlib, 1); if (error_state) return retval; @@ -1641,7 +1620,7 @@ // FIXME -- should things intended for the screen end up // in a octave_value (string)? - save_vars (argv, i, argc, octave_stdout, save_builtins, format, + save_vars (argv, i, argc, octave_stdout, format, save_as_floats, true); } } @@ -1679,7 +1658,7 @@ if (hdf5_file.file_id >= 0) { - save_vars (argv, i, argc, hdf5_file, save_builtins, format, + save_vars (argv, i, argc, hdf5_file, format, save_as_floats, true); hdf5_file.close (); @@ -1706,7 +1685,7 @@ = ((file.rdbuf ())->pubseekoff (0, std::ios::cur) == static_cast<std::streampos> (0)); - save_vars (argv, i, argc, file, save_builtins, format, + save_vars (argv, i, argc, file, format, save_as_floats, write_header_info); file.close (); @@ -1728,7 +1707,7 @@ = ((file.rdbuf ())->pubseekoff (0, std::ios::cur) == static_cast<std::streampos> (0)); - save_vars (argv, i, argc, file, save_builtins, format, + save_vars (argv, i, argc, file, format, save_as_floats, write_header_info); file.close (); @@ -1745,177 +1724,89 @@ return retval; } -static int -crash_dumps_octave_core (void) -{ - Vcrash_dumps_octave_core = check_preference ("crash_dumps_octave_core"); - - return 0; -} - -static int -default_save_options (void) +DEFUN (crash_dumps_octave_core, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} crash_dumps_octave_core ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} crash_dumps_octave_core (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave tries\n\ +to save all current variables the the file \"octave-core\" if it\n\ +crashes or receives a hangup, terminate or similar signal.\n\ +@seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\ +@end deftypefn") { - int status = 0; - - std::string s = builtin_string_variable ("default_save_options"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("default_save_options"); - status = -1; - } - else - Vdefault_save_options = s; - - return status; + return SET_INTERNAL_VARIABLE (crash_dumps_octave_core); } -static int -octave_core_file_limit (void) -{ - double val; - - if (builtin_real_scalar_variable ("octave_core_file_limit", val)) - { - Voctave_core_file_limit = val; - return 0; - } - else - gripe_invalid_value_specified ("octave_core_file_limit"); - - return -1; -} - -static int -octave_core_file_name (void) +DEFUN (default_save_options, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} default_save_options ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} default_save_options (@var{new_val})\n\ +Query or set the internal variable that specifies the default options\n\ +for the @code{save} command, and defines the default format.\n\ +Typical values include @code{\"-ascii\"}, @code{\"-ascii -zip\"}.\n\ +The default value is @code{-ascii}.\n\ +@seealso{save}\n\ +@end deftypefn") { - int status = 0; - - std::string s = builtin_string_variable ("octave_core_file_name"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("octave_core_file_name"); - status = -1; - } - else - Voctave_core_file_name = s; - - return status; -} - -static int -octave_core_file_options (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("octave_core_file_options"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("octave_core_file_options"); - status = -1; - } - else - Voctave_core_file_options = s; - - return status; + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (default_save_options); } -static std::string -default_save_header_format (void) +DEFUN (octave_core_file_limit, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} octave_core_file_limit ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_limit (@var{new_val})\n\ +Query or set the internal variable that specifies the maximum amount\n\ +of memory (in kilobytes) of the top-level workspace that Octave will\n\ +attempt to save when writing data to the crash dump file (the name of\n\ +the file is specified by @var{octave_core_file_name}). If\n\ +@var{octave_core_file_options} flags specifies a binary format,\n\ +then @var{octave_core_file_limit} will be approximately the maximum\n\ +size of the file. If a text file format is used, then the file could\n\ +be much larger than the limit. The default value is -1 (unlimited)\n\ +@seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ +@end deftypefn") { - return - std::string ("# Created by Octave " OCTAVE_VERSION - ", %a %b %d %H:%M:%S %Y %Z <") - + octave_env::get_user_name () - + std::string ("@") - + octave_env::get_host_name () - + std::string (">"); -} - -static int -save_header_format_string (void) -{ - int status = 0; - - octave_value v = builtin_any_variable ("save_header_format_string"); - - if (v.is_string ()) - Vsave_header_format_string = v.string_value (); - else - { - gripe_invalid_value_specified ("save_header_format_string"); - status = -1; - } - - return status; + return SET_INTERNAL_VARIABLE (octave_core_file_limit); } -void -symbols_of_load_save (void) +DEFUN (octave_core_file_name, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} octave_core_file_name ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_name (@var{new_val})\n\ +Query or set the internal variable that specifies the name of the file\n\ +used for saving data from the top-level workspace if Octave aborts.\n\ +The default value is @code{\"octave-core\"}\n\ +@seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ +@end deftypefn") { - DEFVAR (crash_dumps_octave_core, true, crash_dumps_octave_core, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} crash_dumps_octave_core\n\ -If this variable is set to a nonzero value, Octave tries to save all\n\ -current variables the the file \"octave-core\" if it crashes or receives a\n\ -hangup, terminate or similar signal. The default value is 1.\n\ -@seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\ -@end defvr"); - - DEFVAR (default_save_options, "-text", default_save_options, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} default_save_options\n\ -This variable specifies the default options for the @code{save} command,\n\ -and is used to define the default format. Typical values include,\n\ -@code{\"-ascii\"}, @code{\"-ascii -zip\"}. For other possible options\n\ -see the @code{save} command. The initial value of this variable is\n\ -@code{-ascii}.\n\ -@end defvr"); + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name); +} - DEFVAR (octave_core_file_limit, -1.0, octave_core_file_limit, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} octave_core_file_limit\n\ -The maximum amount of memory (in kilobytes) of the top-level workspace\n\ -that Octave will attempt to write when saving data to the\n\ -@var{octave_core_file_name}. If @var{octave_core_file_options} flags a\n\ -binary format, then @var{octave_core_file_limit} will be approximately\n\ -the maximum size of the file. If a text file format is used, then the\n\ -file could be much larger than the limit.\n\ -The default value is -1 (unlimited)\n\ -@seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ -@end defvr"); - - DEFVAR (octave_core_file_name, "octave-core", octave_core_file_name, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} octave_core_file_name\n\ -The name of the file used for saving data from the top-level workspace\n\ -when Octave aborts. The default value is @code{\"octave-core\"}\n\ -@seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ -@end defvr"); - - DEFVAR (octave_core_file_options, "-binary", octave_core_file_options, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} octave_core_file_options\n\ -If Octave aborts, it attempts to save the contents of the top-level\n\ -workspace in a file using this variable to define the format. The value of\n\ -@code{octave_core_file_options} should follow the same format as the options\n\ -that may be used with @code{save}. The default value is Octave's binary\n\ +DEFUN (octave_core_file_options, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} octave_core_file_options ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_options (@var{new_val})\n\ +Query or set the internal variable that specifies the options used for\n\ +saving the workspace data if Octave aborts. The value of\n\ +@code{octave_core_file_options} should follow the same format as the\n\ +options for the @code{save} function. The default value is Octave's binary\n\ format.\n\ @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}\n\ -@end defvr"); +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options); +} - DEFVAR (save_header_format_string, default_save_header_format (), - save_header_format_string, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} save_header_format_string\n\ -This variable specifies the the format string for the comment line\n\ -that is written at the beginning of text-format data files saved by\n\ -Octave. The format string is passed to @code{strftime} and should\n\ -begin with the character @samp{#} and contain no newline characters.\n\ -If the value of @code{save_header_format_string} is the empty string,\n\ +DEFUN (save_header_format_string, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} save_header_format_string ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} save_header_format_string (@var{new_val})\n\ +Query or set the internal variable that specifies the format\n\ +string used for the comment line written at the beginning of\n\ +text-format data files saved by Octave. The format string is\n\ +passed to @code{strftime} and should begin with the character\n\ +@samp{#} and contain no newline characters. If the value of\n\ +@code{save_header_format_string} is the empty string,\n\ the header comment is omitted from text-format data files. The\n\ default value is\n\ \n\ @@ -1923,7 +1814,9 @@ \"# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ @end example\n\ @seealso{strftime}\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (save_header_format_string); } /*
--- a/src/ls-oct-ascii.cc +++ b/src/ls-oct-ascii.cc @@ -68,7 +68,7 @@ #include "ls-oct-ascii.h" // The number of decimal digits to use when writing ascii data. -static int Vsave_precision; +static int Vsave_precision = 15; // Functions for reading ascii data. @@ -448,33 +448,15 @@ return (os && ! fail); } -static int -save_precision (void) +DEFUN (save_precision, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} save_precision ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} save_precision (@var{new_val})\n\ +Query or set the internal variable that specifies the number of\n\ +digits to keep when saving data in text format.\n\ +@end deftypefn") { - double val; - if (builtin_real_scalar_variable ("save_precision", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival >= 0 && ival == val) - { - Vsave_precision = ival; - return 0; - } - } - gripe_invalid_value_specified ("save_precision"); - return -1; -} - -void -symbols_of_ls_oct_ascii (void) -{ - DEFVAR (save_precision, 15.0, save_precision, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} save_precision\n\ -This variable specifies the number of digits to keep when saving data in\n\ -text format. The default value is 17.\n\ -@end defvr"); + return SET_INTERNAL_VARIABLE_WITH_LIMITS (save_precision, -1, INT_MAX); } /*
--- a/src/mkbuiltins +++ b/src/mkbuiltins @@ -1,25 +1,19 @@ #!/bin/sh -if test $# -ne 2; then - echo "usage: mkbuiltins f1 f2" 1>&2 +if test $# -ne 1; then + echo "usage: mkbuiltins f1" 1>&2 exit 1 fi SED=${SED:-'sed'} DEF_FILES=`cat $1` -VAR_FILES=`cat $2` if test -z "$DEF_FILES"; then echo "mkbuiltins: DEF_FILES is empty!" 1>&2 exit 1 fi -if test -z "$VAR_FILES"; then - echo "mkbuiltins: VAR_FILES is empty!" 1>&2 - exit 1 -fi - cat << \EOF // DO NOT EDIT! Generated automatically by mkbuiltins. @@ -59,8 +53,6 @@ #define XDEFALIAS_INTERNAL(alias, name) \ alias_builtin (#alias, #name); -#define XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) - #define XDEFCONST_INTERNAL(name, defn, doc) #define XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ @@ -79,27 +71,9 @@ echo "" done -for file in $VAR_FILES; do - f=`echo $file | $SED 's,^\./,,; s/\.df//; s/-/_/g'` - echo "extern void symbols_of_${f} (void);" -done - cat << \EOF static void -install_builtin_variables (void) -{ -EOF - -for file in $VAR_FILES; do - f=`echo $file | $SED 's,^\./,,; s/\.df//; s/-/_/g'` - echo " symbols_of_${f} ();" -done - -cat << \EOF -} - -static void install_builtin_functions (void) { EOF @@ -117,7 +91,6 @@ void install_builtins (void) { - install_builtin_variables (); install_mapper_functions (); install_builtin_functions (); }
--- a/src/oct-hist.cc +++ b/src/oct-hist.cc @@ -76,22 +76,6 @@ // TRUE means input is coming from temporary history file. bool input_from_tmp_history_file = false; -// Where history is saved. -static std::string Vhistory_file; - -// The number of lines to keep in the history file. -static int Vhistory_size; - -// The format of the timestamp marker written to the history file when -// Octave exits. -static std::string Vhistory_timestamp_format_string; - -// TRUE if we are saving history. -bool Vsaving_history = true; - -// Get some default values, possibly reading them from the -// environment. - static std::string default_history_file (void) { @@ -126,6 +110,9 @@ return file; } +// Where history is saved. +static std::string Vhistory_file = default_history_file (); + static int default_history_size (void) { @@ -144,6 +131,9 @@ return size; } +// The number of lines to keep in the history file. +static int Vhistory_size = default_history_size (); + static std::string default_history_timestamp_format (void) { @@ -155,6 +145,14 @@ + std::string (">"); } +// The format of the timestamp marker written to the history file when +// Octave exits. +static std::string Vhistory_timestamp_format_string + = default_history_timestamp_format (); + +// TRUE if we are saving history. +bool Vsaving_history = true; + // Display, save, or load history. Stolen and modified from bash. // // Arg of -w FILENAME means write file, arg of -r FILENAME @@ -456,7 +454,7 @@ // Call up our favorite editor on the file of commands. - std::string cmd = Veditor; + std::string cmd = VEDITOR; cmd.append (" \""); cmd.append (name); cmd.append ("\""); @@ -551,6 +549,14 @@ } void +initialize_history (void) +{ + command_history::set_file (file_ops::tilde_expand (Vhistory_file)); + + command_history::read (false); +} + +void octave_history_write_timestamp (void) { octave_localtime now; @@ -675,117 +681,72 @@ return retval; } -static int -history_size (void) +DEFUN (history_size, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ +Query or set the internal variable that specifies how many entries\n\ +to store in the history file. The default value is @code{1024},\n\ +but may be overridden by the environment variable @code{OCTAVE_HISTSIZE}.\n\ +@seealso{history_file, history_timestamp_format, saving_history}\n\ +@end deftypefn") { - double val; - if (builtin_real_scalar_variable ("history_size", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival >= 0 && ival == val) - { - Vhistory_size = ival; - command_history::set_size (ival); - return 0; - } - } - gripe_invalid_value_specified ("history_size"); - return -1; -} - -static int -history_file (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("history_file"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("history_file"); - status = -1; - } - else - { - Vhistory_file = s; - command_history::set_file (file_ops::tilde_expand (s)); - } - - return status; + return SET_INTERNAL_VARIABLE_WITH_LIMITS (history_size, -1, INT_MAX); } -static int -history_timestamp_format_string (void) +DEFUN (history_file, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ +Query or set the internal variable that specifies the name of the\n\ +file used to store command history. The default value is\n\ +@code{\"~/.octave_hist\"}, but may be overridden by the environment\n\ +variable @code{OCTAVE_HISTFILE}.\n\ +@seealso{history_size, saving_history, history_timestamp_format_string}\n\ +@end deftypefn") { - int status = 0; - - octave_value v = builtin_any_variable ("history_timestamp_format_string"); + std::string saved_history_file = Vhistory_file; - if (v.is_string ()) - Vhistory_timestamp_format_string = v.string_value (); - else - { - gripe_invalid_value_specified ("history_timestamp_format_string"); - status = -1; - } + octave_value retval = SET_INTERNAL_VARIABLE (history_file); - return status; -} + if (Vhistory_file != saved_history_file) + command_history::set_file (file_ops::tilde_expand (Vhistory_file)); -static int -saving_history (void) -{ - Vsaving_history = check_preference ("saving_history"); - - command_history::ignore_entries (! Vsaving_history); - - return 0; + return retval;; } -void -symbols_of_oct_hist (void) -{ - DEFVAR (history_file, default_history_file (), history_file, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} history_file\n\ -This variable specifies the name of the file used to store command\n\ -history. The default value is @code{\"~/.octave_hist\"}, but may be\n\ -overridden by the environment variable @code{OCTAVE_HISTFILE}.\n\ -@end defvr"); - - double tmp_hist_size = default_history_size (); - - DEFVAR (history_size, tmp_hist_size, history_size, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} history_size\n\ -This variable specifies how many entries to store in the history file.\n\ -The default value is @code{1024}, but may be overridden by the\n\ -environment variable @code{OCTAVE_HISTSIZE}.\n\ -@end defvr"); - - DEFVAR (history_timestamp_format_string, - default_history_timestamp_format (), - history_timestamp_format_string, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} history_timestamp_format_string\n\ -This variable specifies the the format string for the comment line\n\ -that is written to the history file when Octave exits. The format\n\ -string is passed to @code{strftime}. The default value is\n\ +DEFUN (history_timestamp_format_string, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ +Query or set the internal variable that specifies the the format string\n\ +for the comment line that is written to the history file when Octave\n\ +exits. The format string is passed to @code{strftime}. The default\n\ +value is\n\ \n\ @example\n\ \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ @end example\n\ -@seealso{strftime}\n\ -@end defvr"); +@seealso{strftime, history_file, history_size, saving_history}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (history_timestamp_format_string); +} - DEFVAR (saving_history, true, saving_history, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} saving_history\n\ -If the value of @code{saving_history} is nonzero, command entered\n\ -on the command line are saved in the file specified by the variable\n\ -@code{history_file}.\n\ -@end defvr"); +DEFUN (saving_history, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ +Query or set the internal variable that controls whether commands entered\n\ +on the command line are saved in the history file.\n\ +@seealso{history_file, history_size, history_timestamp_format}.\n\ +@end deftypefn") +{ + octave_value retval = SET_INTERNAL_VARIABLE (saving_history); + + command_history::ignore_entries (! Vsaving_history); + + return retval; } /*
--- a/src/oct-hist.h +++ b/src/oct-hist.h @@ -28,6 +28,8 @@ #include "cmd-hist.h" +extern void initialize_history (void); + // Write timestamp to history file. extern void octave_history_write_timestamp (void);
--- a/src/oct-procbuf.cc +++ b/src/oct-procbuf.cc @@ -46,9 +46,6 @@ #include "gripes.h" #include "utils.h" -// Number of microseconds to delay in the parent after forking. -static int Vkluge_procbuf_delay = 0; - // This class is based on the procbuf class from libg++, written by // Per Bothner, Copyright (C) 1993 Free Software Foundation. @@ -141,9 +138,6 @@ exit (127); } - if (Vkluge_procbuf_delay > 0) - octave_usleep (Vkluge_procbuf_delay); - ::close (child_end); if (proc_pid < 0) @@ -233,35 +227,6 @@ #endif } -static int -kluge_procbuf_delay (void) -{ - double val; - if (builtin_real_scalar_variable ("__kluge_procbuf_delay__", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival >= 0 && static_cast<double> (ival) == val) - { - Vkluge_procbuf_delay = ival; - return 0; - } - } - gripe_invalid_value_specified ("__kluge_procbuf_delay__"); - return -1; -} - -void -symbols_of_oct_procbuf (void) -{ - DEFVAR (__kluge_procbuf_delay__, Vkluge_procbuf_delay, kluge_procbuf_delay, - "-*- texinfo -*-\n\ -@defvr __kluge_procbuf_delay__\n\ -Number of microseconds to delay in the parent after forking.\n\ -@end defvr"); - -} - /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/octave.cc +++ b/src/octave.cc @@ -478,17 +478,17 @@ { persist = true; - bind_builtin_variable ("PS1", ">> "); - bind_builtin_variable ("PS2", ""); - bind_builtin_variable ("beep_on_error", true); - bind_builtin_variable ("crash_dumps_octave_core", false); - bind_builtin_variable ("default_save_options", "-mat-binary"); - bind_builtin_variable ("fixed_point_format", true); - bind_builtin_variable ("history_timestamp_format_string", + bind_internal_variable ("PS1", ">> "); + bind_internal_variable ("PS2", ""); + bind_internal_variable ("beep_on_error", true); + bind_internal_variable ("crash_dumps_octave_core", false); + bind_internal_variable ("default_save_options", "-mat-binary"); + bind_internal_variable ("fixed_point_format", true); + bind_internal_variable ("history_timestamp_format_string", "%%-- %D %I:%M %p --%%"); - bind_builtin_variable ("page_screen_output", false); - bind_builtin_variable ("print_empty_dimensions", false); - bind_builtin_variable ("warn_function_name_clash", false); + bind_internal_variable ("page_screen_output", false); + bind_internal_variable ("print_empty_dimensions", false); + bind_internal_variable ("warn_function_name_clash", false); } // You guessed it. @@ -506,7 +506,7 @@ // default variable values must be available for the variables to be // installed, and the call to install_builtins must come before the // options are processed because some command line options override - // defaults by calling bind_builtin_variable. + // defaults by calling bind_internal_variable. sysdep_init (); @@ -520,6 +520,8 @@ initialize_error_handlers (); + initialize_default_warning_state (); + install_defaults (); initialize_pathsearch (); @@ -545,7 +547,7 @@ switch (optc) { case 'H': - bind_builtin_variable ("saving_history", false); + bind_internal_variable ("saving_history", false); break; case 'V': @@ -573,7 +575,7 @@ case 'p': if (args.optarg ()) - bind_builtin_variable ("LOADPATH", args.optarg ()); + bind_internal_variable ("LOADPATH", args.optarg ()); break; case 'q': @@ -583,7 +585,7 @@ case 'x': { double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); - bind_builtin_variable ("echo_executing_commands", tmp); + bind_internal_variable ("echo_executing_commands", tmp); } break; @@ -603,17 +605,17 @@ case EXEC_PATH_OPTION: if (args.optarg ()) - bind_builtin_variable ("EXEC_PATH", args.optarg ()); + bind_internal_variable ("exec_path", args.optarg ()); break; case INFO_FILE_OPTION: if (args.optarg ()) - bind_builtin_variable ("INFO_FILE", args.optarg ()); + bind_internal_variable ("info_file", args.optarg ()); break; case INFO_PROG_OPTION: if (args.optarg ()) - bind_builtin_variable ("INFO_PROGRAM", args.optarg ()); + bind_internal_variable ("info_program", args.optarg ()); break; case NO_INIT_FILE_OPTION: @@ -669,7 +671,7 @@ execute_startup_files (); - command_history::read (false); + initialize_history (); if (! inhibit_startup_message && reading_startup_message_printed) std::cout << std::endl; @@ -735,7 +737,7 @@ // FIXME -- is this the right thing to do? - bind_builtin_variable ("echo_executing_commands", ECHO_CMD_LINE); + bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE); } if (embedded)
--- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -60,11 +60,11 @@ "<unknown type>", "unknown"); // If TRUE, print the name along with the value. -static bool Vprint_answer_id_name; +static bool Vprint_answer_id_name = true; // If TRUE, turn off printing of results in functions (as if a // semicolon has been appended to each statement). -static bool Vsilent_functions; +static bool Vsilent_functions = false; octave_value octave_base_value::squeeze (void) const @@ -1096,53 +1096,28 @@ INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); } -static int -print_answer_id_name (void) +DEFUN (print_answer_id_name, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} print_answer_id_name ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} print_answer_id_name (@var{new_val})\n\ +Query or set the internal variable that controls whether variable\n\ +names are printed along with results produced by evaluating an expression.\n\ +@end deftypefn") { - Vprint_answer_id_name = check_preference ("print_answer_id_name"); - - return 0; -} - -static int -silent_functions (void) -{ - Vsilent_functions = check_preference ("silent_functions"); - - return 0; + return SET_INTERNAL_VARIABLE (print_answer_id_name); } -void -symbols_of_ov_base (void) +DEFUN (silent_functions, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\ +Query or set the internal variable that controls whether internal\n\ +output from a function is suppressed. If this option is disabled,\n\ +Octave will display the results produced by evaluating expressions\n\ +within a function body that are not terminated with a semicolon.\n\ +@end deftypefn") { - DEFVAR (print_answer_id_name, true, print_answer_id_name, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} print_answer_id_name\n\ -If the value of @code{print_answer_id_name} is nonzero, variable\n\ -names are printed along with the result. Otherwise, only the result\n\ -values are printed. The default value is 1.\n\ -@end defvr"); - - DEFVAR (silent_functions, false, silent_functions, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} silent_functions\n\ -If the value of @code{silent_functions} is nonzero, internal output\n\ -from a function is suppressed. Otherwise, the results of expressions\n\ -within a function body that are not terminated with a semicolon will\n\ -have their values printed. The default value is 0.\n\ -\n\ -For example, if the function\n\ -\n\ -@example\n\ -function f ()\n\ - 2 + 2\n\ -endfunction\n\ -@end example\n\ -\n\ -@noindent\n\ -is executed, Octave will either print @samp{ans = 4} or nothing\n\ -depending on the value of @code{silent_functions}.\n\ -@end defvr"); + return SET_INTERNAL_VARIABLE (silent_functions); } /*
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -49,7 +49,7 @@ #include "variables.h" // Maximum nesting level for functions called recursively. -static int Vmax_recursion_depth; +static int Vmax_recursion_depth = 256; // User defined functions. @@ -545,7 +545,7 @@ void octave_user_function::print_code_function_header (void) { - tree_print_code tpc (octave_stdout, Vps4); + tree_print_code tpc (octave_stdout, VPS4); tpc.visit_octave_user_function_header (*this); } @@ -553,7 +553,7 @@ void octave_user_function::print_code_function_trailer (void) { - tree_print_code tpc (octave_stdout, Vps4); + tree_print_code tpc (octave_stdout, VPS4); tpc.visit_octave_user_function_trailer (*this); } @@ -865,26 +865,16 @@ return retval; } -static int -max_recursion_depth (void) +DEFUN (max_recursion_depth, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\ +Query or set the internal limit on the number of times a function may\n\ +be called recursively. If the limit is exceeded, an error message is\n\ +printed and control returns to the top level.\n\ +@end deftypefn") { - Vmax_recursion_depth = check_preference ("max_recursion_depth"); - - return 0; -} - -void -symbols_of_ov_usr_fcn (void) -{ - DEFVAR (max_recursion_depth, 256.0, max_recursion_depth, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} max_recursion_depth\n\ -Limit the number of times a function may be called recursively.\n\ -If the limit is exceeded, an error message is printed and control\n\ -returns to the top level.\n\ -\n\ -The default value is 256.\n\ -@end defvr"); + return SET_INTERNAL_VARIABLE (max_recursion_depth); } /*
--- a/src/pager.cc +++ b/src/pager.cc @@ -57,17 +57,42 @@ // The diary file. static std::ofstream external_diary_file; +static std::string +default_pager (void) +{ + std::string pager_binary = octave_env::getenv ("PAGER"); + +#ifdef OCTAVE_DEFAULT_PAGER + if (pager_binary.empty ()) + { + pager_binary = std::string (OCTAVE_DEFAULT_PAGER); + + if (pager_binary == "less") + { + pager_binary.append (" -e"); + + std::string lessflags = octave_env::getenv ("LESS"); + if (lessflags.empty ()) + pager_binary.append + (" -X -P'-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$'"); + } + } +#endif + + return pager_binary; +} + // The shell command to run as the pager. -static std::string Vpager_binary; +static std::string VPAGER = default_pager (); // TRUE means that if output is going to the pager, it is sent as soon // as it is available. Otherwise, it is buffered and only sent to the // pager when it is time to print another prompt. -static bool Vpage_output_immediately; +static bool Vpage_output_immediately = false; // TRUE means all output intended for the screen should be passed // through the pager. -static bool Vpage_screen_output; +static bool Vpage_screen_output = true; static bool really_flush_to_pager = false; @@ -126,7 +151,7 @@ { if (! external_pager) { - std::string pgr = Vpager_binary; + std::string pgr = VPAGER; if (! pgr.empty ()) { @@ -485,19 +510,14 @@ std::string arg = argv[1]; if (arg == "on") - bind_builtin_variable ("page_screen_output", true); + Vpage_screen_output = true; else if (arg == "off") - bind_builtin_variable ("page_screen_output", false); + Vpage_screen_output = false; else error ("more: unrecognized argument `%s'", arg.c_str ()); } else if (argc == 1) - { - octave_value tmp = builtin_any_variable ("page_screen_output"); - - if (! error_state) - bind_builtin_variable ("page_screen_output", ! tmp.is_true ()); - } + Vpage_screen_output = ! Vpage_screen_output; else print_usage ("more"); @@ -520,98 +540,46 @@ return octave_value (size); } -static std::string -default_pager (void) +DEFUN (page_output_immediately, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} page_output_immediately ()\n\ +@deftypefnx {Built-in Function} {@var{val} =} page_output_immediately (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave sends\n\ +output to the pager as soon as it is available. Otherwise, Octave\n\ +buffers its output and waits until just before the prompt is printed to\n\ +flush it to the pager.\n\ +@end deftypefn") { - std::string pager_binary = octave_env::getenv ("PAGER"); - -#ifdef OCTAVE_DEFAULT_PAGER - if (pager_binary.empty ()) - { - pager_binary = std::string (OCTAVE_DEFAULT_PAGER); - - if (pager_binary == "less") - { - pager_binary.append (" -e"); - - std::string lessflags = octave_env::getenv ("LESS"); - if (lessflags.empty ()) - pager_binary.append - (" -X -P'-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$'"); - } - } -#endif - - return pager_binary; -} - -static int -pager_binary (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("PAGER"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("PAGER"); - status = -1; - } - else - Vpager_binary = s; - - return status; + return SET_INTERNAL_VARIABLE (page_output_immediately); } -static int -page_output_immediately (void) +DEFUN (page_screen_output, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} page_screen_output ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} page_screen_output (@var{new_val})\n\ +Query or set the internal variable that controls whether output intended\n\ +for the terminal window that is longer than one page is sent through a\n\ +pager. This allows you to view one screenful at a time. Some pagers\n\ +(such as @code{less}---see @ref{Installation}) are also capable of moving\n\ +backward on the output.\n\ +@end deftypefn") { - Vpage_output_immediately = check_preference ("page_output_immediately"); - - return 0; + return SET_INTERNAL_VARIABLE (page_screen_output); } -static int -page_screen_output (void) -{ - Vpage_screen_output = check_preference ("page_screen_output"); - - return 0; -} - -void -symbols_of_pager (void) -{ - DEFVAR (PAGER, default_pager (), pager_binary, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} PAGER\n\ -The default value is normally @code{\"less\"}, @code{\"more\"}, or\n\ +DEFUN (PAGER, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} PAGER ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} PAGER (@var{new_val})\n\ +Query or set the internal variable that specifies the program to use\n\ +to display terminal output on your system. The default value is\n\ +normally @code{\"less\"}, @code{\"more\"}, or\n\ @code{\"pg\"}, depending on what programs are installed on your system.\n\ @xref{Installation}.\n\ -\n\ -When running interactively, Octave sends any output intended for your\n\ -terminal that is more than one screen long to the program named by the\n\ -value of the variable @code{PAGER}.\n\ -@end defvr"); - - DEFVAR (page_output_immediately, false, page_output_immediately, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} page_output_immediately\n\ -If the value of @code{page_output_immediately} is nonzero, Octave sends\n\ -output to the pager as soon as it is available. Otherwise, Octave\n\ -buffers its output and waits until just before the prompt is printed to\n\ -flush it to the pager. The default value is 0.\n\ -@end defvr"); - - DEFVAR (page_screen_output, true, page_screen_output, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} page_screen_output\n\ -If the value of @code{page_screen_output} is nonzero, all output\n\ -intended for the screen that is longer than one page is sent through a\n\ -pager. This allows you to view one screenful at a time. Some pagers\n\ -(such as @code{less}---see @ref{Installation}) are also capable of moving\n\ -backward on the output. The default value is 1.\n\ -@end defvr"); +@seealso{page_screen_output, page_output_immediately}\n\ +@end deftypefn") +{ + return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER); } /*
--- a/src/parse.y +++ b/src/parse.y @@ -3212,12 +3212,6 @@ command_editor::set_input_stream (static_cast<FILE *> (f)); } -static void -clear_current_script_file_name (void *) -{ - bind_builtin_variable ("current_script_file_name", octave_value ()); -} - static bool parse_fcn_file (const std::string& ff, bool exec_script, bool force_script = false) { @@ -3329,10 +3323,6 @@ Vsaving_history = false; reading_script_file = true; - unwind_protect::add (clear_current_script_file_name, 0); - - bind_builtin_variable ("current_script_file_name", ff); - octave_user_script *script = new octave_user_script (ff, ff, ""); octave_call_stack::push (script); unwind_protect::add (octave_call_stack::unwind_pop_script, 0);
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -60,26 +60,26 @@ // TRUE means use a scaled fixed point format for `format long' and // `format short'. -static bool Vfixed_point_format; +static bool Vfixed_point_format = false; // The maximum field width for a number printed by the default output // routines. -static int Voutput_max_field_width; +static int Voutput_max_field_width = 10; // The precision of the numbers printed by the default output // routines. -static int Voutput_precision; +static int Voutput_precision = 5; // TRUE means that the dimensions of empty objects should be printed // like this: x = [](2x0). -bool Vprint_empty_dimensions; +bool Vprint_empty_dimensions = true; // TRUE means that the rows of big matrices should be split into // smaller slices that fit on the screen. -static bool Vsplit_long_rows; +static bool Vsplit_long_rows = true; // How many levels of structure elements should we print? -int Vstruct_levels_to_print; +int Vstruct_levels_to_print = 2; // TRUE means don't do any fancy formatting. static bool free_format = false; @@ -2607,8 +2607,8 @@ static void set_output_prec_and_fw (int prec, int fw) { - bind_builtin_variable ("output_precision", prec); - bind_builtin_variable ("output_max_field_width", fw); + Voutput_precision = prec; + Voutput_max_field_width = fw; } static void @@ -2944,93 +2944,14 @@ return retval; } -static int -fixed_point_format (void) -{ - Vfixed_point_format = check_preference ("fixed_point_format"); - - return 0; -} - -static int -output_max_field_width (void) -{ - double val; - if (builtin_real_scalar_variable ("output_max_field_width", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival > 0 && ival == val) - { - Voutput_max_field_width = ival; - return 0; - } - } - gripe_invalid_value_specified ("output_max_field_width"); - return -1; -} - -static int -output_precision (void) -{ - double val; - if (builtin_real_scalar_variable ("output_precision", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival >= 0 && ival == val) - { - Voutput_precision = ival; - return 0; - } - } - gripe_invalid_value_specified ("output_precision"); - return -1; -} - -static int -print_empty_dimensions (void) -{ - Vprint_empty_dimensions = check_preference ("print_empty_dimensions"); - - return 0; -} - -static int -split_long_rows (void) -{ - Vsplit_long_rows = check_preference ("split_long_rows"); - - return 0; -} - -static int -struct_levels_to_print (void) -{ - double val; - if (builtin_real_scalar_variable ("struct_levels_to_print", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival == val) - { - Vstruct_levels_to_print = ival; - return 0; - } - } - gripe_invalid_value_specified ("struct_levels_to_print"); - return -1; -} - -void -symbols_of_pr_output (void) -{ - DEFVAR (fixed_point_format, false, fixed_point_format, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} fixed_point_format\n\ -If the value of this variable is nonzero, Octave will scale all values\n\ -in a matrix so that the largest may be written with one leading digit.\n\ -The scaling factor is printed on the first line of output. For example,\n\ +DEFUN (fixed_point_format, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will\n\ +use a scaled format to print matrix values such that the largest\n\ +element may be written with a single leading digit with the scaling\n\ +factor is printed on the first line of output. For example,\n\ \n\ @example\n\ @group\n\ @@ -3051,28 +2972,16 @@ Notice that first value appears to be zero when it is actually 1. For\n\ this reason, you should be careful when setting\n\ @code{fixed_point_format} to a nonzero value.\n\ -\n\ -The default value of @code{fixed_point_format} is 0.\n\ -@end defvr"); - - DEFVAR (output_max_field_width, 10.0, output_max_field_width, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} output_max_field_width\n\ -This variable specifies the maximum width of a numeric output field.\n\ -The default value is 10.\n\ -@end defvr"); - - DEFVAR (output_precision, 5.0, output_precision, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} output_precision\n\ -This variable specifies the minimum number of significant figures to\n\ -display for numeric output. The default value is 5.\n\ -@end defvr"); - - DEFVAR (print_empty_dimensions, true, print_empty_dimensions, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} print_empty_dimensions\n\ -If the value of @code{print_empty_dimensions} is nonzero, the\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (fixed_point_format); +} + +DEFUN (print_empty_dimensions, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\ +Query or set the internal varaible that controls whether the\n\ dimensions of empty matrices are printed along with the empty matrix\n\ symbol, @samp{[]}. For example, the expression\n\ \n\ @@ -3086,21 +2995,21 @@ @example\n\ ans = [](3x0)\n\ @end example\n\ -@end defvr"); - - DEFVAR (split_long_rows, true, split_long_rows, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} split_long_rows\n\ -For large matrices, Octave may not be able to display all the columns of\n\ -a given row on one line of your screen. This can result in missing\n\ -information or output that is nearly impossible to decipher, depending\n\ -on whether your terminal truncates or wraps long lines.\n\ -\n\ -If the value of @code{split_long_rows} is nonzero, Octave will display\n\ -the matrix in a series of smaller pieces, each of which can fit within\n\ -the limits of your terminal width. Each set of rows is labeled so that\n\ -you can easily see which columns are currently being displayed.\n\ -For example:\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (print_empty_dimensions); +} + +DEFUN (split_long_rows, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\ +Query or set the internal variable that controls whether rows of a matrix\n\ +may be split when displayed to a terminal window. If the rows are split,\n\ +Octave will display the matrix in a series of smaller pieces, each of\n\ +which can fit within the limits of your terminal width and each set of\n\ +rows is labeled so that you can easily see which columns are currently\n\ +being displayed. For example:\n\ \n\ @smallexample\n\ @group\n\ @@ -3118,17 +3027,45 @@ 0.44672 0.94303 0.56564 0.82150\n\ @end group\n\ @end smallexample\n\ -\n\ -@noindent\n\ -The default value of @code{split_long_rows} is nonzero.\n\ -@end defvr"); - - DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} struct_levels_to_print\n\ -You can tell Octave how many structure levels to display by setting the\n\ -built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (split_long_rows); +} + +DEFUN (output_max_field_width, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\ +Query or set the internal variable that specifies the maximum width\n\ +of a numeric output field.\n\ +@seealso{format, output_precision}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, INT_MAX); +} + +DEFUN (output_precision, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\ +Query or set the internal variable that specifies the minimum number of\n\ +significant figures to display for numeric output.\n\ +@seealso{format, output_max_field_width}\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX); +} + +DEFUN (struct_levels_to_print, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ +Query or set the internal variable that specifies the number of\n\ +structure levels to display.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, + -1, INT_MAX); } /*
--- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -39,10 +39,11 @@ #include "pt-assign.h" #include "pt-walk.h" #include "utils.h" +#include "variables.h" // TRUE means print the right hand side of an assignment instead of // the left. -static bool Vprint_rhs_assign_val; +static bool Vprint_rhs_assign_val = false; // Simple assignment expressions. @@ -342,26 +343,18 @@ tw.visit_multi_assignment (*this); } -static int -print_rhs_assign_val (void) +DEFUN (print_rhs_assign_val, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} print_rhs_assign_val ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} print_rhs_assign_val (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will\n\ +print the value of the right hand side of assignment expressions\n\ +instead of the value of the left hand side (after the assignment).\n\ +@end deftypefn") { - Vprint_rhs_assign_val = check_preference ("print_rhs_assign_val"); - - return 0; + return SET_INTERNAL_VARIABLE (print_rhs_assign_val); } -void -symbols_of_pt_assign (void) -{ - DEFVAR (print_rhs_assign_val, false, print_rhs_assign_val, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} print_rhs_assign_val\n\ -If the value of this variable is non-zero, Octave will print the value\n\ -of the right hand side of assignment expressions instead of the value\n\ -of the left hand side (after the assignment).\n\ -@end defvr"); - -} /* ;;; Local Variables: ***
--- a/src/pt-assign.h +++ b/src/pt-assign.h @@ -92,7 +92,7 @@ // True if we should not delete the lhs. bool preserve; - // True if this is an assignment to the built-in variable ans. + // True if this is an assignment to the automatic variable ans. bool ans_ass; // The type of the expression.
--- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -939,52 +939,26 @@ tw.visit_matrix (*this); } -static int -string_fill_char (void) -{ - int status = 0; - - std::string s = builtin_string_variable ("string_fill_char"); - - switch (s.length ()) - { - case 1: - Vstring_fill_char = s[0]; - break; - - case 0: - Vstring_fill_char = '\0'; - break; - - default: - warning ("string_fill_char must be a single character"); - status = -1; - break; - } - - return status; -} - -void -symbols_of_pt_mat (void) -{ - DEFVAR (string_fill_char, " ", string_fill_char, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} string_fill_char\n\ -The value of this variable is used to pad all strings in a string matrix\n\ -to the same length. It should be a single character. The default value\n\ -is @code{\" \"} (a single space). For example,\n\ +DEFUN (string_fill_char, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} string_fill_char ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} string_fill_char (@var{new_val})\n\ +Query or set the internal variable used to pad all rows of a character\n\ +matrix to the same length. It must be a single character. The default\n\ +value is @code{\" \"} (a single space). For example,\n\ \n\ @example\n\ @group\n\ -string_fill_char = \"X\";\n\ +string_fill_char (\"X\");\n\ [ \"these\"; \"are\"; \"strings\" ]\n\ @result{} \"theseXX\"\n\ \"areXXXX\"\n\ \"strings\"\n\ @end group\n\ @end example\n\ -@end defvr"); +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (string_fill_char); } /*
--- a/src/pt-stmt.cc +++ b/src/pt-stmt.cc @@ -78,7 +78,7 @@ if (in_function_body && (Vecho_executing_commands & ECHO_FUNCTIONS)) { - tree_print_code tpc (octave_stdout, Vps4); + tree_print_code tpc (octave_stdout, VPS4); accept (tpc); }
--- a/src/sighandlers.cc +++ b/src/sighandlers.cc @@ -52,6 +52,7 @@ #include "syswait.h" #include "toplev.h" #include "utils.h" +#include "variables.h" // Nonzero means we have already printed a message for this series of // SIGPIPES. We assume that the writer will eventually give up. @@ -66,10 +67,10 @@ // Allow users to avoid writing octave-core for SIGHUP (sent by // closing gnome-terminal, for example). Note that this variable has // no effect if Vcrash_dumps_octave_core is FALSE. -static bool Vsighup_dumps_octave_core; +static bool Vsighup_dumps_octave_core = true; // Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. -static bool Vsigterm_dumps_octave_core; +static bool Vsigterm_dumps_octave_core = true; #if RETSIGTYPE == void #define SIGHANDLER_RETURN(status) return @@ -991,60 +992,41 @@ return retval; } -static int -debug_on_interrupt (void) -{ - Vdebug_on_interrupt = check_preference ("debug_on_interrupt"); - - return 0; -} - -static int -sighup_dumps_octave_core (void) +DEFUN (debug_on_interrupt, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} debug_on_interrupt ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} debug_on_interrupt (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave will try\n\ +to enter debugging mode when it receives an interrupt signal (typically\n\ +generated with @kbd{C-c}). If a second interrupt signal is received\n\ +before reaching the debugging mode, a normal interrupt will occur.\n\ +@end deftypefn") { - Vsighup_dumps_octave_core = check_preference ("sighup_dumps_octave_core"); - - return 0; -} - -static int -sigterm_dumps_octave_core (void) -{ - Vsigterm_dumps_octave_core = check_preference ("sigterm_dumps_octave_core"); - - return 0; + return SET_INTERNAL_VARIABLE (debug_on_interrupt); } -void -symbols_of_sighandlers (void) +DEFUN (sighup_dumps_octave_core, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} sighup_dumps_octave_core ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} sighup_dumps_octave_core (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave tries\n\ +to save all current variables the the file \"octave-core\" if it receives\n\ +a hangup signal.\n\ +@end deftypefn") { - DEFVAR (debug_on_interrupt, false, debug_on_interrupt, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} debug_on_interrupt\n\ -If @code{debug_on_interrupt} is nonzero, Octave will try to enter\n\ -debugging mode when it receives an interrupt signal (typically\n\ -generated with @kbd{C-c}). If a second interrupt signal is received\n\ -before reaching the debugging mode, a normal interrupt will occur.\n\ -The default value is 0.\n\ -@end defvr"); + return SET_INTERNAL_VARIABLE (sighup_dumps_octave_core); +} - DEFVAR (sighup_dumps_octave_core, true, sighup_dumps_octave_core, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} sighup_dumps_octave_core\n\ -If this variable is set to a nonzero value and\n\ -@code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ -current variables the the file \"octave-core\" if it receives a\n\ -hangup signal. The default value is 1.\n\ -@end defvr"); - - DEFVAR (sigterm_dumps_octave_core, true, sigterm_dumps_octave_core, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} sigterm_dumps_octave_core\n\ -If this variable is set to a nonzero value and\n\ -@code{crash_dumps_octave_core} is also nonzero, Octave tries to save all\n\ -current variables the the file \"octave-core\" if it receives a\n\ -terminate signal. The default value is 1.\n\ -@end defvr"); +DEFUN (sigterm_dumps_octave_core, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} sigterm_dumps_octave_core ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} sigterm_dumps_octave_core (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave tries\n\ +to save all current variables the the file \"octave-core\" if it receives\n\ +a terminate signal.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (sigterm_dumps_octave_core); } /*
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -56,13 +56,14 @@ // Should variables be allowed to hide functions of the same name? A // positive value means yes. A negative value means yes, but print a // warning message. Zero means it should be considered an error. -static int Vvariables_can_hide_functions; +static int Vvariables_can_hide_functions = 1; // Nonzero means we print debugging info about symbol table lookups. -static int Vdebug_symtab_lookups; +static bool Vdebug_symtab_lookups = false; // Defines layout for the whos/who -long command -std::string Vwhos_line_format; +std::string Vwhos_line_format + = " %p:4; %ln:6; %cs:16:6:8:1; %rb:12; %lt:-1;\n"; octave_allocator symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def)); @@ -82,8 +83,6 @@ retval = "built-in mapper function"; else if (is_user_function ()) retval = "user-defined function"; - else if (is_builtin_variable ()) - retval = "built-in variable"; else if (is_builtin_function ()) retval = "built-in function"; else if (is_dld_function ()) @@ -130,7 +129,7 @@ defn->accept (tpc); } } - else if (is_user_variable () || is_builtin_variable ()) + else if (is_user_variable ()) { if (pr_type_info && ! quiet) os << name << " is a " << type_as_string () << "\n"; @@ -206,21 +205,7 @@ symbol_record::define (const octave_value& v, unsigned int sym_type) { if (! (is_variable () && read_only_error ("redefine"))) - { - if (definition->type () == symbol_record::BUILTIN_VARIABLE) - sym_type = symbol_record::BUILTIN_VARIABLE; - - definition->define (v, sym_type); - } -} - -void -symbol_record::define_builtin_var (const octave_value& v) -{ - define (v, symbol_record::BUILTIN_VARIABLE); - - if (chg_fcn) - chg_fcn (); + definition->define (v, sym_type); } bool @@ -324,15 +309,6 @@ return is_variable () ? def () : foo; } -inline void -symbol_record::link_to_builtin_variable (void) -{ - symbol_record *tmp_sym = fbi_sym_tab->lookup (name ()); - - if (tmp_sym && tmp_sym->is_builtin_variable ()) - alias (tmp_sym); -} - octave_lvalue symbol_record::variable_reference (void) { @@ -354,14 +330,8 @@ if (! is_defined ()) { - if (! (is_formal_parameter () || is_linked_to_global ())) - link_to_builtin_variable (); - - if (! is_defined ()) - { - octave_value tmp; - define (tmp); - } + octave_value tmp; + define (tmp); } return octave_lvalue (&(def ()), chg_fcn); @@ -1725,55 +1695,24 @@ return h & (table_size - 1); } - -static int -variables_can_hide_functions (void) +DEFUN (debug_symtab_lookups, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} debug_symtab_lookups ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} debug_symtab_lookups (@var{new_val})\n\ +Query or set the internal variable that controls whether debugging\n\ +information is printed when searching for symbols in the symbol tables.\n\ +@end deftypefn") { - Vvariables_can_hide_functions - = check_preference ("variables_can_hide_functions"); - - return 0; -} - -static int -debug_symtab_lookups (void) -{ - Vdebug_symtab_lookups = check_preference ("debug_symtab_lookups"); - - return 0; + return SET_INTERNAL_VARIABLE (debug_symtab_lookups); } -static int -whos_line_format (void) -{ - Vwhos_line_format = builtin_string_variable ("whos_line_format"); - - return 0; -} - -void -symbols_of_symtab (void) -{ - DEFVAR (variables_can_hide_functions, true, variables_can_hide_functions, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} variables_can_hide_functions\n\ -If the value of this variable is nonzero, assignments to variables may\n\ -hide previously defined functions of the same name. A negative value\n\ -will cause Octave to print a warning, but allow the operation.\n\ -@end defvr"); - - DEFVAR (debug_symtab_lookups, false, debug_symtab_lookups, - "-*- texinfo -*-\n\ -@defvr debug_symtab_lookups\n\ -If the value of this variable is nonzero, print debugging info when\n\ -searching for symbols in the symbol tables.\n\ -@end defvr"); - - DEFVAR (whos_line_format, " %p:4; %ln:6; %cs:16:6:8:1; %rb:12; %lt:-1;\n", whos_line_format, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} whos_line_format\n\ -This string decides in what order attributtes of variables are to be printed.\n\ -The following commands are used:\n\ +DEFUN (whos_line_format, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\ +Query or set the format string used by the @code{whos}.\n\ +\n\ +The following escape sequences may be used in the format:\n\ @table @code\n\ @item %b\n\ Prints number of bytes occupied by variables.\n\ @@ -1812,8 +1751,24 @@ dimensions whatsoever.\n\ balance specifies the offset for printing of the dimensions string.\n\ \n\ -Default format is \" %p:4; %ln:6; %cs:16:6:8:1; %rb:12; %lt:-1;\\n\".\n\ -@end defvr"); +The default format is \" %p:4; %ln:6; %cs:16:6:8:1; %rb:12; %lt:-1;\\n\".\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (whos_line_format); +} + +DEFUN (variables_can_hide_functions, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} variables_can_hide_functions ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} variables_can_hide_functions (@var{new_val})\n\ +Query or set the internal variable that controls whether assignments\n\ +to variables may hide previously defined functions of the same name.\n\ +If set to a nonzero value allows hiding, zero causes Octave to\n\ +generate an error, and a negative value cause Octave to print a\n\ +warning, but allow the operation.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (variables_can_hide_functions); } /*
--- a/src/symtab.h +++ b/src/symtab.h @@ -74,8 +74,7 @@ BUILTIN_FUNCTION = 8, COMMAND = 16, RAWCOMMAND = 32, - MAPPER_FUNCTION = 64, - BUILTIN_VARIABLE = 128 + MAPPER_FUNCTION = 64 }; private: @@ -94,10 +93,7 @@ ~symbol_def (void) { } bool is_variable (void) const - { - return (symbol_type & symbol_record::USER_VARIABLE - || symbol_type & symbol_record::BUILTIN_VARIABLE); - } + { return (symbol_type & symbol_record::USER_VARIABLE); } // It's not necessary to check for COMMAND and MAPPER_FUNCTION // here. Those tags are just used as additional qualifiers for @@ -139,9 +135,6 @@ bool is_user_function (void) const { return (symbol_type & symbol_record::USER_FUNCTION); } - bool is_builtin_variable (void) const - { return (symbol_type & symbol_record::BUILTIN_VARIABLE); } - bool is_builtin_function (void) const { return (symbol_type & symbol_record::BUILTIN_FUNCTION); } @@ -330,9 +323,6 @@ bool is_user_variable (void) const { return definition->is_user_variable (); } - bool is_builtin_variable (void) const - { return definition->is_builtin_variable (); } - bool is_map_element (const std::string& elts) const { return definition->is_map_element (elts); } @@ -358,8 +348,6 @@ void define (const octave_value& v, unsigned int sym_type = USER_VARIABLE); - void define_builtin_var (const octave_value& v); - bool define (octave_function *f, unsigned int sym_type); void document (const std::string& h) { definition->document (h); } @@ -467,8 +455,6 @@ bool read_only_error (const char *action); - void link_to_builtin_variable (void); - void maybe_delete_def (void) { if (--definition->count <= 0) @@ -495,11 +481,9 @@ | symbol_record::BUILTIN_FUNCTION \ | symbol_record::COMMAND \ | symbol_record::RAWCOMMAND \ - | symbol_record::MAPPER_FUNCTION \ - | symbol_record::BUILTIN_VARIABLE) + | symbol_record::MAPPER_FUNCTION) -#define SYMTAB_VARIABLES (symbol_record::USER_VARIABLE \ - | symbol_record::BUILTIN_VARIABLE) +#define SYMTAB_VARIABLES (symbol_record::USER_VARIABLE) class symbol_table
--- a/src/utils.cc +++ b/src/utils.cc @@ -328,9 +328,8 @@ @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\ Return the absolute name of @var{file} if it can be found in\n\ @var{path}. The value of @var{path} should be a colon-separated list of\n\ -directories in the format described for the built-in variable\n\ -@code{LOADPATH}. If no file is found, return an empty matrix.\n\ -For example,\n\ +directories in the format described for @code{LOADPATH}. If no file\n\ +is found, return an empty matrix. For example,\n\ \n\ @example\n\ file_in_path (EXEC_PATH, \"sh\")\n\ @@ -741,51 +740,6 @@ } static void -warn_old_style_preference (bool val, const std::string& sval) -{ - warning - ("preference of \"%s\" is obsolete -- use numeric value of %d instead", - sval.c_str (), (val ? 1 : 0)); -} - -// Check the value of a string variable to see if it it's ok to do -// something. -// -// return of 1 => always ok. -// return of 0 => never ok. -// return of -1 => ok, but give me warning (default). - -int -check_preference (const std::string& var) -{ - int pref = -1; - - std::string val = builtin_string_variable (var); - - if (val.empty ()) - { - double dval = 0; - if (builtin_real_scalar_variable (var, dval)) - pref = NINT (dval); - } - else - { - if (val == "yes" || val == "true") - { - warn_old_style_preference (true, val); - pref = 1; - } - else if (val == "never" || val == "no" || val == "false") - { - warn_old_style_preference (false, val); - pref = 0; - } - } - - return pref; -} - -static void check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) { if (nr < 0 || nc < 0)
--- a/src/utils.h +++ b/src/utils.h @@ -65,8 +65,6 @@ extern std::string undo_string_escapes (const std::string& s); -extern int check_preference (const std::string& var); - extern void check_dimensions (dim_vector& dim, const char *warnfor);
--- a/src/variables.cc +++ b/src/variables.cc @@ -60,7 +60,7 @@ // Should Octave always check to see if function files have changed // since they were last compiled? -static int Vignore_function_time_stamp; +static int Vignore_function_time_stamp = 1; // Symbol table for symbols at the top level. symbol_table *top_level_sym_tab = 0; @@ -105,15 +105,6 @@ // Attributes of variables and functions. -// Is this variable a builtin? - -bool -is_builtin_variable (const std::string& name) -{ - symbol_record *sr = fbi_sym_tab->lookup (name); - return (sr && sr->is_builtin_variable ()); -} - // Is this a command-style function? static std::set <std::string> command_set; @@ -799,10 +790,6 @@ { retval = 5; } - else if (var_ok && sr->is_builtin_variable ()) - { - retval = 101; - } } if (! retval @@ -906,8 +893,7 @@ Return 1 if the name exists as a variable, 2 if the name (after\n\ 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, or 103\n\ +built-in function, 7 if the name is a directory, or 103\n\ if the name is a function not associated with a file (entered on\n\ the command line).\n\ \n\ @@ -1258,9 +1244,12 @@ octave_value set_internal_variable (bool& var, const octave_value_list& args, - const char *nm) + int nargout, const char *nm) { - octave_value retval = var; + octave_value retval; + + if (nargout > 0) + retval = var; int nargin = args.length (); @@ -1274,16 +1263,19 @@ error ("%s: expecting arg to be a logical value", nm); } else if (nargin > 1) - print_usage ("automatic_replot"); + print_usage (nm); return retval; } octave_value -set_internal_variable (std::string& var, const octave_value_list& args, - const char *nm) +set_internal_variable (char& var, const octave_value_list& args, + int nargout, const char *nm) { - octave_value retval = var; + octave_value retval; + + if (nargout > 0) + retval = var; int nargin = args.length (); @@ -1292,86 +1284,130 @@ std::string sval = args(0).string_value (); if (! error_state) - var = sval; + { + switch (sval.length ()) + { + case 1: + var = sval[0]; + break; + + case 0: + var = '\0'; + break; + + default: + error ("%s: argument must be a single character", nm); + break; + } + } + else + error ("%s: argument must be a single character", nm); + } + else if (nargin > 1) + print_usage (nm); + + return retval; +} + +octave_value +set_internal_variable (int& var, const octave_value_list& args, + int nargout, const char *nm, + int minval, int maxval) +{ + octave_value retval; + + if (nargout > 0) + retval = var; + + int nargin = args.length (); + + if (nargin == 1) + { + int ival = args(0).int_value (); + + if (! error_state) + { + if (ival < minval) + error ("%s: expecting arg to be greater than %d", minval); + else if (ival > maxval) + error ("%s: expecting arg to be less than or equal to %d", maxval); + else + var = ival; + } + else + error ("%s: expecting arg to be an integer value", nm); + } + else if (nargin > 1) + print_usage (nm); + + return retval; +} + +octave_value +set_internal_variable (double& var, const octave_value_list& args, + int nargout, const char *nm, + double minval, double maxval) +{ + octave_value retval; + + if (nargout > 0) + retval = var; + + int nargin = args.length (); + + if (nargin == 1) + { + double dval = args(0).scalar_value (); + + if (! error_state) + { + if (dval < minval) + error ("%s: expecting arg to be greater than %g", minval); + else if (dval > maxval) + error ("%s: expecting arg to be less than or equal to %g", maxval); + else + var = dval; + } + else + error ("%s: expecting arg to be a scalar value", nm); + } + else if (nargin > 1) + print_usage (nm); + + return retval; +} + +octave_value +set_internal_variable (std::string& var, const octave_value_list& args, + int nargout, const char *nm, bool empty_ok) +{ + octave_value retval; + + if (nargout > 0) + retval = var; + + int nargin = args.length (); + + if (nargin == 1) + { + std::string sval = args(0).string_value (); + + if (! error_state) + { + if (empty_ok || ! sval.empty ()) + var = sval; + else + error ("%s: value must not be empty", nm); + } else error ("%s: expecting arg to be a character string", nm); } else if (nargin > 1) - print_usage ("automatic_replot"); - - return retval; -} - -// Look for the given name in the global symbol table. If it refers -// to a string, return a new copy. If not, return 0; - -std::string -builtin_string_variable (const std::string& name) -{ - symbol_record *sr = fbi_sym_tab->lookup (name); - - // It is a programming error to look for builtins that aren't. - - // Use != here to avoid possible conversion to int of smaller type - // than the sr pointer. - - assert (sr != 0); - - std::string retval; - - octave_value val = sr->def (); - - if (! error_state && val.is_string ()) - retval = val.string_value (); + print_usage (nm); return retval; } -// Look for the given name in the global symbol table. If it refers -// to a real scalar, place the value in d and return 1. Otherwise, -// return 0. - -int -builtin_real_scalar_variable (const std::string& name, double& d) -{ - int status = 0; - symbol_record *sr = fbi_sym_tab->lookup (name); - - // It is a programming error to look for builtins that aren't. - - // Use != here to avoid possible conversion to int of smaller type - // than the sr pointer. - - assert (sr != 0); - - octave_value val = sr->def (); - - if (! error_state && val.is_scalar_type ()) - { - d = val.double_value (); - status = 1; - } - - return status; -} - -// Look for the given name in the global symbol table. - -octave_value -builtin_any_variable (const std::string& name) -{ - symbol_record *sr = fbi_sym_tab->lookup (name); - - // It is a programming error to look for builtins that aren't. - - // Use != here to avoid possible conversion to int of smaller type - // than the sr pointer. - - assert (sr != 0); - - return sr->def (); -} - // Global stuff and links to builtin variables and functions. // Make the definition of the symbol record sr be the same as the @@ -1405,9 +1441,8 @@ // 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 or function, or user -// function of the same name, provided that the name has not been used -// as a formal parameter. +// definition of the builtin function, or user function of the same +// name, provided that the name has not been used as a formal parameter. void link_to_builtin_or_function (symbol_record *sr) @@ -1427,8 +1462,7 @@ tmp_sym = fbi_sym_tab->lookup (nm); if (tmp_sym - && (tmp_sym->is_builtin_variable () - || tmp_sym->is_function ()) + && tmp_sym->is_function () && ! tmp_sym->is_formal_parameter ()) sr->alias (tmp_sym); } @@ -1473,11 +1507,10 @@ if (! error_state) { - if (is_builtin_variable (name) - || is_command_name (name) + if (is_command_name (name) || is_mapper_function_name (name) || is_builtin_function_name (name)) - error ("document: can't redefine help for built-in variables and functions"); + error ("document: can't redefine help for built-in functions"); else { symbol_record *sym_rec = curr_sym_tab->lookup (name); @@ -1577,7 +1610,6 @@ dim_vector dv (0, 0); - Array<symbol_record *> s2 (dv); Array<symbol_record *> s3 (dv); Array<symbol_record *> s4 (dv); Array<symbol_record *> s5 (dv); @@ -1586,9 +1618,6 @@ if (show_builtins) { - s2 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_VARIABLE, - SYMTAB_ALL_SCOPES); - s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); } @@ -1611,22 +1640,18 @@ SYMTAB_GLOBAL_SCOPE); } - octave_idx_type s2_len = s2.length (); octave_idx_type s3_len = s3.length (); octave_idx_type s4_len = s4.length (); octave_idx_type s5_len = s5.length (); octave_idx_type s6_len = s6.length (); octave_idx_type s7_len = s7.length (); - octave_idx_type symbols_len - = s2_len + s3_len + s4_len + s5_len + s6_len + s7_len; + octave_idx_type symbols_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 (s2, k, 0); - k += s2_len; symbols.insert (s3, k, 0); k += s3_len; symbols.insert (s4, k, 0); @@ -1710,10 +1735,6 @@ if (show_builtins) { pad_after += fbi_sym_tab->maybe_list - ("*** built-in variables:", pats, octave_stdout, - show_verbose, symbol_record::BUILTIN_VARIABLE, SYMTAB_ALL_SCOPES); - - pad_after += fbi_sym_tab->maybe_list ("*** built-in functions:", pats, octave_stdout, show_verbose, symbol_record::BUILTIN_FUNCTION, SYMTAB_ALL_SCOPES); } @@ -1763,7 +1784,7 @@ List all currently defined symbols.\n\ \n\ @item -builtins\n\ -List built-in variables and functions. This includes all currently\n\ +List built-in functions. This includes all currently\n\ compiled function files, but does not include all function files that\n\ are in the @code{LOADPATH}.\n\ \n\ @@ -1846,7 +1867,7 @@ void bind_ans (const octave_value& val, bool print) { - static symbol_record *sr = fbi_sym_tab->lookup ("ans", true); + symbol_record *sr = curr_sym_tab->lookup ("ans", true); if (val.is_defined ()) { @@ -1857,46 +1878,14 @@ } } -// Give a global variable a definition. This will insert the symbol -// in the global table if necessary. - -// How is this different than install_builtin_variable? Are both -// functions needed? - void -bind_builtin_variable (const std::string& varname, const octave_value& val, - bool protect, bool eternal, - symbol_record::change_function chg_fcn, - const std::string& help) +bind_internal_variable (const std::string& fname, const octave_value& val) { - symbol_record *sr = fbi_sym_tab->lookup (varname, true); - - // It is a programming error for a builtin symbol to be missing. - // Besides, we just inserted it, so it must be there. - - // Use != here to avoid possible conversion to int of smaller type - // than the sr pointer. - - assert (sr != 0); - - sr->unprotect (); - - // Must do this before define, since define will call the special - // variable function only if it knows about it, and it needs to, so - // that user prefs can be properly initialized. - - if (chg_fcn) - sr->set_change_function (chg_fcn); - - sr->define_builtin_var (val); - - if (protect) - sr->protect (); - - if (eternal) - sr->make_eternal (); - - sr->document (help); + octave_value_list args; + + args(0) = val; + + feval (fname, args, 0); } void @@ -2608,65 +2597,67 @@ return retval; } -// FIXME -- some of these should do their own checking to be -// able to provide more meaningful warning or error messages. - -static int -ignore_function_time_stamp (void) -{ - int pref = 0; - - std::string val = builtin_string_variable ("ignore_function_time_stamp"); - - if (! val.empty ()) - { - if (val == "all") - pref = 2; - else if (val == "system") - pref = 1; - } - - Vignore_function_time_stamp = pref; - - return 0; -} - -// FIXME -- there still may be better places for some of these -// to be defined. - -void -symbols_of_variables (void) -{ - DEFVAR (ans, , 0, +DEFUN (ignore_function_time_stamp, args, nargout, "-*- texinfo -*-\n\ -@defvr {Built-in Variable} ans\n\ -This variable holds the most recently computed result that was not\n\ -explicitly assigned to a variable. For example, after the expression\n\ -\n\ -@example\n\ -3^2 + 4^2\n\ -@end example\n\ -\n\ -@noindent\n\ -is evaluated, the value of @code{ans} is 25.\n\ -@end defvr"); - - DEFVAR (ignore_function_time_stamp, "system", ignore_function_time_stamp, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} ignore_function_time_stamp\n\ -This variable can be used to prevent Octave from making the system call\n\ -@code{stat} each time it looks up functions defined in function files.\n\ -If @code{ignore_function_time_stamp} to @code{\"system\"}, Octave will not\n\ -automatically recompile function files in subdirectories of\n\ +@deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ +Query or set the internal variable that controls whether Octave checks\n\ +the time stamp on files each time it looks up functions defined in\n\ +function files. If the internal variable is set to @code{\"system\"},\n\ +Octave will not automatically recompile function files in subdirectories of\n\ @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ they were last compiled, but will recompile other function files in the\n\ @code{LOADPATH} if they change. If set to @code{\"all\"}, Octave will not\n\ recompile any function files unless their definitions are removed with\n\ -@code{clear}. For any other value of @code{ignore_function_time_stamp},\n\ -Octave will always check to see if functions defined in function files\n\ -need to recompiled. The default value of @code{ignore_function_time_stamp} is\n\ -@code{\"system\"}.\n\ -@end defvr"); +@code{clear}. If set to \"none\", Octave will always check time stamps\n\ +on files to determine whether functions defined in function files\n\ +need to recompiled.\n\ +@end deftypefn") +{ + octave_value retval; + + if (nargout > 0) + { + switch (Vignore_function_time_stamp) + { + case 1: + retval = "system"; + break; + + case 2: + retval = "all"; + break; + + default: + retval = "none"; + break; + } + } + + int nargin = args.length (); + + if (nargin == 1) + { + std::string sval = args(0).string_value (); + + if (! error_state) + { + if (sval == "all") + Vignore_function_time_stamp = 2; + else if (sval == "system") + Vignore_function_time_stamp = 1; + else if (sval == "none") + Vignore_function_time_stamp = 0; + else + error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); + } + else + error ("ignore_function_time_stamp: expecting argument to be character string"); + } + else if (nargin > 1) + print_usage ("ignore_function_time_stamp"); + + return retval; } /*
--- a/src/variables.h +++ b/src/variables.h @@ -36,6 +36,9 @@ class octave_mapper; class string_vector; +#include <climits> +#include <cfloat> + #include <string> #include "ov.h" @@ -46,7 +49,6 @@ extern void initialize_symbol_tables (void); -extern bool is_builtin_variable (const std::string&); extern bool is_command_name (const std::string&); // The next three are here temporarily... @@ -109,13 +111,34 @@ extern octave_value set_internal_variable (bool& var, const octave_value_list& args, - const char *nm); + int nargout, const char *nm); + +extern octave_value +set_internal_variable (char& var, const octave_value_list& args, + int nargout, const char *nm); + +extern octave_value +set_internal_variable (int& var, const octave_value_list& args, + int nargout, const char *nm, + int minval = INT_MIN, int maxval = INT_MAX); + +extern octave_value +set_internal_variable (double& var, const octave_value_list& args, + int nargout, const char *nm, + double minval = DBL_MIN, double maxval = DBL_MAX); extern octave_value set_internal_variable (std::string& var, const octave_value_list& args, - const char *nm); + int nargout, const char *nm, bool empty_ok = true); + +#define SET_INTERNAL_VARIABLE(NM) \ + set_internal_variable (V ## NM, args, nargout, #NM) -#define SET_INTERNAL_VARIABLE(NM) set_internal_variable (V ## NM, args, #NM) +#define SET_NONEMPTY_INTERNAL_STRING_VARIABLE(NM) \ + set_internal_variable (V ## NM, args, nargout, #NM, false) + +#define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL) \ + set_internal_variable (V ## NM, args, nargout, #NM, MINVAL, MAXVAL) extern std::string builtin_string_variable (const std::string&); extern int builtin_real_scalar_variable (const std::string&, double&); @@ -129,10 +152,7 @@ extern void bind_ans (const octave_value& val, bool print); extern void -bind_builtin_variable (const std::string&, const octave_value&, - bool protect = false, bool eternal = false, - symbol_record::change_function f = 0, - const std::string& help = std::string ()); +bind_internal_variable (const std::string& fname, const octave_value& val); extern void mlock (const std::string&); extern void munlock (const std::string&);
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2006-05-04 John W. Eaton <jwe@octave.org> + + * test_prefer.m: Adjust tests for eliminated built-in variables. + 2006-04-29 John W. Eaton <jwe@octave.org> * Makefile.in (check): Use run-octave script.
--- a/test/test_prefer.m +++ b/test/test_prefer.m @@ -98,37 +98,37 @@ %% FIXME How the hell do I test this one in test/assert %% test/octave.test/prefer/prefer-19.m %!#test -%! pid = print_answer_id_name -%! print_answer_id_name = 0; +%! pid = print_answer_id_name (); +%! print_answer_id_name (0); %! a = 1 -%! print_answer_id_name = pid; +%! print_answer_id_name (pid); %% FIXME How the hell do I test this one in test/assert %% test/octave.test/prefer/prefer-20.m %!#test -%! pid = print_answer_id_name -%! print_answer_id_name = 1; +%! pid = print_answer_id_name (); +%! print_answer_id_name (1); %! a = 1 -%! print_answer_id_name = pid; +%! print_answer_id_name (pid); %% test/octave.test/prefer/prefer-21.m %!test -%! ped = print_empty_dimensions; -%! print_empty_dimensions = 0; +%! ped = print_empty_dimensions (); +%! print_empty_dimensions (0); %! a = cell (1, 1); %! b = type -q a; %! assert(!isempty(findstr(b,"[]"))); %! assert(isempty(findstr(b,"[](0x0)"))); -%! print_empty_dimensions = ped; +%! print_empty_dimensions (ped); %% test/octave.test/prefer/prefer-22.m %!test -%! ped = print_empty_dimensions; -%! print_empty_dimensions = 1; +%! ped = print_empty_dimensions (); +%! print_empty_dimensions (1); %! a = cell (1, 1); %! b = type -q a; %! assert(!isempty(findstr(b,"[](0x0)"))); -%! print_empty_dimensions = ped; +%! print_empty_dimensions (ped); %% test/octave.test/prefer/prefer-23.m %!assert(all (size (inv ([])) == [0, 0])); @@ -143,8 +143,8 @@ %% test/octave.test/prefer/prefer-27.m %!test -%! sp = save_precision; -%! save_precision = 1; +%! sp = save_precision (); +%! save_precision (1); %! x = pi; %! nm = tmpnam(); %! save("-text",nm,"x"); @@ -152,12 +152,12 @@ %! load(nm); %! unlink(nm); %! assert(x,3); -%! save_precision = sp; +%! save_precision (sp); %% test/octave.test/prefer/prefer-28.m %!test -%! sp = save_precision; -%! save_precision = 5; +%! sp = save_precision (); +%! save_precision (5); %! x = pi; %! nm = tmpnam(); %! save("-text",nm,"x"); @@ -165,29 +165,29 @@ %! load(nm); %! unlink(nm); %! assert(x,3.1416); -%! save_precision = sp; +%! save_precision (sp); %% FIXME Same problem as above!!! %% test/octave.test/prefer/prefer-29.m %!function f () %! 1 %!#test -%! sf = silent_functions; -%! silent_functions = 0; +%! sf = silent_functions (); +%! silent_functions (0); %! f %! assert(??); -%! silent_functions = sf; +%! silent_functions (sf); %% FIXME Same problem as above!!! %% test/octave.test/prefer/prefer-30.m %!function f () %! 1 %!#test -%! sf = silent_functions; -%! silent_functions = 1; +%! sf = silent_functions (); +%! silent_functions (1); %! f %! assert(??); -%! silent_functions = sf; +%! silent_functions (sf); %% test/octave.test/prefer/prefer-32.m %!test