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-d3aeb78583b8master
parent
d63912947a
commit
22e9283520
|
@ -1,6 +1,8 @@
|
||||||
2015-12-18 Benno Schulenberg <bensberg@justemail.net>
|
2015-12-18 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* src/color.c (color_init): Use less #ifdefs, and adjust indentation.
|
* src/color.c (color_init): Use less #ifdefs, and adjust indentation.
|
||||||
* src/color.c (set_colorpairs): Improve comments and rename vars.
|
* 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>
|
2015-12-11 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* doc/syntax/Makefile.am: Add missing autoconf and nftables syntaxes.
|
* doc/syntax/Makefile.am: Add missing autoconf and nftables syntaxes.
|
||||||
|
|
35
src/files.c
35
src/files.c
|
@ -585,12 +585,9 @@ int is_file_writable(const char *filename)
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We make a new line of text from buf. buf is length buf_len. If
|
/* Make a new line of text from the given buf, which is of length buf_len.
|
||||||
* first_line_ins is TRUE, then we put the new line at the top of the
|
* Then attach this line after prevnode. */
|
||||||
* file. Otherwise, we assume prevnode is the last line of the file,
|
filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode)
|
||||||
* and put our line after prevnode. */
|
|
||||||
filestruct *read_line(char *buf, filestruct *prevnode, bool
|
|
||||||
*first_line_ins, size_t buf_len)
|
|
||||||
{
|
{
|
||||||
filestruct *fileptr = (filestruct *)nmalloc(sizeof(filestruct));
|
filestruct *fileptr = (filestruct *)nmalloc(sizeof(filestruct));
|
||||||
|
|
||||||
|
@ -612,20 +609,17 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||||
fileptr->multidata = NULL;
|
fileptr->multidata = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*first_line_ins) {
|
fileptr->prev = prevnode;
|
||||||
|
|
||||||
|
if (prevnode == NULL) {
|
||||||
/* Special case: we're inserting into the first line. */
|
/* Special case: we're inserting into the first line. */
|
||||||
fileptr->prev = NULL;
|
|
||||||
fileptr->next = openfile->fileage;
|
fileptr->next = openfile->fileage;
|
||||||
openfile->fileage = fileptr;
|
openfile->fileage = fileptr;
|
||||||
fileptr->lineno = 1;
|
fileptr->lineno = 1;
|
||||||
/* Make sure that our edit window stays on the first line. */
|
/* Make sure that our edit window stays on the first line. */
|
||||||
openfile->edittop = fileptr;
|
openfile->edittop = fileptr;
|
||||||
*first_line_ins = FALSE;
|
|
||||||
} else {
|
} else {
|
||||||
assert(prevnode != NULL);
|
|
||||||
|
|
||||||
prevnode->next = fileptr;
|
prevnode->next = fileptr;
|
||||||
fileptr->prev = prevnode;
|
|
||||||
fileptr->next = NULL;
|
fileptr->next = NULL;
|
||||||
fileptr->lineno = prevnode->lineno + 1;
|
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. */
|
/* The current input character. */
|
||||||
char *buf;
|
char *buf;
|
||||||
/* The buffer where we store chunks of the file. */
|
/* The buffer where we store chunks of the file. */
|
||||||
filestruct *fileptr = openfile->current;
|
filestruct *fileptr = openfile->current->prev;
|
||||||
/* The current line of the file. */
|
/* The line after which to start inserting. */
|
||||||
bool first_line_ins = FALSE;
|
|
||||||
/* Whether we're inserting with the cursor on the first line. */
|
|
||||||
int input_int;
|
int input_int;
|
||||||
/* The current value we read from the file, whether an input
|
/* The current value we read from the file, whether an input
|
||||||
* character or EOF. */
|
* character or EOF. */
|
||||||
|
@ -676,11 +668,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
add_undo(INSERT);
|
add_undo(INSERT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (openfile->current == openfile->fileage)
|
|
||||||
first_line_ins = TRUE;
|
|
||||||
else
|
|
||||||
fileptr = openfile->current->prev;
|
|
||||||
|
|
||||||
/* Read the entire file into the filestruct. */
|
/* Read the entire file into the filestruct. */
|
||||||
while ((input_int = getc(f)) != EOF) {
|
while ((input_int = getc(f)) != EOF) {
|
||||||
input = (char)input_int;
|
input = (char)input_int;
|
||||||
|
@ -701,7 +688,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read in the line properly. */
|
/* 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. */
|
/* Reset the line length in preparation for the next line. */
|
||||||
len = 0;
|
len = 0;
|
||||||
|
@ -722,7 +709,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||||
format += 2;
|
format += 2;
|
||||||
|
|
||||||
/* Read in the line properly. */
|
/* 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.
|
/* Reset the line length in preparation for the next line.
|
||||||
* Since we've already read in the next character, reset it
|
* 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
|
#endif
|
||||||
|
|
||||||
/* Read in the last line properly. */
|
/* Read in the last line properly. */
|
||||||
fileptr = read_line(buf, fileptr, &first_line_ins, len);
|
fileptr = read_line(buf, len, fileptr);
|
||||||
num_lines++;
|
num_lines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,8 +291,7 @@ void switch_to_prev_buffer_void(void);
|
||||||
void switch_to_next_buffer_void(void);
|
void switch_to_next_buffer_void(void);
|
||||||
bool close_buffer(bool quiet);
|
bool close_buffer(bool quiet);
|
||||||
#endif
|
#endif
|
||||||
filestruct *read_line(char *buf, filestruct *prevnode, bool
|
filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode);
|
||||||
*first_line_ins, size_t buf_len);
|
|
||||||
void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkwritable);
|
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);
|
int open_file(const char *filename, bool newfie, bool quiet, FILE **f);
|
||||||
char *get_next_filename(const char *name, const char *suffix);
|
char *get_next_filename(const char *name, const char *suffix);
|
||||||
|
|
Loading…
Reference in New Issue