tweaks: move a function to before the one that calls it
parent
bea5e85f3e
commit
ae7f5ebdeb
73
src/nano.c
73
src/nano.c
|
@ -273,6 +273,42 @@ void finish(void)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save the current buffer under the given name (or under the name "nano"
|
||||||
|
* for a nameless buffer). If needed, the name is modified to be unique. */
|
||||||
|
void emergency_save(const char *die_filename, struct stat *die_stat)
|
||||||
|
{
|
||||||
|
bool failed = TRUE;
|
||||||
|
char *targetname;
|
||||||
|
|
||||||
|
if (*die_filename == '\0')
|
||||||
|
die_filename = "nano";
|
||||||
|
|
||||||
|
targetname = get_next_filename(die_filename, ".save");
|
||||||
|
|
||||||
|
if (*targetname != '\0')
|
||||||
|
failed = !write_file(targetname, NULL, TRUE, OVERWRITE, FALSE);
|
||||||
|
|
||||||
|
if (!failed)
|
||||||
|
fprintf(stderr, _("\nBuffer written to %s\n"), targetname);
|
||||||
|
else if (*targetname != '\0')
|
||||||
|
fprintf(stderr, _("\nBuffer not written to %s: %s\n"),
|
||||||
|
targetname, strerror(errno));
|
||||||
|
else
|
||||||
|
fprintf(stderr, _("\nToo many .save files"));
|
||||||
|
|
||||||
|
#ifndef NANO_TINY
|
||||||
|
/* Try to chmod/chown the saved file to the values of the original file,
|
||||||
|
* but ignore any failure as we are in a hurry to get out. */
|
||||||
|
if (die_stat) {
|
||||||
|
IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
|
||||||
|
IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
|
||||||
|
die_stat->st_gid));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free(targetname);
|
||||||
|
}
|
||||||
|
|
||||||
/* Die gracefully -- by restoring the terminal state and saving any buffers
|
/* Die gracefully -- by restoring the terminal state and saving any buffers
|
||||||
* that were modified. */
|
* that were modified. */
|
||||||
void die(const char *msg, ...)
|
void die(const char *msg, ...)
|
||||||
|
@ -313,43 +349,6 @@ void die(const char *msg, ...)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the current buffer under the given name.
|
|
||||||
* If necessary, the name is modified to be unique. */
|
|
||||||
void emergency_save(const char *die_filename, struct stat *die_stat)
|
|
||||||
{
|
|
||||||
char *targetname;
|
|
||||||
bool failed = TRUE;
|
|
||||||
|
|
||||||
/* If the buffer has no name, simply call it "nano". */
|
|
||||||
if (*die_filename == '\0')
|
|
||||||
die_filename = "nano";
|
|
||||||
|
|
||||||
targetname = get_next_filename(die_filename, ".save");
|
|
||||||
|
|
||||||
if (*targetname != '\0')
|
|
||||||
failed = !write_file(targetname, NULL, TRUE, OVERWRITE, FALSE);
|
|
||||||
|
|
||||||
if (!failed)
|
|
||||||
fprintf(stderr, _("\nBuffer written to %s\n"), targetname);
|
|
||||||
else if (*targetname != '\0')
|
|
||||||
fprintf(stderr, _("\nBuffer not written to %s: %s\n"),
|
|
||||||
targetname, strerror(errno));
|
|
||||||
else
|
|
||||||
fprintf(stderr, _("\nToo many .save files"));
|
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
|
||||||
/* Try to chmod/chown the saved file to the values of the original file,
|
|
||||||
* but ignore any failure as we are in a hurry to get out. */
|
|
||||||
if (die_stat) {
|
|
||||||
IGNORE_CALL_RESULT(chmod(targetname, die_stat->st_mode));
|
|
||||||
IGNORE_CALL_RESULT(chown(targetname, die_stat->st_uid,
|
|
||||||
die_stat->st_gid));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
free(targetname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the three window portions nano uses. */
|
/* Initialize the three window portions nano uses. */
|
||||||
void window_init(void)
|
void window_init(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -411,7 +411,6 @@ 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 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);
|
||||||
|
|
Loading…
Reference in New Issue