tweaks: adjust or correct some comments, and rename a function
Also, reshuffle a condition so it takes up less space.
Этот коммит содержится в:
родитель
ab8698df47
Коммит
2c024a74a9
31
src/nano.c
31
src/nano.c
@ -588,12 +588,14 @@ void die(const char *msg, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
openfilestruct *firstone = openfile;
|
openfilestruct *firstone = openfile;
|
||||||
|
|
||||||
|
/* Switch on the cursor and leave curses mode. */
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
|
||||||
/* Restore the old terminal settings. */
|
/* Restore the old terminal settings. */
|
||||||
tcsetattr(0, TCSANOW, &oldterm);
|
tcsetattr(0, TCSANOW, &oldterm);
|
||||||
|
|
||||||
|
/* Display the dying message. */
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
vfprintf(stderr, msg, ap);
|
vfprintf(stderr, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -604,13 +606,14 @@ void die(const char *msg, ...)
|
|||||||
if (ISSET(LOCKING) && openfile->lock_filename)
|
if (ISSET(LOCKING) && openfile->lock_filename)
|
||||||
delete_lockfile(openfile->lock_filename);
|
delete_lockfile(openfile->lock_filename);
|
||||||
#endif
|
#endif
|
||||||
/* If the current file buffer was modified, save it. */
|
/* If the current buffer was modified, ensure it is unpartitioned,
|
||||||
if (openfile->modified) {
|
* then save it. When in restricted mode, we don't save anything,
|
||||||
/* If the buffer is partitioned, unpartition it first. */
|
* because it would write files not mentioned on the command line. */
|
||||||
|
if (openfile->modified && !ISSET(RESTRICTED)) {
|
||||||
if (filepart != NULL)
|
if (filepart != NULL)
|
||||||
unpartition_filestruct(&filepart);
|
unpartition_filestruct(&filepart);
|
||||||
|
|
||||||
die_save_file(openfile->filename, openfile->current_stat);
|
emergency_save(openfile->filename, openfile->current_stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
filepart = NULL;
|
filepart = NULL;
|
||||||
@ -624,21 +627,14 @@ void die(const char *msg, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the current file under the name specified in die_filename, which
|
/* Save the current buffer under the given name.
|
||||||
* is modified to be unique if necessary. */
|
* If necessary, the name is modified to be unique. */
|
||||||
void die_save_file(const char *die_filename, struct stat *die_stat)
|
void emergency_save(const char *die_filename, struct stat *die_stat)
|
||||||
{
|
{
|
||||||
char *targetname;
|
char *targetname;
|
||||||
bool failed = TRUE;
|
bool failed = TRUE;
|
||||||
|
|
||||||
/* If we're using restricted mode, don't write any emergency backup
|
/* If the buffer has no name, simply call it "nano". */
|
||||||
* files, since that would allow reading from or writing to files
|
|
||||||
* not specified on the command line. */
|
|
||||||
if (ISSET(RESTRICTED))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If we can't save, we have really bad problems, but we might as
|
|
||||||
* well try. */
|
|
||||||
if (*die_filename == '\0')
|
if (*die_filename == '\0')
|
||||||
die_filename = "nano";
|
die_filename = "nano";
|
||||||
|
|
||||||
@ -657,9 +653,8 @@ void die_save_file(const char *die_filename, struct stat *die_stat)
|
|||||||
_("Too many backup files?"));
|
_("Too many backup files?"));
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Try and chmod/chown the save file to the values of the original file,
|
/* Try to chmod/chown the saved file to the values of the original file,
|
||||||
* but don't worry if it fails because we're supposed to be bailing as
|
* but ignore any failure as we are in a hurry to get out. */
|
||||||
* fast as possible. */
|
|
||||||
if (die_stat) {
|
if (die_stat) {
|
||||||
IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
|
IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
|
||||||
IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
|
IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
|
||||||
|
@ -421,7 +421,7 @@ void say_there_is_no_help(void);
|
|||||||
#endif
|
#endif
|
||||||
void finish(void);
|
void finish(void);
|
||||||
void die(const char *msg, ...);
|
void die(const char *msg, ...);
|
||||||
void die_save_file(const char *die_filename, struct stat *die_stat);
|
void emergency_save(const char *die_filename, struct stat *die_stat);
|
||||||
void window_init(void);
|
void window_init(void);
|
||||||
void do_exit(void);
|
void do_exit(void);
|
||||||
void close_and_go(void);
|
void close_and_go(void);
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user