tweaks: trim some oververbose comments -- they overshadow the code

The text was harder to understand than the code itself.
master
Benno Schulenberg 2020-05-11 15:57:12 +02:00
parent ff4973458c
commit d80ecf0209
1 changed files with 10 additions and 19 deletions

View File

@ -678,34 +678,24 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
input = (char)input_int; input = (char)input_int;
/* If it's a *nix file ("\n") or a DOS file ("\r\n"), and file /* When the byte before the current one is a CR (and we're still on
* conversion isn't disabled, handle it! */ * 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. */
if (input == '\n') { if (input == '\n') {
#ifndef NANO_TINY #ifndef NANO_TINY
/* If it's a DOS file or a DOS/Mac file ('\r' before '\n' on
* the first line if we think it's a *nix file, or on any
* line otherwise), and file conversion isn't disabled,
* handle it! */
if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) && if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r') { len > 0 && buf[len - 1] == '\r')
format |= 1; format |= 1;
}
/* If it's a Mac file ('\r' without '\n' on the first line if we
* think it's a *nix file, or on any line otherwise), and file
* conversion isn't disabled, handle it! */
} else if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) && } else if ((num_lines == 0 || format != 0) && !ISSET(NO_CONVERT) &&
len > 0 && buf[len - 1] == '\r') { len > 0 && buf[len - 1] == '\r') {
/* If we currently think the file is a *nix file, set format
* to Mac. If we currently think the file is a DOS file,
* set format to both DOS and Mac. */
format |= 2; format |= 2;
#endif #endif
} else { } else {
/* Store the character. */ /* Store the byte. */
buf[len] = input; buf[len] = input;
/* Keep track of the total length of the line. It might have /* Keep track of the total length of the line. It might have
* nulls in it, so we can't just use strlen() later. */ * NUL bytes in it, so we can't just use strlen() later. */
len++; len++;
/* If needed, increase the buffer size, MAX_BUF_SIZE characters at /* If needed, increase the buffer size, MAX_BUF_SIZE characters at
@ -714,6 +704,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
bufx += MAX_BUF_SIZE; bufx += MAX_BUF_SIZE;
buf = charealloc(buf, bufx); buf = charealloc(buf, bufx);
} }
continue; continue;
} }
@ -733,8 +724,8 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
len = 0; len = 0;
#ifndef NANO_TINY #ifndef NANO_TINY
/* If it happens to be a Mac line, store the character after the \r /* If it was a Mac line, then store the byte after the \r
* as the first character of the next line. */ * as the first byte of the next line. */
if (input != '\n') if (input != '\n')
buf[len++] = input; buf[len++] = input;
#endif #endif