comparison scripts/path/savepath.m @ 8608:5cc1fba0a7d6

style and ChangeLog fixes
author John W. Eaton <jwe@octave.org>
date Tue, 27 Jan 2009 22:59:51 -0500
parents 31ab3b83bc8a
children fcf762ba66cf
comparison
equal deleted inserted replaced
8607:08331c2fb00f 8608:5cc1fba0a7d6
35 35
36 beginstring = "## Begin savepath auto-created section, do not edit"; 36 beginstring = "## Begin savepath auto-created section, do not edit";
37 endstring = "## End savepath auto-created section"; 37 endstring = "## End savepath auto-created section";
38 38
39 if (nargin == 0) 39 if (nargin == 0)
40 savefile = ["~", filesep, ".octaverc"]; 40 savefile = fullfile ("~", ".octaverc");
41 endif 41 endif
42 42
43 ## parse the file if it exists to see if we should replace a section 43 ## parse the file if it exists to see if we should replace a section
44 ## or create a section 44 ## or create a section
45 startline = 0; 45 startline = 0;
92 pre = filelines; 92 pre = filelines;
93 post = {}; 93 post = {};
94 elseif (startline == 1) 94 elseif (startline == 1)
95 pre = {}; 95 pre = {};
96 post = filelines(endline+1:end); 96 post = filelines(endline+1:end);
97 elseif (endline == length(filelines)) 97 elseif (endline == length (filelines))
98 pre = filelines(1:startline-1); 98 pre = filelines(1:startline-1);
99 post = {}; 99 post = {};
100 else 100 else
101 ## insert in the middle 101 ## insert in the middle
102 pre = filelines(1:startline-1); 102 pre = filelines(1:startline-1);
127 else 127 else
128 [tmp, n] = setdiff (workingpath, union (command_line_path, octave_path)); 128 [tmp, n] = setdiff (workingpath, union (command_line_path, octave_path));
129 default_path = parsepath (pathdef ()); 129 default_path = parsepath (pathdef ());
130 endif 130 endif
131 ## This is the path we'd like to preserve when octave is run. 131 ## This is the path we'd like to preserve when octave is run.
132 path_to_preserve = workingpath(sort(n)); 132 path_to_preserve = workingpath (sort (n));
133 133
134 ## Determine the path to Octave's user and sytem wide pkgs. 134 ## Determine the path to Octave's user and sytem wide pkgs.
135 [pkg_user, pkg_system] = pkg ("list"); 135 [pkg_user, pkg_system] = pkg ("list");
136 pkg_user_path = cell (1, numel (pkg_user)); 136 pkg_user_path = cell (1, numel (pkg_user));
137 pkg_system_path = cell (1, numel (pkg_system)); 137 pkg_system_path = cell (1, numel (pkg_system));
144 pkg_path = union (pkg_user_path, pkg_system_path); 144 pkg_path = union (pkg_user_path, pkg_system_path);
145 145
146 ## Rely on Octave's initialization to include the pkg path elements. 146 ## Rely on Octave's initialization to include the pkg path elements.
147 if (! isempty (pkg_path)) 147 if (! isempty (pkg_path))
148 [tmp, n] = setdiff (path_to_preserve, strcat (pkg_path, ":")); 148 [tmp, n] = setdiff (path_to_preserve, strcat (pkg_path, ":"));
149 path_to_preserve = path_to_preserve(sort(n)); 149 path_to_preserve = path_to_preserve (sort (n));
150 endif 150 endif
151 151
152 ## Split the path to be saved into two groups. Those path elements that 152 ## Split the path to be saved into two groups. Those path elements that
153 ## belong at the beginning and those at the end. 153 ## belong at the beginning and those at the end.
154 if (! isempty (default_path)) 154 if (! isempty (default_path))
155 n1 = strmatch (default_path{1}, path_to_preserve, "exact"); 155 n1 = strmatch (default_path{1}, path_to_preserve, "exact");
156 n2 = strmatch (default_path{end}, path_to_preserve, "exact"); 156 n2 = strmatch (default_path{end}, path_to_preserve, "exact");
157 n_middle = round (0.5*(n1+n2)); 157 n_middle = round (0.5*(n1+n2));
158 [tmp, n] = setdiff (path_to_preserve, default_path); 158 [tmp, n] = setdiff (path_to_preserve, default_path);
159 path_to_save = path_to_preserve(sort (n)); 159 path_to_save = path_to_preserve (sort (n));
160 ## Remove pwd 160 ## Remove pwd
161 path_to_save = path_to_save (! strcmpi (path_to_save, strcat (".", pathsep))); 161 path_to_save = path_to_save (! strcmpi (path_to_save,
162 strcat (".", pathsep)));
162 n = ones (size (path_to_save)); 163 n = ones (size (path_to_save));
163 for m = 1:numel(path_to_save) 164 for m = 1:numel(path_to_save)
164 n(m) = strmatch (path_to_save{m}, path_to_preserve); 165 n(m) = strmatch (path_to_save{m}, path_to_preserve);
165 endfor 166 endfor
166 path_to_save_begin = path_to_save(n <= n_middle); 167 path_to_save_begin = path_to_save(n <= n_middle);