Index: src/global.c =================================================================== --- src/global.c (revision 5509) +++ src/global.c (working copy) @@ -40,6 +40,8 @@ /* Whether the current keystroke is an extended keypad value. */ bool focusing = FALSE; /* Whether an update of the edit window should center the cursor. */ +int mistakes; + /* Number of mistakes in the path of the specified file. */ #ifndef NANO_TINY int controlleft = CONTROL_LEFT; Index: src/files.c =================================================================== --- src/files.c (revision 5512) +++ src/files.c (working copy) @@ -33,6 +33,29 @@ #include #include +/* Determine whether the components in a path are valid directories. + * Anything above zero means that it contains non-existent ones. */ + int determine(const char *a) +{ + int i, len = strlen(a); + char *x; + struct stat buf2; + + mistakes = 0; + x = charalloc(len * sizeof(char)); + + for (i = len; i >= 0; --i) { + if (a[i] == '/') { + strncpy(x, a, i + 1); + x[i + 2] = '\0'; + if (stat(x, &buf2) == -1) + ++mistakes; + } + } + free(x); + return mistakes; +} + /* Add an entry to the openfile openfilestruct. This should only be * called from open_buffer(). */ void make_new_buffer(void) @@ -908,6 +931,7 @@ * with a 0 return value. *f is set to the opened file. */ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) { + int m; struct stat fileinfo, fileinfo2; int fd; char *full_filename; @@ -934,8 +958,13 @@ } if (newfie) { - if (!quiet) - statusbar(_("New File")); + if (!quiet) { + m = determine(filename); + if (m == 0) + statusbar(_("New File")); + else + statusbar(_("Invalid path")); + } return -2; } statusbar(_("\"%s\" not found"), filename); @@ -2230,7 +2259,7 @@ ans = mallocstrcpy(NULL, #ifndef NANO_TINY - (!exiting && openfile->mark_set) ? "" : + ((!exiting && openfile->mark_set) || mistakes > 0) ? "" : #endif openfile->filename); Index: src/proto.h =================================================================== --- src/proto.h (revision 5509) +++ src/proto.h (working copy) @@ -34,6 +34,7 @@ extern bool meta_key; extern bool func_key; extern bool focusing; +extern int mistakes; #ifndef NANO_TINY extern int controlleft; @@ -281,6 +282,7 @@ void do_uncut_text(void); /* All functions in files.c. */ +int determine(const char *a); void make_new_buffer(void); void initialize_buffer_text(void); void open_buffer(const char *filename, bool undoable);