Mercurial > hg > octave-lyh
changeset 4051:b79da8779a0e
[project @ 2002-08-17 19:38:32 by jwe]
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-08-17 John W. Eaton <jwe@bevo.che.wisc.edu> + + * configure.in: Check for sstream. + 2002-08-16 John W. Eaton <jwe@bevo.che.wisc.edu> * Makeconf.in (%.d : %.cc): Add $*.df to LHS of dependency list.
--- a/configure.in +++ b/configure.in @@ -22,7 +22,7 @@ ### 02111-1307, USA. AC_INIT -AC_REVISION($Revision: 1.363 $) +AC_REVISION($Revision: 1.364 $) AC_PREREQ(2.52) AC_CONFIG_SRCDIR([src/octave.cc]) AC_CONFIG_HEADER(config.h) @@ -790,13 +790,21 @@ AC_HEADER_TIME AC_HEADER_SYS_WAIT +### C headers + AC_CHECK_HEADERS(assert.h curses.h dlfcn.h fcntl.h float.h \ - floatingpoint.h grp.h ieeefp.h limits.h memory.h \ - nan.h ncurses.h poll.h pwd.h stdlib.h string.h sys/ioctl.h \ + floatingpoint.h grp.h ieeefp.h limits.h memory.h nan.h \ + ncurses.h poll.h pwd.h stdlib.h string.h sys/ioctl.h \ sys/param.h sys/poll.h sys/resource.h sys/select.h sys/stat.h \ sys/time.h sys/times.h sys/types.h sys/utsname.h termcap.h \ unistd.h varargs.h) +### C++ headers + +AC_LANG_PUSH(C++) +AC_CHECK_HEADERS(sstream) +AC_LANG_POP(C++) + have_termios_h=no AC_CHECK_HEADERS($TERMIOS_H, have_termios_h=yes) AC_CHECK_HEADERS(termio.h, have_termio_h=yes, have_termio_h=no)
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,17 @@ +2002-08-17 John W. Eaton <jwe@bevo.che.wisc.edu> + + * DASPK.cc: Include lo-sstream.h and use macros instead of using + strstream classes directly. + * DASRT.cc: Likewise. + * DASSL.cc: Likewise. + * LSODE.cc: Likewise. + * ODESSA.cc: Likewise. + + * cmd-hist.cc: Don't include <strstream>. + * oct-shlib.cc: Likewise. + + * lo-sstream.h: New file. + 2002-08-16 John W. Eaton <jwe@bevo.che.wisc.edu> * LSODE.h (rel_tol, abs_tol, px, pabs_tol, piwork, prwork, itol):
--- a/liboctave/DASPK.cc +++ b/liboctave/DASPK.cc @@ -31,11 +31,10 @@ #include <cfloat> #include <cmath> -#include <strstream> - #include "DASPK.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-sstream.h" typedef int (*daspk_fcn_ptr) (const double&, const double*, const double*, const double&, @@ -672,11 +671,10 @@ { std::string retval; - std::ostrstream buf; - buf << t << ends; - const char *t = buf.str (); - std::string t_curr = t; - delete [] t; + OSSTREAM buf; + buf << t << OSSTREAM_ENDS; + std::string t_curr = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); switch (istate) {
--- a/liboctave/DASRT.cc +++ b/liboctave/DASRT.cc @@ -28,25 +28,13 @@ #include <config.h> #endif -#include <strstream.h> - -#include <cstdlib> #include <cfloat> #include <cmath> -#include "defun-dld.h" -#include "error.h" -#include "gripes.h" -#include "oct-obj.h" -#include "ov-fcn.h" -#include "pager.h" -#include "parse.h" -#include "unwind-prot.h" -#include "utils.h" -#include "variables.h" #include "DASRT.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-sstream.h" typedef int (*dasrt_fcn_ptr) (const double&, const double*, const double*, double*, int&, double*, int*); @@ -563,11 +551,10 @@ { std::string retval; - std::ostrstream buf; - buf << t << ends; - const char *t = buf.str (); - std::string t_curr = t; - delete [] t; + OSSTREAM buf; + buf << t << OSSTREAM_ENDS; + std::string t_curr = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); switch (istate) {
--- a/liboctave/DASSL-opts.in +++ b/liboctave/DASSL-opts.in @@ -36,6 +36,7 @@ tolerance must also be a vector of the same length. The local error test applied at each integration step is + @example abs (local error in x(i)) <= rtol(i) * abs (Y(i)) + atol(i) @end example @@ -62,7 +63,7 @@ OPTION NAME = "compute consistent initial condition" DOC_ITEM -If nonzero, dassl will attempt to compute a consistent set of intial +If nonzero, @code{dassl} will attempt to compute a consistent set of intial conditions. This is generally not reliable, so it is best to provide a consistent set and leave this option set to zero. END_DOC_ITEM @@ -113,7 +114,7 @@ NAME = "maximum step size" DOC_ITEM Setting the maximum stepsize will avoid passing over very large -regions. +regions (default is not specified). END_DOC_ITEM TYPE = "double" INIT_VALUE = "-1.0"
--- a/liboctave/DASSL.cc +++ b/liboctave/DASSL.cc @@ -31,11 +31,10 @@ #include <cfloat> #include <cmath> -#include <strstream> - #include "DASSL.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-sstream.h" typedef int (*dassl_fcn_ptr) (const double&, const double*, const double*, double*, int&, double*, int*); @@ -487,11 +486,10 @@ { std::string retval; - std::ostrstream buf; - buf << t << ends; - const char *t = buf.str (); - std::string t_curr = t; - delete [] t; + OSSTREAM buf; + buf << t << OSSTREAM_ENDS; + std::string t_curr = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); switch (istate) {
--- a/liboctave/LSODE-opts.in +++ b/liboctave/LSODE-opts.in @@ -4,6 +4,10 @@ OPTION NAME = "absolute tolerance" + DOC_ITEM +Absolute tolerance. May be either vector or scalar. If a vector, it +must match the dimension of the state vector. + END_DOC_ITEM TYPE = "Array<double>" SET_ARG_TYPE = "const $TYPE&" INIT_BODY @@ -24,7 +28,39 @@ END_OPTION OPTION + NAME = "relative tolerance" + DOC_ITEM +Relative tolerance parameter. Unlike the absolute tolerance, this +parameter may only be a scalar. + +The local error test applied at each integration step is + +@example + abs (local error in x(i)) <= rtol * abs (y(i)) + atol(i) +@end example + END_DOC_ITEM + TYPE = "double" + INIT_VALUE = "::sqrt (DBL_EPSILON)" + SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" +END_OPTION + +OPTION NAME = "integration method" +A string specifing the method of integration to use to solve the ODE +system. Valid values are + +@table @asis +@item \"adams\" +@itemx \"non-stiff\" +No Jacobian used (even if it is available). +@item \"bdf\" +@item \"stiff\" +Use stiff backward differentiation formula (BDF) method. If a +function to compute the Jacobian is not supplied, @code{lsode} will +compute a finite difference approximation of the Jacobian matrix. +@end table + DOC_ITEM + END_DOC_ITEM TYPE = "std::string" SET_ARG_TYPE = "const $TYPE&" INIT_VALUE = ""stiff"" @@ -41,6 +77,10 @@ OPTION NAME = "initial step size" + DOC_ITEM +The step size to be attempted on the first step (default is determined +automatically). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "-1.0" SET_EXPR = "(val >= 0.0) ? val : -1.0" @@ -48,6 +88,10 @@ OPTION NAME = "maximum step size" + DOC_ITEM +Setting the maximum stepsize will avoid passing over very large +regions (default is not specified). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "-1.0" SET_EXPR = "(val >= 0.0) ? val : -1.0" @@ -55,20 +99,19 @@ OPTION NAME = "minimum step size" + DOC_ITEM +The minimum absolute step size allowed (default is 0). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "0.0" SET_EXPR = "(val >= 0.0) ? val : 0.0" END_OPTION OPTION - NAME = "relative tolerance" - TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" - SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" -END_OPTION - -OPTION NAME = "step limit" + DOC_ITEM +Maximum number of steps allowed (default is 100000). + END_DOC_ITEM TYPE = "int" INIT_VALUE = "100000" SET_EXPR = "val"
--- a/liboctave/LSODE.cc +++ b/liboctave/LSODE.cc @@ -31,11 +31,10 @@ #include <cfloat> #include <cmath> -#include <strstream> - #include "LSODE.h" #include "f77-fcn.h" #include "lo-error.h" +#include "lo-sstream.h" typedef int (*lsode_fcn_ptr) (const int&, const double&, double*, double*, int&); @@ -286,11 +285,10 @@ { std::string retval; - std::ostrstream buf; - buf << t << ends; - const char *t = buf.str (); - std::string t_curr = t; - delete [] t; + OSSTREAM buf; + buf << t << OSSTREAM_ENDS; + std::string t_curr = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); switch (istate) {
--- a/liboctave/ODESSA-opts.in +++ b/liboctave/ODESSA-opts.in @@ -4,6 +4,10 @@ OPTION NAME = "absolute tolerance" + DOC_ITEM +Absolute tolerance. May be either vector or scalar. If a vector, it +must match the dimension of the state vector. + END_DOC_ITEM TYPE = "Array<double>" SET_ARG_TYPE = "const $TYPE&" INIT_BODY @@ -24,7 +28,24 @@ END_OPTION OPTION + NAME = "relative tolerance" + TYPE = "double" + INIT_VALUE = "::sqrt (DBL_EPSILON)" + SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" +END_OPTION + +OPTION NAME = "integration method" + DOC_ITEM +Relative tolerance parameter. Unlike the absolute tolerance, this +parameter may only be a scalar. + +The local error test applied at each integration step is + +@example + abs (local error in x(i)) <= rtol * abs (y(i)) + atol(i) +@end example + END_DOC_ITEM TYPE = "std::string" SET_ARG_TYPE = "const $TYPE&" INIT_VALUE = {"stiff"} @@ -41,6 +62,10 @@ OPTION NAME = "initial step size" + DOC_ITEM +The step size to be attempted on the first step (default is determined +automatically). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "-1.0" SET_EXPR = "(val >= 0.0) ? val : -1.0" @@ -48,6 +73,10 @@ OPTION NAME = "maximum step size" + DOC_ITEM +Setting the maximum stepsize will avoid passing over very large +regions (default is not specified). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "-1.0" SET_EXPR = "(val >= 0.0) ? val : -1.0" @@ -55,20 +84,19 @@ OPTION NAME = "minimum step size" + DOC_ITEM +The minimum absolute step size allowed (default is 0). + END_DOC_ITEM TYPE = "double" INIT_VALUE = "0.0" SET_EXPR = "(val >= 0.0) ? val : 0.0" END_OPTION OPTION - NAME = "relative tolerance" - TYPE = "double" - INIT_VALUE = "::sqrt (DBL_EPSILON)" - SET_EXPR = "(val > 0.0) ? val : ::sqrt (DBL_EPSILON)" -END_OPTION - -OPTION NAME = "step limit" + DOC_ITEM +Maximum number of steps allowed (default is 100000). + END_DOC_ITEM TYPE = "int" INIT_VALUE = "100000" SET_EXPR = "val"
--- a/liboctave/ODESSA.cc +++ b/liboctave/ODESSA.cc @@ -28,12 +28,9 @@ #include <config.h> #endif -#include <cstdlib> #include <cfloat> #include <cmath> -#include <strstream> - // For instantiating the Array<Matrix> object. #include "Array.h" #include "Array.cc" @@ -41,15 +38,7 @@ #include "ODESSA.h" #include "f77-fcn.h" #include "lo-error.h" -#include "error.h" -#include "gripes.h" -#include "oct-obj.h" -#include "ov-fcn.h" -#include "pager.h" -#include "parse.h" -#include "unwind-prot.h" -#include "utils.h" -#include "variables.h" +#include "lo-sstream.h" typedef int (*odessa_fcn_ptr) (int*, const double&, double*, double*, double*); @@ -457,11 +446,10 @@ { std::string retval; - std::ostrstream buf; - buf << t << ends; - const char *t = buf.str (); - std::string t_curr = t; - delete [] t; + OSSTREAM buf; + buf << t << OSSTREAM_ENDS; + std::string t_curr = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); switch (istate) {
--- a/liboctave/Quad-opts.in +++ b/liboctave/Quad-opts.in @@ -2,6 +2,9 @@ OPTION NAME = "absolute tolerance" + DOC_ITEM +Absolute tolerance; may be zero for pure relative error test. + END_DOC_ITEM TYPE = "double" INIT_VALUE = "::sqrt (DBL_EPSILON)" SET_EXPR = "val" @@ -9,6 +12,11 @@ OPTION NAME = "relative tolerance" + DOC_ITEM +Nonnegative relative tolerance. If the absolute tolerance is zero, +the relative tolerance must be greater than or equal to +@code{max (50*eps, 0.5e-28)}. + END_DOC_ITEM TYPE = "double" INIT_VALUE = "::sqrt (DBL_EPSILON)" SET_EXPR = "val"
--- a/liboctave/cmd-hist.cc +++ b/liboctave/cmd-hist.cc @@ -27,7 +27,6 @@ #include <cstring> #include <iostream> -#include <strstream> #include <string> #include "cmd-edit.h" @@ -41,8 +40,6 @@ #include <cstdlib> -#include <strstream> - #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif
new file mode 100644 --- /dev/null +++ b/liboctave/lo-sstream.h @@ -0,0 +1,62 @@ +/* + +Copyright (C) 2002 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_liboctave_sstream_h) +#define octave_liboctave_sstream_h 1 + +#ifdef HAVE_SSTREAM + +#include <sstream> + +#define STRINGSTREAMBUF std::stringbuf + +#define ISSTREAM std::istringstream + +#define OSSTREAM std::ostringstream +#define OSSTREAM_STR(os) (os).str () +#define OSSTREAM_C_STR(os) (os).str () . c_str () +#define OSSTREAM_ENDS "" +#define OSSTREAM_FREEZE(os) do { } while (0) + +#else + +#include <strstream> + +#define STRINGSTREAMBUF std::strstreambuf + +#define ISSTREAM std::istrstream + +#define OSSTREAM std::ostrstream +#define OSSTREAM_STR(os) std::string ((os).str ()) +#define OSSTREAM_C_STR(os) (os).str () +#define OSSTREAM_ENDS std::ends +#define OSSTREAM_FREEZE(os) do { (os).freeze (false); } while (0) + +#endif + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/liboctave/oct-shlib.cc +++ b/liboctave/oct-shlib.cc @@ -29,8 +29,6 @@ #include <cstring> #endif -#include <strstream> - extern "C" { #if defined (WITH_DL)
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,35 @@ +2002-08-17 John W. Eaton <jwe@bevo.che.wisc.edu> + + * pager.h: Include lo-sstream.h and use macros instead of using + strstreambuf class directly. + + * load-save.cc (read_mat_ascii_data): Handle istrstream here too. + + * procstream.h (procstream::procstream): Also accept std::string arg. + (iprocstream::iprocstream, iprocstream::open): Likewise. + (oprocstream::oprocstream, oprocstream::open): Likewise. + (procstreambase::procstreambase, procstreambase::open): Likewise. + + * pt-plot.cc (gnuplot_terminal_type): Now std::string&, not char*. + (send_to_plot_stream): Likewise, for cmd arg. + + * pt-plot.h, pt-plot.cc: Include lo-sstream.h and use macros + instead of using strstream classes directly. + * oct-strstrm.h: Likewise. + * error.h, error.cc: Likewise. + * oct-stream.h, oct-stream.cc: Likewise. + * lex.l: Likewise. + * toplev.cc: Likewise. + * utils.cc: Likewise. + * pt.cc: Likewise. + * pr-output.cc: Likewise. + * ov-list.cc: Likewise. + * ov-cs-list.cc: Likewise. + * ov-cell.cc: Likewise. + * load-save.cc: Likewise. + * help.cc: Likewise. + * dirfns.cc: Likewise. + 2002-08-15 Paul Kienzle <pkienzle@jazz.ncnr.nist.gov> * input.cc (octave_read): Do a better job of buffering.
--- a/src/DLD-FUNCTIONS/qz.cc +++ b/src/DLD-FUNCTIONS/qz.cc @@ -31,11 +31,10 @@ #include "config.h" #include <cfloat> +#include <cmath> + #include <iostream> -#include <iomanip.h> -#include <math.h> -#include <string.h> -#include <strstream.h> +#include <iomanip> #include "CmplxQRP.h" #include "dbleQR.h"
--- a/src/debug.cc +++ b/src/debug.cc @@ -26,7 +26,6 @@ #include <iostream> #include <fstream> -#include <strstream> #include <string> #include "defun.h"
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -30,7 +30,6 @@ #include <cstdlib> #include <cstring> -#include <strstream> #include <string> #ifdef HAVE_UNISTD_H @@ -43,6 +42,7 @@ #include "file-ops.h" #include "file-stat.h" #include "glob-match.h" +#include "lo-sstream.h" #include "oct-env.h" #include "str-vec.h" @@ -167,18 +167,17 @@ if (error_state) return retval; - std::ostrstream ls_buf; + OSSTREAM ls_buf; ls_buf << "ls -C "; for (int i = 1; i < argc; i++) ls_buf << file_ops::tilde_expand (argv[i]) << " "; - ls_buf << std::ends; - char *ls_command = ls_buf.str (); + ls_buf << OSSTREAM_ENDS; - iprocstream *cmd = new iprocstream (ls_command); + iprocstream *cmd = new iprocstream (OSSTREAM_STR (ls_buf)); - delete [] ls_command; + OSSTREAM_FREEZE (ls_buf); unwind_protect::add (cleanup_iprocstream, cmd);
--- a/src/error.cc +++ b/src/error.cc @@ -27,9 +27,10 @@ #include <cstdarg> #include <cstring> -#include <strstream> #include <string> +#include "lo-sstream.h" + #include "defun.h" #include "error.h" #include "input.h" @@ -100,7 +101,7 @@ bool discard_error_messages = false; // The message buffer. -static std::ostrstream *error_message_buffer = 0; +static OSSTREAM *error_message_buffer = 0; // Warning messages are never buffered. @@ -109,24 +110,22 @@ { flush_octave_stdout (); - std::ostrstream output_buf; + OSSTREAM output_buf; if (name) output_buf << name << ": "; octave_vformat (output_buf, fmt, args); - output_buf << std::endl << std::ends; - - char *msg = output_buf.str (); + output_buf << std::endl << OSSTREAM_ENDS; // XXX FIXME XXX -- we really want to capture the message before it // has all the formatting goop attached to it. We probably also // want just the message, not the traceback information. - std::string msg_string = msg; + std::string msg_string = OSSTREAM_STR (output_buf); - delete [] msg; + OSSTREAM_FREEZE (output_buf); if (! warning_state) { @@ -150,7 +149,7 @@ bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; - std::ostrstream output_buf; + OSSTREAM output_buf; if (to_beep_or_not_to_beep_p) output_buf << "\a"; @@ -160,17 +159,15 @@ octave_vformat (output_buf, fmt, args); - output_buf << std::endl << std::ends; - - char *msg = output_buf.str (); + output_buf << std::endl << OSSTREAM_ENDS; // XXX FIXME XXX -- we really want to capture the message before it // has all the formatting goop attached to it. We probably also // want just the message, not the traceback information. - std::string msg_string = msg; + std::string msg_string = OSSTREAM_STR (output_buf); - delete [] msg; + OSSTREAM_FREEZE (output_buf); if (! error_state && name && ! strcmp (name, "error")) { @@ -184,7 +181,7 @@ if (! error_message_buffer) { - error_message_buffer = new std::ostrstream; + error_message_buffer = new OSSTREAM; // XXX FIXME XXX -- this is ugly, but it prevents // @@ -329,7 +326,7 @@ // even if there were multiple statements on the original source // line. - std::ostrstream output_buf; + OSSTREAM output_buf; output_buf << std::endl; @@ -337,13 +334,11 @@ curr_statement->accept (tpc); - output_buf << std::endl << std::ends; - - char *msg = output_buf.str (); + output_buf << std::endl << OSSTREAM_ENDS; - pr_where_1 ("%s", msg); + pr_where_1 ("%s", OSSTREAM_C_STR (output_buf)); - delete [] msg; + OSSTREAM_FREEZE (output_buf); } } @@ -721,13 +716,13 @@ { if (error_message_buffer) { - *error_message_buffer << std::ends; - - char *error_text = error_message_buffer->str (); + *error_message_buffer << OSSTREAM_ENDS; - bind_builtin_variable ("__error_text__", error_text, true); + bind_builtin_variable ("__error_text__", + OSSTREAM_STR (*error_message_buffer), + true); - delete [] error_text; + OSSTREAM_FREEZE (*error_message_buffer); delete error_message_buffer;
--- a/src/error.h +++ b/src/error.h @@ -24,7 +24,6 @@ #define octave_error_h 1 #include <string> -#include <strstream> #define panic_impossible() \ panic ("impossible state reached in file `%s' at line %d", \
--- a/src/help.cc +++ b/src/help.cc @@ -29,7 +29,6 @@ #include <iostream> #include <fstream> -#include <strstream> #include <string> #ifdef HAVE_UNISTD_H @@ -41,6 +40,7 @@ #include "cmd-edit.h" #include "file-ops.h" +#include "lo-sstream.h" #include "oct-env.h" #include "str-vec.h" @@ -507,12 +507,7 @@ { int status = 0; - static char *cmd_str = 0; - - delete [] cmd_str; - cmd_str = 0; - - std::ostrstream cmd_buf; + OSSTREAM cmd_buf; cmd_buf << Vinfo_prog << " --file " << Vinfo_file; @@ -528,14 +523,14 @@ if (nm.length () > 0) cmd_buf << " --index-search " << nm; - cmd_buf << std::ends; - - cmd_str = cmd_buf.str (); + cmd_buf << OSSTREAM_ENDS; volatile octave_interrupt_handler old_interrupt_handler = octave_ignore_interrupts (); - status = system (cmd_str); + status = system (OSSTREAM_C_STR (cmd_buf)); + + OSSTREAM_FREEZE (cmd_buf); octave_set_interrupt_handler (old_interrupt_handler); @@ -616,7 +611,8 @@ if (cols > 80) cols = 72; - std::ostrstream buf; + OSSTREAM buf; + buf << "sed -e 's/^[#%]+ *//' -e 's/^ *@/@/' | " << Vmakeinfo_prog << " -D \"VERSION " << OCTAVE_VERSION << "\"" @@ -629,13 +625,11 @@ << " --force" << " --output " << tmp_file_name << " > /dev/null 2>&1" - << std::ends; - - char *cmd = buf.str (); + << OSSTREAM_ENDS; - oprocstream filter (cmd); + oprocstream filter (OSSTREAM_STR (buf)); - delete [] cmd; + OSSTREAM_FREEZE (buf); if (filter && filter.is_open ()) { @@ -898,7 +892,7 @@ if (idx < argc) { - std::ostrstream output_buf; + OSSTREAM output_buf; for (int i = idx; i < argc; i++) { @@ -915,13 +909,11 @@ if (nargout != 0) { - output_buf << std::ends; - - char *s = output_buf.str (); + output_buf << OSSTREAM_ENDS; - retval = s; + retval = OSSTREAM_STR (output_buf); - delete [] s; + OSSTREAM_FREEZE (output_buf); } } else
--- a/src/lex.l +++ b/src/lex.l @@ -31,12 +31,12 @@ #include <cctype> #include <cstring> -#include <strstream> #include <string> #include "SLStack.h" #include "cmd-edit.h" +#include "lo-sstream.h" // These would be alphabetical, but y.tab.h must be included before // oct-gperf.h and y.tab.h must be included after token.h and the tree @@ -1787,7 +1787,7 @@ static bool have_continuation (bool trailing_comments_ok) { - std::ostrstream buf; + OSSTREAM buf; std::string comment_buf; @@ -1879,15 +1879,14 @@ return false; cleanup: - buf << std::ends; - char *s = buf.str (); - if (s) - { - int len = strlen (s); - while (len--) - unput (s[len]); - } - delete [] s; + + buf << OSSTREAM_ENDS; + std::string s = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); + + int len = s.length (); + while (len--) + unput (s[len]); return false; } @@ -1941,7 +1940,7 @@ static int handle_string (char delim, int text_style) { - std::ostrstream buf; + OSSTREAM buf; int bos_line = input_line_number; int bos_col = current_input_column; @@ -1994,10 +1993,9 @@ else { unput (c); - buf << std::ends; - char *t = buf.str (); - std::string s = do_string_escapes (t); - delete [] t; + buf << OSSTREAM_ENDS; + std::string s = do_string_escapes (OSSTREAM_STR (buf)); + OSSTREAM_FREEZE (buf); if (text_style && lexer_flags.doing_set) {
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -35,7 +35,6 @@ #include <iomanip> #include <iostream> #include <fstream> -#include <strstream> #include <string> #ifdef HAVE_HDF5 @@ -47,6 +46,7 @@ #include "file-ops.h" #include "glob-match.h" #include "lo-mappers.h" +#include "lo-sstream.h" #include "mach-info.h" #include "oct-env.h" #include "oct-time.h" @@ -358,7 +358,7 @@ { if (c == '%' || c == '#') { - std::ostrstream buf; + OSSTREAM buf; while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) ; // Skip whitespace and comment characters. @@ -369,14 +369,14 @@ while (is.get (c) && isalpha (c)) buf << c; - buf << std::ends; - char *tmp = buf.str (); + buf << OSSTREAM_ENDS; + const char *tmp = OSSTREAM_C_STR (buf); + OSSTREAM_FREEZE (buf); int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); - delete [] tmp; if (match) { - std::ostrstream value; + OSSTREAM value; while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) ; // Skip whitespace and the colon. @@ -386,8 +386,9 @@ while (is.get (c) && c != '\n') value << c; } - value << std::ends; - retval = value.str (); + value << OSSTREAM_ENDS; + retval = strsave (OSSTREAM_C_STR (value)); + OSSTREAM_FREEZE (value); break; } } @@ -426,7 +427,7 @@ { if (c == '%' || c == '#') { - std::ostrstream buf; + OSSTREAM buf; while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) ; // Skip whitespace and comment characters. @@ -437,10 +438,10 @@ while (is.get (c) && isalpha (c)) buf << c; - buf << std::ends; - char *tmp = buf.str (); + buf << OSSTREAM_ENDS; + const char *tmp = OSSTREAM_C_STR (buf); int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); - delete [] tmp; + OSSTREAM_FREEZE (buf); if (match) { @@ -2023,7 +2024,11 @@ { std::string buf = get_mat_data_input_line (is); +#ifdef HAVE_SSTREAM + std::istringstream tmp_stream (buf); +#else std::istrstream tmp_stream (buf.c_str ()); +#endif for (int j = 0; j < nc; j++) { @@ -2939,8 +2944,10 @@ Octave_map retstruct; - std::ostrstream output_buf; + OSSTREAM output_buf; + int count = 0; + for (;;) { bool global = false; @@ -3064,16 +3071,14 @@ if (list_only && count) { - output_buf << std::ends; - - char *msg = output_buf.str (); + output_buf << OSSTREAM_ENDS; + std::string msg = OSSTREAM_STR (output_buf); + OSSTREAM_FREEZE (output_buf); if (nargout > 0) retval = msg; else octave_stdout << msg; - - delete [] msg; } else if (! retstruct.empty ()) retval = retstruct;
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -28,12 +28,12 @@ #include <cstring> #include <iomanip> -#include <strstream> #include <fstream> #include <string> #include "lo-ieee.h" #include "lo-mappers.h" +#include "lo-sstream.h" #include "lo-utils.h" #include "str-vec.h" @@ -166,7 +166,7 @@ have_more = true; if (! buf) - buf = new std::ostrstream (); + buf = new OSSTREAM (); if (s[i] == '%') { @@ -241,25 +241,22 @@ { if (buf) { - *buf << std::ends; - - char *text = buf->str (); - - if (text) + *buf << OSSTREAM_ENDS; + + std::string text = OSSTREAM_STR (*buf); + + OSSTREAM_FREEZE (*buf); + + if (! text.empty ()) { - if (*text) - { - scanf_format_elt *elt - = new scanf_format_elt (text, width, discard, type, - modifier, char_class); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } - - delete [] text; + scanf_format_elt *elt + = new scanf_format_elt (text.c_str (), width, discard, type, + modifier, char_class); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; } delete buf; @@ -594,7 +591,7 @@ if (! buf) { - buf = new std::ostrstream (); + buf = new OSSTREAM (); empty_buf = true; } @@ -662,25 +659,22 @@ { if (buf) { - *buf << std::ends; - - char *text = buf->str (); - - if (text) + *buf << OSSTREAM_ENDS; + + std::string text = OSSTREAM_STR (*buf); + + OSSTREAM_FREEZE (*buf); + + if (! text.empty ()) { - if (*text) - { - printf_format_elt *elt - = new printf_format_elt (text, args, fw, prec, flags, - type, modifier); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } - - delete [] text; + printf_format_elt *elt + = new printf_format_elt (text.c_str (), args, fw, prec, flags, + type, modifier); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; } delete buf; @@ -941,9 +935,7 @@ { std::istream& is = *isp; - // XXX FIXME XXX -- this should probably be converted to use - // sstream when that is available. - std::ostrstream buf; + OSSTREAM buf; int c = 0; int char_count = 0; @@ -985,10 +977,9 @@ } else { - buf << std::ends; - char *tmp = buf.str (); - retval = tmp; - delete [] tmp; + buf << OSSTREAM_ENDS; + retval = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); } } else @@ -1229,38 +1220,42 @@ \ int width = elt->width ? elt->width : 1; \ \ - char *tmp = new char[width + 1]; \ + char *tbuf = new char[width + 1]; \ \ int c = EOF; \ int n = 0; \ \ while (is && n < width && (c = is.get ()) != EOF) \ - tmp[n++] = (char) c; \ + tbuf[n++] = (char) c; \ + \ + tbuf[n] = '\0'; \ \ - tmp[n] = '\0' + std::string tmp = tbuf; \ + \ + delete [] tbuf // For a `%s' format, skip initial whitespace and then read until the // next whitespace character. #define BEGIN_S_CONVERSION() \ int width = elt->width; \ \ - char *tmp = 0; \ + std::string tmp; \ \ do \ { \ if (width) \ { \ - tmp = new char [width+1]; \ + char *tbuf = new char [width+1]; \ + \ + OCTAVE_SCAN (is, *elt, tbuf); \ \ - OCTAVE_SCAN (is, *elt, tmp); \ - \ - tmp[width] = '\0'; \ + tbuf[width] = '\0'; \ + tmp = tbuf; \ + delete [] tbuf; \ } \ else \ { \ - std::string buf; \ - is >> std::ws >> buf; \ - tmp = strsave (buf.c_str()); \ + is >> std::ws >> tmp; \ } \ } \ while (0) @@ -1269,21 +1264,23 @@ #define BEGIN_CHAR_CLASS_CONVERSION() \ int width = elt->width; \ \ - char *tmp = 0; \ + std::string tmp; \ \ do \ { \ if (width) \ { \ - tmp = new char[width+1]; \ + char *tbuf = new char[width+1]; \ + \ + OCTAVE_SCAN (is, *elt, tbuf); \ \ - OCTAVE_SCAN (is, *elt, tmp); \ - \ - tmp[width] = '\0'; \ + tbuf[width] = '\0'; \ + tmp = tbuf; \ + delete [] tbuf; \ } \ else \ { \ - std::ostrstream buf; \ + OSSTREAM buf; \ \ std::string char_class = elt->char_class; \ \ @@ -1305,11 +1302,11 @@ if (c != EOF) \ is.putback (c); \ \ - buf << std::ends; \ + buf << OSSTREAM_ENDS; \ + tmp = OSSTREAM_STR (buf); \ + OSSTREAM_FREEZE (buf); \ \ - tmp = buf.str (); \ - \ - if (strlen (tmp) == 0) \ + if (tmp.empty ()) \ is.setstate (std::ios::failbit); \ } \ } \ @@ -1318,7 +1315,7 @@ #define FINISH_CHARACTER_CONVERSION() \ do \ { \ - width = strlen (tmp); \ + width = tmp.length (); \ \ if (is) \ { \ @@ -1351,8 +1348,6 @@ } \ } \ } \ - \ - delete [] tmp; \ } \ while (0) @@ -1818,8 +1813,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; @@ -1834,8 +1827,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; } @@ -1848,8 +1839,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; } @@ -3133,7 +3122,7 @@ // XXX FIXME XXX -- this should probably be converted to use sstream // when that is available. - std::ostrstream buf; + OSSTREAM buf; buf << "\n" << " number mode arch name\n" @@ -3162,13 +3151,11 @@ } } - buf << "\n" << std::ends; - - char *tmp = buf.str (); - - retval = tmp; - - delete [] tmp; + buf << "\n" << OSSTREAM_ENDS; + + retval = OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); return retval; }
--- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -29,11 +29,11 @@ class octave_value_list; #include <iostream> -#include <strstream> #include <string> #include "Array.h" #include "data-conv.h" +#include "lo-sstream.h" #include "lo-utils.h" #include "mach-info.h" @@ -159,7 +159,7 @@ Array<scanf_format_elt*> list; // Temporary buffer. - std::ostrstream *buf; + OSSTREAM *buf; void add_elt_to_list (int width, bool discard, char type, char modifier, int& num_elts, @@ -291,7 +291,7 @@ Array<printf_format_elt*> list; // Temporary buffer. - std::ostrstream *buf; + OSSTREAM *buf; void add_elt_to_list (int args, const std::string& flags, int fw, int prec, char type, char modifier,
--- a/src/oct-strstrm.h +++ b/src/oct-strstrm.h @@ -23,9 +23,10 @@ #if !defined (octave_octave_strstream_h) #define octave_octave_strstream_h 1 -#include <strstream> #include <string> +#include "lo-sstream.h" + #include "oct-stream.h" class @@ -114,7 +115,7 @@ private: - std::istrstream is; + ISSTREAM is; // No copying! @@ -147,10 +148,9 @@ std::string str (void) { - os << std::ends; - char *tmp = os.str (); - std::string retval = tmp; - delete [] tmp; + os << OSSTREAM_ENDS; + std::string retval = OSSTREAM_STR (os); + OSSTREAM_FREEZE (os); return retval; } @@ -166,7 +166,7 @@ private: - std::ostrstream os; + OSSTREAM os; // No copying!
--- a/src/octave.cc +++ b/src/octave.cc @@ -33,7 +33,6 @@ #include <fstream> #include <iostream> -#include <strstream> #ifdef HAVE_UNISTD_H #ifdef HAVE_SYS_TYPES_H
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -29,8 +29,8 @@ #endif #include <iostream> -#include <strstream> +#include "lo-sstream.h" #include "lo-utils.h" #include "defun.h" @@ -268,15 +268,14 @@ { for (int i = 0; i < nr; i++) { - std::ostrstream buf; - buf << "[" << i+1 << "," << j+1 << "]" << std::ends; - const char *nm = buf.str (); + OSSTREAM buf; + buf << "[" << i+1 << "," << j+1 << "]" << OSSTREAM_ENDS; octave_value val = matrix(i,j); - val.print_with_name (os, nm); + val.print_with_name (os, OSSTREAM_STR (buf)); - delete [] nm; + OSSTREAM_FREEZE (buf); } }
--- a/src/ov-cs-list.cc +++ b/src/ov-cs-list.cc @@ -29,8 +29,8 @@ #endif #include <iostream> -#include <strstream> +#include "lo-sstream.h" #include "lo-utils.h" #include "defun.h" @@ -238,15 +238,14 @@ for (int i = 0; i < n; i++) { - std::ostrstream buf; - buf << "[" << i+1 << "]" << std::ends; - const char *nm = buf.str (); + OSSTREAM buf; + buf << "[" << i+1 << "]" << OSSTREAM_ENDS; octave_value val = lst(i); - val.print_with_name (os, nm); + val.print_with_name (os, OSSTREAM_STR (buf)); - delete [] nm; + OSSTREAM_FREEZE (buf); } decrement_indent_level ();
--- a/src/ov-list.cc +++ b/src/ov-list.cc @@ -29,8 +29,8 @@ #endif #include <iostream> -#include <strstream> +#include "lo-sstream.h" #include "lo-utils.h" #include "defun.h" @@ -236,15 +236,15 @@ for (int i = 0; i < n; i++) { - std::ostrstream buf; - buf << "[" << i+1 << "]" << std::ends; - const char *nm = buf.str (); + OSSTREAM buf; + + buf << "[" << i+1 << "]" << OSSTREAM_ENDS; octave_value val = lst(i); - val.print_with_name (os, nm); + val.print_with_name (os, OSSTREAM_STR (buf)); - delete [] nm; + OSSTREAM_FREEZE (buf); } decrement_indent_level ();
--- a/src/pager.cc +++ b/src/pager.cc @@ -288,7 +288,7 @@ octave_pager_stream::octave_pager_stream (void) : std::ostream (0), pb (0) { - pb = new octave_pager_buf; + pb = new octave_pager_buf (); rdbuf (pb); setf (unitbuf); } @@ -326,7 +326,7 @@ octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0) { - db = new octave_diary_buf; + db = new octave_diary_buf (); rdbuf (db); setf (unitbuf); }
--- a/src/pager.h +++ b/src/pager.h @@ -24,20 +24,21 @@ #define octave_pager_h 1 #include <iostream> -#include <strstream> #include <string> +#include "lo-sstream.h" + #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif class -octave_pager_buf : public std::strstreambuf +octave_pager_buf : public STRINGSTREAMBUF { public: - octave_pager_buf (int size = 0) - : std::strstreambuf (size), diary_skip (0) { } + octave_pager_buf (void) + : STRINGSTREAMBUF (), diary_skip (0) { } void flush_current_contents_to_diary (void); @@ -83,11 +84,11 @@ }; class -octave_diary_buf : public std::strstreambuf +octave_diary_buf : public STRINGSTREAMBUF { public: - octave_diary_buf (int size = 0) : std::strstreambuf (size) { } + octave_diary_buf (void) : STRINGSTREAMBUF () { } protected:
--- a/src/parse.y +++ b/src/parse.y @@ -38,8 +38,6 @@ #include <cstdlib> #endif -#include <strstream.h> - #include "Cell.h" #include "Matrix.h" #include "cmd-edit.h" @@ -47,6 +45,7 @@ #include "file-ops.h" #include "file-stat.h" #include "oct-time.h" +#include "lo-sstream.h" #include "comment-list.h" #include "defun.h" @@ -1483,7 +1482,7 @@ { int err_col = current_input_column - 1; - std::ostrstream output_buf; + OSSTREAM output_buf; if (reading_fcn_file || reading_script_file) output_buf << "parse error near line " << input_line_number @@ -1503,7 +1502,7 @@ if (current_input_line[len-1] == '\n') current_input_line.resize (len-1); -// Print the line, maybe with a pointer near the error token. + // Print the line, maybe with a pointer near the error token. output_buf << ">>> " << current_input_line << "\n"; @@ -1516,13 +1515,11 @@ output_buf << "^"; } - output_buf << "\n" << std::ends; - - char *msg = output_buf.str (); - - parse_error ("%s", msg); - - delete [] msg; + output_buf << "\n" << OSSTREAM_ENDS; + + parse_error ("%s", OSSTREAM_C_STR (output_buf)); + + OSSTREAM_FREEZE (output_buf); } // Error mesages for mismatched end tokens. @@ -1702,19 +1699,17 @@ { tree_constant *tc_retval = new tree_constant (tmp); - std::ostrstream buf; + OSSTREAM buf; tree_print_code tpc (buf); e->accept (tpc); - buf << std::ends; - - char *s = buf.str (); - - tc_retval->stash_original_text (s); - - delete [] s; + buf << OSSTREAM_ENDS; + + tc_retval->stash_original_text (OSSTREAM_STR (buf)); + + OSSTREAM_FREEZE (buf); delete e; @@ -1749,19 +1744,17 @@ { tree_constant *tc_retval = new tree_constant (tmp); - std::ostrstream buf; + OSSTREAM buf; tree_print_code tpc (buf); e->accept (tpc); - buf << std::ends; - - char *s = buf.str (); - - tc_retval->stash_original_text (s); - - delete [] s; + buf << OSSTREAM_ENDS; + + tc_retval->stash_original_text (OSSTREAM_STR (buf)); + + OSSTREAM_FREEZE (buf); delete e; @@ -1805,19 +1798,17 @@ { tree_constant *tc_retval = new tree_constant (tmp); - std::ostrstream buf; + OSSTREAM buf; tree_print_code tpc (buf); e->accept (tpc); - buf << std::ends; - - char *s = buf.str (); - - tc_retval->stash_original_text (s); - - delete [] s; + buf << OSSTREAM_ENDS; + + tc_retval->stash_original_text (OSSTREAM_STR (buf)); + + OSSTREAM_FREEZE (buf); delete e; @@ -2724,19 +2715,17 @@ { tree_constant *tc_retval = new tree_constant (tmp); - std::ostrstream buf; + OSSTREAM buf; tree_print_code tpc (buf); m->accept (tpc); - buf << std::ends; - - char *s = buf.str (); - - tc_retval->stash_original_text (s); - - delete [] s; + buf << OSSTREAM_ENDS; + + tc_retval->stash_original_text (OSSTREAM_STR (buf)); + + OSSTREAM_FREEZE (buf); delete m;
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -31,7 +31,6 @@ #include <iomanip> #include <iostream> -#include <strstream> #include <string> #include "CMatrix.h" @@ -39,6 +38,7 @@ #include "cmd-edit.h" #include "dMatrix.h" #include "lo-mappers.h" +#include "lo-sstream.h" #include "mach-info.h" #include "oct-cmplx.h" #include "str-vec.h" @@ -1789,12 +1789,11 @@ args(0).print (octave_stdout); else { - std::ostrstream buf; + OSSTREAM buf; args(0).print (buf); - buf << std::ends; - char *tmp = buf.str (); - retval = tmp; - delete [] tmp; + buf << OSSTREAM_ENDS; + retval = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); } } else
--- a/src/procstream.cc +++ b/src/procstream.cc @@ -30,6 +30,14 @@ #include "procstream.h" +procstreambase::procstreambase (const std::string& command, int mode) +{ + pb_init (); + + if (! pb.open (command.c_str (), mode)) + std::ios::setstate (std::ios::badbit); +} + procstreambase::procstreambase (const char *command, int mode) { pb_init ();
--- a/src/procstream.h +++ b/src/procstream.h @@ -28,6 +28,7 @@ #endif #include <iostream> +#include <string> #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> @@ -42,10 +43,15 @@ procstreambase (void) { pb_init (); } + procstreambase (const std::string& name, int mode); + procstreambase (const char *name, int mode); ~procstreambase (void) { close (); } + void open (const std::string& name, int mode) + { open (name.c_str (), mode); } + void open (const char *name, int mode); int is_open (void) const { return pb.is_open (); } @@ -73,11 +79,17 @@ iprocstream (void) : std::istream (0), procstreambase () { } + iprocstream (const std::string& name, int mode = std::ios::in) + : std::istream (0), procstreambase (name, mode) { } + iprocstream (const char *name, int mode = std::ios::in) : std::istream (0), procstreambase (name, mode) { } ~iprocstream (void) { } + void open (const std::string& name, int mode = std::ios::in) + { procstreambase::open (name, mode); } + void open (const char *name, int mode = std::ios::in) { procstreambase::open (name, mode); } @@ -96,11 +108,17 @@ oprocstream (void) : std::ostream (0), procstreambase () { } + oprocstream (const std::string& name, int mode = std::ios::out) + : std::ostream (0), procstreambase(name, mode) { } + oprocstream (const char *name, int mode = std::ios::out) : std::ostream (0), procstreambase(name, mode) { } ~oprocstream (void) { } + void open (const std::string& name, int mode = std::ios::out) + { procstreambase::open (name, mode); } + void open (const char *name, int mode = std::ios::out) { procstreambase::open (name, mode); } @@ -119,11 +137,17 @@ procstream (void) : std::iostream (0), procstreambase () { } + procstream (const std::string& name, int mode) + : std::iostream (0), procstreambase (name, mode) { } + procstream (const char *name, int mode) : std::iostream (0), procstreambase (name, mode) { } ~procstream (void) { } + void open (const std::string& name, int mode) + { procstreambase::open (name, mode); } + void open (const char *name, int mode) { procstreambase::open (name, mode); }
--- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -29,7 +29,6 @@ #endif #include <iostream> -#include <strstream> #include <string> #include "str-vec.h"
--- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -29,7 +29,6 @@ #endif #include <iostream> -#include <strstream> #include "defun.h" #include "error.h"
--- a/src/pt-cell.cc +++ b/src/pt-cell.cc @@ -29,7 +29,6 @@ #endif #include <iostream> -#include <strstream> #include "Cell.h" #include "defun.h"
--- a/src/pt-exp.cc +++ b/src/pt-exp.cc @@ -29,7 +29,6 @@ #endif #include <iostream> -#include <strstream> #include <string> #include "error.h"
--- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -29,7 +29,6 @@ #endif #include <iostream> -#include <strstream> #include "defun.h" #include "error.h"
--- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -32,7 +32,6 @@ #include <fstream> #include <iostream> -#include <strstream> #include <string> #ifdef HAVE_UNISTD_H @@ -83,7 +82,7 @@ static bool parametric_plot = false; // The gnuplot terminal type. -static char *gnuplot_terminal_type = 0; +static std::string gnuplot_terminal_type; // Should the graph window be cleared before plotting the next line? static bool clear_before_plotting = true; @@ -187,14 +186,14 @@ initialized = true; *plot_stream << "set data style lines\n"; - if (gnuplot_terminal_type) + if (! gnuplot_terminal_type.empty ()) *plot_stream << "set term " << gnuplot_terminal_type << Vgnuplot_command_end; } } static int -send_to_plot_stream (const char *cmd) +send_to_plot_stream (const std::string& cmd) { if (! (plot_stream && *plot_stream)) { @@ -208,11 +207,9 @@ int splot_len = Vgnuplot_command_splot.length (); int plot_len = Vgnuplot_command_plot.length (); - std::string s = cmd; - - bool is_replot = (Vgnuplot_command_replot == s.substr (0, replot_len)); - bool is_splot = (Vgnuplot_command_splot == s.substr (0, splot_len)); - bool is_plot = (Vgnuplot_command_plot == s.substr (0, plot_len)); + bool is_replot = (Vgnuplot_command_replot == cmd.substr (0, replot_len)); + bool is_splot = (Vgnuplot_command_splot == cmd.substr (0, splot_len)); + bool is_plot = (Vgnuplot_command_plot == cmd.substr (0, plot_len)); if (plot_line_count == 0 && is_replot) error ("replot: no previous plot"); @@ -247,7 +244,7 @@ open_plot_stream (); - std::ostrstream plot_buf; + OSSTREAM plot_buf; switch (ndim) { @@ -311,27 +308,25 @@ return; } - plot_buf << Vgnuplot_command_end << std::ends; + plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; // Just testing... // char *message = plot_buf.str (); // std::cout << "[*]" << message << "[*]\n"; + std::string message = OSSTREAM_STR (plot_buf); + if (parametric_plot && ndim == 2) { warning ("can't make 2D parametric plot -- setting noparametric..."); send_to_plot_stream ("set noparametric\n"); - char *message = plot_buf.str (); send_to_plot_stream (message); - delete [] message; send_to_plot_stream ("set parametric\n"); } else - { - char *message = plot_buf.str (); - send_to_plot_stream (message); - delete [] message; - } + send_to_plot_stream (message); + + OSSTREAM_FREEZE (plot_buf); } void @@ -348,7 +343,7 @@ } void -plot_limits::print (int ndim, std::ostrstream& plot_buf) +plot_limits::print (int ndim, OSSTREAM& plot_buf) { if (ndim == 2 || ndim == 3) { @@ -380,7 +375,7 @@ } void -plot_range::print (std::ostrstream& plot_buf) +plot_range::print (OSSTREAM& plot_buf) { plot_buf << " ["; @@ -504,7 +499,7 @@ } int -subplot_using::print (int ndim, int n_max, std::ostrstream& plot_buf) +subplot_using::print (int ndim, int n_max, OSSTREAM& plot_buf) { int status = eval (ndim, n_max); @@ -537,7 +532,7 @@ } int -subplot_style::print (std::ostrstream& plot_buf) +subplot_style::print (OSSTREAM& plot_buf) { if (! sp_style.empty ()) { @@ -629,7 +624,7 @@ } int -subplot_axes::print (std::ostrstream& plot_buf) +subplot_axes::print (OSSTREAM& plot_buf) { if (! sp_axes.empty ()) plot_buf << " " << Vgnuplot_command_axes << " " << sp_axes; @@ -685,7 +680,7 @@ } int -subplot::handle_plot_data (int ndim, std::ostrstream& plot_buf) +subplot::handle_plot_data (int ndim, OSSTREAM& plot_buf) { if (sp_plot_data) { @@ -772,7 +767,7 @@ } int -subplot::print (int ndim, std::ostrstream& plot_buf) +subplot::print (int ndim, OSSTREAM& plot_buf) { int status = handle_plot_data (ndim, plot_buf); @@ -830,7 +825,7 @@ } int -subplot_list::print (int ndim, std::ostrstream& plot_buf) +subplot_list::print (int ndim, OSSTREAM& plot_buf) { int status = 0; @@ -930,11 +925,11 @@ { if (plot_stream && *plot_stream) { - std::ostrstream plot_buf; - plot_buf << "cd \"" << newdir << "\"" << Vgnuplot_command_end << std::ends; - char *message = plot_buf.str (); - send_to_plot_stream (message); - delete [] message; + OSSTREAM plot_buf; + plot_buf << "cd \"" << newdir << "\"" << Vgnuplot_command_end + << OSSTREAM_ENDS; + send_to_plot_stream (OSSTREAM_STR (plot_buf)); + OSSTREAM_FREEZE (plot_buf); } } @@ -1110,7 +1105,7 @@ if (error_state) return retval; - std::ostrstream plot_buf; + OSSTREAM plot_buf; if (argc > 1) { @@ -1120,15 +1115,16 @@ parametric_plot = false; else if (almost_match ("term", argv[1], 1)) { - delete [] gnuplot_terminal_type; - std::ostrstream buf; + gnuplot_terminal_type = ""; + OSSTREAM buf; int i; for (i = 2; i < argc-1; i++) buf << argv[i] << " "; if (i < argc) buf << argv[i]; - buf << Vgnuplot_command_end << std::ends; - gnuplot_terminal_type = buf.str (); + buf << Vgnuplot_command_end << OSSTREAM_ENDS; + gnuplot_terminal_type = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); } } @@ -1139,12 +1135,11 @@ if (i < argc) plot_buf << argv[i]; - plot_buf << Vgnuplot_command_end << std::ends; + plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; - char *plot_command = plot_buf.str (); - send_to_plot_stream (plot_command); + send_to_plot_stream (OSSTREAM_STR (plot_buf)); - delete [] plot_command; + OSSTREAM_FREEZE (plot_buf); return retval; } @@ -1172,7 +1167,7 @@ if (error_state) return retval; - std::ostrstream plot_buf; + OSSTREAM plot_buf; int i; for (i = 0; i < argc-1; i++) @@ -1180,12 +1175,11 @@ if (i < argc) plot_buf << argv[i]; - plot_buf << Vgnuplot_command_end << std::ends; + plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; - char *plot_command = plot_buf.str (); - send_to_plot_stream (plot_command); + send_to_plot_stream (OSSTREAM_STR (plot_buf)); - delete [] plot_command; + OSSTREAM_FREEZE (plot_buf); return retval; }
--- a/src/pt-plot.h +++ b/src/pt-plot.h @@ -28,7 +28,8 @@ #endif #include <iostream> -#include <strstream> + +#include "lo-sstream.h" class tree_expression; class tree_plot_command; @@ -100,7 +101,7 @@ ~plot_limits (void); - void print (int ndim, std::ostrstream& plot_buf); + void print (int ndim, OSSTREAM& plot_buf); plot_range *x_limits (void) { return x_range; } plot_range *y_limits (void) { return y_range; } @@ -133,7 +134,7 @@ ~plot_range (void); - void print (std::ostrstream& plot_buf); + void print (OSSTREAM& plot_buf); tree_expression *lower_bound (void) { return lower; } @@ -188,7 +189,7 @@ ColumnVector values (int ndim, int n_max = 0); - int print (int ndim, int n_max, std::ostrstream& plot_buf); + int print (int ndim, int n_max, OSSTREAM& plot_buf); int qualifier_count (void) { return qual_count; } @@ -233,7 +234,7 @@ ~subplot_style (void); - int print (std::ostrstream& plot_buf); + int print (OSSTREAM& plot_buf); bool columns_ok (int nc); @@ -273,7 +274,7 @@ ~subplot_axes (void) { } - int print (std::ostrstream& plot_buf); + int print (OSSTREAM& plot_buf); std::string axes (void) { return sp_axes; } @@ -354,9 +355,9 @@ octave_value extract_plot_data (int ndim, octave_value& data); - int handle_plot_data (int ndim, std::ostrstream& plot_buf); + int handle_plot_data (int ndim, OSSTREAM& plot_buf); - int print (int ndim, std::ostrstream& plot_buf); + int print (int ndim, OSSTREAM& plot_buf); tree_expression *plot_data (void) { return sp_plot_data; } @@ -407,7 +408,7 @@ ~subplot_list (void); - int print (int ndim, std::ostrstream& plot_buf); + int print (int ndim, OSSTREAM& plot_buf); void accept (tree_walker& tw);
--- a/src/pt.cc +++ b/src/pt.cc @@ -29,9 +29,10 @@ #endif #include <iostream> -#include <strstream> #include <string> +#include "lo-sstream.h" + #include "pt.h" #include "pt-pr-code.h" @@ -53,19 +54,17 @@ std::string tree::str_print_code (void) { - std::ostrstream buf; + OSSTREAM buf; tree_print_code tpc (buf); accept (tpc); - buf << std::ends; - - const char *s = buf.str (); + buf << OSSTREAM_ENDS; - std::string retval = s; + std::string retval = OSSTREAM_STR (buf); - delete [] s; + OSSTREAM_FREEZE (buf); return retval; }
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -30,7 +30,6 @@ #include <fstream> #include <iostream> -#include <strstream> #include <string> #ifdef HAVE_UNISTD_H @@ -49,6 +48,7 @@ #include "file-ops.h" #include "lo-error.h" #include "lo-mappers.h" +#include "lo-sstream.h" #include "oct-env.h" #include "str-vec.h" @@ -341,7 +341,7 @@ if (*cmd) { - std::ostrstream output_buf; + OSSTREAM output_buf; // XXX FIXME XXX -- sometimes, the subprocess hasn't written // anything before we try to read from the procstream. The @@ -373,14 +373,12 @@ else cmd_status = 127; - output_buf << std::ends; - - char *msg = output_buf.str (); + output_buf << OSSTREAM_ENDS; retval(1) = (double) cmd_status; - retval(0) = msg; + retval(0) = OSSTREAM_STR (output_buf); - delete [] msg; + OSSTREAM_FREEZE (output_buf); } unwind_protect::run ();
--- a/src/utils.cc +++ b/src/utils.cc @@ -30,7 +30,6 @@ #include <fstream> #include <iostream> -#include <strstream> #include <string> #ifdef HAVE_UNISTD_H @@ -60,6 +59,7 @@ #include "dir-ops.h" #include "file-ops.h" #include "file-stat.h" +#include "lo-sstream.h" #include "oct-cmplx.h" #include "oct-env.h" #include "pathsearch.h" @@ -727,19 +727,19 @@ #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY - std::ostrstream buf; + OSSTREAM buf; buf.vform (fmt, args); - buf << std::ends; + buf << OSSTREAM_ENDS; - char *s = buf.str (); + std::string s = OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); os << s; - retval = strlen (s); - - delete [] s; + retval = s.length (); #else