Patch for setwd() to show path in error message
On 11/01/2013 20:22, Henrik Bengtsson wrote:
Below is a patch for setwd() to show path in error message. Current it just gives error messages such as: Error in setwd(libdir) : cannot change working directory with the patch it should (read untested) give: Error in setwd(libdir) : cannot change working directory to 'path/that/fails/'
And why is this needed? You know it is 'libdir' and could check what that was (or if doing this programatically, check its existence first). As you fumbled towards, it would require all the translations to be redone, so we don't do this sort of thing lightly. (Redone twice if it were done correctly, AFAICS.) The .pot and .po files are generated automatically, but not filled in automatically. This is all in the manuals .... In any case, the correct procedure was to file an enhancement request on R-bugs, with a case and after testing on both platforms you are proposing to patch.
PATCH:
% diff -u util.c "util,patch.c"
--- util.c 2012-12-16 13:13:05.002249900 -0800
+++ util,patch.c 2013-01-11 11:52:16.843236400 -0800
@@ -696,14 +696,14 @@
{
const wchar_t *path = filenameToWchar(STRING_ELT(s, 0), TRUE);
if(_wchdir(path) < 0)
- error(_("cannot change working directory"));
+ error(_("cannot change working directory to '%s'"), path);
That is a wchar_t*, so the format would need to be %ls.
}
#else
{
const char *path
= R_ExpandFileName(translateChar(STRING_ELT(s, 0)));
if(chdir(path) < 0)
- error(_("cannot change working directory"));
+ error(_("cannot change working directory to '%s'"), path);
}
#endif
return(wd);
TRANSLATIONS:
I have zero experience with GNU gettext/*.po files, but I understand
that the above change requires updates to src/library/base/*.po files,
which now looks like (e.g. de.po):
#: src/main/util.c:699 src/main/util.c:706
msgid "cannot change working directory"
msgstr "kann Arbeitsverzeichnis nicht wechseln"
A generic/automatic update would be to use the format:
#: src/main/util.c:699 src/main/util.c:706
msgid "cannot change working directory: '%s'"
msgstr "kann Arbeitsverzeichnis nicht wechseln: '%s'"
but I don't think that is in line with the current R style.
/Henrik
PS. Background for this patch:
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2395&group_id=34&atid=194
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595