[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: difference between path / pathdef
From: |
John W. Eaton |
Subject: |
Re: difference between path / pathdef |
Date: |
Thu, 17 Jan 2008 03:46:49 -0500 |
On 15-Jan-2008, John W. Eaton wrote:
| On 15-Jan-2008, Ben Abbott wrote:
|
| | ## A path definition in the user octaverc has precedence over the site
| | if numel (user_pathscript)
| | try
| | eval (user_pathscript);
| | val = path;
| | catch
| | warning (['Path defined in ',user_octaverc,' produced an error'])
| | end_try_catch
|
| I think we should try to avoid the eval here. What is the format of
| user_pathscript?
I checked in the following changes to avoid eval and to also try to
properly handle paths that contain single quote characters.
Is __extractpath__ only expected to be used in pathdef? If so, why
not make it a subfunction of pathdef instead of having it in a
separate file?
jwe
scripts/ChangeLog:
2008-01-17 John W. Eaton <address@hidden>
* path/savepath.m: Print newline before initial comment line.
Double up single quote characters.
* path/__extractpath__.m: Return just the path as a string.
Undo single quote character doubling.
* path/pathdef.m: Avoid eval. Simplify.
Index: scripts/path/__extractpath__.m
===================================================================
RCS file: /cvs/octave/scripts/path/__extractpath__.m,v
retrieving revision 1.3
diff -u -u -r1.3 __extractpath__.m
--- scripts/path/__extractpath__.m 17 Jan 2008 08:14:32 -0000 1.3
+++ scripts/path/__extractpath__.m 17 Jan 2008 08:45:18 -0000
@@ -82,10 +82,13 @@
## Extract the path specifiation.
if (startline > endline || (startline > 0 && endline == 0))
error ("savepath: unable to parse file, %s", savefile);
- elseif startline > 0
- specifiedpath = filelines(startline:endline);
+ elseif (startline > 0)
+ ## Undo doubling of single quote characters performed by savepath.
+ specifiedpath = strrep (regexprep (strcat
(filelines(startline:endline){:}),
+ " *path *\\('(.*)'\\); *", "$1"),
+ "''", "'");
else
- specifiedpath = {};
+ specifiedpath = "";
endif
endfunction
Index: scripts/path/pathdef.m
===================================================================
RCS file: /cvs/octave/scripts/path/pathdef.m,v
retrieving revision 1.3
diff -u -u -r1.3 pathdef.m
--- scripts/path/pathdef.m 17 Jan 2008 08:14:32 -0000 1.3
+++ scripts/path/pathdef.m 17 Jan 2008 08:45:18 -0000
@@ -32,63 +32,30 @@
function val = pathdef ()
- ## Use Octave's orignal path as the default default.
- val = __pathorig__ ();
-
## Locate the site octaverc file.
pathdir = octave_config_info ("localstartupfiledir");
site_octaverc = fullfile (pathdir, "octaverc");
- ## locate the user ~\.octaverc file.
+ ## Locate the user ~\.octaverc file.
user_octaverc = fullfile ("~", ".octaverc");
## Extract the specified paths from the site and user octaverc"s.
- site_pathscript = __extractpath__ (site_octaverc);
+ site_path = __extractpath__ (site_octaverc);
if (exist (user_octaverc, "file"))
- user_pathscript = __extractpath__ (user_octaverc);
+ user_path = __extractpath__ (user_octaverc);
else
- user_pathscript = "";
+ user_path = "";
endif
## A path definition in the user octaverc has precedence over the
## site.
- ## FIXME -- use a subfunction here to avoid code duplication?
-
- if (numel (user_pathscript))
- try
- if (numel (user_pathscript) == 1)
- n = strfind (user_pathscript{1}, "'");
- if (numel(n) == 1)
- n = strfind (user_pathscript{1}, "\"");
- endif
- val = user_pathscript{1}(n(1):n(end));
- else
- presentpath = path;
- eval (user_pathscript);
- val = path;
- path (presentpath);
- endif
- catch
- warning ("pathdef: invalid path found in `%s'", user_octaverc);
- end_try_catch
- elseif (numel (site_pathscript))
- try
- if (numel (site_pathscript) == 1)
- n = strfind (site_pathscript{1}, "'");
- if (numel(n) == 1)
- n = strfind (site_pathscript{1}, "\"");
- endif
- val = site_pathscript{1}(n(1):n(end));
- else
- presentpath = path;
- eval (site_pathscript);
- val = path;
- path (presentpath);
- endif
- catch
- warning ("pathdef: invalid path found in `%s'", site_octaverc);
- end_try_catch
+ if (! isempty (user_path))
+ val = user_path;
+ elseif (! isempty (site_path))
+ val = site_path;
+ else
+ val = __pathorig__ ();
endif
endfunction
Index: scripts/path/savepath.m
===================================================================
RCS file: /cvs/octave/scripts/path/savepath.m,v
retrieving revision 1.14
diff -u -u -r1.14 savepath.m
--- scripts/path/savepath.m 17 Jan 2008 08:14:32 -0000 1.14
+++ scripts/path/savepath.m 17 Jan 2008 08:45:18 -0000
@@ -113,9 +113,10 @@
endfor
## Use single quotes for PATH argument to avoid string escape
- ## processing.
- fprintf (fid, "%s\n path ('%s');\n%s\n",
- beginstring, path (), endstring);
+ ## processing. Since we are using single quotes around the arg,
+ ## double any single quote characters found in the string.
+ fprintf (fid, "\n%s\n path ('%s');\n%s\n",
+ beginstring, strrep (path (), "'", "''"), endstring);
for i = 1:length (post)
fprintf (fid, "%s\n", post{i});
- Re: difference between path / pathdef, Ben Abbott, 2008/01/15
- Re: difference between path / pathdef, John W. Eaton, 2008/01/15
- Re: difference between path / pathdef, Ben Abbott, 2008/01/15
- Re: difference between path / pathdef, John W. Eaton, 2008/01/15
- Re: difference between path / pathdef, Ben Abbott, 2008/01/16
- Re: difference between path / pathdef, John W. Eaton, 2008/01/17
- Re: difference between path / pathdef, Ben Abbott, 2008/01/17
Re: difference between path / pathdef,
John W. Eaton <=