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));
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;
}
/* 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. */
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;
#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;
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
#endif
/* Read in the last line properly. */
- fileptr = read_line(buf, fileptr, &first_line_ins, len);
+ fileptr = read_line(buf, len, fileptr);
num_lines++;
}
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);