Getting rid of a global variable.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5574 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
a91a1c7bbd
commit
fe3d849a75
|
@ -1,5 +1,6 @@
|
||||||
2016-01-20 Benno Schulenberg <bensberg@justemail.net>
|
2016-01-20 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* src/files.c (open_buffer): Readjust the indentation and a comment.
|
* src/files.c (open_buffer): Readjust the indentation and a comment.
|
||||||
|
* src/files.c (has_valid_path): Get rid of a global variable.
|
||||||
|
|
||||||
2016-01-20 Rishabh Dave <rishabhddave@gmail.com>
|
2016-01-20 Rishabh Dave <rishabhddave@gmail.com>
|
||||||
* src/files.c (verify_path, open_buffer): When opening a new buffer,
|
* src/files.c (verify_path, open_buffer): When opening a new buffer,
|
||||||
|
|
23
src/files.c
23
src/files.c
|
@ -33,27 +33,26 @@
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
/* Determine whether the containing directory of the given filename exists.
|
/* Verify that the containing directory of the given filename exists. */
|
||||||
* Pass the result back in the global variable valid_path. */
|
bool has_valid_path(const char *filename)
|
||||||
void verify_path(const char *filename)
|
|
||||||
{
|
{
|
||||||
char *parentdir;
|
char *parentdir;
|
||||||
struct stat parentinfo;
|
struct stat parentinfo;
|
||||||
|
bool validity = TRUE;
|
||||||
|
|
||||||
if (strrchr(filename, '/') == NULL)
|
if (strrchr(filename, '/') == NULL)
|
||||||
parentdir = mallocstrcpy(NULL, ".");
|
parentdir = mallocstrcpy(NULL, ".");
|
||||||
else
|
else
|
||||||
parentdir = dirname(mallocstrcpy(NULL, filename));
|
parentdir = dirname(mallocstrcpy(NULL, filename));
|
||||||
|
|
||||||
if (stat(parentdir, &parentinfo) != -1 && S_ISDIR(parentinfo.st_mode))
|
if (stat(parentdir, &parentinfo) == -1 || !S_ISDIR(parentinfo.st_mode)) {
|
||||||
valid_path = TRUE;
|
|
||||||
else {
|
|
||||||
statusbar(_("Directory '%s' does not exist"), parentdir);
|
statusbar(_("Directory '%s' does not exist"), parentdir);
|
||||||
valid_path = FALSE;
|
validity = FALSE;
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
free(parentdir);
|
free(parentdir);
|
||||||
|
return validity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an entry to the openfile openfilestruct. This should only be
|
/* Add an entry to the openfile openfilestruct. This should only be
|
||||||
|
@ -135,7 +134,7 @@ void set_modified(void)
|
||||||
titlebar(NULL);
|
titlebar(NULL);
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (!ISSET(LOCKING) || openfile->filename[0] == '\0' || !valid_path)
|
if (!ISSET(LOCKING) || openfile->filename[0] == '\0')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (openfile->lock_filename == NULL) {
|
if (openfile->lock_filename == NULL) {
|
||||||
|
@ -404,10 +403,10 @@ bool open_buffer(const char *filename, bool undoable)
|
||||||
if (new_buffer) {
|
if (new_buffer) {
|
||||||
make_new_buffer();
|
make_new_buffer();
|
||||||
|
|
||||||
verify_path(filename);
|
if (!has_valid_path(filename))
|
||||||
|
quiet = TRUE;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (valid_path) {
|
else {
|
||||||
if (ISSET(LOCKING) && filename[0] != '\0') {
|
if (ISSET(LOCKING) && filename[0] != '\0') {
|
||||||
int lockstatus = do_lockfile(filename);
|
int lockstatus = do_lockfile(filename);
|
||||||
if (lockstatus < 0) {
|
if (lockstatus < 0) {
|
||||||
|
@ -977,7 +976,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newfie) {
|
if (newfie) {
|
||||||
if (!quiet && valid_path)
|
if (!quiet)
|
||||||
statusbar(_("New File"));
|
statusbar(_("New File"));
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,6 @@ bool func_key;
|
||||||
/* Whether the current keystroke is an extended keypad value. */
|
/* Whether the current keystroke is an extended keypad value. */
|
||||||
bool focusing = FALSE;
|
bool focusing = FALSE;
|
||||||
/* Whether an update of the edit window should center the cursor. */
|
/* Whether an update of the edit window should center the cursor. */
|
||||||
bool valid_path;
|
|
||||||
/* Whether the containing directory of a specified file exists. */
|
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
int controlleft = CONTROL_LEFT;
|
int controlleft = CONTROL_LEFT;
|
||||||
|
|
|
@ -34,7 +34,6 @@ extern volatile sig_atomic_t sigwinch_counter;
|
||||||
extern bool meta_key;
|
extern bool meta_key;
|
||||||
extern bool func_key;
|
extern bool func_key;
|
||||||
extern bool focusing;
|
extern bool focusing;
|
||||||
extern bool valid_path;
|
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
extern int controlleft;
|
extern int controlleft;
|
||||||
|
|
Loading…
Reference in New Issue