per DB's patch, simplify the saving of emergency files in die(),
die_save_file(), and get_next_filename() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1889 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
6b24856c2f
commit
049e4a5db3
|
@ -84,6 +84,9 @@ CVS code -
|
||||||
when compiling with every option manually turned on, including
|
when compiling with every option manually turned on, including
|
||||||
NANO_SMALL. (David Benbennick)
|
NANO_SMALL. (David Benbennick)
|
||||||
- files.c:
|
- files.c:
|
||||||
|
get_next_filename()
|
||||||
|
- Tweak for efficiency, and add the ".save" suffix to the file
|
||||||
|
here. (David Benbennick)
|
||||||
close_open_file()
|
close_open_file()
|
||||||
- Tweak to no longer rely on the return values of
|
- Tweak to no longer rely on the return values of
|
||||||
open_(prev|next)file(). (DLR)
|
open_(prev|next)file(). (DLR)
|
||||||
|
@ -107,6 +110,11 @@ CVS code -
|
||||||
thanks_for_all_the_fish()
|
thanks_for_all_the_fish()
|
||||||
- Delete topwin, edit, and bottomwin. (David Benbennick)
|
- Delete topwin, edit, and bottomwin. (David Benbennick)
|
||||||
- nano.c:
|
- nano.c:
|
||||||
|
die()
|
||||||
|
- Don't add the ".save" suffix to a saved file here anymore,
|
||||||
|
since get_next_filename() does that now. (David Benbennick)
|
||||||
|
die_save_file()
|
||||||
|
- Tweak for efficiency. (David Benbennick)
|
||||||
help_init()
|
help_init()
|
||||||
- Fix the display of the translated key descriptions "Up" and
|
- Fix the display of the translated key descriptions "Up" and
|
||||||
"Space" under all circumstances, and make the help browser
|
"Space" under all circumstances, and make the help browser
|
||||||
|
|
18
src/files.c
18
src/files.c
|
@ -394,19 +394,22 @@ bool open_file(const char *filename, int insert, int quiet)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function will return the name of the first available extension
|
/* This function will return the name of the first available extension
|
||||||
* of a filename (starting with the filename, then filename.1, etc).
|
* of a filename (starting with the filename.save, then filename.save.1,
|
||||||
* Memory is allocated for the return value. If no writable extension
|
* etc). Memory is allocated for the return value. If no writable
|
||||||
* exists, we return "". */
|
* extension exists, we return "". */
|
||||||
char *get_next_filename(const char *name)
|
char *get_next_filename(const char *name)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *buf = NULL;
|
char *buf;
|
||||||
struct stat fs;
|
size_t namelen = strlen(name);
|
||||||
|
|
||||||
buf = charalloc(strlen(name) + num_of_digits(INT_MAX) + 2);
|
buf = charalloc(namelen + num_of_digits(INT_MAX) + 7);
|
||||||
strcpy(buf, name);
|
strcpy(buf, name);
|
||||||
|
strcpy(buf + namelen, ".save");
|
||||||
|
namelen += 5;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
struct stat fs;
|
||||||
|
|
||||||
if (stat(buf, &fs) == -1)
|
if (stat(buf, &fs) == -1)
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -414,8 +417,7 @@ char *get_next_filename(const char *name)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
strcpy(buf, name);
|
sprintf(buf + namelen, ".%d", i);
|
||||||
sprintf(&buf[strlen(name)], ".%d", i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We get here only if there is no possible save file. */
|
/* We get here only if there is no possible save file. */
|
||||||
|
|
12
src/nano.c
12
src/nano.c
|
@ -104,7 +104,7 @@ void finish(void)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Die (gracefully?) */
|
/* Die (gracefully?). */
|
||||||
void die(const char *msg, ...)
|
void die(const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -170,15 +170,9 @@ void die_save_file(const char *die_filename)
|
||||||
/* If we can't save, we have REAL bad problems, but we might as well
|
/* If we can't save, we have REAL bad problems, but we might as well
|
||||||
TRY. */
|
TRY. */
|
||||||
if (die_filename[0] == '\0')
|
if (die_filename[0] == '\0')
|
||||||
ret = get_next_filename("nano.save");
|
die_filename = "nano";
|
||||||
else {
|
|
||||||
char *buf = charalloc(strlen(die_filename) + 6);
|
|
||||||
|
|
||||||
strcpy(buf, die_filename);
|
ret = get_next_filename(die_filename);
|
||||||
strcat(buf, ".save");
|
|
||||||
ret = get_next_filename(buf);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
if (ret[0] != '\0')
|
if (ret[0] != '\0')
|
||||||
failed = -1 == write_file(ret, TRUE, FALSE, TRUE);
|
failed = -1 == write_file(ret, TRUE, FALSE, TRUE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue