From ecc3d7f39eb63d297a250cb5cd89ef3b9ff3cefa Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Tue, 5 Jun 2001 23:24:55 +0000 Subject: [PATCH] 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 --- ChangeLog | 6 ++++-- files.c | 18 ++++++++++-------- nano.c | 6 +++--- proto.h | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a4d0d83..e4e17585 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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: diff --git a/files.c b/files.c index 866bbbcf..492df5a8 100644 --- a/files.c +++ b/files.c @@ -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; diff --git a/nano.c b/nano.c index f269d368..bed69385 100644 --- a/nano.c +++ b/nano.c @@ -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; } diff --git a/proto.h b/proto.h index b713b5fe..39e86d38 100644 --- a/proto.h +++ b/proto.h @@ -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);