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:
*
* 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;
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);
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 {
/* 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;
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;
set_modified();
} else
#endif
- i = write_file(answer, 0, append);
+ i = write_file(answer, 0, append, 0);
display_main_list();
return i;
* 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 */
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;
}
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);