annotate scripts/path/savepath.m @ 19631:db92e7e28e1f

strip trailing whitespace from most source files * NEWS, doc/interpreter/contributors.in, doc/interpreter/func.txi, doc/interpreter/genpropdoc.m, doc/interpreter/octave_logo.eps, doc/interpreter/plot.txi, doc/interpreter/stmt.txi, examples/data/Makefile.am, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/load-path.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/variables.cc, libinterp/octave-value/ov-classdef.cc, libinterp/octave-value/ov-classdef.h, libinterp/octave.cc, libinterp/parse-tree/lex.h, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/pt-classdef.h, liboctave/system/file-ops.cc, liboctave/system/oct-env.cc, m4/acinclude.m4, scripts/deprecated/finite.m, scripts/deprecated/fmod.m, scripts/deprecated/fnmatch.m, scripts/deprecated/luinc.m, scripts/deprecated/octave_tmp_file_name.m, scripts/deprecated/syl.m, scripts/deprecated/usage.m, scripts/general/inputParser.m, scripts/general/interp1.m, scripts/general/interp2.m, scripts/general/interp3.m, scripts/general/isequal.m, scripts/general/private/__isequal__.m, scripts/geometry/voronoi.m, scripts/image/image.m, scripts/image/imshow.m, scripts/image/ind2rgb.m, scripts/linear-algebra/bandwidth.m, scripts/linear-algebra/isbanded.m, scripts/miscellaneous/bzip2.m, scripts/miscellaneous/cast.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/delete.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/getappdata.m, scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isappdata.m, scripts/miscellaneous/ls.m, scripts/miscellaneous/mex.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/orderfields.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/setfield.m, scripts/miscellaneous/symvar.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/ver.m, scripts/miscellaneous/what.m, scripts/miscellaneous/xor.m, scripts/miscellaneous/zip.m, scripts/optimization/fminbnd.m, scripts/optimization/sqp.m, scripts/path/private/getsavepath.m, scripts/path/savepath.m, scripts/pkg/pkg.m, scripts/pkg/private/installed_packages.m, scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m, scripts/plot/draw/private/__quiver__.m, scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m, scripts/plot/draw/surface.m, scripts/plot/draw/surfnorm.m, scripts/plot/util/copyobj.m, scripts/plot/util/hgload.m, scripts/plot/util/hgsave.m, scripts/plot/util/isprop.m, scripts/plot/util/linkprop.m, scripts/plot/util/private/__go_draw_axes__.m, scripts/set/setdiff.m, scripts/set/union.m, scripts/signal/periodogram.m, scripts/sparse/eigs.m, scripts/sparse/ilu.m, scripts/sparse/qmr.m, scripts/sparse/sprand.m, scripts/sparse/sprandn.m, scripts/specfun/beta.m, scripts/specfun/ellipke.m, scripts/specfun/isprime.m, scripts/statistics/base/lscov.m, scripts/testfun/__run_test_suite__.m, scripts/testfun/test.m: Strip trailing whitespace.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:29:54 -0500
parents ffbd2cc7ca91
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 14216
diff changeset
1 ## Copyright (C) 2005-2013 Bill Denney
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
2 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
4 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
8 ## your option) any later version.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
9 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
14 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
18
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
20 ## @deftypefn {Function File} {} savepath ()
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {} savepath (@var{file})
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
22 ## @deftypefnx {Function File} {@var{status} =} savepath (@dots{})
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## Save the unique portion of the current function search path that is
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
24 ## not set during Octave's initialization process to @var{file}.
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ##
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
26 ## If @var{file} is omitted, Octave looks in the current directory for a
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ## project-specific @file{.octaverc} file in which to save the path
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ## information. If no such file is present then the user's configuration file
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## @file{~/.octaverc} is used.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ##
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## If successful, @code{savepath} returns 0.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ##
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ## The @code{savepath} function makes it simple to customize a user's
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
34 ## configuration file to restore the working paths necessary for a particular
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
35 ## instance of Octave. Assuming no filename is specified, Octave will
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
36 ## automatically restore the saved directory paths from the appropriate
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## @file{.octaverc} file when starting up. If a filename has been specified
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
38 ## then the paths may be restored manually by calling @code{source @var{file}}.
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
39 ## @seealso{path, addpath, rmpath, genpath, pathdef}
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
40 ## @end deftypefn
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
41
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
42 ## Author: Bill Denney <bill@givebillmoney.com>
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
43
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 function retval = savepath (file)
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
45
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
46 beginstring = "## Begin savepath auto-created section, do not edit";
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
47 endstring = "## End savepath auto-created section";
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
48
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19570
diff changeset
49 ## Use project-specific or user's .octaverc when no file specified
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
50 if (nargin == 0)
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
51 file = fullfile (pwd, ".octaverc");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 if (! exist (file, "file"))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 file = fullfile ("~", ".octaverc");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
54 endif
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
55 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
56
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
57 ## Read in the file
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
58 [filelines, startline, endline] = getsavepath (file);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
59
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
60 ## Determine where the savepath lines are placed in the file.
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
61 if (isempty (filelines)
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
62 || (startline == 1 && endline == length (filelines)))
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
63 ## savepath is the entire file.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
64 pre = post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
65 elseif (endline == 0)
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
66 ## Drop the savepath statements at the end of the file.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
67 pre = filelines;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
68 post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
69 elseif (startline == 1)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
70 pre = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
71 post = filelines(endline+1:end);
8608
5cc1fba0a7d6 style and ChangeLog fixes
John W. Eaton <jwe@octave.org>
parents: 8586
diff changeset
72 elseif (endline == length (filelines))
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
73 pre = filelines(1:startline-1);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
74 post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
75 else
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
76 ## Insert in the middle.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
77 pre = filelines(1:startline-1);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
78 post = filelines(endline+1:end);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
79 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
80
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
81 ## Write the results.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
82 [fid, msg] = fopen (file, "wt");
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
83 if (fid < 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
84 error ("savepath: unable to open file for writing, %s, %s", file, msg);
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7017
diff changeset
85 endif
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
86 unwind_protect
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
87 fprintf (fid, "%s\n", pre{:});
5736
e07baa8b93b9 [project @ 2006-04-04 19:41:45 by jwe]
jwe
parents: 5735
diff changeset
88
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
89 ## Remove the portion of the path defined via the command line
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
90 ## and/or the environment.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
91 workingpath = parsepath (path);
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
92 cmd_line_path = parsepath (command_line_path ());
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
93 octave_path = parsepath (getenv ("OCTAVE_PATH"));
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
94 default_path = pathdef ();
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
95 if (isempty (default_path))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
96 ## This occurs when running octave via run-octave. In this instance
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
97 ## the entire path is specified via the command line and pathdef()
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
98 ## is empty.
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99 [~, n] = setdiff (workingpath, octave_path);
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
100 default_path = cmd_line_path;
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
101 else
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
102 [~, n] = setdiff (workingpath, union (cmd_line_path, octave_path));
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
103 default_path = parsepath (default_path);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
104 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
105 ## This is the path we'd like to preserve when octave is run.
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
106 path_to_preserve = workingpath(sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
107
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
108 ## Determine the path to Octave's user and system wide packages.
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
109 [pkg_user, pkg_system] = pkg ("list");
19570
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
110
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
111 ## Conversion from cell array of structs to cellstr of archprefixes.
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
112 pkg_path = unique (cellfun (@(elt) elt.archprefix,
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
113 [pkg_user, pkg_system],
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
114 "uniformoutput", false));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
115
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
116 ## Rely on Octave's initialization to include the pkg path elements.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
117 if (! isempty (pkg_path))
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
118 [~, n] = setdiff (path_to_preserve, strcat (pkg_path, ":"));
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
119 path_to_preserve = path_to_preserve(sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
120 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
121
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
122 ## Split the path to be saved into two groups. Those path elements that
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
123 ## belong at the beginning and those at the end.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
124 if (! isempty (default_path))
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
125 n1 = find (strcmp (default_path{1}, path_to_preserve));
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
126 n2 = find (strcmp (default_path{end}, path_to_preserve));
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
127 n_middle = round ((n1+n2)/2);
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
128 [~, n] = setdiff (path_to_preserve, default_path);
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
129 path_to_save = path_to_preserve(sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
130 ## Remove pwd
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
131 path_to_save(strcmp (path_to_save, ["." pathsep])) = [];
19370
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
132 if (! isempty (path_to_save))
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
133 n = ones (numel (path_to_save), 1);
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
134 for m = 1:numel (path_to_save)
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
135 n(m) = find (strcmp (path_to_save{m}, path_to_preserve));
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
136 endfor
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
137 path_to_save_begin = path_to_save(n <= n_middle);
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
138 path_to_save_end = path_to_save(n > n_middle);
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
139 else
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
140 path_to_save_begin = {};
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
141 path_to_save_end = {};
3a905b642408 savepath.m: Fix failing BIST test
Rik <rik@octave.org>
parents: 19369
diff changeset
142 endif
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
143 else
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
144 path_to_save_begin = path_to_preserve;
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
145 path_to_save_end = {};
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
146 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
147 path_to_save_begin = cell2mat (path_to_save_begin);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
148 path_to_save_end = cell2mat (path_to_save_end);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
149
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
150 ## Use single quotes for PATH argument to avoid string escape
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
151 ## processing. Since we are using single quotes around the arg,
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
152 ## double any single quote characters found in the string.
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
153 fprintf (fid, "%s\n", beginstring);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
154 if (! isempty (path_to_save_begin))
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
155 n = find (path_to_save_begin != pathsep, 1, "last");
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
156 fprintf (fid, " addpath ('%s', '-begin');\n",
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
157 strrep (path_to_save_begin(1:n), "'", "''"));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
158 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
159 if (! isempty (path_to_save_end))
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
160 n = find (path_to_save_end != pathsep, 1, "last");
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
161 fprintf (fid, " addpath ('%s', '-end');\n",
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
162 strrep (path_to_save_end(1:n), "'", "''"));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
163 endif
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
164 fprintf (fid, "%s\n", endstring);
5736
e07baa8b93b9 [project @ 2006-04-04 19:41:45 by jwe]
jwe
parents: 5735
diff changeset
165
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
166 fprintf (fid, "%s\n", post{:});
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
167 unwind_protect_cleanup
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
168 status = fclose (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
169 if (status < 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
170 error ("savepath: could not close savefile after writing, %s", file);
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
171 elseif (nargin == 0)
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
172 warning ("off", "backtrace", "local");
19570
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
173 warning ("Octave:savepath-local",
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
174 "savepath: current path saved to %s", file);
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
175 endif
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
176 end_unwind_protect
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
177
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
178 if (nargout > 0)
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
179 retval = 0;
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
180 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
181
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
182 endfunction
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
183
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
184 ## Convert single string of paths to cell array of paths
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
185 function path_elements = parsepath (p)
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
186 path_elements = strcat (ostrsplit (p, pathsep), pathsep);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
187 endfunction
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
188
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
189 %!test
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
190 %! fname = tempname ();
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
191 %! status = savepath (fname);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
192 %! assert (status == 0);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
193 %! old_dir = pwd;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
194 %! unwind_protect
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
195 %! cd (P_tmpdir);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
196 %! if (exist (fullfile (pwd, ".octaverc")))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
197 %! unlink (".octaverc");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
198 %! endif
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
199 %! ## Create blank .octaverc file
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19570
diff changeset
200 %! fid = fopen (".octaverc", "wt");
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
201 %! assert (fid >= 0);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
202 %! fclose (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
203 %! ## Save path into local .octaverc file
19570
ffbd2cc7ca91 savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents: 19370
diff changeset
204 %! warning ("off", "Octave:savepath-local");
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
205 %! status = savepath ();
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
206 %! assert (status == 0);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
207 %! ## Compare old and new versions
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
208 %! fid = fopen (fname, "rb");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
209 %! assert (fid >= 0);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
210 %! orig_data = fread (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
211 %! fclose (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
212 %! fid = fopen (".octaverc", "rb");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
213 %! assert (fid >= 0);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
214 %! new_data = fread (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
215 %! fclose (fid);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
216 %! assert (orig_data, new_data);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
217 %! unwind_protect_cleanup
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
218 %! cd (old_dir);
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19570
diff changeset
219 %! end_unwind_protect
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
220