Mercurial > hg > octave-avbm
changeset 5659:960f4b9a26af
[project @ 2006-03-10 15:35:20 by jwe]
author | jwe |
---|---|
date | Fri, 10 Mar 2006 15:35:21 +0000 |
parents | 7b45fda21557 |
children | 4c4d31ecb0e4 |
files | scripts/ChangeLog scripts/miscellaneous/unix.m scripts/plot/print.m src/ChangeLog src/oct-stream.cc src/oct-stream.h src/ov.cc src/ov.h src/symtab.cc src/symtab.h src/toplev.cc src/variables.cc |
diffstat | 12 files changed, 251 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2006-03-09 John W. Eaton <jwe@octave.org> + + * miscellaneous/unix.m, plot/print.m: + Swap order of outputs from system. + 2006-03-06 Keith Goodman <kwgoodman@gmail.com> * audio/lin2mu.m, audio/loadaudio.m, audio/mu2lin.m,
--- a/scripts/miscellaneous/unix.m +++ b/scripts/miscellaneous/unix.m @@ -36,7 +36,7 @@ if (nargin < 1 || nargin > 2) usage ( "[status, text] = unix (cmd, '-echo')"); elseif (isunix ()) - [text, status] = system (cmd); + [status, text] = system (cmd); if (nargin > 1 || nargout == 0) printf ("%s\n", text); endif
--- a/scripts/plot/print.m +++ b/scripts/plot/print.m @@ -342,7 +342,7 @@ if (! isempty (convertname)) command = sprintf ("convert '%s' '%s'", name, convertname); - [output, errcode] = system (command); + [errcode, output] = system (command); unlink (name); if (errcode) error ("print: could not convert");
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,28 @@ +2006-03-10 John W. Eaton <jwe@octave.org> + + * symtab.cc (symbol_table::glob, symbol_table::symbol_list, + symbol_table::subsymbol_list): Force result to be a column + vector. + + * oct-stream.h (octave_stream::stream_ok): Undo previous change. + Eliminate who parameter. Change all callers. + + * variables.cc (do_who): Return more info in structure array for + verbose output. + * symtab.h (symbol_record::size, symbol_record::class_name, + symbol_record::is_sparse_type, symbol_record::is_complex_type, + symbol_record::size, symbol_record::symbol_def::class_name, + symbol_record::symbol_def::is_sparse_type, + symbol_record::symbol_def::is_complex_type): New functions. + * ov.h (octave_value::size): New function. + 2006-03-09 John W. Eaton <jwe@octave.org> + * toplev.cc (run_command_and_return_output): Swap output and + status for compatibility. + + * Makefile.in (defaults.h, oct-conf.h): Force updates. + * defaults.h.in (OCTAVE_RELEASE): New macro. * octave.cc (F__version_info__): New arg, release.
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -2791,7 +2791,7 @@ { int retval = -1; - if (stream_ok ("fflush")) + if (stream_ok ()) retval = rep->flush (); return retval; @@ -2802,7 +2802,7 @@ { std::string retval; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->getl (max_len, err, who); return retval; @@ -2836,7 +2836,7 @@ { std::string retval; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->gets (max_len, err, who); return retval; @@ -2870,7 +2870,7 @@ { int status = -1; - if (stream_ok ("fseek")) + if (stream_ok ()) { clearerr (); @@ -2977,7 +2977,7 @@ { long retval = -1; - if (stream_ok ("tell")) + if (stream_ok ()) retval = rep->tell (); return retval; @@ -2988,7 +2988,7 @@ { int retval = -1; - if (stream_ok ("frewind")) + if (stream_ok ()) retval = rep->rewind (); return retval; @@ -2999,7 +2999,7 @@ { bool retval = false; - if (stream_ok ("is_open")) + if (stream_ok ()) retval = rep->is_open (); return retval; @@ -3008,7 +3008,7 @@ void octave_stream::close (void) { - if (stream_ok ("close")) + if (stream_ok ()) rep->close (); } @@ -3266,7 +3266,7 @@ octave_value retval; - if (stream_ok ("fread")) + if (stream_ok ()) { // XXX FIXME XXX -- we may eventually want to make this extensible. @@ -3329,7 +3329,7 @@ { octave_idx_type retval = -1; - if (stream_ok ("fwrite")) + if (stream_ok ()) { if (! error_state) { @@ -3604,7 +3604,7 @@ { octave_value retval; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->scanf (fmt, size, count, who); return retval; @@ -3640,7 +3640,7 @@ { octave_value_list retval; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->oscanf (fmt, who); return retval; @@ -3676,7 +3676,7 @@ { int retval = -1; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->printf (fmt, args, who); return retval; @@ -3712,7 +3712,7 @@ { int retval = -1; - if (stream_ok (who)) + if (stream_ok ()) retval = rep->puts (s, who); return retval; @@ -3745,7 +3745,7 @@ { int retval = -1; - if (stream_ok ("feof")) + if (stream_ok ()) retval = rep->eof (); return retval; @@ -3756,7 +3756,7 @@ { std::string retval = "invalid stream object"; - if (stream_ok ("ferror", false, false)) + if (stream_ok (false)) retval = rep->error (clear, err_num); return retval; @@ -3767,7 +3767,7 @@ { std::string retval; - if (stream_ok ("name")) + if (stream_ok ()) retval = rep->name (); return retval; @@ -3778,7 +3778,7 @@ { int retval = 0; - if (stream_ok ("mode")) + if (stream_ok ()) retval = rep->mode (); return retval; @@ -3789,7 +3789,7 @@ { oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; - if (stream_ok ("float_format")) + if (stream_ok ()) retval = rep->float_format (); return retval; @@ -3833,27 +3833,6 @@ return retval; } -bool -octave_stream::stream_ok (const std::string& who, bool clear, bool warn) const -{ - bool retval = true; - - if (rep) - { - if (clear) - rep->clear (); - } - else - { - if (warn) - ::warning ("%s: attempt to use invalid I/O stream", who.c_str ()); - - retval = false; - } - - return retval; -} - octave_stream_list *octave_stream_list::instance = 0; bool
--- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -591,8 +591,20 @@ // The actual representation of this stream. octave_base_stream *rep; - bool stream_ok (const std::string& who, bool clear = true, - bool warn = true) const; + bool stream_ok (bool clear = true) const + { + bool retval = true; + + if (rep) + { + if (clear) + rep->clear (); + } + else + retval = false; + + return retval; + } void invalid_operation (const std::string& who, const char *rw) {
--- a/src/ov.cc +++ b/src/ov.cc @@ -1081,6 +1081,21 @@ return n_dims; } +Matrix +octave_value::size (void) const +{ + dim_vector dv = dims (); + + int n_dims = dv.length (); + + Matrix retval (1, n_dims); + + while (n_dims--) + retval(n_dims) = dv(n_dims); + + return retval; +} + Cell octave_value::cell_value (void) const {
--- a/src/ov.h +++ b/src/ov.h @@ -373,6 +373,8 @@ virtual octave_idx_type capacity (void) const { return rep->capacity (); } + Matrix size (void) const; + virtual size_t byte_size (void) const { return rep->byte_size (); }
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -1086,7 +1086,7 @@ int n = size (); - Array<symbol_record *> subsymbols (n); + Array<symbol_record *> subsymbols (dim_vector (n, 1)); int pats_length = pats.length (); if (n == 0) @@ -1136,7 +1136,7 @@ } } - subsymbols.resize (count); + subsymbols.resize (dim_vector (count, 1)); return subsymbols; } @@ -1149,7 +1149,7 @@ int n = size (); - Array<symbol_record *> symbols (n); + Array<symbol_record *> symbols (dim_vector (n, 1)); if (n == 0) return symbols; @@ -1178,7 +1178,7 @@ } } - symbols.resize (count); + symbols.resize (dim_vector (count, 1)); return symbols; } @@ -1324,8 +1324,8 @@ int len = symbols.length (), i; std::string param_string = "benpst"; - Array<int> param_length(param_string.length ()); - Array<std::string> param_names(param_string.length ()); + Array<int> param_length (dim_vector (param_string.length (), 1)); + Array<std::string> param_names (dim_vector (param_string.length (), 1)); size_t pos_b, pos_t, pos_e, pos_n, pos_p, pos_s; pos_b = param_string.find ('b'); // Bytes @@ -1547,7 +1547,7 @@ int sym_len = xsymbols.length (), subsym_len = xsubsymbols.length (), len = sym_len + subsym_len; - Array<symbol_record *> symbols (len); + Array<symbol_record *> symbols (dim_vector (len, 1)); if (len > 0) { @@ -1616,7 +1616,7 @@ int n = size (); - Array<symbol_record *> symbols (n); + Array<symbol_record *> symbols (dim_vector (n, 1)); if (n == 0) return symbols; @@ -1645,7 +1645,7 @@ } } - symbols.resize (count); + symbols.resize (dim_vector (count, 1)); return symbols; }
--- a/src/symtab.h +++ b/src/symtab.h @@ -171,6 +171,18 @@ bool is_matrix_type (void) const { return definition.is_matrix_type (); } + bool is_sparse_type (void) const + { return definition.is_sparse_type (); } + + bool is_complex_type (void) const + { return definition.is_complex_type (); } + + std::string class_name (void) const + { return definition.class_name (); } + + Matrix size (void) const + { return definition.size (); } + size_t byte_size (void) const { return definition.byte_size (); }; @@ -384,6 +396,18 @@ bool is_matrix_type (void) const { return definition->is_matrix_type (); } + bool is_sparse_type (void) const + { return definition->is_sparse_type (); } + + bool is_complex_type (void) const + { return definition->is_complex_type (); } + + std::string class_name (void) const + { return definition->class_name (); } + + Matrix size (void) const + { return definition->size (); } + size_t byte_size (void) const { return definition->byte_size (); };
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -372,8 +372,8 @@ output_buf << OSSTREAM_ENDS; - retval(1) = (double) cmd_status; - retval(0) = OSSTREAM_STR (output_buf); + retval(0) = (double) cmd_status; + retval(1) = OSSTREAM_STR (output_buf); OSSTREAM_FREEZE (output_buf); } @@ -417,9 +417,9 @@ printf (\"%s\n\", system (cmd, 1));\n\ @end example\n\ \n\ -The @code{system} function can return two values. The first is any\n\ -output from the command that was written to the standard output stream,\n\ -and the second is the output status of the command. For example,\n\ +The @code{system} function can return two values. The first is the\n\ +exit status of the command and the second is any output from the\n\ +command that was written to the standard output stream. For example,\n\ \n\ @example\n\ [output, status] = system (\"echo foo; exit 2\");\n\
--- a/src/variables.cc +++ b/src/variables.cc @@ -1457,6 +1457,21 @@ return retval; } +// XXX FIXME XXX -- this function is duplicated in symtab.cc with the +// name maybe_list_cmp_fcn. + +static int +symbol_record_name_compare (const void *a_arg, const void *b_arg) +{ + const symbol_record *a = *(X_CAST (const symbol_record **, a_arg)); + const symbol_record *b = *(X_CAST (const symbol_record **, b_arg)); + + std::string a_nm = a->name (); + std::string b_nm = b->name (); + + return a_nm.compare (b_nm); +} + static octave_value do_who (int argc, const string_vector& argv, int return_list) { @@ -1518,58 +1533,141 @@ if (return_list) { - string_vector names; + // XXX FIXME XXX -- maybe symbol_list should return a std::list + // object instead of an Array. + + dim_vector dv (0, 0); + + Array<symbol_record *> s1 (dv); + Array<symbol_record *> s2 (dv); + Array<symbol_record *> s3 (dv); + Array<symbol_record *> s4 (dv); + Array<symbol_record *> s5 (dv); + Array<symbol_record *> s6 (dv); + Array<symbol_record *> s7 (dv); if (show_builtins) { - names.append (fbi_sym_tab->name_list - (pats, true, symbol_record::BUILTIN_CONSTANT, - SYMTAB_ALL_SCOPES)); - - names.append (fbi_sym_tab->name_list - (pats, true, symbol_record::BUILTIN_VARIABLE, - SYMTAB_ALL_SCOPES)); - - names.append (fbi_sym_tab->name_list - (pats, true, symbol_record::BUILTIN_FUNCTION, - SYMTAB_ALL_SCOPES)); + s1 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_CONSTANT, + SYMTAB_ALL_SCOPES); + + s2 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_VARIABLE, + SYMTAB_ALL_SCOPES); + + s3 = fbi_sym_tab->symbol_list (pats, symbol_record::BUILTIN_FUNCTION, + SYMTAB_ALL_SCOPES); } if (show_functions) { - names.append (fbi_sym_tab->name_list - (pats, true, symbol_record::DLD_FUNCTION, - SYMTAB_ALL_SCOPES)); - - names.append (fbi_sym_tab->name_list - (pats, true, symbol_record::USER_FUNCTION, - SYMTAB_ALL_SCOPES)); + s4 = fbi_sym_tab->symbol_list (pats, symbol_record::DLD_FUNCTION, + SYMTAB_ALL_SCOPES); + + s5 = fbi_sym_tab->symbol_list (pats, symbol_record::USER_FUNCTION, + SYMTAB_ALL_SCOPES); } if (show_variables) { - names.append (curr_sym_tab->name_list - (pats, true, symbol_record::USER_VARIABLE, - SYMTAB_LOCAL_SCOPE)); - - names.append (curr_sym_tab->name_list - (pats, true, symbol_record::USER_VARIABLE, - SYMTAB_GLOBAL_SCOPE)); + s6 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, + SYMTAB_LOCAL_SCOPE); + + s7 = curr_sym_tab->symbol_list (pats, symbol_record::USER_VARIABLE, + SYMTAB_GLOBAL_SCOPE); } + octave_idx_type s1_len = s1.length (); + octave_idx_type s2_len = s2.length (); + octave_idx_type s3_len = s3.length (); + octave_idx_type s4_len = s4.length (); + 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 + = s1_len + s2_len + s3_len + s4_len + s5_len + s6_len + s7_len; + + Array<symbol_record *> symbols (dim_vector (symbols_len, 1)); + + octave_idx_type k = 0; + + symbols.insert (s1, k, 0); + k += s1_len; + symbols.insert (s2, k, 0); + k += s2_len; + symbols.insert (s3, k, 0); + k += s3_len; + symbols.insert (s4, k, 0); + k += s4_len; + symbols.insert (s5, k, 0); + k += s5_len; + symbols.insert (s6, k, 0); + k += s6_len; + symbols.insert (s7, k, 0); + + symbols.qsort (symbol_record_name_compare); + if (show_verbose) { - int len = names.length (); - - octave_value_list ovl (len, octave_value ()); - - for (int j = 0; j < len; j++) - ovl(j) = names(j); - - retval = Octave_map ("name", ovl); + Array<octave_value> name_info (symbols_len, 1); + Array<octave_value> size_info (symbols_len, 1); + Array<octave_value> bytes_info (symbols_len, 1); + Array<octave_value> class_info (symbols_len, 1); + Array<octave_value> global_info (symbols_len, 1); + Array<octave_value> sparse_info (symbols_len, 1); + Array<octave_value> complex_info (symbols_len, 1); + Array<octave_value> nesting_info (symbols_len, 1); + + for (octave_idx_type j = 0; j < symbols_len; j++) + { + symbol_record *sr = symbols(j); + + Octave_map ni; + + std::string caller_function_name; + if (curr_caller_function) + caller_function_name = curr_caller_function->name (); + + ni.assign ("function", caller_function_name); + ni.assign ("level", 1); + + name_info(j) = sr->name (); + size_info(j) = sr->size (); + bytes_info(j) = sr->byte_size (); + class_info(j) = sr->class_name (); + global_info(j) = sr->is_linked_to_global (); + sparse_info(j) = sr->is_sparse_type (); + complex_info(j) = sr->is_complex_type (); + nesting_info(j) = ni; + } + + Octave_map info; + + info.assign ("name", name_info); + info.assign ("size", size_info); + info.assign ("bytes", bytes_info); + info.assign ("class", class_info); + info.assign ("global", global_info); + info.assign ("sparse", sparse_info); + info.assign ("complex", complex_info); + info.assign ("nesting", nesting_info); + + retval = info; } else - retval = Cell (names); + { + string_vector names; + + if (symbols_len > 0) + { + names.resize (symbols_len); + + for (octave_idx_type j = 0; j < symbols_len; j++) + names[j] = symbols(j)->name (); + } + + retval = Cell (names); + } } else {