Mercurial > hg > octave-nkf
annotate scripts/path/savepath.m @ 19794: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 |
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 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5732 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5732 | 18 |
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}. |
19530
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 | 40 ## @end deftypefn |
41 | |
42 ## Author: Bill Denney <bill@givebillmoney.com> | |
43 | |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 function retval = savepath (file) |
5732 | 45 |
46 beginstring = "## Begin savepath auto-created section, do not edit"; | |
47 endstring = "## End savepath auto-created section"; | |
48 | |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19733
diff
changeset
|
49 ## Use project-specific or user's .octaverc when no file specified |
5733 | 50 if (nargin == 0) |
19530
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 | 55 endif |
56 | |
19530
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 | 59 |
19530
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 | 61 if (isempty (filelines) |
62 || (startline == 1 && endline == length (filelines))) | |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 ## savepath is the entire file. |
5732 | 64 pre = post = {}; |
65 elseif (endline == 0) | |
19530
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 | 67 pre = filelines; |
68 post = {}; | |
69 elseif (startline == 1) | |
70 pre = {}; | |
71 post = filelines(endline+1:end); | |
8608 | 72 elseif (endline == length (filelines)) |
5732 | 73 pre = filelines(1:startline-1); |
74 post = {}; | |
75 else | |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 ## Insert in the middle. |
5732 | 77 pre = filelines(1:startline-1); |
78 post = filelines(endline+1:end); | |
79 endif | |
80 | |
19530
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 | 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 | 85 endif |
7392 | 86 unwind_protect |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
87 fprintf (fid, "%s\n", pre{:}); |
5736 | 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); |
19530
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")); |
19530
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); |
19530
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 |
19530
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. |
19530
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 |
19530
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"); |
19733
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
diff
changeset
|
110 |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
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:
19531
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:
19531
diff
changeset
|
113 [pkg_user, pkg_system], |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
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 |
19530
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)); |
19530
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 |
19530
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])) = []; |
19531 | 132 if (! isempty (path_to_save)) |
133 n = ones (numel (path_to_save), 1); | |
134 for m = 1:numel (path_to_save) | |
135 n(m) = find (strcmp (path_to_save{m}, path_to_preserve)); | |
136 endfor | |
137 path_to_save_begin = path_to_save(n <= n_middle); | |
138 path_to_save_end = path_to_save(n > n_middle); | |
139 else | |
140 path_to_save_begin = {}; | |
141 path_to_save_end = {}; | |
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 | 150 ## Use single quotes for PATH argument to avoid string escape |
7393 | 151 ## processing. Since we are using single quotes around the arg, |
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 | 165 |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
166 fprintf (fid, "%s\n", post{:}); |
7392 | 167 unwind_protect_cleanup |
19530
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 | 171 elseif (nargin == 0) |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
172 warning ("off", "backtrace", "local"); |
19733
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
diff
changeset
|
173 warning ("Octave:savepath-local", |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
diff
changeset
|
174 "savepath: current path saved to %s", file); |
7392 | 175 endif |
176 end_unwind_protect | |
5732 | 177 |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
178 if (nargout > 0) |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 retval = 0; |
5732 | 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 |
19530
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) |
19530
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 |
19530
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 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19733
diff
changeset
|
200 %! fid = fopen (".octaverc", "wt"); |
19530
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 |
19733
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19531
diff
changeset
|
204 %! warning ("off", "Octave:savepath-local"); |
19530
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); |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19733
diff
changeset
|
219 %! end_unwind_protect |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
220 |