Mercurial > hg > octave-terminal
changeset 7393:a2e8cfe2fd17
[project @ 2008-01-17 08:46:54 by jwe]
author | jwe |
---|---|
date | Thu, 17 Jan 2008 08:46:54 +0000 |
parents | 17f2cdb5232e |
children | 872b263b7e62 |
files | scripts/ChangeLog scripts/path/__extractpath__.m scripts/path/pathdef.m scripts/path/savepath.m |
diffstat | 4 files changed, 27 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,12 @@ 2008-01-17 John W. Eaton <jwe@octave.org> + * 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. + * path/pathdef.m: Use fullfile instead of concatenating with filesep. * path/__extractpath__.m, path/savepath.m: Use unwind_protect to avoid possible file descriptor leak.
--- a/scripts/path/__extractpath__.m +++ b/scripts/path/__extractpath__.m @@ -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
--- a/scripts/path/pathdef.m +++ b/scripts/path/pathdef.m @@ -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
--- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -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});