Mercurial > hg > octave-terminal
changeset 1728:42b4f904f1af
[project @ 1996-01-09 11:36:01 by jwe]
author | jwe |
---|---|
date | Tue, 09 Jan 1996 11:41:43 +0000 |
parents | ba9b08842dbe |
children | 227706b05144 |
files | liboctave/chMatrix.cc liboctave/chMatrix.h src/balance.cc src/colloc.cc src/dassl.cc src/data.cc src/dirfns.cc src/error.cc src/file-io.cc src/fsolve.cc src/input.cc src/load-save.cc src/lsode.cc src/npsol.cc src/pr-output.cc src/pt-const.cc src/pt-const.h src/pt-plot.cc src/qpsol.cc src/quad.cc src/rand.cc src/schur.cc src/sysdep.cc src/timefns.cc src/toplev.cc src/utils.cc src/variables.cc |
diffstat | 27 files changed, 224 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/chMatrix.cc +++ b/liboctave/chMatrix.cc @@ -32,6 +32,8 @@ #include <cstdio> #include <cstring> +#include <string> + #include <iostream.h> // #include <sys/types.h> // XXX FIXME XXX @@ -91,7 +93,7 @@ return *this; } -char * +string charMatrix::row_as_string (int r) const { if (r < 0 || r >= rows ()) @@ -102,9 +104,7 @@ int nc = cols (); - char *retval = new char [nc + 1]; - - retval[nc] = '\0'; + string retval (nc, '\0'); for (int i = 0; i < nc; i++) retval[i] = elem (r, i);
--- a/liboctave/chMatrix.h +++ b/liboctave/chMatrix.h @@ -31,11 +31,14 @@ // For FILE... #include <cstdio> +#include <string> + #include "MArray.h" #include "mx-defs.h" -class charMatrix : public MArray2<char> +class +charMatrix : public MArray2<char> { friend class ComplexMatrix; @@ -62,7 +65,7 @@ charMatrix& insert (const char *s, int r, int c); charMatrix& insert (const charMatrix& a, int r, int c); - char *row_as_string (int r) const; + string row_as_string (int r) const; #if 0 Matrix& insert (const RowVector& a, int r, int c);
--- a/src/balance.cc +++ b/src/balance.cc @@ -27,6 +27,8 @@ #include <config.h> #endif +#include <string> + #include "CMatrix.h" #include "CmplxAEPBAL.h" #include "CmplxAEPBAL.h" @@ -73,6 +75,7 @@ } const char *bal_job; + string tstr; int my_nargin; // # args w/o optional string arg // Determine if balancing option is listed. Set my_nargin to the @@ -80,7 +83,8 @@ if (args(nargin-1).is_string ()) { - bal_job = args(nargin-1).string_value (); + tstr = args(nargin-1).string_value (); + bal_job = tstr.c_str (); my_nargin = nargin-1; } else
--- a/src/colloc.cc +++ b/src/colloc.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include "CollocWt.h" #include "defun-dld.h" @@ -84,7 +86,8 @@ return retval; } - const char *s = args(i).string_value (); + string tstr = args(i).string_value (); + const char *s = tstr.c_str (); if (s && (((*s == 'R' || *s == 'r') && strlen (s) == 1) || strcmp (s, "right") == 0))
--- a/src/dassl.cc +++ b/src/dassl.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "DAE.h" @@ -333,7 +335,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/data.cc +++ b/src/data.cc @@ -33,6 +33,8 @@ #include <config.h> #endif +#include <string> + #include "defun.h" #include "error.h" #include "gripes.h" @@ -804,7 +806,8 @@ retval = 0.0; if (args(0).is_map () && args(1).is_string ()) { - const char *s = args(1).string_value (); + string tstr = args(1).string_value (); + const char *s = tstr.c_str (); tree_constant tmp = args(0).lookup_map_element (s, 0, 1); retval = (double) tmp.is_defined (); }
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -44,6 +44,8 @@ #include <cstdlib> #include <cstring> +#include <string> + #include <strstream.h> #include "defun.h" @@ -501,7 +503,8 @@ if (args.length () == 1) { - const char *dirname = args(0).string_value (); + string tstr = args(0).string_value (); + const char *dirname = tstr.c_str (); if (error_state) { @@ -590,7 +593,8 @@ if (args.length () == 1) { - const char *dirname = args(0).string_value (); + string tstr = args(0).string_value (); + const char *dirname = tstr.c_str (); if (error_state) gripe_wrong_type_arg ("mkdir", args(0)); @@ -630,7 +634,8 @@ if (args.length () == 1) { - const char *dirname = args(0).string_value (); + string tstr = args(0).string_value (); + const char *dirname = tstr.c_str (); if (error_state) gripe_wrong_type_arg ("rmdir", args(0)); @@ -670,12 +675,16 @@ if (args.length () == 2) { - const char *from = args(0).string_value (); + string tstr1 = args(0).string_value (); + const char *from = tstr1.c_str (); + if (error_state) gripe_wrong_type_arg ("rename", args(0)); else { - const char *to = args(1).string_value (); + string tstr2 = args(1).string_value (); + const char *to = tstr2.c_str (); + if (error_state) gripe_wrong_type_arg ("rename", args(1)); else if (rename (from, to) < 0)
--- a/src/error.cc +++ b/src/error.cc @@ -28,6 +28,8 @@ #include <cstdarg> #include <cstring> +#include <string> + #include <strstream.h> #include "defun.h" @@ -202,6 +204,8 @@ { Octave_object retval; + string tstr; + int nargin = args.length (); tree_constant arg = ((nargin > 1) ? Fsprintf (args, 1) : args) (0); @@ -210,7 +214,8 @@ { if (arg.is_string ()) { - msg = arg.string_value (); + tstr = arg.string_value (); + msg = tstr.c_str (); if (! msg) return retval;
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -39,6 +39,8 @@ #include <cstdlib> #include <cctype> +#include <string> + #include <strstream.h> #ifdef HAVE_UNISTD_H @@ -115,7 +117,8 @@ int file_count = file_list.length (); for (int i = 0; i < file_count; i++) { - const char *file_name = arg.string_value (); + string tstr = arg.string_value (); + const char *file_name = tstr.c_str (); file = file_list (p); if (file.name () == file_name) return p; @@ -191,7 +194,8 @@ { if (arg.is_string ()) { - const char *name = arg.string_value (); + string tstr = arg.string_value (); + const char *name = tstr.c_str (); struct stat buffer; int status = stat (name, &buffer); @@ -481,8 +485,10 @@ return retval; } - const char *name = args(0).string_value (); - const char *mode = args(1).string_value (); + string tstr1 = args(0).string_value (); + const char *name = tstr1.c_str (); + string tstr2 = args(1).string_value (); + const char *mode = tstr2.c_str (); if (! valid_mode (mode)) { @@ -935,7 +941,8 @@ case 's': { - const char *val = args(fmt_arg_count++).string_value (); + string tstr = args(fmt_arg_count++).string_value (); + const char *val = tstr.c_str (); if (error_state) goto invalid_conversion; @@ -952,7 +959,8 @@ case 'c': { - const char *val = args(fmt_arg_count++).string_value (); + string tstr = args(fmt_arg_count++).string_value (); + const char *val = tstr.c_str (); if (error_state || strlen (val) != 1) goto invalid_conversion; @@ -988,6 +996,7 @@ Octave_object retval; fmt_arg_count = 0; const char *fmt; + string fmt_str; file_info file; if (strcmp (type, "fprintf") == 0) @@ -1005,7 +1014,8 @@ return retval; } - fmt = args(1).string_value (); + fmt_str = args(1).string_value (); + fmt = fmt_str.c_str (); if (error_state) { @@ -1017,7 +1027,8 @@ } else { - fmt = args(0).string_value (); + fmt_str = args(0).string_value (); + fmt = fmt_str.c_str (); if (error_state) { @@ -1308,6 +1319,7 @@ { Octave_object retval; const char *scanf_fmt = 0; + string scanf_fmt_str; char *tmp_file = 0; int tmp_file_open = 0; FILE *fptr = 0; @@ -1317,7 +1329,8 @@ if (strcmp (type, "scanf") != 0) { - scanf_fmt = args(1).string_value (); + scanf_fmt_str = args(1).string_value (); + scanf_fmt = scanf_fmt_str.c_str (); if (error_state) { @@ -1349,10 +1362,14 @@ if ((! fptr && args(0).is_string ()) || (doing_fscanf && file.number () == 0)) { - const char *string; + string xstring_str; + const char *xstring; if (strcmp (type, "scanf") == 0) - scanf_fmt = args(0).string_value (); + { + scanf_fmt_str = args(0).string_value (); + scanf_fmt = scanf_fmt_str.c_str (); + } if (strcmp (type, "scanf") == 0 || (doing_fscanf && file.number () == 0)) @@ -1364,13 +1381,16 @@ flush_output_to_pager (); - string = gnu_readline (""); - - if (string && *string) - maybe_save_history (string); + xstring = gnu_readline (""); + + if (xstring && *xstring) + maybe_save_history (xstring); } else - string = args(0).string_value (); + { + xstring_str = args(0).string_value (); + xstring = xstring_str.c_str (); + } tmp_file = octave_tmp_file_name (); @@ -1383,13 +1403,13 @@ tmp_file_open = 1; unlink (tmp_file); - if (! string) + if (! xstring) { error ("%s: no string to scan", type); return retval; } - int success = fputs (string, fptr); + int success = fputs (xstring, fptr); fflush (fptr); rewind (fptr); @@ -1579,9 +1599,11 @@ // Get type and number of bytes per element to read. const char *prec = "uchar"; + string tstr; if (nargin > 2) { - prec = args(2).string_value (); + tstr = args(2).string_value (); + prec = tstr.c_str (); if (error_state) { @@ -1766,9 +1788,11 @@ // Get type and number of bytes per element to read. const char *prec = "uchar"; + string tstr; if (nargin > 2) { - prec = args(2).string_value (); + tstr = args(2).string_value (); + prec = tstr.c_str (); if (error_state) { @@ -1935,8 +1959,10 @@ return retval; } - const char *name = args(0).string_value (); - const char *mode = args(1).string_value (); + string tstr1 = args(0).string_value (); + const char *name = tstr1.c_str (); + string tstr2 = args(1).string_value (); + const char *mode = tstr2.c_str (); if (mode[1] || (mode[0] != 'w' && mode[0] != 'r')) { @@ -2058,7 +2084,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); if (pipe (stdin_pipe) || pipe (stdout_pipe)) { @@ -2150,7 +2177,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); retval (0) = (double) system (name); return retval; @@ -2185,7 +2213,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); pid = fork (); @@ -2318,7 +2347,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); if (! args(1).is_scalar_type ()) { @@ -2367,7 +2397,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); retval (0) = (double) unlink (name); @@ -2454,7 +2485,8 @@ if (args.length () == 1) { - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); static char *fname = 0; @@ -2489,7 +2521,8 @@ if (args.length () == 1) { - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); static char *fname = 0;
--- a/src/fsolve.cc +++ b/src/fsolve.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "NLEqn.h" @@ -299,7 +301,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/input.cc +++ b/src/input.cc @@ -44,6 +44,8 @@ #include <cassert> #include <csignal> +#include <string> + #include <iostream.h> #include <strstream.h> @@ -1008,9 +1010,11 @@ read_as_string++; const char *prompt = "debug> "; + string tstr; if (nargin > 0) { - prompt = args(0).string_value (); + tstr = args(0).string_value (); + prompt = tstr.c_str (); if (error_state) {
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -30,6 +30,8 @@ #include <cstring> #include <cctype> +#include <string> + #include <iostream.h> #include <fstream.h> #include <strstream.h> @@ -2512,9 +2514,9 @@ { FOUR_BYTE_INT len = chm.cols (); os.write (&len, 4); - const char *tmp = chm.row_as_string (i); + string tstr = chm.row_as_string (i); + const char *tmp = tstr.data (); os.write (tmp, len); - delete [] tmp; } } else if (tc.is_range ()) @@ -2819,9 +2821,9 @@ { int len = chm.cols (); os << "# length: " << len << "\n"; - char *tmp = chm.row_as_string (i); + string tstr = chm.row_as_string (i); + char *tmp = tstr.data (); os.write (tmp, len); - delete [] tmp; os << "\n"; } }
--- a/src/lsode.cc +++ b/src/lsode.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "ODE.h" @@ -314,7 +316,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/npsol.cc +++ b/src/npsol.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "NPSOL.h" @@ -801,7 +803,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -29,6 +29,8 @@ #include <cmath> #include <cstring> +#include <string> + #include <iostream.h> #include <strstream.h> @@ -1515,7 +1517,8 @@ for (int i = 0; i < nstr; i++) { - char *row = chm.row_as_string (i); + string tstr = chm.row_as_string (i); + const char *row = tstr.c_str (); if (pr_as_read_syntax) {
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -32,6 +32,8 @@ #include <cctype> #include <cstring> +#include <string> + #include <fstream.h> #include <iostream.h> #include <strstream.h> @@ -1448,16 +1450,17 @@ } } -const char * +string TC_REP::string_value (void) const { + string retval; + if (type_tag == char_matrix_constant_str) - return char_matrix->row_as_string (0); // XXX FIXME??? XXX + retval = char_matrix->row_as_string (0); // XXX FIXME??? XXX else - { - gripe_invalid_conversion (type_as_string (), "string"); - return 0; - } + gripe_invalid_conversion (type_as_string (), "string"); + + return retval; } Range
--- a/src/pt-const.h +++ b/src/pt-const.h @@ -30,6 +30,8 @@ #include <cstdlib> +#include <string> + #include <iostream.h> #include "Range.h" @@ -215,7 +217,7 @@ ComplexMatrix complex_matrix_value (int frc_str_conv = 0) const; charMatrix char_matrix_value (int frc_str_conv = 0) const; charMatrix all_strings (void) const; - const char *string_value (void) const; + string string_value (void) const; Range range_value (void) const; Octave_map map_value (void) const; @@ -546,7 +548,7 @@ charMatrix all_strings (void) const { return rep->all_strings (); } - const char *string_value (void) const + string string_value (void) const { return rep->string_value (); } Range range_value (void) const
--- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -31,6 +31,8 @@ #include <cstring> +#include <string> + #include <fstream.h> #include <iostream.h> #include <strstream.h> @@ -731,7 +733,9 @@ int n_max = 0; - file = tilde_expand (data.string_value ()); + string tstr = data.string_value (); + + file = tilde_expand (tstr.c_str ()); ifstream ftmp (file); if (ftmp) {
--- a/src/qpsol.cc +++ b/src/qpsol.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "QPSOL.h" @@ -416,7 +418,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/quad.cc +++ b/src/quad.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include <strstream.h> #include "Quad.h" @@ -371,7 +373,8 @@ } else if (nargin == 1 || nargin == 2) { - const char *keyword = args(0).string_value (); + string tstr = args(0).string_value (); + const char *keyword = tstr.c_str (); if (! error_state) {
--- a/src/rand.cc +++ b/src/rand.cc @@ -27,6 +27,8 @@ #include <ctime> +#include <string> + #include "f77-uscore.h" #include "defun-dld.h" @@ -169,7 +171,8 @@ if (tmp.is_string ()) { - const char *s_arg = tmp.string_value (); + string tstr = tmp.string_value (); + const char *s_arg = tstr.c_str (); if (strcmp (s_arg, "dist") == 0) { @@ -255,13 +258,17 @@ } else if (nargin == 2) { - if (args(0).is_string () - && strcmp (args(0).string_value (), "seed") == 0) + if (args(0).is_string ()) { - double d = args(1).double_value (); + string tstr = args(0).string_value (); - if (! error_state) - set_rand_seed (d); + if (strcmp (tstr.c_str (), "seed") == 0) + { + double d = args(1).double_value (); + + if (! error_state) + set_rand_seed (d); + } } else {
--- a/src/schur.cc +++ b/src/schur.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include "CmplxSCHUR.h" #include "dbleSCHUR.h" @@ -62,9 +64,12 @@ tree_constant arg = args(0); const char *ord = "U"; + string tstr; + if (nargin == 2) { - ord = args(1).string_value (); + tstr = args(1).string_value (); + ord = tstr.c_str (); if (error_state) {
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -40,6 +40,8 @@ #include <cstdlib> #include <cstring> +#include <string> + #ifdef HAVE_UNISTD_H #include <sys/types.h> #include <unistd.h> @@ -541,7 +543,8 @@ if (nargin == 1) { - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); if (! error_state) { @@ -567,11 +570,13 @@ if (nargin == 2) { - const char *var = args(0).string_value (); + string tstr1 = args(0).string_value (); + const char *var = tstr1.c_str (); if (! error_state) { - const char *val = args(1).string_value (); + string tstr2 = args(1).string_value (); + const char *val = tstr2.c_str (); if (! error_state) oct_putenv (var, val);
--- a/src/timefns.cc +++ b/src/timefns.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <string> + #include "defun.h" #include "help.h" #include "oct-map.h" @@ -80,7 +82,8 @@ tm.tm_yday = NINT (m ["yday"] . double_value ()); tm.tm_isdst = NINT (m ["isdst"] . double_value ()); #ifdef HAVE_TMZONE - tm.tm_zone = (m ["zone"] . string_value ()); + string tstr = m ["zone"] . string_value (); + tm.tm_zone = tstr.c_str (); #endif return &tm; @@ -272,7 +275,8 @@ if (args.length () == 2 && args(0).is_string () && args(1).is_map ()) { - const char *fmt = args(0).string_value (); + string tstr = args(0).string_value (); + const char *fmt = tstr.c_str (); Octave_map map = args(1).map_value (); double fraction;
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -32,6 +32,8 @@ #include <cstring> #include <ctime> +#include <string> + #include <fstream.h> #include <iostream.h> #include <strstream.h> @@ -231,7 +233,8 @@ if (nargin == 1) { - const char *file = args(0).string_value (); + string tstr = args(0).string_value (); + const char *file = tstr.c_str (); if (! error_state) { @@ -491,7 +494,8 @@ static Octave_object eval_string (const tree_constant& arg, int& parse_status, int nargout) { - const char *string = arg.string_value (); + string tstr = arg.string_value (); + const char *string = tstr.c_str (); if (error_state) { @@ -569,7 +573,8 @@ tree_constant tc_command = args(0); - const char *tmp_str = tc_command.string_value (); + string tstr = tc_command.string_value (); + const char *tmp_str = tstr.c_str (); if (error_state) {
--- a/src/utils.cc +++ b/src/utils.cc @@ -29,6 +29,8 @@ #include <csetjmp> #include <cstring> +#include <string> + #include <fstream.h> #include <iostream.h> #include <strstream.h> @@ -522,7 +524,10 @@ argv = new char * [n + 1]; argv[0] = strsave (fcn_name); for (int i = 0; i < n; i++) - argv[i+1] = strsave (args(i).string_value ()); + { + string tstr = args(i).string_value (); + argv[i+1] = strsave (tstr.c_str ()); + } } else error ("%s: expecting all arguments to be strings", fcn_name); @@ -798,7 +803,8 @@ if (nargin == 1 && args(0).is_string ()) { - char *str = undo_string_escapes (args(0).string_value ()); + string tstr = args(0).string_value (); + char *str = undo_string_escapes (tstr.c_str ()); retval = str; delete [] str; }
--- a/src/variables.cc +++ b/src/variables.cc @@ -29,6 +29,8 @@ #include <cstdio> #include <cstring> +#include <string> + #include <strstream.h> #ifdef HAVE_UNISTD_H @@ -129,8 +131,13 @@ const char *fcn_name = 0; + string tstr; + if (arg.is_string ()) - fcn_name = arg.string_value (); + { + tstr = arg.string_value (); + fcn_name = tstr.c_str (); + } if (! fcn_name || error_state) { @@ -171,7 +178,8 @@ return retval; } - const char *name = args(0).string_value (); + string tstr = args(0).string_value (); + const char *name = tstr.c_str (); if (error_state) { @@ -207,7 +215,8 @@ return retval; } - char *name = strsave (args(0).string_value ()); + string tstr = args(0).string_value (); + char *name = strsave (tstr.c_str ()); if (error_state) { @@ -928,7 +937,8 @@ if (! error_state && val.is_string ()) { - const char *s = val.string_value (); + string tstr = val.string_value (); + const char *s = tstr.c_str (); if (s) retval = strsave (s);