Mercurial > hg > octave-lojdl
changeset 9266:1d3b91166b9c
allow pathsep to be set
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 May 2009 17:20:07 -0400 |
parents | 7f3a1a90f4f4 |
children | cf4683ff0b2c |
files | ChangeLog liboctave/pathsearch.h src/dirfns.cc |
diffstat | 3 files changed, 51 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-05-26 John W. Eaton <jwe@octave.org> + + * src/dirfns.cc (Fpathsep): Allow path separator to be set. + 2009-03-17 Thomas Weber <thomas.weber.mail at gmail.com> * configure.in: fix typo with regards to termios.h
--- a/liboctave/pathsearch.h +++ b/liboctave/pathsearch.h @@ -88,6 +88,11 @@ return static_members::path_sep_char (); } + static void path_sep_char (char c) + { + static_members::path_sep_char (c); + } + static std::string path_sep_str (void) { return static_members::path_sep_str (); @@ -131,6 +136,15 @@ return instance_ok () ? instance->xpath_sep_char : 0; } + static void path_sep_char (char c) + { + if (instance_ok ()) + { + instance->xpath_sep_char = c; + instance->xpath_sep_str = std::string (1, c); + } + } + static std::string path_sep_str (void) { return instance_ok () ? instance->xpath_sep_str : std::string ();
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -671,19 +671,47 @@ return retval; } -DEFUN (pathsep, args, , +DEFUN (pathsep, args, nargout, "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} pathsep ()\n\ -Return the system-dependent character used to separate directories in\n\ +@deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\ +@deftypefn {Built-in Function} {@var{old_val} =} pathsep (@var{new_val})\n\ +Query or set the character used to separate directories in\n\ a path.\n\ @seealso{filesep, dir, ls}\n\ @end deftypefn") { octave_value retval; - if (args.length () == 0) + int nargin = args.length (); + + if (nargout > 0 || nargin == 0) retval = dir_path::path_sep_str (); - else + + if (nargin == 1) + { + std::string sval = args(0).string_value (); + + if (! error_state) + { + switch (sval.length ()) + { + case 1: + dir_path::path_sep_char (sval[0]); + break; + + case 0: + dir_path::path_sep_char ('\0'); + break; + + default: + error ("pathsep: argument must be a single character"); + break; + } + } + else + error ("pathsep: argument must be a single character"); + } + else if (nargin > 1) print_usage (); return retval;