write_file() - New arg, nonamechange, means whether or not to update the current filename after writing the file out.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@677 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2001-06-05 23:24:55 +00:00
parent d21195f882
commit ecc3d7f39e
4 changed files with 18 additions and 14 deletions

View File

@ -60,8 +60,10 @@ Cvs code -
files less than 1K being displayed as 0B (Rocco).
do_writeout()
- New code to allow writing selected text to a separate file.
When this is done, the current filename is not changed, the
modification state is preserved, etc.
When this is done, the current state is prserved.
write_file()
- New arg, nonamechange, means whether or not to update the
current filename after writing the file out.
- global.c:
- Updated some of the lists for the "Goto Directory" code (Rocco)
- move.c:

18
files.c
View File

@ -334,8 +334,11 @@ int do_insertfile(void)
*
* append means, not surprisingly, whether we are appending instead
* of overwriting.
*
* nonamechange means don't change the current filename, it is ignored
* if tmp == 1.
*/
int write_file(char *name, int tmp, int append)
int write_file(char *name, int tmp, int append, int nonamechange)
{
long size, lineswritten = 0;
static char *buf = NULL;
@ -503,7 +506,9 @@ int write_file(char *name, int tmp, int append)
mask, realname, strerror(errno));
if (!tmp) {
filename = mallocstrcpy(filename, realname);
if (nonamechange)
filename = mallocstrcpy(filename, realname);
statusbar(_("Wrote %d lines"), lineswritten);
UNSET(MODIFIED);
titlebar(NULL);
@ -528,7 +533,7 @@ int do_writeout(char *path, int exiting, int append)
if ((exiting) && (ISSET(TEMP_OPT))) {
if (filename[0]) {
i = write_file(answer, 0, 0);
i = write_file(answer, 0, 0, 0);
display_main_list();
return i;
} else {
@ -595,14 +600,12 @@ int do_writeout(char *path, int exiting, int append)
/* Here's where we allow the selected text to be written to
a separate file. */
if (ISSET(MARK_ISSET) && !exiting) {
char *backup = NULL;
filestruct *fileagebak = fileage;
filestruct *filebotbak = filebot;
filestruct *cutback = cutbuffer;
int oldmod = 0;
/* Okay, since write_file changes the filename, back it up */
backup = mallocstrcpy(backup, filename);
if (ISSET(MODIFIED))
oldmod = 1;
@ -619,10 +622,9 @@ int do_writeout(char *path, int exiting, int append)
for (filebot = cutbuffer; filebot->next != NULL;
filebot = filebot->next)
;
i = write_file(answer, 0, append);
i = write_file(answer, 0, append, 1);
/* Now restore everything */
backup = mallocstrcpy(filename, backup);
fileage = fileagebak;
filebot = filebotbak;
cutbuffer = cutback;
@ -630,7 +632,7 @@ int do_writeout(char *path, int exiting, int append)
set_modified();
} else
#endif
i = write_file(answer, 0, append);
i = write_file(answer, 0, append, 0);
display_main_list();
return i;

6
nano.c
View File

@ -118,13 +118,13 @@ void die(char *msg, ...)
* but we might as well TRY. */
if (filename[0] == '\0') {
name = "nano.save";
i = write_file(name, 1, 0);
i = write_file(name, 1, 0, 0);
} else {
char *buf = charalloc(strlen(filename) + 6);
strcpy(buf, filename);
strcat(buf, ".save");
i = write_file(buf, 1, 0);
i = write_file(buf, 1, 0, 0);
name = buf;
}
/* Restore the old term settings */
@ -1482,7 +1482,7 @@ int do_spell(void)
return 0;
}
if (write_file(temp, 1, 0) == -1) {
if (write_file(temp, 1, 0, 0) == -1) {
statusbar(_("Spell checking failed: unable to write temp file!"));
return 0;
}

View File

@ -81,7 +81,7 @@ int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus);
int strlenpt(char *buf);
int statusq(int allowtabs, shortcut s[], int slen, char *def, char *msg, ...);
int write_file(char *name, int tmpfile, int append);
int write_file(char *name, int tmpfile, int append, int nonamechange);
int do_cut_text(void);
int do_uncut_text(void);
int no_help(void);