1
1

Chopping a superfluous boolean parameter -- 'prevnode' being NULL is

enough indication that the first line is being read.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5498 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Benno Schulenberg 2015-12-18 19:18:23 +00:00
родитель d63912947a
Коммит 22e9283520
3 изменённых файлов: 14 добавлений и 26 удалений

Просмотреть файл

@ -1,6 +1,8 @@
2015-12-18 Benno Schulenberg <bensberg@justemail.net>
* src/color.c (color_init): Use less #ifdefs, and adjust indentation.
* src/color.c (set_colorpairs): Improve comments and rename vars.
* src/files.c (read_line): Chop a superfluous bool -- 'prevnode' being
NULL is enough indication that the first line is being read.
2015-12-11 Benno Schulenberg <bensberg@justemail.net>
* doc/syntax/Makefile.am: Add missing autoconf and nftables syntaxes.

Просмотреть файл

@ -585,12 +585,9 @@ int is_file_writable(const char *filename)
return ans;
}
/* We make a new line of text from buf. buf is length buf_len. If
* first_line_ins is TRUE, then we put the new line at the top of the
* file. Otherwise, we assume prevnode is the last line of the file,
* and put our line after prevnode. */
filestruct *read_line(char *buf, filestruct *prevnode, bool
*first_line_ins, size_t buf_len)
/* Make a new line of text from the given buf, which is of length buf_len.
* Then attach this line after prevnode. */
filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode)
{
filestruct *fileptr = (filestruct *)nmalloc(sizeof(filestruct));
@ -612,20 +609,17 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
fileptr->multidata = NULL;
#endif
if (*first_line_ins) {
fileptr->prev = prevnode;
if (prevnode == NULL) {
/* Special case: we're inserting into the first line. */
fileptr->prev = NULL;
fileptr->next = openfile->fileage;
openfile->fileage = fileptr;
fileptr->lineno = 1;
/* Make sure that our edit window stays on the first line. */
openfile->edittop = fileptr;
*first_line_ins = FALSE;
} else {
assert(prevnode != NULL);
prevnode->next = fileptr;
fileptr->prev = prevnode;
fileptr->next = NULL;
fileptr->lineno = prevnode->lineno + 1;
}
@ -652,10 +646,8 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
/* The current input character. */
char *buf;
/* The buffer where we store chunks of the file. */
filestruct *fileptr = openfile->current;
/* The current line of the file. */
bool first_line_ins = FALSE;
/* Whether we're inserting with the cursor on the first line. */
filestruct *fileptr = openfile->current->prev;
/* The line after which to start inserting. */
int input_int;
/* The current value we read from the file, whether an input
* character or EOF. */
@ -676,11 +668,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
add_undo(INSERT);
#endif
if (openfile->current == openfile->fileage)
first_line_ins = TRUE;
else
fileptr = openfile->current->prev;
/* Read the entire file into the filestruct. */
while ((input_int = getc(f)) != EOF) {
input = (char)input_int;
@ -701,7 +688,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
#endif
/* Read in the line properly. */
fileptr = read_line(buf, fileptr, &first_line_ins, len);
fileptr = read_line(buf, len, fileptr);
/* Reset the line length in preparation for the next line. */
len = 0;
@ -722,7 +709,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
format += 2;
/* Read in the line properly. */
fileptr = read_line(buf, fileptr, &first_line_ins, len);
fileptr = read_line(buf, len, fileptr);
/* Reset the line length in preparation for the next line.
* Since we've already read in the next character, reset it
@ -788,7 +775,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
#endif
/* Read in the last line properly. */
fileptr = read_line(buf, fileptr, &first_line_ins, len);
fileptr = read_line(buf, len, fileptr);
num_lines++;
}

Просмотреть файл

@ -291,8 +291,7 @@ void switch_to_prev_buffer_void(void);
void switch_to_next_buffer_void(void);
bool close_buffer(bool quiet);
#endif
filestruct *read_line(char *buf, filestruct *prevnode, bool
*first_line_ins, size_t buf_len);
filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode);
void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkwritable);
int open_file(const char *filename, bool newfie, bool quiet, FILE **f);
char *get_next_filename(const char *name, const char *suffix);