1
1

fix various file- and rcfile-opening bugs

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4080 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
David Lawrence Ramsey 2007-04-18 18:22:13 +00:00
родитель dc588aea5d
Коммит 7fc36c77d2
3 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -1,6 +1,17 @@
2007-04-18 David Lawrence Ramsey <pooka109@gmail.com> 2007-04-18 David Lawrence Ramsey <pooka109@gmail.com>
* files.c (open_file): Open files using their full paths
whenever possible, so that ~user/file.txt and "~user/file.txt"
are treated the same way if ~user is a user's home directory.
* files.c (real_dir_from_tilde): Simplify. * files.c (real_dir_from_tilde): Simplify.
* rcfile.c (parse_include): Open files using their full paths
whenever possible, so that ~user/file.txt and "~user/file.txt"
are treated the same way if ~user is a user's home directory.
* rcfile.c (parse_include): Properly check for the included
file's being a directory, a character file, or a block file.
* rcfile.c (parse_include): For consistency, display the
filename as the user entered it if we can't read the specified
file.
* winio.c (parse_kbinput): Interpret Cancel and Shift-Cancel. * winio.c (parse_kbinput): Interpret Cancel and Shift-Cancel.
* winio.c (get_escape_seq_kbinput): Add missing comments. * winio.c (get_escape_seq_kbinput): Add missing comments.

Просмотреть файл

@ -586,10 +586,17 @@ int open_file(const char *filename, bool newfie, FILE **f)
{ {
struct stat fileinfo; struct stat fileinfo;
int fd; int fd;
char *full_filename;
assert(filename != NULL && f != NULL); assert(filename != NULL && f != NULL);
if (stat(filename, &fileinfo) == -1) { /* Get the specified file's full path. */
full_filename = get_full_path(filename);
if (full_filename == NULL)
full_filename = mallocstrcpy(NULL, filename);
if (stat(full_filename, &fileinfo) == -1) {
if (newfie) { if (newfie) {
statusbar(_("New File")); statusbar(_("New File"));
return -2; return -2;
@ -606,8 +613,9 @@ int open_file(const char *filename, bool newfie, FILE **f)
_("\"%s\" is a device file"), filename); _("\"%s\" is a device file"), filename);
beep(); beep();
return -1; return -1;
} else if ((fd = open(filename, O_RDONLY)) == -1) { } else if ((fd = open(full_filename, O_RDONLY)) == -1) {
statusbar(_("Error reading %s: %s"), filename, strerror(errno)); statusbar(_("Error reading %s: %s"), filename,
strerror(errno));
beep(); beep();
return -1; return -1;
} else { } else {
@ -623,6 +631,8 @@ int open_file(const char *filename, bool newfie, FILE **f)
statusbar(_("Reading File")); statusbar(_("Reading File"));
} }
free(full_filename);
return 0; return 0;
} }

Просмотреть файл

@ -363,25 +363,23 @@ void parse_include(char *ptr)
/* Get the specified file's full path. */ /* Get the specified file's full path. */
full_option = get_full_path(option); full_option = get_full_path(option);
if (full_option == NULL) { if (full_option == NULL)
rcfile_error(_("Error reading %s: %s"), option, strerror(errno)); full_option = mallocstrcpy(NULL, option);
goto cleanup_include;
}
/* Don't open directories, character files, or block files. */ /* Don't open directories, character files, or block files. */
if (stat(nanorc, &rcinfo) != -1) { if (stat(full_option, &rcinfo) != -1) {
if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) ||
S_ISBLK(rcinfo.st_mode)) { S_ISBLK(rcinfo.st_mode)) {
rcfile_error(S_ISDIR(rcinfo.st_mode) ? rcfile_error(S_ISDIR(rcinfo.st_mode) ?
_("\"%s\" is a directory") : _("\"%s\" is a directory") :
_("\"%s\" is a device file"), nanorc); _("\"%s\" is a device file"), option);
goto cleanup_include; goto cleanup_include;
} }
} }
/* Open the new syntax file. */ /* Open the new syntax file. */
if ((rcstream = fopen(full_option, "rb")) == NULL) { if ((rcstream = fopen(full_option, "rb")) == NULL) {
rcfile_error(_("Error reading %s: %s"), full_option, rcfile_error(_("Error reading %s: %s"), option,
strerror(errno)); strerror(errno));
goto cleanup_include; goto cleanup_include;
} }