inserting: prune a duplicate variable
Index i follows almost synchronously the value of len. Since we're adding characters to the intermediate buffer always only at the end, just use len as the index.master
parent
086b85215f
commit
f5c6246433
15
src/files.c
15
src/files.c
|
@ -728,8 +728,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
/* The number of lines in the file. */
|
/* The number of lines in the file. */
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
/* The length of the current line of the file. */
|
/* The length of the current line of the file. */
|
||||||
size_t i = 0;
|
|
||||||
/* The position in the current line of the file. */
|
|
||||||
size_t bufx = MAX_BUF_SIZE;
|
size_t bufx = MAX_BUF_SIZE;
|
||||||
/* The size of each chunk of the file that we read. */
|
/* The size of each chunk of the file that we read. */
|
||||||
char input = '\0';
|
char input = '\0';
|
||||||
|
@ -771,7 +769,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
* line otherwise), and file conversion isn't disabled,
|
* line otherwise), and file conversion isn't disabled,
|
||||||
* handle it! */
|
* handle it! */
|
||||||
if (!ISSET(NO_CONVERT) && (num_lines == 0 || format != 0) &&
|
if (!ISSET(NO_CONVERT) && (num_lines == 0 || format != 0) &&
|
||||||
i > 0 && buf[i - 1] == '\r') {
|
len > 0 && buf[len - 1] == '\r') {
|
||||||
if (format == 0 || format == 2)
|
if (format == 0 || format == 2)
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
|
@ -785,13 +783,12 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
|
|
||||||
num_lines++;
|
num_lines++;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
i = 0;
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* If it's a Mac file ('\r' without '\n' on the first line if we
|
/* 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
|
* think it's a *nix file, or on any line otherwise), and file
|
||||||
* conversion isn't disabled, handle it! */
|
* conversion isn't disabled, handle it! */
|
||||||
} else if (!ISSET(NO_CONVERT) && (num_lines == 0 ||
|
} else if (!ISSET(NO_CONVERT) && (num_lines == 0 ||
|
||||||
format != 0) && i > 0 && buf[i - 1] == '\r') {
|
format != 0) && len > 0 && buf[len - 1] == '\r') {
|
||||||
/* If we currently think the file is a *nix file, set format
|
/* If we currently think the file is a *nix file, set format
|
||||||
* to Mac. If we currently think the file is a DOS file,
|
* to Mac. If we currently think the file is a DOS file,
|
||||||
* set format to both DOS and Mac. */
|
* set format to both DOS and Mac. */
|
||||||
|
@ -809,7 +806,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
num_lines++;
|
num_lines++;
|
||||||
buf[0] = input;
|
buf[0] = input;
|
||||||
buf[1] = '\0';
|
buf[1] = '\0';
|
||||||
i = 1;
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Calculate the total length of the line. It might have
|
/* Calculate the total length of the line. It might have
|
||||||
|
@ -821,14 +817,13 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
* we may indeed have to use a buffer this big later on, so
|
* we may indeed have to use a buffer this big later on, so
|
||||||
* we don't decrease it at all. We do free it at the end,
|
* we don't decrease it at all. We do free it at the end,
|
||||||
* though. */
|
* though. */
|
||||||
if (i >= bufx - 1) {
|
if (len >= bufx) {
|
||||||
bufx += MAX_BUF_SIZE;
|
bufx += MAX_BUF_SIZE;
|
||||||
buf = charealloc(buf, bufx);
|
buf = charealloc(buf, bufx);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[i] = input;
|
buf[len - 1] = input;
|
||||||
buf[i + 1] = '\0';
|
buf[len] = '\0';
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue