Mercurial > hg > octave-avbm
changeset 2181:138b3c98dc85
[project @ 1996-05-13 18:02:31 by jwe]
author | jwe |
---|---|
date | Mon, 13 May 1996 18:06:22 +0000 |
parents | b087e5e62bec |
children | e1045534495d |
files | src/input.cc src/input.h src/lex.l src/load-save.cc src/pt-const.cc src/pt-const.h src/user-prefs.cc src/user-prefs.h src/variables.cc |
diffstat | 9 files changed, 314 insertions(+), 755 deletions(-) [+] |
line wrap: on
line diff
--- a/src/input.cc +++ b/src/input.cc @@ -63,6 +63,7 @@ #include "defun.h" #include "dirfns.h" #include "error.h" +#include "gripes.h" #include "help.h" #include "input.h" #include "oct-map.h" @@ -80,6 +81,18 @@ #include "utils.h" #include "variables.h" +// Primary prompt string. +static string Vps1; + +// Secondary prompt string. +static string Vps2; + +// String printed before echoed input (enabled by --echo-input). +string Vps4; + +// Character to append after successful command-line completion attempts. +static char Vcompletion_append_char; + // Global pointer for eval(). string current_eval_string; @@ -371,12 +384,12 @@ if (forced_interactive) { if (promptflag > 0) - octave_stdout << decode_prompt_string (user_pref.ps1); + octave_stdout << decode_prompt_string (Vps1); else - octave_stdout << decode_prompt_string (user_pref.ps2); + octave_stdout << decode_prompt_string (Vps2); } else - octave_stdout << decode_prompt_string (user_pref.ps4); + octave_stdout << decode_prompt_string (Vps4); if (! input_string.empty ()) { @@ -465,8 +478,8 @@ if ((interactive || forced_interactive) && (! (reading_fcn_file || reading_script_file))) { - const char *ps = (promptflag > 0) ? user_pref.ps1.c_str () : - user_pref.ps2.c_str (); + const char *ps = (promptflag > 0) ? Vps1.c_str () : + Vps2.c_str (); string prompt = decode_prompt_string (ps); @@ -855,7 +868,7 @@ rl_completion_append_character = '.'; else rl_completion_append_character - = user_pref.completion_append_char; + = Vcompletion_append_char; return buf; } @@ -1184,6 +1197,78 @@ 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; + + 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; +} + +void +symbols_of_input (void) +{ + DEFVAR (PS1, "\\s:\\#> ", 0, ps1, + "primary prompt string"); + + DEFVAR (PS2, "> ", 0, ps2, + "secondary prompt string"); + + DEFVAR (PS4, "+ ", 0, ps4, + "string printed before echoed input (enabled by --echo-input)"); + + DEFVAR (completion_append_char, " ", 0, completion_append_char, + "the string to append after successful command-line completion attempts"); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/input.h +++ b/src/input.h @@ -69,6 +69,10 @@ char *gnu_readline (const char *s); +extern string Vps4; + +extern void symbols_of_input (void); + #endif /*
--- a/src/lex.l +++ b/src/lex.l @@ -43,6 +43,7 @@ // because it may not be protected to allow it to be included multiple // times. +#include "defun.h" #include "error.h" #include "input.h" #include "lex.h"
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -1766,8 +1766,8 @@ else if (tc.is_string ()) { begin_unwind_frame ("save_mat_binary_data"); - unwind_protect_int (user_pref.implicit_str_to_num_ok); - user_pref.implicit_str_to_num_ok = 1; + unwind_protect_int (Vimplicit_str_to_num_ok); + Vimplicit_str_to_num_ok = 1; Matrix m = tc.matrix_value (); os.write (m.data (), 8 * len); run_unwind_frame ("save_mat_binary_data");
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -38,11 +38,14 @@ #include <SLList.h> +#include "Array-flags.h" + #include "mx-base.h" #include "Range.h" #include "str-vec.h" #include "arith-ops.h" +#include "defun.h" #include "error.h" #include "gripes.h" #include "idx-vector.h" @@ -84,6 +87,56 @@ // Multiplier for allocating new blocks. static const int tc_rep_newlist_grow_size = 128; +// If TRUE, allow assignments like +// +// octave> A(1) = 3; A(2) = 5 +// +// for A already defined and a matrix type. +static bool Vdo_fortran_indexing; + +// Should we allow things like: +// +// octave> 'abc' + 0 +// 97 98 99 +// +// to happen? A positive value means yes. A negative value means +// yes, but print a warning message. Zero means it should be +// considered an error. +int Vimplicit_str_to_num_ok; + +// Should we allow silent conversion of complex to real when a real +// type is what we're really looking for? 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 Vok_to_lose_imaginary_part; + +// If TRUE, create column vectors when doing assignments like: +// +// octave> A(1) = 3; A(2) = 5 +// +// (for A undefined). Only matters when resize_on_range_error is also +// TRUE. +static bool Vprefer_column_vectors; + +// If TRUE, prefer logical (zore-one) indexing over normal indexing +// when there is a conflice. For example, given a = [2, 3], the +// expression a ([1, 1]) would return [2 3] (instead of [2 2], which +// would be returned if prefer_zero_one_indxing were FALSE). +static bool Vprefer_zero_one_indexing; + +// Should operations on empty matrices return empty matrices or an +// error? A positive value means yes. A negative value means yes, +// but print a warning message. Zero means it should be considered an +// error. +int Vpropagate_empty_matrices; + +// If TRUE, resize matrices when performing and indexed assignment and +// the indices are outside the current bounds. +bool Vresize_on_range_error; + +// How many levels of structure elements should we print? +static int Vstruct_levels_to_print; + // Indentation level for structures. static int struct_indent = 0; @@ -465,7 +518,7 @@ else { int pcv = (prefer_column_vector < 0) - ? user_pref.prefer_column_vectors + ? Vprefer_column_vectors : prefer_column_vector; if (pcv) @@ -498,7 +551,7 @@ else { int pcv = (prefer_column_vector < 0) - ? user_pref.prefer_column_vectors + ? Vprefer_column_vectors : prefer_column_vector; if (pcv) @@ -604,7 +657,7 @@ else { int pcv = (prefer_column_vector < 0) - ? user_pref.prefer_column_vectors + ? Vprefer_column_vectors : prefer_column_vector; if (pcv) @@ -648,7 +701,7 @@ else { int pcv = (prefer_column_vector < 0) - ? user_pref.prefer_column_vectors + ? Vprefer_column_vectors : prefer_column_vector; if (pcv) @@ -1152,7 +1205,7 @@ case matrix_constant: { - if (user_pref.do_fortran_indexing && rows () > 0 && columns () > 0) + if (Vdo_fortran_indexing && rows () > 0 && columns () > 0) retval = matrix->elem (0, 0); else gripe_invalid_conversion ("real matrix", "real scalar"); @@ -1162,7 +1215,7 @@ case complex_matrix_constant: case complex_scalar_constant: { - int flag = user_pref.ok_to_lose_imaginary_part; + int flag = Vok_to_lose_imaginary_part; if (flag < 0) warn_implicit_conversion ("complex scalar", "real scalar"); @@ -1173,7 +1226,7 @@ retval = ::real (*complex_scalar); else if (type_tag == complex_matrix_constant) { - if (user_pref.do_fortran_indexing + if (Vdo_fortran_indexing && rows () > 0 && columns () > 0) retval = ::real (complex_matrix->elem (0, 0)); else @@ -1191,7 +1244,7 @@ { int len = char_matrix->rows (); if ((char_matrix->rows () == 1 && len == 1) - || (len > 1 && user_pref.do_fortran_indexing)) + || (len > 1 && Vdo_fortran_indexing)) retval = toascii ((int) char_matrix->elem (0, 0)); else gripe_invalid_conversion ("char matrix", "real scalar"); @@ -1202,7 +1255,7 @@ { int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; if (flag < 0) warn_implicit_conversion ("string", "real scalar"); @@ -1210,7 +1263,7 @@ int len = char_matrix->rows (); if (flag && ((char_matrix->rows () == 1 && len == 1) - || (len > 1 && user_pref.do_fortran_indexing))) + || (len > 1 && Vdo_fortran_indexing))) retval = toascii ((int) char_matrix->elem (0, 0)); else gripe_invalid_conversion ("string", "real scalar"); @@ -1220,7 +1273,7 @@ case range_constant: { int nel = range->nelem (); - if (nel == 1 || (nel > 1 && user_pref.do_fortran_indexing)) + if (nel == 1 || (nel > 1 && Vdo_fortran_indexing)) retval = range->base (); else gripe_invalid_conversion ("range", "real scalar"); @@ -1253,7 +1306,7 @@ case complex_scalar_constant: case complex_matrix_constant: { - int flag = user_pref.ok_to_lose_imaginary_part; + int flag = Vok_to_lose_imaginary_part; if (flag < 0) warn_implicit_conversion ("complex matrix", "real matrix"); @@ -1279,7 +1332,7 @@ { int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; if (flag < 0) warn_implicit_conversion ("string", "real matrix"); @@ -1321,7 +1374,7 @@ case complex_matrix_constant: case matrix_constant: { - if (user_pref.do_fortran_indexing && rows () > 0 && columns () > 0) + if (Vdo_fortran_indexing && rows () > 0 && columns () > 0) { if (type_tag == complex_matrix_constant) retval = complex_matrix->elem (0, 0); @@ -1337,7 +1390,7 @@ { int len = char_matrix->cols (); if ((char_matrix->rows () == 1 && len == 1) - || (len > 1 && user_pref.do_fortran_indexing)) + || (len > 1 && Vdo_fortran_indexing)) retval = toascii ((int) char_matrix->elem (0, 0)); else gripe_invalid_conversion ("char matrix", "complex scalar"); @@ -1348,7 +1401,7 @@ { int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; if (flag < 0) warn_implicit_conversion ("string", "complex scalar"); @@ -1356,7 +1409,7 @@ int len = char_matrix->cols (); if (flag && ((char_matrix->rows () == 1 && len == 1) - || (len > 1 && user_pref.do_fortran_indexing))) + || (len > 1 && Vdo_fortran_indexing))) retval = toascii ((int) char_matrix->elem (0, 0)); else gripe_invalid_conversion ("string", "complex scalar"); @@ -1366,7 +1419,7 @@ case range_constant: { int nel = range->nelem (); - if (nel == 1 || (nel > 1 && user_pref.do_fortran_indexing)) + if (nel == 1 || (nel > 1 && Vdo_fortran_indexing)) retval = range->base (); else gripe_invalid_conversion ("range", "complex scalar"); @@ -1412,7 +1465,7 @@ { int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; if (flag < 0) warn_implicit_conversion ("string", "complex matrix"); @@ -1445,7 +1498,7 @@ int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; switch (type_tag) { @@ -1553,7 +1606,7 @@ retval.elem (i) = m.elem (i, 0); } else if (nr > 0 && nc > 0 - && (user_pref.do_fortran_indexing || force_vector_conversion)) + && (Vdo_fortran_indexing || force_vector_conversion)) { retval.resize (nr * nc); int k = 0; @@ -1597,7 +1650,7 @@ retval.elem (i) = m.elem (i, 0); } else if (nr > 0 && nc > 0 - && (user_pref.do_fortran_indexing || force_vector_conversion)) + && (Vdo_fortran_indexing || force_vector_conversion)) { retval.resize (nr * nc); int k = 0; @@ -1759,7 +1812,7 @@ int new_nr = 1; int new_nc = 1; - if (user_pref.prefer_column_vectors) + if (Vprefer_column_vectors) new_nr = len; else new_nc = len; @@ -1883,7 +1936,7 @@ case char_matrix_constant_str: { - if (! force_string_conv && ! user_pref.implicit_str_to_num_ok) + if (! force_string_conv && ! Vimplicit_str_to_num_ok) { ::error ("string to numeric conversion failed --\ default conversion turned off"); @@ -1987,7 +2040,7 @@ { int flag = force_string_conv; if (! flag) - flag = user_pref.implicit_str_to_num_ok; + flag = Vimplicit_str_to_num_ok; if (flag < 0) warn_implicit_conversion ("string", "char matrix"); @@ -2249,9 +2302,9 @@ begin_unwind_frame ("OCT_VAL_REP_print"); unwind_protect_int (struct_indent); - unwind_protect_int (user_pref.struct_levels_to_print); - - if (user_pref.struct_levels_to_print-- > 0) + unwind_protect_int (Vstruct_levels_to_print); + + if (Vstruct_levels_to_print-- > 0) { output_buf.form ("\n%*s{\n", struct_indent, ""); @@ -2365,7 +2418,7 @@ if (first_empty || second_empty) { - int flag = user_pref.propagate_empty_matrices; + int flag = Vpropagate_empty_matrices; if (flag < 0) warning ("binary operation on empty matrix"); else if (flag == 0) @@ -2543,7 +2596,7 @@ if (a.rows () == 0 || a.columns () == 0) { - int flag = user_pref.propagate_empty_matrices; + int flag = Vpropagate_empty_matrices; if (flag < 0) warning ("unary operation on empty matrix"); else if (flag == 0) @@ -2697,7 +2750,7 @@ int nc = m.cols (); if (nr <= 1 || nc <= 1 - || user_pref.do_fortran_indexing) + || Vdo_fortran_indexing) { switch (type_tag) { @@ -3107,6 +3160,117 @@ return is_map (); } +static int +do_fortran_indexing (void) +{ + Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); + + liboctave_dfi_flag = Vdo_fortran_indexing; + + return 0; +} + +static int +implicit_str_to_num_ok (void) +{ + Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); + + return 0; +} + +static int +ok_to_lose_imaginary_part (void) +{ + Vok_to_lose_imaginary_part = check_preference ("ok_to_lose_imaginary_part"); + + return 0; +} + +static int +prefer_column_vectors (void) +{ + Vprefer_column_vectors + = check_preference ("prefer_column_vectors"); + + liboctave_pcv_flag = Vprefer_column_vectors; + + return 0; +} + +static int +prefer_zero_one_indexing (void) +{ + Vprefer_zero_one_indexing = check_preference ("prefer_zero_one_indexing"); + + liboctave_pzo_flag = Vprefer_zero_one_indexing; + + return 0; +} + +static int +propagate_empty_matrices (void) +{ + Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); + + return 0; +} + +static int +resize_on_range_error (void) +{ + Vresize_on_range_error = check_preference ("resize_on_range_error"); + + liboctave_rre_flag = Vresize_on_range_error; + + 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 >= 0 && (double) ival == val) + { + Vstruct_levels_to_print = ival; + return 0; + } + } + gripe_invalid_value_specified ("struct_levels_to_print"); + return -1; +} + +void +symbols_of_pt_const (void) +{ + DEFVAR (do_fortran_indexing, 0.0, 0, do_fortran_indexing, + "allow single indices for matrices"); + + DEFVAR (implicit_str_to_num_ok, 0.0, 0, implicit_str_to_num_ok, + "allow implicit string to number conversion"); + + DEFVAR (ok_to_lose_imaginary_part, "warn", 0, ok_to_lose_imaginary_part, + "silently convert from complex to real by dropping imaginary part"); + + DEFVAR (prefer_column_vectors, 1.0, 0, prefer_column_vectors, + "prefer column/row vectors"); + + DEFVAR (prefer_zero_one_indexing, 0.0, 0, prefer_zero_one_indexing, + "when there is a conflict, prefer zero-one style indexing"); + + DEFVAR (propagate_empty_matrices, 1.0, 0, propagate_empty_matrices, + "operations on empty matrices return an empty matrix, not an error"); + + DEFVAR (resize_on_range_error, 1.0, 0, resize_on_range_error, + "enlarge matrices on assignment"); + + DEFVAR (struct_levels_to_print, 2.0, 0, struct_levels_to_print, + "number of levels of structure elements to print"); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/pt-const.h +++ b/src/pt-const.h @@ -691,7 +691,11 @@ bool print_as_structure (void) { return rep->print_as_structure (); } }; -extern int Vresize_on_range_error; +extern int Vimplicit_str_to_num_ok; + +extern int Vpropagate_empty_matrices; + +extern bool Vresize_on_range_error; void symbols_of_pt_const (void);
--- a/src/user-prefs.cc +++ b/src/user-prefs.cc @@ -28,8 +28,6 @@ #include <cstdlib> #include <cstring> -#include "Array-flags.h" - #include "error.h" #include "gripes.h" #include "mappers.h" @@ -49,56 +47,24 @@ void init_user_prefs (void) { - user_pref.automatic_replot = 0; - user_pref.beep_on_error = 0; - user_pref.define_all_return_values = 0; - user_pref.do_fortran_indexing = 0; - user_pref.empty_list_elements_ok = 0; - user_pref.gnuplot_has_multiplot = 0; user_pref.history_size = 0; user_pref.ignore_function_time_stamp = 0; - user_pref.implicit_str_to_num_ok = 0; - user_pref.ok_to_lose_imaginary_part = 0; - user_pref.output_max_field_width = 0; - user_pref.output_precision = 0; - user_pref.page_output_immediately = 0; - user_pref.page_screen_output = 0; - user_pref.prefer_column_vectors = 0; - user_pref.prefer_zero_one_indexing = 0; user_pref.print_answer_id_name = 0; - user_pref.print_empty_dimensions = 0; - user_pref.propagate_empty_matrices = 0; user_pref.read_only_constants = 1; - user_pref.resize_on_range_error = 0; - user_pref.return_last_computed_value = 0; user_pref.save_precision = 0; user_pref.saving_history = 0; - user_pref.silent_functions = 0; - user_pref.split_long_rows = 0; - user_pref.struct_levels_to_print = 0; user_pref.suppress_verbose_help_message = 0; user_pref.treat_neg_dim_as_zero = 0; - user_pref.warn_assign_as_truth_value = 0; - user_pref.warn_comma_in_global_decl = 0; user_pref.warn_divide_by_zero = 0; - user_pref.warn_function_name_clash = 0; - user_pref.whitespace_in_literal_matrix = 0; - - user_pref.completion_append_char = '\0'; user_pref.default_save_format = string (); user_pref.editor = string (); user_pref.exec_path = string (); - user_pref.gnuplot_binary = string (); user_pref.history_file = string (); user_pref.imagepath = string (); user_pref.info_file = string (); user_pref.info_prog = string (); user_pref.loadpath = string (); - user_pref.pager_binary = string (); - user_pref.ps1 = string (); - user_pref.ps2 = string (); - user_pref.ps4 = string (); user_pref.pwd = string (); } @@ -109,10 +75,7 @@ // return of 0 => never ok. // return of -1 => ok, but give me warning (default). -// XXX FIXME XXX -- should also allow zero to mean "false" and nonzero -// to mean "true". - -static int +int check_preference (const string& var) { int pref = -1; @@ -142,59 +105,6 @@ // XXX FIXME XXX -- some of these should do their own checking to be // able to provide more meaningful warning or error messages. -// Should a replot command be generated automatically each time a plot -// changes in some way? - -int -automatic_replot (void) -{ - user_pref.automatic_replot = check_preference ("automatic_replot"); - - return 0; -} - - -// Should we beep obnoxiously before printing error messages? - -int -beep_on_error (void) -{ - user_pref.beep_on_error = check_preference ("beep_on_error"); - - return 0; -} - - -// Should variables returned from functions have default values if -// they are otherwise uninitialized? - -int -define_all_return_values (void) -{ - user_pref.define_all_return_values - = check_preference ("define_all_return_values"); - - return 0; -} - - -// Should we allow assignments like: -// -// octave> A(1) = 3; A(2) = 5 -// -// for A already defined and a matrix type? - -int -do_fortran_indexing (void) -{ - user_pref.do_fortran_indexing = check_preference ("do_fortran_indexing"); - - liboctave_dfi_flag = user_pref.do_fortran_indexing; - - return 0; -} - - // Echo commands as they are executed? // // 1 ==> echo commands read from script files @@ -213,31 +123,6 @@ } -// Should ignore empty elements in a matrix list (i.e., is an -// expression like `[[], 1]' ok? - -int -empty_list_elements_ok (void) -{ - user_pref.empty_list_elements_ok - = check_preference ("empty_list_elements_ok"); - - return 0; -} - - -// Does gnuplot appear to support multiplot? - -int -gnuplot_has_multiplot (void) -{ - user_pref.gnuplot_has_multiplot - = check_preference ("gnuplot_has_multiplot"); - - return 0; -} - - // How many lines of command history should we save? int @@ -284,98 +169,6 @@ } -// Should we allow things like: -// -// octave> 'abc' + 0 -// 97 98 99 -// -// to happen? - -int -implicit_str_to_num_ok (void) -{ - user_pref.implicit_str_to_num_ok - = check_preference ("implicit_str_to_num_ok"); - - return 0; -} - - -// Should we allow silent conversion of complex to real when a real -// type is what we're really looking for? - -int -ok_to_lose_imaginary_part (void) -{ - user_pref.ok_to_lose_imaginary_part - = check_preference ("ok_to_lose_imaginary_part"); - - return 0; -} - - -// If output is going to the pager, should we send it as soon as it is -// available, or wait until we are ready to prompt for input? - -int -page_output_immediately (void) -{ - user_pref.page_output_immediately - = check_preference ("page_output_immediately"); - - return 0; -} - - -// If possible, send all output intended for the screen through the -// pager. - -int -page_screen_output (void) -{ - user_pref.page_screen_output = check_preference ("page_screen_output"); - - return 0; -} - - -// When doing assignments like: -// -// octave> A(1) = 3; A(2) = 5 -// -// (for A undefined) should we build column vectors? Returning true -// only matters when resize_on_range_error is also true. - -int -prefer_column_vectors (void) -{ - user_pref.prefer_column_vectors - = check_preference ("prefer_column_vectors"); - - liboctave_pcv_flag = user_pref.prefer_column_vectors; - - return 0; -} - - -// For things like -// -// a = [2,3]; a([1,1]) -// -// return [2 3] instead of [2 2]. - -int -prefer_zero_one_indexing (void) -{ - user_pref.prefer_zero_one_indexing - = check_preference ("prefer_zero_one_indexing"); - - liboctave_pzo_flag = user_pref.prefer_zero_one_indexing; - - return 0; -} - - // Should we print things like // // octave> a = [1,2;3,4] @@ -393,30 +186,6 @@ } -// Should we also print the dimensions of empty matrices? - -int -print_empty_dimensions (void) -{ - user_pref.print_empty_dimensions - = check_preference ("print_empty_dimensions"); - - return 0; -} - - -// Should operations on empty matrices return empty matrices or an -// error? - -int -propagate_empty_matrices (void) -{ - user_pref.propagate_empty_matrices - = check_preference ("propagate_empty_matrices"); - - return 0; -} - // Should built-in constants always be read only? int @@ -427,33 +196,6 @@ return 0; } -// When doing assignments, should we resize matrices if the indices -// are outside the current bounds? - -int -resize_on_range_error (void) -{ - user_pref.resize_on_range_error - = check_preference ("resize_on_range_error"); - - liboctave_rre_flag = user_pref.resize_on_range_error; - - return 0; -} - - -// If a function does not return any values explicitly, return the -// last computed value. - -int -return_last_computed_value (void) -{ - user_pref.return_last_computed_value - = check_preference ("return_last_computed_value"); - - return 0; -} - // Should we save command history? @@ -466,49 +208,6 @@ } -// Suppress printing results in called functions. - -int -silent_functions (void) -{ - user_pref.silent_functions = check_preference ("silent_functions"); - - return 0; -} - - -// Should should big matrices be split into smaller slices for output? - -int -split_long_rows (void) -{ - user_pref.split_long_rows = check_preference ("split_long_rows"); - - return 0; -} - - -// How many levels of structure elements should we print? - -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 >= 0 && (double) ival == val) - { - user_pref.struct_levels_to_print = ival; - return 0; - } - } - gripe_invalid_value_specified ("struct_levels_to_print"); - return -1; -} - - // Suppress printing of additional help message in help and usage // functions? @@ -538,38 +237,6 @@ } -// Generate a warning for the assignment in things like -// -// octave> if (a = 2 < n) -// -// but not -// -// octave> if ((a = 2) < n) - -int -warn_assign_as_truth_value (void) -{ - user_pref.warn_assign_as_truth_value - = check_preference ("warn_assign_as_truth_value"); - - return 0; -} - - -// Generate a warning for the comma in things like -// -// octave> global a, b = 2 - -int -warn_comma_in_global_decl (void) -{ - user_pref.warn_comma_in_global_decl - = check_preference ("warn_comma_in_global_decl"); - - return 0; -} - - // On IEEE machines, allow divide by zero errors to be suppressed. int @@ -580,126 +247,6 @@ return 0; } -// Generate warning if declared function name disagrees with the name -// of the file in which it is defined. - -int -warn_function_name_clash (void) -{ - user_pref.warn_function_name_clash - = check_preference ("warn_function_name_clash"); - - return 0; -} - - -// Generate warning if a statement in a function is not terminated -// with a semicolon. Useful for checking functions that should only -// produce output using explicit printing statements. - -int -warn_missing_semicolon (void) -{ - user_pref.warn_missing_semicolon - = check_preference ("warn_missing_semicolon"); - - return 0; -} - - -// Should whitespace in a literal matrix list be automatically -// converted to commas and semicolons? -// -// user specifies value of pref -// -------------- ------------- -// "ignore" 2 -// "traditional" 1 -// anything else 0 -// -// Octave will never insert a comma in a literal matrix list if the -// user specifies "ignore". For example, the statement [1 2] will -// result in an error instead of being treated the same as [1, 2], and -// the statement -// -// [ 1, 2, -// 3, 4 ] -// -// will result in the vector [1 2 3 4] instead of a matrix. -// -// Traditional behavior makes Octave convert spaces to a comma between -// identifiers and `('. For example, the statement -// -// [eye (2)] -// -// will be parsed as -// -// [eye, (2)] -// -// and will result in an error since the `eye' function will be -// called with no arguments. To get around this, you would have to -// omit the space between `eye' and the `('. -// -// The default value is 0, which results in behavior that is the same -// as traditional, except that Octave does not convert spaces to a -// comma between identifiers and `('. For example, the statement -// -// [eye (2)] -// -// will result in a call to `eye' with the argument `2'. - -int -whitespace_in_literal_matrix (void) -{ - int pref = 0; - string val = builtin_string_variable ("whitespace_in_literal_matrix"); - if (! val.empty ()) - { - if (val.compare ("ignore", 0, 6) == 0) - pref = 2; - else if (val.compare ("traditional", 0, 11) == 0) - pref = 1; - } - user_pref.whitespace_in_literal_matrix = pref; - return 0; -} - - -int -set_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 && (double) ival == val) - { - user_pref.output_max_field_width = ival; - return 0; - } - } - gripe_invalid_value_specified ("output_max_field_width"); - return -1; -} - -int -set_output_precision (void) -{ - double val; - if (builtin_real_scalar_variable ("output_precision", val) - && ! xisnan (val)) - { - int ival = NINT (val); - if (ival >= 0 && (double) ival == val) - { - user_pref.output_precision = ival; - return 0; - } - } - gripe_invalid_value_specified ("output_precision"); - return -1; -} - int set_save_precision (void) { @@ -719,32 +266,6 @@ } int -sv_completion_append_char (void) -{ - int status = 0; - - string s = builtin_string_variable ("completion_append_char"); - - switch (s.length ()) - { - case 1: - user_pref.completion_append_char = s[0]; - break; - - case 0: - user_pref.completion_append_char = '\0'; - break; - - default: - warning ("completion_append_char must be a single character"); - status = -1; - break; - } - - return status; -} - -int sv_default_save_format (void) { int status = 0; @@ -863,24 +384,6 @@ } int -sv_gnuplot_binary (void) -{ - int status = 0; - - string s = builtin_string_variable ("gnuplot_binary"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("gnuplot_binary"); - status = -1; - } - else - user_pref.gnuplot_binary = s; - - return status; -} - -int sv_history_file (void) { int status = 0; @@ -974,54 +477,6 @@ } int -sv_pager_binary (void) -{ - int status = 0; - - string s = builtin_string_variable ("PAGER"); - - if (s.empty ()) - { - gripe_invalid_value_specified ("PAGER"); - status = -1; - } - else - user_pref.pager_binary = s; - - return status; -} - -int -sv_ps1 (void) -{ - int status = 0; - - user_pref.ps1 = builtin_string_variable ("PS1"); - - return status; -} - -int -sv_ps2 (void) -{ - int status = 0; - - user_pref.ps2 = builtin_string_variable ("PS2"); - - return status; -} - -int -sv_ps4 (void) -{ - int status = 0; - - user_pref.ps4 = builtin_string_variable ("PS4"); - - return status; -} - -int sv_pwd (void) { int status = 0;
--- a/src/user-prefs.h +++ b/src/user-prefs.h @@ -27,58 +27,25 @@ struct user_preferences { - int automatic_replot; - int beep_on_error; - int define_all_return_values; - int do_fortran_indexing; int echo_executing_commands; - int empty_list_elements_ok; - int gnuplot_has_multiplot; int history_size; int ignore_function_time_stamp; - int implicit_str_to_num_ok; - int ok_to_lose_imaginary_part; - int output_max_field_width; - int output_precision; - int page_output_immediately; - int page_screen_output; - int prefer_column_vectors; - int prefer_zero_one_indexing; int print_answer_id_name; - int print_empty_dimensions; - int propagate_empty_matrices; int read_only_constants; - int resize_on_range_error; - int return_last_computed_value; int save_precision; int saving_history; - int silent_functions; - int split_long_rows; - int struct_levels_to_print; int suppress_verbose_help_message; int treat_neg_dim_as_zero; - int warn_assign_as_truth_value; - int warn_comma_in_global_decl; int warn_divide_by_zero; - int warn_missing_semicolon; - int warn_function_name_clash; - int whitespace_in_literal_matrix; - - char completion_append_char; string default_save_format; string editor; string exec_path; - string gnuplot_binary; string history_file; string imagepath; string info_file; string info_prog; string loadpath; - string pager_binary; - string ps1; - string ps2; - string ps4; string pwd; }; @@ -86,59 +53,26 @@ extern void init_user_prefs (void); -extern int automatic_replot (void); -extern int beep_on_error (void); -extern int define_all_return_values (void); -extern int do_fortran_indexing (void); extern int echo_executing_commands (void); -extern int empty_list_elements_ok (void); -extern int gnuplot_has_multiplot (void); extern int history_size (void); extern int ignore_function_time_stamp (void); -extern int implicit_str_to_num_ok (void); -extern int ok_to_lose_imaginary_part (void); -extern int page_output_immediately (void); -extern int page_screen_output (void); -extern int prefer_column_vectors (void); -extern int prefer_zero_one_indexing (void); extern int print_answer_id_name (void); -extern int print_empty_dimensions (void); -extern int propagate_empty_matrices (void); extern int read_only_constants (void); -extern int resize_on_range_error (void); -extern int return_last_computed_value (void); extern int saving_history (void); -extern int silent_functions (void); -extern int split_long_rows (void); -extern int struct_levels_to_print (void); extern int suppress_verbose_help_message (void); extern int treat_neg_dim_as_zero (void); -extern int warn_assign_as_truth_value (void); -extern int warn_comma_in_global_decl (void); extern int warn_divide_by_zero (void); -extern int warn_function_name_clash (void); -extern int warn_missing_semicolon (void); -extern int whitespace_in_literal_matrix (void); -extern int set_output_max_field_width (void); -extern int set_output_precision (void); extern int set_save_precision (void); -extern int sv_completion_append_char (void); - extern int sv_default_save_format (void); extern int sv_editor (void); extern int sv_exec_path (void); -extern int sv_gnuplot_binary (void); extern int sv_history_file (void); extern int sv_imagepath (void); extern int sv_info_file (void); extern int sv_info_prog (void); extern int sv_loadpath (void); -extern int sv_pager_binary (void); -extern int sv_ps1 (void); -extern int sv_ps2 (void); -extern int sv_ps4 (void); extern int sv_pwd (void); enum echo_state @@ -149,6 +83,8 @@ ECHO_CMD_LINE = 4 }; +extern int check_preference (const string& var); + #endif /*
--- a/src/variables.cc +++ b/src/variables.cc @@ -63,7 +63,11 @@ #include "pt-const.h" #include "oct-obj.h" #include "pt-exp.h" +#include "pt-fcn.h" #include "pt-fvc.h" +#include "pt-mat.h" +#include "pt-plot.h" +#include "pr-output.h" #include "syscalls.h" #include "unwind-prot.h" #include "user-prefs.h" @@ -1598,15 +1602,6 @@ DEFCONSTX ("OCTAVE_VERSION", SBV_OCTAVE_VERSION, OCTAVE_VERSION, 0, 0, "Octave version"); - DEFVAR (PS1, "\\s:\\#> ", 0, sv_ps1, - "primary prompt string"); - - DEFVAR (PS2, "> ", 0, sv_ps2, - "secondary prompt string"); - - DEFVAR (PS4, "+ ", 0, sv_ps4, - "string printed before echoed input (enabled by --echo-input)"); - DEFCONST (PWD, get_working_directory ("initialize_globals"), 0, sv_pwd, "current working directory"); @@ -1629,16 +1624,6 @@ DEFCONST (argv, , 0, 0, "the command line arguments this program was invoked with"); - DEFVAR (automatic_replot, 0.0, 0, automatic_replot, - "if true, auto-insert a replot command when a plot changes"); - - DEFVAR (beep_on_error, 0.0, 0, beep_on_error, - "if true, beep before printing error messages"); - - DEFVAR (completion_append_char, " ", 0, sv_completion_append_char, - "the string to append after successful command-line completion\n\ -attempts"); - DEFCONST (error_text, "", 0, 0, "the text of error messages that would have been printed in the body of the most recent unwind_protect statement or the TRY part of\n\ @@ -1646,23 +1631,10 @@ eval(), or if no error has ocurred within them, the value of\n\ __error_text__ is guaranteed to be the empty string."); - DEFVAR (default_return_value, Matrix (), 0, 0, - "the default for value for unitialized variables returned from\n\ -functions. Only used if the variable initialize_return_values is\n\ -set to \"true\"."); - DEFVAR (default_save_format, "ascii", 0, sv_default_save_format, "default format for files created with save, may be one of\n\ \"binary\", \"text\", or \"mat-binary\""); - DEFVAR (define_all_return_values, 0.0, 0, define_all_return_values, - "control whether values returned from functions should have a\n\ -value even if one has not been explicitly assigned. See also\n\ -default_return_value"); - - DEFVAR (do_fortran_indexing, 0.0, 0, do_fortran_indexing, - "allow single indices for matrices"); - DEFVAR (echo_executing_commands, 0.0, 0, echo_executing_commands, "echo commands as they are executed"); } @@ -1679,24 +1651,9 @@ DEFCONST (e, e_val, 0, 0, "exp (1)"); - DEFVAR (empty_list_elements_ok, "warn", 0, empty_list_elements_ok, - "ignore the empty element in expressions like `a = [[], 1]'"); - DEFCONST (eps, DBL_EPSILON, 0, 0, "machine precision"); - DEFVAR (gnuplot_binary, "gnuplot", 0, sv_gnuplot_binary, - "path to gnuplot binary"); - -#ifdef GNUPLOT_HAS_MULTIPLOT - double with_multiplot = 1.0; -#else - double with_multiplot = 0.0; -#endif - - DEFVAR (gnuplot_has_multiplot, with_multiplot, 0, gnuplot_has_multiplot, - "true if gnuplot supports multiplot, false otherwise"); - DEFVAR (history_file, default_history_file (), 0, sv_history_file, "name of command history file"); @@ -1709,9 +1666,6 @@ DEFVAR (ignore_function_time_stamp, "system", 0, ignore_function_time_stamp, "don't check to see if function files have changed since they were\n\ last compiled. Possible values are \"system\" and \"all\""); - - DEFVAR (implicit_str_to_num_ok, 0.0, 0, implicit_str_to_num_ok, - "allow implicit string to number conversion"); } static void @@ -1726,15 +1680,6 @@ DEFCONST (nan, octave_NaN, 0, 0, "not a number"); - DEFVAR (ok_to_lose_imaginary_part, "warn", 0, ok_to_lose_imaginary_part, - "silently convert from complex to real by dropping imaginary part"); - - DEFVAR (output_max_field_width, 10.0, 0, set_output_max_field_width, - "maximum width of an output field for numeric output"); - - DEFVAR (output_precision, 5.0, 0, set_output_precision, - "number of significant figures to display for numeric output"); - #if defined (M_PI) double pi_val = M_PI; #else @@ -1743,12 +1688,6 @@ DEFCONST (pi, pi_val, 0, 0, "ratio of the circumference of a circle to its diameter"); - - DEFVAR (prefer_column_vectors, 1.0, 0, prefer_column_vectors, - "prefer column/row vectors"); - - DEFVAR (prefer_zero_one_indexing, 0.0, 0, prefer_zero_one_indexing, - "when there is a conflict, prefer zero-one style indexing"); } static void @@ -1757,9 +1696,6 @@ DEFVAR (print_answer_id_name, 1.0, 0, print_answer_id_name, "set output style to print `var_name = ...'"); - DEFVAR (print_empty_dimensions, 1.0, 0, print_empty_dimensions, - "also print dimensions of empty matrices"); - DEFCONST (program_invocation_name, raw_prog_name, 0, 0, "the full name of the current program or script, including the\n\ directory specification"); @@ -1767,9 +1703,6 @@ DEFCONST (program_name, prog_name, 0, 0, "the name of the current program or script"); - DEFVAR (propagate_empty_matrices, 1.0, 0, propagate_empty_matrices, - "operations on empty matrices return an empty matrix, not an error"); - #if 0 DEFVAR (read_only_constants, 1.0, 0, read_only_constants, "allow built-in constants to be modified"); @@ -1780,13 +1713,6 @@ DEFCONST (realmin, DBL_MIN, 0, 0, "realmin (): return smallest representable floating point number"); - - DEFVAR (resize_on_range_error, 1.0, 0, resize_on_range_error, - "enlarge matrices on assignment"); - - DEFVAR (return_last_computed_value, 0.0, 0, return_last_computed_value, - "if a function does not return any values explicitly, return the\n\ - last computed value"); } static void @@ -1798,15 +1724,6 @@ DEFVAR (saving_history, 1.0, 0, saving_history, "save command history"); - DEFVAR (silent_functions, 0.0, 0, silent_functions, - "suppress printing results in called functions"); - - DEFVAR (split_long_rows, 1.0, 0, split_long_rows, - "split long matrix rows instead of wrapping"); - - DEFVAR (struct_levels_to_print, 2.0, 0, struct_levels_to_print, - "number of levels of structure elements to print"); - #ifdef USE_GNU_INFO DEFVAR (suppress_verbose_help_message, 0.0, 0, suppress_verbose_help_message, "suppress printing of message pointing to additional help in the\n\ @@ -1829,24 +1746,8 @@ static void install_builtin_variables_8 (void) { - DEFVAR (warn_assign_as_truth_value, 1.0, 0, warn_assign_as_truth_value, - "produce warning for assignments used as truth values"); - - DEFVAR (warn_comma_in_global_decl, 1.0, 0, warn_comma_in_global_decl, - "produce warning for commas in global declarations"); - DEFVAR (warn_divide_by_zero, 1.0, 0, warn_divide_by_zero, "on IEEE machines, allow divide by zero errors to be suppressed"); - - DEFVAR (warn_function_name_clash, 1.0, 0, warn_function_name_clash, - "produce warning if function name conflicts with file name"); - - DEFVAR (warn_missing_semicolon, 0.0, 0, warn_missing_semicolon, - "produce a warning if a statement in a function file is not -terminated with a semicolon"); - - DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, - "control auto-insertion of commas and semicolons in literal matrices"); } void @@ -1861,7 +1762,16 @@ install_builtin_variables_7 (); install_builtin_variables_8 (); + symbols_of_error (); + symbols_of_input (); + symbols_of_lex (); symbols_of_pager (); + symbols_of_parse (); + symbols_of_pr_output (); + symbols_of_pt_const (); + symbols_of_pt_fcn (); + symbols_of_pt_mat (); + symbols_of_pt_plot (); symbols_of_syscalls (); }