# HG changeset patch # User Rik # Date 1466384647 25200 # Node ID c46e2532d4218b6fd3ebeb284b64c1cb48f60b8b # Parent a5924b0cbf4283b007412093b3760fe2029363c8 Add directories through addpath in the correct order (bug #48247). * load-path.cc (Faddpath): Copy input args to function into local variable arglist. Reverse arglist if 'append' option is given. diff -r a5924b0cbf42 -r c46e2532d421 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Sun Jun 19 06:23:54 2016 -0700 +++ b/libinterp/corefcn/load-path.cc Sun Jun 19 18:04:07 2016 -0700 @@ -2402,8 +2402,8 @@ @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ @end deftypefn") { - // Originally written by Bill Denney and Etienne Grossman. Heavily - // modified and translated to C++ by jwe. + // Originally written by Bill Denney and Etienne Grossman. + // Heavily modified and translated to C++ by jwe. int nargin = args.length (); @@ -2448,20 +2448,22 @@ bool need_to_update = false; - for (int i = 0; i < nargin; i++) + octave_value_list arglist (args.slice (0, nargin)); + if (! append) + arglist.reverse (); + + for (int i = 0; i < arglist.length (); i++) { - std::string arg = args(i).xstring_value ("addpath: all arguments must be strings"); + std::string arg = arglist(i).xstring_value ("addpath: all arguments must be strings"); std::list dir_elts = split_path (arg); if (! append) std::reverse (dir_elts.begin (), dir_elts.end ()); - for (std::list::const_iterator p = dir_elts.begin (); - p != dir_elts.end (); - p++) + for (const auto& p : dir_elts) { - std::string dir = *p; + std::string dir = p; //dir = regexprep (dir_elts{j}, '//+', "/"); //dir = regexprep (dir, '/$', "");