# HG changeset patch # User John W. Eaton # Date 1424568944 18000 # Node ID bafcfc5b99af40f82c1c351a1728f1015ab16e9b # Parent 81078b0e39e8a49114e3a14b60382f61e05bc5f1 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 "-". diff -r 81078b0e39e8 -r bafcfc5b99af libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Sat Feb 21 18:24:10 2015 -0500 +++ b/libinterp/corefcn/load-save.cc Sat Feb 21 20:35:44 2015 -0500 @@ -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()); + } } }