tweaks: correct a comment, and avoid third repetition of some conditions

master
Benno Schulenberg 2020-05-12 20:53:08 +02:00
parent fcbf85887b
commit 56bf29409b
1 changed files with 10 additions and 12 deletions

View File

@ -675,16 +675,20 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
break;
}
/* When the byte before the current one is a CR (and we're still on
* the first line OR the format is already non-Unix, and we're not
* converting), then mark the format as DOS or Mac or a mixture. */
/* When the byte before the current one is a CR and we're doing
* format conversion, then strip this CR when it's before a LF
* OR when the file is in Mac format. Also, when still on the
* first line, set the format to either DOS (1) or Mac (2). */
if (input == '\n') {
#ifndef NANO_TINY
if (num_lines == 0 && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r')
format = 1;
if (len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT)) {
buf[--len] = '\0';
if (num_lines == 0)
format = 1;
}
} else if ((num_lines == 0 || format == 2) && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r') {
buf[--len] = '\0';
format = 2;
#endif
} else {
@ -705,12 +709,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
continue;
}
#ifndef NANO_TINY
/* If it's a DOS or Mac line, strip the '\r' from it. */
if (len > 0 && buf[len - 1] == '\r' && !ISSET(NO_CONVERT))
buf[--len] = '\0';
#endif
/* Store the data and make a new line. */
bottomline->data = encode_data(buf, len);
bottomline->next = make_new_node(bottomline);