Mercurial > octave
annotate scripts/path/savepath.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 7854d5752dd2 |
children | 5d3faba0342e |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 2005-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5732 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5732 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
13 ## (at your option) any later version. |
5732 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
18 ## GNU General Public License for more details. |
5732 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5732 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
27 ## @deftypefn {} {} savepath () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
28 ## @deftypefnx {} {} savepath (@var{file}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
29 ## @deftypefnx {} {@var{status} =} savepath (@dots{}) |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
30 ## 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
|
31 ## not set during Octave's initialization process to @var{file}. |
19335
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 ## 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
|
34 ## 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
|
35 ## 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
|
36 ## @file{~/.octaverc} is used. |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 ## |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 ## If successful, @code{savepath} returns 0. |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 ## |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 ## 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
|
41 ## 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
|
42 ## 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
|
43 ## 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
|
44 ## @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
|
45 ## 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
|
46 ## @seealso{path, addpath, rmpath, genpath, pathdef} |
5732 | 47 ## @end deftypefn |
48 | |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
49 function retval = savepath (file) |
5732 | 50 |
51 beginstring = "## Begin savepath auto-created section, do not edit"; | |
52 endstring = "## End savepath auto-created section"; | |
53 | |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19536
diff
changeset
|
54 ## Use project-specific or user's .octaverc when no file specified |
5733 | 55 if (nargin == 0) |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 file = fullfile (pwd, ".octaverc"); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 if (! exist (file, "file")) |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 file = fullfile ("~", ".octaverc"); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 endif |
5732 | 60 endif |
61 | |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 ## Read in the file |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 [filelines, startline, endline] = getsavepath (file); |
5732 | 64 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 ## Determine where the savepath lines are placed in the file. |
5733 | 66 if (isempty (filelines) |
67 || (startline == 1 && endline == length (filelines))) | |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 ## savepath is the entire file. |
5732 | 69 pre = post = {}; |
70 elseif (endline == 0) | |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 ## Drop the savepath statements at the end of the file. |
5732 | 72 pre = filelines; |
73 post = {}; | |
74 elseif (startline == 1) | |
75 pre = {}; | |
76 post = filelines(endline+1:end); | |
8608 | 77 elseif (endline == length (filelines)) |
5732 | 78 pre = filelines(1:startline-1); |
79 post = {}; | |
80 else | |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 ## Insert in the middle. |
5732 | 82 pre = filelines(1:startline-1); |
83 post = filelines(endline+1:end); | |
84 endif | |
85 | |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 ## 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
|
87 [fid, msg] = fopen (file, "wt"); |
5732 | 88 if (fid < 0) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
89 error ("savepath: unable to open FILE for writing, %s, %s", file, msg); |
7151 | 90 endif |
7392 | 91 unwind_protect |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 fprintf (fid, "%s\n", pre{:}); |
5736 | 93 |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
94 ## 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
|
95 ## and/or the environment. |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
96 workingpath = parsepath (path); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 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
|
98 octave_path = parsepath (getenv ("OCTAVE_PATH")); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 default_path = pathdef (); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 if (isempty (default_path)) |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
101 ## 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
|
102 ## 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
|
103 ## is empty. |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 [~, n] = setdiff (workingpath, octave_path); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 default_path = cmd_line_path; |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
106 else |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 [~, 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
|
108 default_path = parsepath (default_path); |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
109 endif |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
110 ## This is the path we'd like to preserve when octave is run. |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 path_to_preserve = workingpath(sort (n)); |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
112 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 ## 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
|
114 [pkg_user, pkg_system] = pkg ("list"); |
19536
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
115 |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
116 ## 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:
19336
diff
changeset
|
117 pkg_path = unique (cellfun (@(elt) elt.archprefix, |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
118 [pkg_user, pkg_system], |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
119 "uniformoutput", false)); |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
120 |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
121 ## 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
|
122 if (! isempty (pkg_path)) |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
123 [~, n] = setdiff (path_to_preserve, strcat (pkg_path, ":")); |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 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
|
125 endif |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
126 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 ## 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
|
128 ## 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
|
129 if (! isempty (default_path)) |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
130 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
|
131 n2 = find (strcmp (default_path{end}, path_to_preserve)); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 n_middle = round ((n1+n2)/2); |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
133 [~, n] = setdiff (path_to_preserve, default_path); |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
134 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
|
135 ## Remove pwd |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
136 path_to_save(strcmp (path_to_save, ["." pathsep])) = []; |
19336 | 137 if (! isempty (path_to_save)) |
138 n = ones (numel (path_to_save), 1); | |
139 for m = 1:numel (path_to_save) | |
140 n(m) = find (strcmp (path_to_save{m}, path_to_preserve)); | |
141 endfor | |
142 path_to_save_begin = path_to_save(n <= n_middle); | |
143 path_to_save_end = path_to_save(n > n_middle); | |
144 else | |
145 path_to_save_begin = {}; | |
146 path_to_save_end = {}; | |
147 endif | |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
148 else |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
149 path_to_save_begin = path_to_preserve; |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
150 path_to_save_end = {}; |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
151 endif |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
152 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
|
153 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
|
154 |
7392 | 155 ## Use single quotes for PATH argument to avoid string escape |
7393 | 156 ## processing. Since we are using single quotes around the arg, |
157 ## 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
|
158 fprintf (fid, "%s\n", beginstring); |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
159 if (! isempty (path_to_save_begin)) |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
160 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
|
161 fprintf (fid, " addpath ('%s', '-begin');\n", |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
162 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
|
163 endif |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
164 if (! isempty (path_to_save_end)) |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
165 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
|
166 fprintf (fid, " addpath ('%s', '-end');\n", |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
167 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
|
168 endif |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
169 fprintf (fid, "%s\n", endstring); |
5736 | 170 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
171 fprintf (fid, "%s\n", post{:}); |
7392 | 172 unwind_protect_cleanup |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
173 status = fclose (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 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
|
175 error ("savepath: could not close savefile after writing, %s", file); |
7392 | 176 elseif (nargin == 0) |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 warning ("off", "backtrace", "local"); |
19536
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
178 warning ("Octave:savepath-local", |
ffbd2cc7ca91
savepath: avoid possible error in struct concatenation
John W. Eaton <jwe@octave.org>
parents:
19336
diff
changeset
|
179 "savepath: current path saved to %s", file); |
7392 | 180 endif |
181 end_unwind_protect | |
5732 | 182 |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
183 if (nargout > 0) |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
184 retval = 0; |
5732 | 185 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
186 |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
187 endfunction |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
188 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
189 ## 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
|
190 function path_elements = parsepath (p) |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 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
|
192 endfunction |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
7393
diff
changeset
|
193 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
194 |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 %!test |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 %! fname = tempname (); |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
197 %! test_dir = tempname (); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
198 %! unwind_protect |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
199 %! if (! mkdir (test_dir)) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
200 %! error ("unable to create directory for tests"); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
201 %! endif |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
202 %! status = savepath (fname); |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
203 %! assert (status == 0); |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
204 %! old_dir = pwd (); |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
205 %! unwind_protect |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
206 %! cd (test_dir); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
207 %! if (exist (fullfile (pwd, ".octaverc"))) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
208 %! unlink (".octaverc"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
209 %! endif |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
210 %! ## Create blank .octaverc file |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
211 %! fid = fopen (".octaverc", "wt"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
212 %! assert (fid >= 0); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
213 %! fclose (fid); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
214 %! ## Save path into local .octaverc file |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
215 %! warning ("off", "Octave:savepath-local", "local"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
216 %! status = savepath (); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
217 %! assert (status == 0); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
218 %! ## Compare old and new versions |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
219 %! fid = fopen (fname, "rb"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
220 %! assert (fid >= 0); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
221 %! orig_data = fread (fid); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
222 %! fclose (fid); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
223 %! fid = fopen (".octaverc", "rb"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
224 %! assert (fid >= 0); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
225 %! new_data = fread (fid); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
226 %! fclose (fid); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
227 %! assert (orig_data, new_data); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
228 %! unwind_protect_cleanup |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
229 %! cd (old_dir); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
230 %! end_unwind_protect |
19335
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 %! unwind_protect_cleanup |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
232 %! confirm_recursive_rmdir (false, "local"); |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
233 %! sts = rmdir (test_dir, "s"); |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22323
diff
changeset
|
234 %! unlink (fname); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19536
diff
changeset
|
235 %! end_unwind_protect |