diff --git a/ChangeLog b/ChangeLog index d69c3c31aba357f4a9a6fbd29083a680ab54438e..39b37030d6ead9f4acc34600a4969919223a3b14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ .mk as Makefiles. Suggested by Emmanuel Bourg in Debian bug #804845. * src/color.c (color_update): Tell the user when a syntax name given on the command line does not exist. This fixes Savannah bug #46503. + * src/nano.c (splice_node): Inserting a new node into a linked list + requires just two parameters: the insertion point and the new node. 2015-11-23 Benno Schulenberg <bensberg@justemail.net> * src/nano.c (main), src/winio.c (parse_kbinput): Make Ctrl+Left and diff --git a/src/nano.c b/src/nano.c index 2d75f2b658c3041df892c7cff5dbd07cac950934..d515380d047f0aa6215451ba15741ef1650ebe46 100644 --- a/src/nano.c +++ b/src/nano.c @@ -95,16 +95,15 @@ filestruct *copy_node(const filestruct *src) } /* Splice a node into an existing filestruct. */ -void splice_node(filestruct *begin, filestruct *newnode, filestruct - *end) +void splice_node(filestruct *begin, filestruct *newnode) { assert(newnode != NULL && begin != NULL); - newnode->next = end; + newnode->next = begin->next; newnode->prev = begin; + if (begin->next != NULL) + begin->next->prev = newnode; begin->next = newnode; - if (end != NULL) - end->prev = newnode; } /* Unlink a node from the rest of the filestruct and delete it. */ diff --git a/src/proto.h b/src/proto.h index e0a66b834559d1bd31d210e01349e1f06e8c076e..798ef12abcb17b4f0147a154922a9f9515271276 100644 --- a/src/proto.h +++ b/src/proto.h @@ -432,8 +432,7 @@ void do_right(void); /* All functions in nano.c. */ filestruct *make_new_node(filestruct *prevnode); filestruct *copy_node(const filestruct *src); -void splice_node(filestruct *begin, filestruct *newnode, filestruct - *end); +void splice_node(filestruct *begin, filestruct *newnode); void unlink_node(filestruct *fileptr); void delete_node(filestruct *fileptr); filestruct *copy_filestruct(const filestruct *src); diff --git a/src/search.c b/src/search.c index 202c9db46e4fc5cf393da5856511509a3d1e7127..dea199daa26a167cb6f4497d79a88f92cdc35b4d 100644 --- a/src/search.c +++ b/src/search.c @@ -1323,7 +1323,7 @@ void update_history(filestruct **h, const char *s) /* Add the new entry to the end. */ (*hbot)->data = mallocstrcpy((*hbot)->data, s); - splice_node(*hbot, make_new_node(*hbot), (*hbot)->next); + splice_node(*hbot, make_new_node(*hbot)); *hbot = (*hbot)->next; (*hbot)->data = mallocstrcpy(NULL, ""); diff --git a/src/text.c b/src/text.c index a7d717a53ac11c9bedbe774bd35dcf3ffe02e2ed..c21f6f8baac2db8863001744c9c6a9f3cdf648ef 100644 --- a/src/text.c +++ b/src/text.c @@ -546,7 +546,7 @@ void do_undo(void) data[u->mark_begin_x] = '\0'; free(f->data); f->data = data; - splice_node(f, t, f->next); + splice_node(f, t); if (f == openfile->filebot) openfile->filebot = t; goto_line_posx(u->lineno, u->begin); @@ -677,7 +677,7 @@ void do_redo(void) data[u->begin] = '\0'; free(f->data); f->data = data; - splice_node(f, shoveline, f->next); + splice_node(f, shoveline); if (f == openfile->filebot) openfile->filebot = shoveline; renumber(shoveline); @@ -788,7 +788,7 @@ void do_enter() #endif openfile->current_x = extra; - splice_node(openfile->current, newnode, openfile->current->next); + splice_node(openfile->current, newnode); if (openfile->current == openfile->filebot) openfile->filebot = newnode; @@ -2139,9 +2139,7 @@ void do_justify(bool full_justify) /* Make a new line, and copy the text after where we're * going to break this line to the beginning of the new * line. */ - splice_node(openfile->current, - make_new_node(openfile->current), - openfile->current->next); + splice_node(openfile->current, make_new_node(openfile->current)); /* If this paragraph is non-quoted, and autoindent isn't * turned on, set the indentation length to zero so that the