Only in original_src: .deps diff -ur original_src/files.c my_src/files.c --- original_src/files.c 2015-12-06 09:01:30.000000000 +0530 +++ my_src/files.c 2016-01-09 23:01:54.067353034 +0530 @@ -33,6 +33,48 @@ #include #include +/* Determine whether the components in a path are valid directories. If + * some component is faulty return it, else return NULL. */ + char *fault_in_path(const char *filename) +{ + int lenpath, lenparent, lenpparent; + lenpath= strlen(filename); + char *parentdir = charalloc(lenpath * sizeof(char)); + char *pparentdir = charalloc(lenpath * sizeof(char)); + /* pparentdir implies parent of parent directory */ + char *fault; + struct stat parentinfo, pparentinfo; + + strcpy(parentdir, filename); + parentdir = dirname(parentdir); + strcpy(pparentdir, parentdir); + pparentdir = dirname(pparentdir); + + /* If path exists, and parent directory is a directory and not a regular or + * some other file, then New File can be established, so return NULL. */ + if (stat(parentdir, &parentinfo) != -1 && S_ISDIR(parentinfo.st_mode)) + return NULL; + + do { + /* Check if parent's parent directory exists, if not keep checking further. + * If it does exist, extract faulty directory, turn faulty_path flag on and + * return faulty directory. */ + if (stat(pparentdir, &pparentinfo) == -1 || !S_ISDIR(pparentinfo.st_mode)) { + strcpy(parentdir, pparentdir); + } else { + lenparent = strlen(parentdir); + (strcmp(pparentdir, ".") == 0) ? (lenpparent = 0) + : (lenpparent = strlen(pparentdir)); + fault = charalloc((lenparent - lenpparent + 1) * sizeof(char)); + strncpy(fault, parentdir + lenpparent, lenparent - lenpparent); + fault[lenparent - lenpparent] = '\0'; + openfile->faulty_path = TRUE; + return fault; + } + pparentdir = dirname(pparentdir); + } while (TRUE); +} + /* Add an entry to the openfile openfilestruct. This should only be * called from open_buffer(). */ void make_new_buffer(void) @@ -61,6 +103,7 @@ openfile->current_y = 0; openfile->modified = FALSE; + openfile->faulty_path = FALSE; #ifndef NANO_TINY openfile->mark_set = FALSE; openfile->mark_begin = NULL; @@ -172,7 +215,7 @@ if (fd < 0 || filestream == NULL) { statusbar(_("Error writing lock file %s: %s"), lockfilename, - strerror(errno)); + strerror(errno)); goto free_and_fail; } @@ -256,7 +299,6 @@ size_t locknamesize = strlen(filename) + strlen(locking_prefix) + strlen(locking_suffix) + 3; char *lockfilename = charalloc(locknamesize); - char *lockfiledir = NULL; static char lockprog[11], lockuser[17]; struct stat fileinfo; int lockfd, lockpid; @@ -269,54 +311,43 @@ fprintf(stderr, "lock file name is %s\n", lockfilename); #endif if (stat(lockfilename, &fileinfo) != -1) { - ssize_t readtot = 0; - ssize_t readamt = 0; - char *lockbuf = charalloc(8192); - char *promptstr = charalloc(128); - int ans; - if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { - statusbar(_("Error opening lock file %s: %s"), - lockfilename, strerror(errno)); - return -1; - } - do { - readamt = read(lockfd, &lockbuf[readtot], BUFSIZ); - readtot += readamt; - } while (readtot < 8192 && readamt > 0); - - if (readtot < 48) { - statusbar(_("Error reading lock file %s: Not enough data read"), - lockfilename); - return -1; - } - strncpy(lockprog, &lockbuf[2], 10); - lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24]; - strncpy(lockuser, &lockbuf[28], 16); + ssize_t readtot = 0; + ssize_t readamt = 0; + char *lockbuf = charalloc(8192); + char *promptstr = charalloc(128); + int ans; + if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { + statusbar(_("Error opening lock file %s: %s"), + lockfilename, strerror(errno)); + return -1; + } + do { + readamt = read(lockfd, &lockbuf[readtot], BUFSIZ); + readtot += readamt; + } while (readtot < 8192 && readamt > 0); + + if (readtot < 48) { + statusbar(_("Error reading lock file %s: Not enough data read"), + lockfilename); + return -1; + } + strncpy(lockprog, &lockbuf[2], 10); + lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24]; + strncpy(lockuser, &lockbuf[28], 16); #ifdef DEBUG fprintf(stderr, "lockpid = %d\n", lockpid); fprintf(stderr, "program name which created this lock file should be %s\n", lockprog); fprintf(stderr, "user which created this lock file should be %s\n", lockuser); #endif - /* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */ - sprintf(promptstr, _("File %s is being edited (by %s with %s, PID %d); continue?"), - filename, lockuser, lockprog, lockpid); - ans = do_yesno_prompt(FALSE, promptstr); - if (ans < 1) { - blank_statusbar(); - return -1; - } - } else { - lockfiledir = mallocstrcpy(NULL, lockfilename); - lockfiledir = dirname(lockfiledir); - if (stat(lockfiledir, &fileinfo) == -1) { - statusbar(_("Error writing lock file: Directory \'%s\' doesn't exist"), - lockfiledir); - free(lockfiledir); - return 0; - } - free(lockfiledir); + /* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */ + sprintf(promptstr, _("File %s is being edited (by %s with %s, PID %d); continue?"), + filename, lockuser, lockprog, lockpid); + ans = do_yesno_prompt(FALSE, promptstr); + if (ans < 1) { + blank_statusbar(); + return -1; + } } - return write_lockfile(lockfilename, filename, FALSE); } #endif /* !NANO_TINY */ @@ -336,6 +367,8 @@ int rc; /* rc == -2 means that we have a new file. -1 means that the * open() failed. 0 means that the open() succeeded. */ + char *fault; + /* Holds faulty component in path of filename. */ assert(filename != NULL); @@ -366,6 +399,14 @@ * buffer and lock the corresponding file. */ if (new_buffer) { make_new_buffer(); + + if ((fault = fault_in_path(filename)) != NULL) { + statusbar(_("New File. Directory \'%s\' doesn't exist"), fault); + UNSET(LOCKING); + } else { + statusbar(_("New File")); + } + beep(); #ifndef NANO_TINY if (ISSET(LOCKING) && filename[0] != '\0') { @@ -914,9 +955,8 @@ #endif } -/* Open the file (and decide if it exists). If newfie is TRUE, display - * "New File" if the file is missing. Otherwise, say "[filename] not - * found". +/* Open the file (and decide if it exists). If newfie is TRUE, return + * -2 otherwise, say "[filename] not found". * * Return -2 if we say "New File", -1 if the file isn't opened, and the * fd opened otherwise. The file might still have an error while reading @@ -948,11 +988,9 @@ return 0; } - if (newfie) { - if (!quiet) - statusbar(_("New File")); - return -2; - } + if (newfie) + return -2; + statusbar(_("\"%s\" not found"), filename); beep(); return -1; @@ -2247,7 +2285,7 @@ ans = mallocstrcpy(NULL, #ifndef NANO_TINY - (!exiting && openfile->mark_set) ? "" : + ((!exiting && openfile->mark_set) || openfile->faulty_path) ? "" : #endif openfile->filename); Only in my_src: Makefile Only in my_src: nano diff -ur original_src/nano.h my_src/nano.h --- original_src/nano.h 2015-12-06 10:30:29.000000000 +0530 +++ my_src/nano.h 2016-01-09 22:02:45.643339000 +0530 @@ -384,6 +384,8 @@ /* The file's y-coordinate position. */ bool modified; /* Whether the file has been modified. */ + bool faulty_path; + /* If mentioned file's path is faulty. */ #ifndef NANO_TINY bool mark_set; /* Whether the mark is on in this file. */ diff -ur original_src/proto.h my_src/proto.h --- original_src/proto.h 2015-12-05 10:36:09.000000000 +0530 +++ my_src/proto.h 2016-01-09 22:01:33.215339000 +0530 @@ -278,6 +278,7 @@ void do_uncut_text(void); /* All functions in files.c. */ +char *fault_in_path(const char *filename); void make_new_buffer(void); void initialize_buffer_text(void); void open_buffer(const char *filename, bool undoable); diff -ur original_src/winio.c my_src/winio.c --- original_src/winio.c 2015-12-06 09:01:30.000000000 +0530 +++ my_src/winio.c 2016-01-09 22:02:43.811339000 +0530 @@ -2122,7 +2122,7 @@ prefix = _("DIR:"); else #endif - if (openfile->filename[0] == '\0') { + if ((openfile->filename[0] == '\0' || openfile->faulty_path )) { prefix = _("New Buffer"); newfie = TRUE; } else