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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10821
diff changeset
1 ## Copyright (C) 2005-2011 Bill Denney
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10821
diff changeset
2 ## Copyright (C) 2007-2009 Ben Abbott
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
3 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
5 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
9 ## your option) any later version.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
10 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
15 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
18 ## <http://www.gnu.org/licenses/>.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
19
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefn {Function File} {@var{val} =} pathdef ()
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
22 ## Return the default path for Octave.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
23 ## The path information is extracted from one of three sources.
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
24 ## In order of preference, those are;
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
25 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
26 ## @enumerate
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
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
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
31 ## @item Octave's path prior to changes by any octaverc.
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
32 ## @end enumerate
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
33 ## @seealso{path, addpath, rmpath, genpath, savepath, pathsep}
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
34 ## @end deftypefn
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
35
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
36 function val = pathdef ()
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
37
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
38 ## Locate the site octaverc file.
7391
f071480b7eac [project @ 2008-01-17 07:50:33 by jwe]
jwe
parents: 7388
diff changeset
39 pathdir = octave_config_info ("localstartupfiledir");
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
40 site_octaverc = fullfile (pathdir, "octaverc");
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
41
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
42 ## Locate the user ~\.octaverc file.
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
43 user_octaverc = fullfile ("~", ".octaverc");
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
44
7391
f071480b7eac [project @ 2008-01-17 07:50:33 by jwe]
jwe
parents: 7388
diff changeset
45 ## Extract the specified paths from the site and user octaverc"s.
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
46 site_path = __extractpath__ (site_octaverc);
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
47 if (exist (user_octaverc, "file"))
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
48 user_path = __extractpath__ (user_octaverc);
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
49 else
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
50 user_path = "";
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
51 endif
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
52
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
53 ## A path definition in the user octaverc has precedence over the
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
54 ## site.
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
55
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
56 if (! isempty (user_path))
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
57 val = user_path;
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
58 elseif (! isempty (site_path))
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
59 val = site_path;
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
60 else
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
61 val = __pathorig__ ();
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
62 endif
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
63
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
100 result = fgetl (fid);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
101 if (isnumeric (result))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
102 ## End at the end of file.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
103 linenum = -1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
104 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
105 linenum++;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
106 filelines{linenum} = result;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
107 ## Find the first and last lines if they exist in the file.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
108 if (strcmp (result, beginstring))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
109 startline = linenum + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
110 elseif (strcmp (result, endstring))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
111 endline = linenum - 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
112 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
130 " *path *\\('(.*)'\\); *", "$1"),
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9899
diff changeset
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