# HG changeset patch # User jwe # Date 1200559614 0 # Node ID a2e8cfe2fd176c39522e9967848ebfe65753858b # Parent 17f2cdb5232e60dcde56bb2b66717a95d3c635cc [project @ 2008-01-17 08:46:54 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,12 @@ 2008-01-17 John W. Eaton + * 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. diff --git a/scripts/path/__extractpath__.m b/scripts/path/__extractpath__.m --- 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 diff --git a/scripts/path/pathdef.m b/scripts/path/pathdef.m --- 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 diff --git a/scripts/path/savepath.m b/scripts/path/savepath.m --- 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});