Common subdirectories: original_src/src/.deps and my_src/src/.deps diff -u original_src/src/files.c my_src/src/files.c --- original_src/src/files.c 2015-12-06 09:01:30.000000000 +0530 +++ my_src/src/files.c 2015-12-24 16:41:15.366328000 +0530 @@ -33,6 +33,31 @@ #include #include +/*0 implies valid address and filename, file doesn't exist at mentioned folder. +-1 implies invalid address incorrect address. -2 implies invalid filename.*/ + int determine(const char *a) +{ + int i, len = strlen(a); + char *x; + struct stat buf2; + + mistakes = 0; + x = charalloc(sizeof(a)); + + for (i = len; i >= 0; --i) { + if (a[i] == '/') { + x = realloc(x, i + 2); + strcpyfu(x, a, 0, i + 1); + x[i + 2] = '\0'; + if (stat(x, &buf2) == -1) + ++mistakes; + } + } + free(x); + x = NULL; + return mistakes; +} + /* Add an entry to the openfile openfilestruct. This should only be * called from open_buffer(). */ void make_new_buffer(void) @@ -923,6 +948,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; @@ -949,9 +975,15 @@ } if (newfie) { - if (!quiet) - statusbar(_("New File")); - return -2; + if (!quiet) { + m = determine(filename); + if (m == 0) + statusbar(_("New File")); + else if (m > 0) + statusbar(_("Invalid path")); + else + statusbar(_("Unexpected Error")); + } return -2; } statusbar(_("\"%s\" not found"), filename); beep(); @@ -2247,7 +2279,7 @@ ans = mallocstrcpy(NULL, #ifndef NANO_TINY - (!exiting && openfile->mark_set) ? "" : + ((!exiting && openfile->mark_set) || mistakes > 0) ? "" : #endif openfile->filename); diff -u original_src/src/global.c my_src/src/global.c --- original_src/src/global.c 2015-12-05 10:36:09.000000000 +0530 +++ my_src/src/global.c 2015-12-23 17:04:56.360383000 +0530 @@ -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; + /*Mistakes in the path of the file mentioned.*/ #ifndef NANO_TINY int controlleft = CONTROL_LEFT; Binary files original_src/src/nano and my_src/src/nano differ diff -u original_src/src/proto.h my_src/src/proto.h --- original_src/src/proto.h 2015-12-05 10:36:09.000000000 +0530 +++ my_src/src/proto.h 2015-12-23 16:53:32.932380000 +0530 @@ -34,6 +34,7 @@ extern bool meta_key; extern bool func_key; extern bool focusing; +extern int mistakes; #ifndef NANO_TINY extern int controlleft; @@ -278,6 +279,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); @@ -712,6 +714,7 @@ void do_verbatim_input(void); /* All functions in utils.c. */ +char *strcpyfu(char *dest, const char *src, int from, int upto); void get_homedir(void); bool parse_num(const char *str, ssize_t *val); bool parse_line_column(const char *str, ssize_t *line, ssize_t *column); diff -u original_src/src/utils.c my_src/src/utils.c --- original_src/src/utils.c 2015-12-05 10:36:09.000000000 +0530 +++ my_src/src/utils.c 2015-12-21 18:44:56.048403000 +0530 @@ -30,6 +30,24 @@ #include #include + char *strcpyfu(char *dest, const char *src, int from, int upto) +{ + int i = from; + while (i > 0) { + ++src; + --i; + } + i = from; + while ( i < upto && *src != '\0') { + *dest = *src; + ++dest; + ++src; + ++i; + } + *dest = '\0'; + return dest; +} + /* Return the user's home directory. We use $HOME, and if that fails, * we fall back on the home directory of the effective user ID. */ void get_homedir(void)