Mercurial > hg > octave-nkf
changeset 20022:bafcfc5b99af
if save file name is "-" and nargout is 0, write to stdout
* load-save.cc (Fsave): If save file name is "-" and nargout is 0,
write to stdout. Update doc string to mention file name of "-".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 21 Feb 2015 20:35:44 -0500 |
parents | 81078b0e39e8 |
children | 85d9cb769e8b |
files | libinterp/corefcn/load-save.cc |
diffstat | 1 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc +++ b/libinterp/corefcn/load-save.cc @@ -1476,13 +1476,14 @@ } } -DEFUN (save, args, , +DEFUN (save, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Command} {} save file\n\ @deftypefnx {Command} {} save options file\n\ @deftypefnx {Command} {} save options file @var{v1} @var{v2} @dots{}\n\ @deftypefnx {Command} {} save options file -struct @var{STRUCT} @var{f1} @var{f2} @dots{}\n\ -@deftypefnx {Command} {} {@var{s} =} save @samp{-} @var{v1} @var{v2} @dots{}\n\ +@deftypefnx {Command} {} save @code{\"-\"} @var{v1} @var{v2} @dots{}\n\ +@deftypefnx {Built-in Function} {@var{s} =} save (@code{\"-\"} @var{v1} @var{v2} @dots{})\n\ Save the named variables @var{v1}, @var{v2}, @dots{}, in the file\n\ @var{file}. The special filename @samp{-} may be used to return the\n\ content of the variables as a string. If no variable names are listed,\n\ @@ -1504,6 +1505,9 @@ then the @var{options}, @var{file}, and variable name arguments\n\ (@var{v1}, @dots{}) must be specified as character strings.\n\ \n\ +If called with a filename of @qcode{\"-\"}, write the output to stdout\n\ +if nargout is 0, otherwise return the output in a character string.\n\ +\n\ @table @code\n\ @item -append\n\ Append to the destination instead of overwriting.\n\ @@ -1659,10 +1663,14 @@ if (append) warning ("save: ignoring -append option for output to stdout"); - std::ostringstream output_buf; - save_vars (argv, i, argc, output_buf, format, - save_as_floats, true); - retval = octave_value (output_buf.str()); + if (nargout == 0) + save_vars (argv, i, argc, std::cout, format, save_as_floats, true); + else + { + std::ostringstream output_buf; + save_vars (argv, i, argc, output_buf, format, save_as_floats, true); + retval = octave_value (output_buf.str()); + } } }