annotate scripts/path/pathdef.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19369
diff changeset
1 ## Copyright (C) 2005-2015 Bill Denney
11523
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.
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ##
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## The path information is extracted from one of four sources.
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
25 ## The possible sources, in order of preference, are:
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
26 ##
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
27 ## @enumerate
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ## @item @file{.octaverc}
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ##
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
30 ## @item @file{~/.octaverc}
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
31 ##
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## @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
33 ##
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
34 ## @item Octave's path prior to changes by any octaverc file.
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
35 ## @end enumerate
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
36 ## @seealso{path, addpath, rmpath, genpath, savepath}
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
37 ## @end deftypefn
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
38
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
39 function val = pathdef ()
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
40
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
41 if (nargin > 0)
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
42 print_usage ();
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
43 endif
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
44
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
45 ## Locate any project-specific .octaverc file.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
46 proj_octaverc = fullfile (pwd, ".octaverc");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
47 if (exist (proj_octaverc, "file"))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
48 proj_path = __extractpath__ (proj_octaverc);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
49 if (! isempty (proj_path))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
50 val = proj_path;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
51 return;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 endif
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 endif
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
54
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55 ## Locate the user's ~/.octaverc file.
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
56 user_octaverc = fullfile ("~", ".octaverc");
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
57 if (exist (user_octaverc, "file"))
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
58 user_path = __extractpath__ (user_octaverc);
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
59 if (! isempty (user_path))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
60 val = user_path;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
61 return;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
62 endif
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
63 endif
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
64
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
65 ## No user octaverc file, locate the site octaverc file.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
66 pathdir = octave_config_info ("localstartupfiledir");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
67 site_octaverc = fullfile (pathdir, "octaverc");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
68 site_path = __extractpath__ (site_octaverc);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
69 if (! isempty (site_path))
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
70 val = site_path;
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
71 return;
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
72 endif
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
73
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
74 ## No project, user, or site octaverc file. Use Octave's default.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
75 val = __pathorig__ ();
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
76
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
77 endfunction
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
78
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
79 ## Extract the path information from the script/function @var{file}, created by
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
80 ## @file{savepath.m}. If successful, @code{__extractpath__} returns the path
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
81 ## specified in @var{file}.
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
82
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
83 ## Author: Ben Abbott <bpabbott@mac.com>
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
84
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
85 function path = __extractpath__ (savefile)
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
86
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
87 [filelines, startline, endline] = getsavepath (savefile);
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
88 if (startline > 0)
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
89 tmp = regexprep (filelines(startline+1:endline-1),
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
90 "^.*path \\('([^\']+)'.*$", "$1");
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
91 path = strjoin (tmp, ":");
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
92 else
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
93 path = "";
7388
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
94 endif
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
95
0e1ccfe1bf91 [project @ 2008-01-16 06:31:23 by jwe]
jwe
parents:
diff changeset
96 endfunction
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
97
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
98
19369
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
99 ## FIXME: Need some better BIST tests
bb8d3f17248d Overhaul savepath.m, pathdef.m, matlabroot.m.
Rik <rik@octave.org>
parents: 17744
diff changeset
100 %!assert (ischar (pathdef ()))
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
101