tweaks: rewrap a bunch of lines and some comments

This commit is contained in:
Benno Schulenberg 2016-06-14 11:06:04 +02:00
parent 49cb559c5b
commit 95f417fa9a
6 changed files with 65 additions and 86 deletions

View File

@ -1178,8 +1178,7 @@ void do_insertfile(
size_t top_x, bot_x;
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x,
&right_side_up);
(const filestruct **)&bot, &bot_x, &right_side_up);
single_line = (top == bot);
}

View File

@ -218,17 +218,15 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
} else
p->filebot = NULL;
/* Save the line above the top of the partition, detach the top of
* the partition from it, and save the text before top_x in
* top_data. */
/* Remember which line is above the top of the partition, detach the
* top of the partition from it, and save the text before top_x. */
p->top_prev = top->prev;
top->prev = NULL;
p->top_data = mallocstrncpy(NULL, top->data, top_x + 1);
p->top_data[top_x] = '\0';
/* Save the line below the bottom of the partition, detach the
* bottom of the partition from it, and save the text after bot_x in
* bot_data. */
/* Remember which line is below the bottom of the partition, detach the
* bottom of the partition from it, and save the text after bot_x. */
p->bot_next = bot->next;
bot->next = NULL;
p->bot_data = mallocstrcpy(NULL, bot->data + bot_x);
@ -237,8 +235,7 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
null_at(&bot->data, bot_x);
/* Remove all text before top_x at the top of the partition. */
charmove(top->data, top->data + top_x, strlen(top->data) -
top_x + 1);
charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1);
align(&top->data);
/* Return the partition. */
@ -261,7 +258,7 @@ void unpartition_filestruct(partition **p)
if (openfile->fileage->prev != NULL)
openfile->fileage->prev->next = openfile->fileage;
openfile->fileage->data = charealloc(openfile->fileage->data,
strlen((*p)->top_data) + strlen(openfile->fileage->data) + 1);
strlen((*p)->top_data) + strlen(openfile->fileage->data) + 1);
strcpy(openfile->fileage->data, (*p)->top_data);
free((*p)->top_data);
strcat(openfile->fileage->data, tmp);
@ -274,7 +271,7 @@ void unpartition_filestruct(partition **p)
if (openfile->filebot->next != NULL)
openfile->filebot->next->prev = openfile->filebot;
openfile->filebot->data = charealloc(openfile->filebot->data,
strlen(openfile->filebot->data) + strlen((*p)->bot_data) + 1);
strlen(openfile->filebot->data) + strlen((*p)->bot_data) + 1);
strcat(openfile->filebot->data, (*p)->bot_data);
free((*p)->bot_data);
@ -315,9 +312,8 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
* the edit window is inside the partition, and keep track of
* whether the mark begins inside the partition. */
filepart = partition_filestruct(top, top_x, bot, bot_x);
edittop_inside = (openfile->edittop->lineno >=
openfile->fileage->lineno && openfile->edittop->lineno <=
openfile->filebot->lineno);
edittop_inside = (openfile->edittop->lineno >= openfile->fileage->lineno &&
openfile->edittop->lineno <= openfile->filebot->lineno);
#ifndef NANO_TINY
if (openfile->mark_set) {
mark_inside = (openfile->mark_begin->lineno >=
@ -332,8 +328,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
}
#endif
/* Get the number of characters in the text, and subtract it from
* totsize. */
/* Subtract the number of characters in the text from the file size. */
openfile->totsize -= get_totsize(top, bot);
if (*file_top == NULL) {
@ -343,7 +338,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
*file_top = openfile->fileage;
*file_bot = openfile->filebot;
/* Renumber starting with file_top. */
/* Renumber, starting with file_top. */
renumber(*file_top);
} else {
filestruct *file_bot_save = *file_bot;
@ -366,13 +361,11 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
delete_node(openfile->fileage);
/* Renumber starting with the line after the original
* file_bot. */
/* Renumber, starting with the line after the original file_bot. */
renumber(file_bot_save->next);
}
/* Since the text has now been saved, remove it from the
* filestruct. */
/* Since the text has now been saved, remove it from the filestruct. */
openfile->fileage = (filestruct *)nmalloc(sizeof(filestruct));
openfile->fileage->data = mallocstrcpy(NULL, "");
openfile->filebot = openfile->fileage;
@ -408,12 +401,10 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
refresh_needed = TRUE;
}
/* Renumber starting with the beginning line of the old
* partition. */
/* Renumber, starting with the beginning line of the old partition. */
renumber(top_save);
/* If the NO_NEWLINES flag isn't set, and the text doesn't end with
* a magicline, add a new magicline. */
/* If the text doesn't end with a magicline, and it should, add one. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
new_magicline();
}
@ -439,17 +430,16 @@ void copy_from_filestruct(filestruct *somebuffer)
size_t top_x, bot_x;
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
(const filestruct **)&bot, &bot_x, &right_side_up);
single_line = (top == bot);
}
#endif
/* Partition the filestruct so that it contains no text, and keep
* track of whether the top of the edit window is inside the
* partition. */
filepart = partition_filestruct(openfile->current,
openfile->current_x, openfile->current, openfile->current_x);
/* Partition the filestruct so that it contains no text, and remember
* whether the top of the edit window is at the start of the buffer. */
filepart = partition_filestruct(openfile->current, openfile->current_x,
openfile->current, openfile->current_x);
edittop_inside = (openfile->edittop == openfile->fileage);
/* Put the top and bottom of the current filestruct at the top and
@ -489,10 +479,8 @@ void copy_from_filestruct(filestruct *somebuffer)
}
#endif
/* Get the number of characters in the copied text, and add it to
* totsize. */
openfile->totsize += get_totsize(openfile->fileage,
openfile->filebot);
/* Add the number of characters in the copied text to the file size. */
openfile->totsize += get_totsize(openfile->fileage, openfile->filebot);
/* Update the current y-coordinate to account for the number of
* lines the copied text has, less one since the first line will be
@ -510,12 +498,10 @@ void copy_from_filestruct(filestruct *somebuffer)
* again, plus the copied text. */
unpartition_filestruct(&filepart);
/* Renumber starting with the beginning line of the old
* partition. */
/* Renumber, starting with the beginning line of the old partition. */
renumber(top_save);
/* If the NO_NEWLINES flag isn't set, and the text doesn't end with
* a magicline, add a new magicline. */
/* If the text doesn't end with a magicline, and it should, add one. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
new_magicline();
}
@ -1864,12 +1850,11 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
#endif
while (i < output_len) {
/* If allow_cntrls is TRUE, convert nulls and newlines properly. */
/* If control codes are allowed, encode a null as a newline, and
* let a newline character create a whole new line. */
if (allow_cntrls) {
/* Null to newline, if needed. */
if (output[i] == '\0')
output[i] = '\n';
/* Newline to Enter, if needed. */
else if (output[i] == '\n') {
do_enter();
i++;
@ -1877,31 +1862,29 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
}
}
/* Interpret the next multibyte character. */
/* Get the next multibyte character. */
char_buf_len = parse_mbchar(output + i, char_buf, NULL);
i += char_buf_len;
/* If allow_cntrls is FALSE, filter out an ASCII control character. */
/* If controls are not allowed, ignore an ASCII control character. */
if (!allow_cntrls && is_ascii_cntrl_char(*(output + i - char_buf_len)))
continue;
/* If the NO_NEWLINES flag isn't set, when a character is
* added to the magicline, it means we need a new magicline. */
/* If we're adding to the magicline, create a new magicline. */
if (!ISSET(NO_NEWLINES) && openfile->filebot == openfile->current)
new_magicline();
/* More dangerousness fun =) */
openfile->current->data = charealloc(openfile->current->data,
current_len + char_buf_len + 1);
assert(openfile->current_x <= current_len);
/* Make room for the new character and copy it into the line. */
openfile->current->data = charealloc(openfile->current->data,
current_len + char_buf_len + 1);
charmove(openfile->current->data + openfile->current_x + char_buf_len,
openfile->current->data + openfile->current_x,
current_len - openfile->current_x + 1);
strncpy(openfile->current->data + openfile->current_x, char_buf,
char_buf_len);
char_buf_len);
current_len += char_buf_len;
openfile->totsize++;
set_modified();

