Mercurial > hg > octave-nkf
annotate scripts/path/savepath.m @ 20787:40ed9b46a800
new octave_value::string_value method with optional error message
* ov.h (octave_value::string_vector): New method.
ov-base.cc, ov-base.h (octave_base_value::string_vector):
New default method.
ov-str-mat.cc, ov-str-mat.h (octave_char_matrix_str::string_value):
New method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 16:43:22 -0400 |
parents | 76f67400649e |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19794
diff
changeset
|
1 ## Copyright (C) 2005-2015 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 |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
189 |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
190 %!test |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 %! fname = tempname (); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
192 %! status = savepath (fname); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
193 %! assert (status == 0); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
194 %! old_dir = pwd; |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 %! unwind_protect |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 %! cd (P_tmpdir); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 %! if (exist (fullfile (pwd, ".octaverc"))) |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
198 %! unlink (".octaverc"); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
199 %! endif |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
200 %! ## Create blank .octaverc file |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19733
diff
changeset
|
201 %! fid = fopen (".octaverc", "wt"); |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
202 %! assert (fid >= 0); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
203 %! fclose (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
204 %! ## Save path into local .octaverc file |
20725
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20038
diff
changeset
|
205 %! warning ("off", "Octave:savepath-local", "local"); |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
206 %! status = savepath (); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
207 %! assert (status == 0); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
208 %! ## Compare old and new versions |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
209 %! fid = fopen (fname, "rb"); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 %! assert (fid >= 0); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
211 %! orig_data = fread (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
212 %! fclose (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
213 %! fid = fopen (".octaverc", "rb"); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 %! assert (fid >= 0); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 %! new_data = fread (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
216 %! fclose (fid); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
217 %! assert (orig_data, new_data); |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
218 %! unwind_protect_cleanup |
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
219 %! cd (old_dir); |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19733
diff
changeset
|
220 %! end_unwind_protect |
19530
bb8d3f17248d
Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 |