Inserting a new node into a linked list by using just two parameters:

the insertion point and the new node.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5437 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-11-24 13:24:01 +00:00
parent 9c821dfe2e
commit fbe4376822
5 changed files with 12 additions and 14 deletions

View File

@ -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

View File

@ -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. */

View File

@ -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);

View File

@ -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, "");

View File

@ -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