annotate scripts/path/savepath.m @ 16618:13728d41fb6a

use functions to handle colors in Windows GUI terminal * QWinTerminalImpl.cpp (QConsolePrivate::backgroundColor, QConsolePrivate::foregroundColor, QConsolePrivate::selectionColor, QConsolePrivate::cursorColor, QConsolePrivate::setBackgroundColor, QConsolePrivate::setForegroundColor, QConsolePrivate::setSelectionColor, QConsolePrivate::setCursorColor): New functions. (QConsolePrivate::m_backgroundColor, QConsolePrivate::m_foregroundColor): Delete member variables. (QConsolePrivate::QConsolePrivate): Call setBackgroundColor and setForegroundColor to set default colors. (QWinTerminalImpl::viewPaintEvent): Use functions to access colors.
author John W. Eaton <jwe@octave.org>
date Mon, 06 May 2013 02:20:01 -0400
parents b3730ed107a6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11589
diff changeset
1 ## Copyright (C) 2005-2012 Bill Denney
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
2 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
4 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
8 ## your option) any later version.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
9 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
14 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6807
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
18
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
20 ## @deftypefn {Function File} {} savepath ()
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {} savepath (@var{file})
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
22 ## @deftypefnx {Function File} {@var{status} =} savepath (@dots{})
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## Save the unique portion of the current function search path that is
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
24 ## not set during Octave's initialization process to @var{file}.
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
25 ## If @var{file} is omitted, @file{~/.octaverc} is used. If successful,
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5736
diff changeset
26 ## @code{savepath} returns 0.
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
27 ## @seealso{path, addpath, rmpath, genpath, pathdef}
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
29
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
30 ## Author: Bill Denney <bill@givebillmoney.com>
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
31
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
32 function retval = savepath (file)
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
33
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
34 ret = 1;
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
35
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
36 beginstring = "## Begin savepath auto-created section, do not edit";
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
37 endstring = "## End savepath auto-created section";
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
38
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
39 if (nargin == 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
40 file = fullfile ("~", ".octaverc");
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
41 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
42
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 ## parse the file if it exists to see if we should replace an
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 ## existing section or create a new section
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
45 startline = endline = 0;
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
46 filelines = {};
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
47 if (exist (file) == 2)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
48 [fid, msg] = fopen (file, "rt");
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
49 if (fid < 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
50 error ("savepath: could not open file, %s: %s", file, msg);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
51 endif
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
52 unwind_protect
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
53 linenum = 0;
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
54 while (ischar (line = fgetl (fid)))
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55 filelines{++linenum} = line;
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 ## 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
57 if (strcmp (line, beginstring))
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 startline = linenum;
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 elseif (strcmp (line, endstring))
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 endline = linenum;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9038
diff changeset
61 endif
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
62 endwhile
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
63 unwind_protect_cleanup
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
64 closeread = fclose (fid);
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
65 if (closeread < 0)
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 error ("savepath: could not close file after reading, %s", file);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
67 endif
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
68 end_unwind_protect
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
69 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
70
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
71 if (startline > endline || (startline > 0 && endline == 0))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
72 error ("savepath: unable to parse file, %s", file);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
73 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
74
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
75 ## put the current savepath lines into the file
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
76 if (isempty (filelines)
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
77 || (startline == 1 && endline == length (filelines)))
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
78 ## savepath is the entire file
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
79 pre = post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
80 elseif (endline == 0)
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
81 ## drop the savepath statements at the end of the file
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
82 pre = filelines;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
83 post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
84 elseif (startline == 1)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
85 pre = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
86 post = filelines(endline+1:end);
8608
5cc1fba0a7d6 style and ChangeLog fixes
John W. Eaton <jwe@octave.org>
parents: 8586
diff changeset
87 elseif (endline == length (filelines))
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
88 pre = filelines(1:startline-1);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
89 post = {};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
90 else
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
91 ## insert in the middle
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
92 pre = filelines(1:startline-1);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
93 post = filelines(endline+1:end);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
94 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
95
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
96 ## write the results
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
97 [fid, msg] = fopen (file, "wt");
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
98 if (fid < 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
99 error ("savepath: unable to open file for writing, %s, %s", file, msg);
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7017
diff changeset
100 endif
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
101 unwind_protect
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
102 for i = 1:length (pre)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
103 fprintf (fid, "%s\n", pre{i});
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
104 endfor
5736
e07baa8b93b9 [project @ 2006-04-04 19:41:45 by jwe]
jwe
parents: 5735
diff changeset
105
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
106 ## Remove the portion of the path defined via the command line
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
107 ## and/or the environment.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
108 workingpath = parsepath (path);
8609
fcf762ba66cf load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents: 8608
diff changeset
109 command_line_path = parsepath (command_line_path ());
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
110 octave_path = parsepath (getenv ("OCTAVE_PATH"));
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
111 pathdef = pathdef ();
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
112 if (isempty (pathdef))
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
113 ## This occurs when running octave via run-octave. In this instance
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
114 ## the entire path is specified via the command line and pathdef()
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
115 ## is empty.
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
116 [~, n] = setdiff (workingpath, octave_path);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
117 default_path = command_line_path;
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
118 else
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
119 [~, n] = setdiff (workingpath, union (command_line_path, octave_path));
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
120 default_path = parsepath (pathdef);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
121 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
122 ## This is the path we'd like to preserve when octave is run.
8608
5cc1fba0a7d6 style and ChangeLog fixes
John W. Eaton <jwe@octave.org>
parents: 8586
diff changeset
123 path_to_preserve = workingpath (sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
124
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
125 ## Determine the path to Octave's user and sytem wide pkgs.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
126 [pkg_user, pkg_system] = pkg ("list");
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
127 pkg_user_path = cell (1, numel (pkg_user));
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
128 pkg_system_path = cell (1, numel (pkg_system));
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
129 for n = 1:numel (pkg_user)
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
130 pkg_user_path{n} = pkg_user{n}.archprefix;
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
131 endfor
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
132 for n = 1:numel (pkg_system)
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
133 pkg_system_path{n} = pkg_system{n}.archprefix;
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
134 endfor
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
135 pkg_path = union (pkg_user_path, pkg_system_path);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
136
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
137 ## Rely on Octave's initialization to include the pkg path elements.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
138 if (! isempty (pkg_path))
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
139 [~, n] = setdiff (path_to_preserve, strcat (pkg_path, ":"));
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
140 path_to_preserve = path_to_preserve(sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
141 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
142
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
143 ## Split the path to be saved into two groups. Those path elements that
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
144 ## belong at the beginning and those at the end.
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
145 if (! isempty (default_path))
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
146 n1 = find (strcmp (default_path{1}, path_to_preserve));
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
147 n2 = find (strcmp (default_path{end}, path_to_preserve));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
148 n_middle = round (0.5*(n1+n2));
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
149 [~, n] = setdiff (path_to_preserve, default_path);
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
150 path_to_save = path_to_preserve(sort (n));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
151 ## Remove pwd
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
152 path_to_save = path_to_save(! strcmp (path_to_save, ["." pathsep]));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
153 n = ones (size (path_to_save));
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
154 for m = 1:numel (path_to_save)
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
155 n(m) = find (strcmp (path_to_save{m}, path_to_preserve));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
156 endfor
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
157 path_to_save_begin = path_to_save(n <= n_middle);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
158 path_to_save_end = path_to_save(n > n_middle);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
159 else
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
160 path_to_save_begin = path_to_preserve;
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
161 path_to_save_end = {};
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
162 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
163 path_to_save_begin = cell2mat (path_to_save_begin);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
164 path_to_save_end = cell2mat (path_to_save_end);
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
165
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
166 ## Use single quotes for PATH argument to avoid string escape
7393
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
167 ## processing. Since we are using single quotes around the arg,
a2e8cfe2fd17 [project @ 2008-01-17 08:46:54 by jwe]
jwe
parents: 7392
diff changeset
168 ## double any single quote characters found in the string.
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
169 fprintf (fid, "%s\n", beginstring);
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
170 if (! isempty (path_to_save_begin))
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
171 n = find (path_to_save_begin != pathsep, 1, "last");
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
172 fprintf (fid, " addpath ('%s', '-begin');\n",
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
173 strrep (path_to_save_begin(1:n), "'", "''"));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
174 endif
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
175 if (! isempty (path_to_save_end))
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
176 n = find (path_to_save_end != pathsep, 1, "last");
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
177 fprintf (fid, " addpath ('%s', '-end');\n",
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
178 strrep (path_to_save_end(1:n), "'", "''"));
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
179 endif
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
180 fprintf (fid, "%s\n", endstring);
5736
e07baa8b93b9 [project @ 2006-04-04 19:41:45 by jwe]
jwe
parents: 5735
diff changeset
181
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
182 for i = 1:length (post)
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
183 fprintf (fid, "%s\n", post{i});
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
184 endfor
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
185 unwind_protect_cleanup
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
186 closeread = fclose (fid);
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
187 if (closeread < 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
188 error ("savepath: could not close savefile after writing, %s", file);
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
189 elseif (nargin == 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11032
diff changeset
190 warning ("savepath: current path saved to %s", file);
7392
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
191 endif
17f2cdb5232e [project @ 2008-01-17 08:14:32 by jwe]
jwe
parents: 7391
diff changeset
192 end_unwind_protect
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
193
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
194 ret = 0;
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
195
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
196 if (nargout > 0)
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
197 retval = ret;
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
198 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
199
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
200 endfunction
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
201
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
202 function path_elements = parsepath (p)
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
203 pat = sprintf ('([^%s]+[%s$])', pathsep, pathsep);
14216
b3730ed107a6 Clean up scripts in path/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
204 path_elements = regexpi (strcat (p, pathsep), pat, "match");
8586
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
205 endfunction
31ab3b83bc8a savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents: 7393
diff changeset
206