Mercurial > hg > octave-lyh
annotate scripts/path/pathdef.m @ 12740:0fe2eb81e6d0 stable
maint: don't remove distributed files with make distclean target
* Makefile.am (MAINTAINERCLEANFILES): New variable.
(DISTCLEANFILES): Remove $(INFO_FILES) and ChangeLog from the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 Jun 2011 12:54:28 -0400 |
parents | c792872f8942 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2005-2011 Bill Denney |
2 ## Copyright (C) 2007-2009 Ben Abbott | |
7388 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
17 ## along with Octave; see the file COPYING. If not, see | |
18 ## <http://www.gnu.org/licenses/>. | |
19 | |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {@var{val} =} pathdef () | |
22 ## Return the default path for Octave. | |
23 ## The path information is extracted from one of three sources. | |
24 ## In order of preference, those are; | |
25 ## | |
26 ## @enumerate | |
27 ## @item @file{~/.octaverc} | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
28 ## |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
7393
diff
changeset
|
29 ## @item @file{<octave-home>/@dots{}/<version>/m/startup/octaverc} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
30 ## |
7392 | 31 ## @item Octave's path prior to changes by any octaverc. |
7388 | 32 ## @end enumerate |
33 ## @seealso{path, addpath, rmpath, genpath, savepath, pathsep} | |
34 ## @end deftypefn | |
35 | |
36 function val = pathdef () | |
37 | |
7392 | 38 ## Locate the site octaverc file. |
7391 | 39 pathdir = octave_config_info ("localstartupfiledir"); |
7392 | 40 site_octaverc = fullfile (pathdir, "octaverc"); |
7388 | 41 |
7393 | 42 ## Locate the user ~\.octaverc file. |
7392 | 43 user_octaverc = fullfile ("~", ".octaverc"); |
7388 | 44 |
7391 | 45 ## Extract the specified paths from the site and user octaverc"s. |
7393 | 46 site_path = __extractpath__ (site_octaverc); |
7392 | 47 if (exist (user_octaverc, "file")) |
7393 | 48 user_path = __extractpath__ (user_octaverc); |
7388 | 49 else |
7393 | 50 user_path = ""; |
7388 | 51 endif |
52 | |
7392 | 53 ## A path definition in the user octaverc has precedence over the |
54 ## site. | |
55 | |
7393 | 56 if (! isempty (user_path)) |
57 val = user_path; | |
58 elseif (! isempty (site_path)) | |
59 val = site_path; | |
60 else | |
61 val = __pathorig__ (); | |
7388 | 62 endif |
63 | |
64 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
65 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
66 ## Extact the path information from the script/function @var{file}, |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
67 ## created by @file{savepath.m}. If @var{file} is omitted, |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
68 ## @file{~/.octaverc} is used. If successful, @code{__extractpath__} |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
69 ## returns the path specified in @var{file}. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
70 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
71 ## Author: Ben Abbott <bpabbott@mac.com> |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
72 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
73 function specifiedpath = __extractpath__ (savefile) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
74 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
75 ## The majority of this code was borrowed from savepath.m. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
76 ## FIXME -- is there some way to share the common parts instead of |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
77 ## duplicating? |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
78 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
79 beginstring = "## Begin savepath auto-created section, do not edit"; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
80 endstring = "## End savepath auto-created section"; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
81 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
82 if (nargin == 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
83 savefile = tilde_expand ("~/.octaverc"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
84 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
85 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
86 ## Parse the file if it exists to see if we should replace a section |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
87 ## or create a section. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
88 startline = 0; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
89 endline = 0; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
90 filelines = {}; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
91 if (exist (savefile) == 2) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
92 ## read in all lines of the file |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
93 [fid, msg] = fopen (savefile, "rt"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
94 if (fid < 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
95 error ("__extractpath__: could not open savefile, %s: %s", savefile, msg); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
96 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
97 unwind_protect |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
98 linenum = 0; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
99 while (linenum >= 0) |
10549 | 100 result = fgetl (fid); |
101 if (isnumeric (result)) | |
102 ## End at the end of file. | |
103 linenum = -1; | |
104 else | |
105 linenum++; | |
106 filelines{linenum} = result; | |
107 ## Find the first and last lines if they exist in the file. | |
108 if (strcmp (result, beginstring)) | |
109 startline = linenum + 1; | |
110 elseif (strcmp (result, endstring)) | |
111 endline = linenum - 1; | |
112 endif | |
113 endif | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
114 endwhile |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
115 unwind_protect_cleanup |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
116 closeread = fclose (fid); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
117 if (closeread < 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
118 error ("__extractpath__: could not close savefile after reading, %s", |
10549 | 119 savefile); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
120 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
121 end_unwind_protect |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
122 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
123 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
124 ## Extract the path specifiation. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
125 if (startline > endline || (startline > 0 && endline == 0)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
126 error ("__extractpath__: unable to parse file, %s", savefile); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
127 elseif (startline > 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
128 ## Undo doubling of single quote characters performed by savepath. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
129 specifiedpath = strrep (regexprep (cstrcat (filelines(startline:endline){:}), |
10549 | 130 " *path *\\('(.*)'\\); *", "$1"), |
131 "''", "'"); | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
132 else |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 specifiedpath = ""; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
134 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
135 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
136 endfunction |