Mercurial > octave
changeset 19211:bbb1fbd900d4
ls.m: Return Matlab compatible output when called with functional form.
* ls.m: Return a char array with multiple files per row when called in
functional form. This is identical to output when called with command
form. Allow multiple arguments to be bundled into a single string in
functional calling form. Add BIST tests for this on UNIX platforms.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 04 Oct 2014 19:34:30 -0700 |
parents | 841d8f606bcd |
children | b85d4930528d |
files | scripts/miscellaneous/ls.m |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/ls.m Sat Oct 04 11:48:06 2014 -0700 +++ b/scripts/miscellaneous/ls.m Sat Oct 04 19:34:30 2014 -0700 @@ -76,6 +76,10 @@ else ## Escape any special characters in filename args = regexprep (args, '([^][\w.*?-])', '\\$1'); + ## Undo escaped spaces following command args + ## Only used for command form where single str contains many args. + ## Example: list = ls ("-l /usr/bin") + args = regexprep (args, '(-\w+)(?:\\ )+', '$1 '); endif args = sprintf ("%s ", args{:}); else @@ -92,7 +96,7 @@ elseif (nargout == 0) puts (output); else - retval = strvcat (regexp (output, '\S+', 'match'){:}); + retval = strvcat (regexp (output, "[\r\n]+", "split"){:}); endif else ## Just let the output flow if the pager is off. That way the @@ -109,6 +113,17 @@ %! assert (ischar (list)); %! assert (! isempty (list)); +%!test +%! if (isunix ()) +%! list = ls ("/"); +%! list = (list')(:)'; # transform to a single row vector +%! assert (! isempty (strfind (list, "sbin"))); +%! list2 = ls ("-l /"); +%! list2 = (list2')(:)'; # transform to a single row vector +%! assert (! isempty (strfind (list2, "sbin"))); +%! assert (rows (list) == rows (list2)); +%! endif + %!error <all arguments must be character strings> ls (1) ## Test below is valid, but produces confusing output on screen %!#error <command exited abnormally> ls ("-!")