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

18
files.c
View File

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

6
nano.c
View File

@ -118,13 +118,13 @@ void die(char *msg, ...)
* but we might as well TRY. */ * but we might as well TRY. */
if (filename[0] == '\0') { if (filename[0] == '\0') {
name = "nano.save"; name = "nano.save";
i = write_file(name, 1, 0); i = write_file(name, 1, 0, 0);
} else { } else {
char *buf = charalloc(strlen(filename) + 6); char *buf = charalloc(strlen(filename) + 6);
strcpy(buf, filename); strcpy(buf, filename);
strcat(buf, ".save"); strcat(buf, ".save");
i = write_file(buf, 1, 0); i = write_file(buf, 1, 0, 0);
name = buf; name = buf;
} }
/* Restore the old term settings */ /* Restore the old term settings */
@ -1482,7 +1482,7 @@ int do_spell(void)
return 0; 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!")); statusbar(_("Spell checking failed: unable to write temp file!"));
return 0; 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 actual_x(filestruct * fileptr, int xplus);
int strlenpt(char *buf); int strlenpt(char *buf);
int statusq(int allowtabs, shortcut s[], int slen, char *def, char *msg, ...); 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_cut_text(void);
int do_uncut_text(void); int do_uncut_text(void);
int no_help(void); int no_help(void);