7388
|
1 ## Copyright (C) 2008 Ben Abbott |
|
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 |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {@var{val} =} pathdef () |
|
21 ## Return the default path for Octave. |
|
22 ## The path information is extracted from one of three sources. |
|
23 ## In order of preference, those are; |
|
24 ## |
|
25 ## @enumerate |
|
26 ## @item @file{~/.octaverc} |
|
27 ## @item @file{<octave-home>/.../<version>/m/startup/octaverc} |
|
28 ## @item Octave's path prior to changes by any octaverc. |
|
29 ## @end enumerate |
|
30 ## @seealso{path, addpath, rmpath, genpath, savepath, pathsep} |
|
31 ## @end deftypefn |
|
32 |
|
33 function val = pathdef () |
|
34 |
|
35 ## Save the path present when called. This will be used to restore |
|
36 ## path when done. |
|
37 presentpath = path; |
|
38 |
|
39 ## Use Octave's orignal path as the default default. |
|
40 val = __pathorig__; |
|
41 |
|
42 ## Locate the site octaverc file (is there a better way?). |
|
43 prestr = [OCTAVE_HOME, filesep]; |
|
44 poststr = [filesep, version, filesep, 'm', filesep', 'startup']; |
|
45 ncolon = [0, strfind(presentpath,':'), numel(presentpath)+1]; |
|
46 site_octaverc = ''; |
|
47 for nc = 1:(numel(ncolon)-1) |
|
48 pathdir = presentpath((ncolon(nc)+1):(ncolon(nc+1)-1)); |
|
49 npre = strfind (pathdir, prestr); |
|
50 npost = strfind (pathdir, poststr); |
|
51 if (npre == 1 && |
|
52 npost > numel (prestr) && |
|
53 npost == numel (pathdir) - numel (poststr)+1) |
|
54 site_octaverc = [pathdir, filesep, 'octaverc']; |
|
55 break; |
|
56 endif |
|
57 endfor |
|
58 if isempty (site_octaverc) || ~exist (site_octaverc, 'file') |
|
59 regexp_octaverc = [prestr, '*', poststr, filesep, 'octaverc']; |
|
60 warning (['pathdef: could not locate `',regexp_octaverc,'''.']) |
|
61 endif |
|
62 |
|
63 ## locate the user ~\.octaverc file. |
|
64 user_octaverc = tilde_expand ("~/.octaverc"); |
|
65 |
|
66 ## Extract the specified paths from the site and user octaverc's. |
|
67 site_pathscript = __extractpath__ (site_octaverc); |
|
68 if exist (user_octaverc, 'file') |
|
69 user_pathscript = __extractpath__ (user_octaverc); |
|
70 else |
|
71 user_pathscript = ''; |
|
72 endif |
|
73 |
|
74 ## A path definition in the user octaverc has precedence over the site |
|
75 if numel (user_pathscript) |
|
76 try |
|
77 eval (user_pathscript); |
|
78 val = path; |
|
79 catch |
|
80 warning (['Path defined in ',user_octaverc,' produced an error']) |
|
81 end_try_catch |
|
82 elseif numel (site_pathscript) |
|
83 try |
|
84 eval (site_pathscript); |
|
85 val = path; |
|
86 catch |
|
87 warning (['Path defined in ',site_octaverc,' produced an error']) |
|
88 end_try_catch |
|
89 endif |
|
90 |
|
91 ## Restore the path |
|
92 path (presentpath); |
|
93 |
|
94 endfunction |
|
95 |
|
96 |