View File

@ -628,7 +628,7 @@ ssize_t do_replace_loop(
if (old_mark_set) {
/* If the mark is on, frame the region, and turn the mark off. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
(const filestruct **)&bot, &bot_x, &right_side_up);
openfile->mark_set = FALSE;
/* Start either at the top or the bottom of the marked region. */

View File

@ -306,7 +306,7 @@ void do_indent(ssize_t cols)
/* If the mark is on, use all lines covered by the mark. */
if (openfile->mark_set)
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL);
(const filestruct **)&bot, &bot_x, NULL);
/* Otherwise, use the current line. */
else {
top = openfile->current;
@ -472,8 +472,8 @@ void do_comment()
/* Determine which lines to work on. */
if (openfile->mark_set)
mark_order((const filestruct **) &top, &top_x,
(const filestruct **) &bot, &bot_x, NULL);
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL);
else {
top = openfile->current;
bot = top;
@ -2037,7 +2037,7 @@ void backup_lines(filestruct *first_line, size_t par_len)
* current and filebot if filebot is the last line in the
* paragraph. */
assert(par_len > 0 && openfile->current->lineno + par_len <=
openfile->filebot->lineno + 1);
openfile->filebot->lineno + 1);
/* Move bot down par_len lines to the line after the last line of
* the paragraph, if there is one. */
@ -2047,7 +2047,7 @@ void backup_lines(filestruct *first_line, size_t par_len)
/* Move the paragraph from the current buffer's filestruct to the
* justify buffer. */
move_to_filestruct(&jusbuffer, &jusbottom, top, 0, bot,
(i == 1 && bot == openfile->filebot) ? strlen(bot->data) : 0);
(i == 1 && bot == openfile->filebot) ? strlen(bot->data) : 0);
/* Copy the paragraph back to the current buffer's filestruct from
* the justify buffer. */
@ -2524,8 +2524,8 @@ void do_justify(bool full_justify)
/* Partition the filestruct so that it contains only the
* text of the justified paragraph. */
filepart = partition_filestruct(first_par_line, 0,
last_par_line, filebot_inpar ?
strlen(last_par_line->data) : 0);
last_par_line, filebot_inpar ?
strlen(last_par_line->data) : 0);
/* Remove the text of the justified paragraph, and
* replace it with the text in the justify buffer. */
@ -2650,7 +2650,7 @@ bool do_int_spell_fix(const char *word)
/* If the mark is on, start at the beginning of the marked region. */
if (old_mark_set) {
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
(const filestruct **)&bot, &bot_x, &right_side_up);
/* If the region is marked normally, swap the end points, so that
* (current, current_x) (where searching starts) is at the top. */
if (right_side_up) {
@ -3030,7 +3030,7 @@ const char *do_alt_speller(char *tempfile_name)
if (old_mark_set) {
/* Trim the filestruct so that it contains only the marked text. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
/* Foresay whether a magicline will be added when the
@ -3606,7 +3606,7 @@ void do_wordlinechar_count(void)
* contains only the marked text, and turn the mark off. */
if (old_mark_set) {
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL);
(const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x);
openfile->mark_set = FALSE;
}

View File

@ -539,8 +539,9 @@ void new_magicline(void)
void remove_magicline(void)
{
if (openfile->filebot->data[0] == '\0' &&
openfile->filebot != openfile->fileage) {
assert(openfile->filebot != openfile->edittop && openfile->filebot != openfile->current);
openfile->filebot != openfile->fileage) {
assert(openfile->filebot != openfile->edittop &&
openfile->filebot != openfile->current);
openfile->filebot = openfile->filebot->prev;
free_filestruct(openfile->filebot->next);
@ -560,8 +561,8 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL);
if ((openfile->current->lineno == openfile->mark_begin->lineno &&
openfile->current_x > openfile->mark_begin_x) ||
openfile->current->lineno > openfile->mark_begin->lineno) {
openfile->current_x > openfile->mark_begin_x) ||
openfile->current->lineno > openfile->mark_begin->lineno) {
*top = openfile->mark_begin;
*top_x = openfile->mark_begin_x;
*bot = openfile->current;

View File

@ -2586,21 +2586,19 @@ void edit_draw(filestruct *fileptr, const char *converted, int
#endif /* !DISABLE_COLOR */
#ifndef NANO_TINY
/* If the mark is on, we need to display it. */
if (openfile->mark_set && (fileptr->lineno <=
openfile->mark_begin->lineno || fileptr->lineno <=
openfile->current->lineno) && (fileptr->lineno >=
openfile->mark_begin->lineno || fileptr->lineno >=
openfile->current->lineno)) {
/* fileptr is at least partially selected. */
const filestruct *top;
/* Either current or mark_begin, whichever is first. */
size_t top_x;
/* current_x or mark_begin_x, corresponding to top. */
const filestruct *bot;
size_t bot_x;
/* If the mark is on, and fileptr is at least partially selected, we
* need to paint it. */
if (openfile->mark_set &&
(fileptr->lineno <= openfile->mark_begin->lineno ||
fileptr->lineno <= openfile->current->lineno) &&
(fileptr->lineno >= openfile->mark_begin->lineno ||
fileptr->lineno >= openfile->current->lineno)) {
const filestruct *top, *bot;
/* The lines where the marked region begins and ends. */
size_t top_x, bot_x;
/* The x positions where the marked region begins and ends. */
int x_start;
/* Starting column for mvwaddnstr(). Zero-based. */
/* The starting column for mvwaddnstr(). Zero-based. */
int paintlen;
/* Number of characters to paint on this line. There are
* COLS characters on a whole line. */
@ -2614,7 +2612,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
if (bot->lineno > fileptr->lineno || bot_x > endpos)
bot_x = endpos;
/* The selected bit of fileptr is on this page. */
/* Only paint if the marked bit of fileptr is on this page. */
if (top_x < endpos && bot_x > startpos) {
assert(startpos <= top_x);
@ -2630,8 +2628,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
if (bot_x >= endpos)
paintlen = -1;
else
paintlen = strnlenpt(fileptr->data, bot_x) - (x_start +
start);
paintlen = strnlenpt(fileptr->data, bot_x) - (x_start + start);
/* If x_start is before the beginning of the page, shift
* paintlen x_start characters to compensate, and put
@ -2649,8 +2646,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
paintlen = actual_x(converted + index, paintlen);
wattron(edit, hilite_attribute);
mvwaddnstr(edit, line, x_start, converted + index,
paintlen);
mvwaddnstr(edit, line, x_start, converted + index, paintlen);
wattroff(edit, hilite_attribute);
}
}