tweaks: rename two variables, and reduce the scope of a third

master
Benno Schulenberg 2020-05-11 16:59:39 +02:00
parent ef4b0edd4e
commit 2dd97a0352
1 changed files with 11 additions and 17 deletions

View File

@ -625,19 +625,16 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
/* 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. */
char input = '\0'; size_t bufsize = LUMPSIZE;
/* The current input character. */ /* The size of the line buffer; increased as needed. */
char *buf; char *buf = charalloc(bufsize);
/* The buffer in which we assemble each line of the file. */ /* The buffer in which we assemble each line of the file. */
size_t bufx = LUMPSIZE;
/* The allocated size of the line buffer; increased as needed. */
linestruct *topline; linestruct *topline;
/* The top of the new buffer where we store the read file. */ /* The top of the new buffer where we store the read file. */
linestruct *bottomline; linestruct *bottomline;
/* The bottom of the new buffer. */ /* The bottom of the new buffer. */
int input_int; int onevalue;
/* The current value we read from the file, whether an input /* The current value we read from the file, either a byte or EOF. */
* character or EOF. */
int errornumber; int errornumber;
/* The error code, in case an error occurred during reading. */ /* The error code, in case an error occurred during reading. */
bool writable = TRUE; bool writable = TRUE;
@ -647,8 +644,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */ /* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
#endif #endif
buf = charalloc(bufx);
#ifndef NANO_TINY #ifndef NANO_TINY
if (undoable) if (undoable)
add_undo(INSERT, NULL); add_undo(INSERT, NULL);
@ -671,16 +666,15 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
control_C_was_pressed = FALSE; control_C_was_pressed = FALSE;
/* Read the entire file into the new buffer. */ /* Read in the entire file, byte by byte, line by line. */
while ((input_int = getc_unlocked(f)) != EOF) { while ((onevalue = getc_unlocked(f)) != EOF) {
char input = (char)onevalue;
if (control_C_was_pressed) { if (control_C_was_pressed) {
statusline(ALERT, _("Interrupted")); statusline(ALERT, _("Interrupted"));
break; break;
} }
input = (char)input_int;
/* When the byte before the current one is a CR (and we're still on /* 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 * 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. */ * converting), then mark the format as DOS or Mac or a mixture. */
@ -703,9 +697,9 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
/* When needed, increase the line-buffer size. Don't bother /* When needed, increase the line-buffer size. Don't bother
* decreasing it -- it gets freed when reading is finished. */ * decreasing it -- it gets freed when reading is finished. */
if (len == bufx) { if (len == bufsize) {
bufx += LUMPSIZE; bufsize += LUMPSIZE;
buf = charealloc(buf, bufx); buf = charealloc(buf, bufsize);
} }
continue; continue;