tweaks: stop passing 'cutbuffer' and 'cutbottom' back and forth

All extractions are done into the cutbuffer, so it is pointless to pass
'cutbuffer' and 'cutbottom' in and back out as parameters all the time.
Just use those global variables directly.

Also, rename the function as there is no longer a buffer among its
parameters.
master
Benno Schulenberg 2019-05-01 11:26:26 +02:00
parent 2b9dd6c574
commit 85fc41470b
4 changed files with 24 additions and 29 deletions

View File

@ -214,10 +214,9 @@ void cut_line(void)
* head of this line to the head of the next line into the cutbuffer;
* otherwise, move all of the text of this line into the cutbuffer. */
if (openfile->current != openfile->filebot)
extract_buffer(&cutbuffer, &cutbottom, openfile->current, 0,
openfile->current->next, 0);
extract(openfile->current, 0, openfile->current->next, 0);
else
extract_buffer(&cutbuffer, &cutbottom, openfile->current, 0,
extract(openfile->current, 0,
openfile->current, strlen(openfile->current->data));
openfile->placewewant = 0;
}
@ -232,7 +231,7 @@ void cut_marked(bool *right_side_up)
get_region((const linestruct **)&top, &top_x,
(const linestruct **)&bot, &bot_x, right_side_up);
extract_buffer(&cutbuffer, &cutbottom, top, top_x, bot, bot_x);
extract(top, top_x, bot, bot_x);
openfile->placewewant = xplustabs();
}
@ -247,11 +246,11 @@ void cut_to_eol(void)
* the cutbuffer. Otherwise, when not at the end of the buffer,
* move the line separation into the cutbuffer. */
if (openfile->current_x < data_len)
extract_buffer(&cutbuffer, &cutbottom, openfile->current,
openfile->current_x, openfile->current, data_len);
extract(openfile->current, openfile->current_x,
openfile->current, data_len);
else if (openfile->current != openfile->filebot) {
extract_buffer(&cutbuffer, &cutbottom, openfile->current,
openfile->current_x, openfile->current->next, 0);
extract(openfile->current, openfile->current_x,
openfile->current->next, 0);
openfile->placewewant = xplustabs();
}
}
@ -259,8 +258,7 @@ void cut_to_eol(void)
/* Move all text from the cursor position to end-of-file into the cutbuffer. */
void cut_to_eof(void)
{
extract_buffer(&cutbuffer, &cutbottom,
openfile->current, openfile->current_x,
extract(openfile->current, openfile->current_x,
openfile->filebot, strlen(openfile->filebot->data));
}
#endif /* !NANO_TINY */

View File

@ -276,9 +276,8 @@ void unpartition_buffer(partition **p)
}
/* Move all text between (top, top_x) and (bot, bot_x) from the current buffer
* to the given other buffer (beginning at buffer_top, ending at buffer_bot. */
void extract_buffer(linestruct **buffer_top, linestruct **buffer_bot,
linestruct *top, size_t top_x, linestruct *bot, size_t bot_x)
* into the cutbuffer. */
void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x)
{
bool edittop_inside;
#ifndef NANO_TINY
@ -315,30 +314,30 @@ void extract_buffer(linestruct **buffer_top, linestruct **buffer_bot,
/* If the given buffer is empty, just move all the text directly into it;
* otherwise, append the text to what is already there. */
if (*buffer_top == NULL) {
*buffer_top = openfile->filetop;
*buffer_bot = openfile->filebot;
renumber_from(*buffer_top);
if (cutbuffer == NULL) {
cutbuffer = openfile->filetop;
cutbottom = openfile->filebot;
renumber_from(cutbuffer);
} else {
linestruct *was_bottom = *buffer_bot;
linestruct *was_bottom = cutbottom;
/* Tack the data of the first line of the text onto the data of
* the last line in the given buffer. */
(*buffer_bot)->data = charealloc((*buffer_bot)->data,
strlen((*buffer_bot)->data) +
cutbottom->data = charealloc(cutbottom->data,
strlen(cutbottom->data) +
strlen(openfile->filetop->data) + 1);
strcat((*buffer_bot)->data, openfile->filetop->data);
strcat(cutbottom->data, openfile->filetop->data);
/* Attach the second line of the text (if any) to the last line
* of the buffer, then remove the now superfluous first line. */
(*buffer_bot)->next = openfile->filetop->next;
cutbottom->next = openfile->filetop->next;
delete_node(openfile->filetop);
/* If there is a second line, make the reverse attachment too and
* update the buffer pointer to point at the end of the text. */
if ((*buffer_bot)->next != NULL) {
(*buffer_bot)->next->prev = *buffer_bot;
*buffer_bot = openfile->filebot;
if (cutbottom->next != NULL) {
cutbottom->next->prev = cutbottom;
cutbottom = openfile->filebot;
}
renumber_from(was_bottom);

View File

@ -401,8 +401,7 @@ void renumber_from(linestruct *line);
partition *partition_buffer(linestruct *top, size_t top_x,
linestruct *bot, size_t bot_x);
void unpartition_buffer(partition **p);
void extract_buffer(linestruct **file_top, linestruct **file_bot,
linestruct *top, size_t top_x, linestruct *bot, size_t bot_x);
void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x);
void ingraft_buffer(linestruct *somebuffer);
void copy_from_buffer(linestruct *somebuffer);
#ifdef ENABLE_MULTIBUFFER

View File

@ -2046,8 +2046,7 @@ void do_justify(bool full_justify)
/* Do the equivalent of a marked cut into an empty cutbuffer. */
cutbuffer = NULL;
extract_buffer(&cutbuffer, &cutbottom, first_par_line, top_x,
last_par_line, bot_x);
extract(first_par_line, top_x, last_par_line, bot_x);
#ifndef NANO_TINY
update_undo(CUT);