Mercurial > hg > octave-nkf
diff src/strfns.cc @ 5690:161ebd1f3410
[project @ 2006-03-17 06:17:24 by jwe]
author | jwe |
---|---|
date | Fri, 17 Mar 2006 06:17:25 +0000 |
parents | 86adc85cc471 |
children | 6286c96121c2 |
line wrap: on
line diff
--- a/src/strfns.cc +++ b/src/strfns.cc @@ -373,6 +373,56 @@ return retval; } +DEFUN (list_in_columns, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} list_in_columns (@var{arg}, @var{width})\n\ +Return a string containing the elements of @var{arg} listed in\n\ +columns with an overall maximum width of @var{width}. The argument\n\ +@var{arg} must be a cell array of character strings or a character array.\n\ +If @var{width} is not specified, the width of the terminal screen is used.\n\ +@seealso{terminal_size}\n\ +@end deftypefn") +{ + octave_value retval; + + int nargin = args.length (); + + if (nargin == 1 || nargin == 2) + { + string_vector s = args(0).all_strings (); + + if (! error_state) + { + OSSTREAM buf; + + if (nargin == 1) + // Let list_in_columns query terminal width. + s.list_in_columns (buf); + else + { + int width = args(1).int_value (); + + if (! error_state) + s.list_in_columns (buf, width); + else + error ("list_in_columns: expecting width to be an integer"); + } + + buf << OSSTREAM_ENDS; + + retval = OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); + } + else + error ("list_in_columns: expecting cellstr or char array"); + } + else + print_usage ("list_in_columns"); + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***