commit 09b919a68f30e7c527dbcc421842474e46fbeef5
parent 2f718e11a7ff896eae63cca75b0821ea301f66cf
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 23 Mar 2021 19:53:18 +0100
files: always register the format, also when the file is unwritable
When saving the buffer under a different name, it should by default
have the same format as the original file.
This fixes https://savannah.gnu.org/bugs/?60278.
Bug existed since version 2.6.0, commit 0293eac1.
Diffstat:
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -656,8 +656,8 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
bool writable = TRUE;
/* Whether the file is writable (in case we care). */
#ifndef NANO_TINY
- int format = 0;
- /* 0 = Unix, 1 = DOS, 2 = Mac. */
+ format_type format = NIX_FILE;
+ /* The type of line ending the file uses: Unix, DOS, or Mac. */
#endif
#ifndef NANO_TINY
@@ -697,12 +697,12 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
#ifndef NANO_TINY
if (len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
if (num_lines == 0)
- format = 1;
+ format = DOS_FILE;
len--;
}
} else if ((num_lines == 0 || format == 2) &&
len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
- format = 2;
+ format = MAC_FILE;
len--;
#endif
} else {
@@ -781,7 +781,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
* strip this CR and indicate that an extra blank line is needed. */
if (buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
if (num_lines == 0)
- format = 2;
+ format = MAC_FILE;
buf[--len] = '\0';
mac_line_needs_newline = TRUE;
}
@@ -810,24 +810,23 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
if (!writable)
statusline(ALERT, _("File '%s' is unwritable"), filename);
#ifndef NANO_TINY
- else if (format == 2) {
+ else if (format == MAC_FILE)
/* TRANSLATORS: Keep the next three messages at most 78 characters. */
- openfile->fmt = MAC_FILE;
statusline(HUSH, P_("Read %zu line (Converted from Mac format)",
"Read %zu lines (Converted from Mac format)",
num_lines), num_lines);
- } else if (format == 1) {
- openfile->fmt = DOS_FILE;
+ else if (format == DOS_FILE)
statusline(HUSH, P_("Read %zu line (Converted from DOS format)",
"Read %zu lines (Converted from DOS format)",
num_lines), num_lines);
- }
#endif
- else {
- openfile->fmt = NIX_FILE;
+ else
statusline(HUSH, P_("Read %zu line", "Read %zu lines",
num_lines), num_lines);
- }
+
+#ifndef NANO_TINY
+ openfile->fmt = format;
+#endif
/* If we inserted less than a screenful, don't center the cursor. */
if (undoable && less_than_a_screenful(was_lineno, was_leftedge))