Mercurial > hg > octave-nkf
annotate scripts/path/pathdef.m @ 15107:03381a36f70d
generate convenience libraries for new parse-tree and interpfcn subdirectories
* src/Makefile.am (liboctinterp_la_SOURCES): Include octave.cc in the
list, not $(DIST_SRC).
(liboctinterp_la_LIBADD): Include octave-value/liboctave-value.la,
parse-tree/libparse-tree.la, interp-core/libinterp-core.la,
interpfcn/libinterpfcn.la, and corefcn/libcorefcn.la in the list.
* src/interp-core/module.mk (noinst_LTLIBRARIES): Add
interp-core/libinterp-core.la to the list.
(interp_core_libinterp_core_la_SOURCES): New variable.
* src/interpfcn/module.mk (noinst_LTLIBRARIES): Add
interpfcn/libinterpfcn.la to the list.
(interpfcn_libinterpfcn_la_SOURCES): New variable.
* src/parse-tree/module.mk (noinst_LTLIBRARIES): Add
parse-tree/libparse-tree.la to the list.
(parse_tree_libparse_tree_la_SOURCES): New variable.
* src/octave-value/module.mk (noinst_LTLIBRARIES): Add
octave-value/liboctave-value.la to the list.
(octave_value_liboctave_value_la_SOURCES): New variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 05 Aug 2012 09:04:30 -0400 |
parents | b3730ed107a6 |
children | 1c89599167a6 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2005-2012 Bill Denney |
11523 | 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. | |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
24 ## The possible sources, in order of preference, are: |
7388 | 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 |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
33 ## @seealso{path, addpath, rmpath, genpath, savepath} |
7388 | 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 |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
42 ## Locate the user's ~/.octaverc file. |
7392 | 43 user_octaverc = fullfile ("~", ".octaverc"); |
7388 | 44 |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
45 ## Extract the specified paths from the site and user octavercs. |
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 | |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 ## A path definition in the user rcfile has precedence over the site rcfile. |
7393 | 54 if (! isempty (user_path)) |
55 val = user_path; | |
56 elseif (! isempty (site_path)) | |
57 val = site_path; | |
58 else | |
59 val = __pathorig__ (); | |
7388 | 60 endif |
61 | |
62 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
63 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
64 ## 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
|
65 ## 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
|
66 ## @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
|
67 ## returns the path specified in @var{file}. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
68 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
69 ## Author: Ben Abbott <bpabbott@mac.com> |
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 function specifiedpath = __extractpath__ (savefile) |
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 ## The majority of this code was borrowed from savepath.m. |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 ## FIXME: is there some way to share the common parts instead of duplicating? |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
75 ## ANSWER: Yes. Create a private directory and extract this section of code |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 ## and place it there in a new function only visible by pathdef() and |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
77 ## savepath(). |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
78 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
|
79 endstring = "## End savepath auto-created section"; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
80 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
81 if (nargin == 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
82 savefile = tilde_expand ("~/.octaverc"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
83 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
84 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
85 ## 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
|
86 ## or create a section. |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 startline = endline = 0; |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
88 filelines = {}; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
89 if (exist (savefile) == 2) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
90 [fid, msg] = fopen (savefile, "rt"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
91 if (fid < 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
92 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
|
93 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
94 unwind_protect |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
95 linenum = 0; |
14216
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
96 while (ischar (line = fgetl (fid))) |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
97 filelines{++linenum} = line; |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 ## find the first and last lines if they exist in the file |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 if (strcmp (line, beginstring)) |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 startline = linenum; |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
101 elseif (strcmp (line, endstring)) |
b3730ed107a6
Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
102 endline = linenum; |
10549 | 103 endif |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
104 endwhile |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
105 unwind_protect_cleanup |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
106 closeread = fclose (fid); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
107 if (closeread < 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
108 error ("__extractpath__: could not close savefile after reading, %s", |
10549 | 109 savefile); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
110 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
111 end_unwind_protect |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
112 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
113 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
114 ## Extract the path specifiation. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
115 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
|
116 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
|
117 elseif (startline > 0) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
118 ## 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
|
119 specifiedpath = strrep (regexprep (cstrcat (filelines(startline:endline){:}), |
10549 | 120 " *path *\\('(.*)'\\); *", "$1"), |
121 "''", "'"); | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
122 else |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
123 specifiedpath = ""; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
124 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
125 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 endfunction |