tweaks: elide a variable that is a copy of another
parent
6f23d9c18c
commit
8a88cea256
48
src/text.c
48
src/text.c
|
@ -2067,8 +2067,6 @@ void justify_paragraph(filestruct **line, size_t quote_len,
|
||||||
filestruct *sampleline;
|
filestruct *sampleline;
|
||||||
/* The line from which the indentation is copied -- either
|
/* The line from which the indentation is copied -- either
|
||||||
* the first and only or the second line of the paragraph. */
|
* the first and only or the second line of the paragraph. */
|
||||||
filestruct *jusline;
|
|
||||||
/* The line of the current paragraph that we're justifying. */
|
|
||||||
size_t lead_len;
|
size_t lead_len;
|
||||||
/* Length of the quote part plus the indentation part. */
|
/* Length of the quote part plus the indentation part. */
|
||||||
ssize_t break_pos;
|
ssize_t break_pos;
|
||||||
|
@ -2084,44 +2082,41 @@ void justify_paragraph(filestruct **line, size_t quote_len,
|
||||||
lead_string = mallocstrncpy(NULL, sampleline->data, lead_len + 1);
|
lead_string = mallocstrncpy(NULL, sampleline->data, lead_len + 1);
|
||||||
lead_string[lead_len] = '\0';
|
lead_string[lead_len] = '\0';
|
||||||
|
|
||||||
/* Start justifying on the first line. */
|
|
||||||
jusline = *line;
|
|
||||||
|
|
||||||
/* First tack all the lines of the paragraph together, skipping
|
/* First tack all the lines of the paragraph together, skipping
|
||||||
* the quoting and indentation on all lines after the first. */
|
* the quoting and indentation on all lines after the first. */
|
||||||
while (par_len > 1) {
|
while (par_len > 1) {
|
||||||
filestruct *next_line = jusline->next;
|
filestruct *next_line = (*line)->next;
|
||||||
size_t line_len = strlen(jusline->data);
|
size_t line_len = strlen((*line)->data);
|
||||||
size_t next_line_len = strlen(next_line->data);
|
size_t next_line_len = strlen(next_line->data);
|
||||||
|
|
||||||
lead_len = quote_len + indent_length(next_line->data + quote_len);
|
lead_len = quote_len + indent_length(next_line->data + quote_len);
|
||||||
|
|
||||||
/* We're just about to tack the next line onto this one. If
|
/* We're just about to tack the next line onto this one. If
|
||||||
* this line isn't empty, make sure it ends in a space. */
|
* this line isn't empty, make sure it ends in a space. */
|
||||||
if (line_len > 0 && jusline->data[line_len - 1] != ' ') {
|
if (line_len > 0 && (*line)->data[line_len - 1] != ' ') {
|
||||||
jusline->data = charealloc(jusline->data, line_len + 2);
|
(*line)->data = charealloc((*line)->data, line_len + 2);
|
||||||
jusline->data[line_len++] = ' ';
|
(*line)->data[line_len++] = ' ';
|
||||||
jusline->data[line_len] = '\0';
|
(*line)->data[line_len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
jusline->data = charealloc(jusline->data,
|
(*line)->data = charealloc((*line)->data,
|
||||||
line_len + next_line_len - lead_len + 1);
|
line_len + next_line_len - lead_len + 1);
|
||||||
strcat(jusline->data, next_line->data + lead_len);
|
strcat((*line)->data, next_line->data + lead_len);
|
||||||
|
|
||||||
unlink_node(next_line);
|
unlink_node(next_line);
|
||||||
par_len--;
|
par_len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change all blank characters to spaces and remove excess spaces. */
|
/* Change all blank characters to spaces and remove excess spaces. */
|
||||||
justify_format(jusline, quote_len + indent_length(jusline->data + quote_len));
|
justify_format(*line, quote_len + indent_length((*line)->data + quote_len));
|
||||||
|
|
||||||
/* Now break this long line into pieces that each fit with wrap_at columns. */
|
/* Now break this long line into pieces that each fit with wrap_at columns. */
|
||||||
while (strlenpt(jusline->data) > wrap_at) {
|
while (strlenpt((*line)->data) > wrap_at) {
|
||||||
size_t line_len = strlen(jusline->data);
|
size_t line_len = strlen((*line)->data);
|
||||||
|
|
||||||
/* Find a point in the line where it can be broken. */
|
/* Find a point in the line where it can be broken. */
|
||||||
break_pos = break_line(jusline->data + lead_len,
|
break_pos = break_line((*line)->data + lead_len,
|
||||||
wrap_at - strnlenpt(jusline->data, lead_len), FALSE);
|
wrap_at - strnlenpt((*line)->data, lead_len), FALSE);
|
||||||
|
|
||||||
/* If we can't break the line, or don't need to, we're done. */
|
/* If we can't break the line, or don't need to, we're done. */
|
||||||
if (break_pos == -1 || break_pos + lead_len == line_len)
|
if (break_pos == -1 || break_pos + lead_len == line_len)
|
||||||
|
@ -2133,30 +2128,27 @@ void justify_paragraph(filestruct **line, size_t quote_len,
|
||||||
|
|
||||||
/* Insert a new line after the current one, and copy the leading part
|
/* Insert a new line after the current one, and copy the leading part
|
||||||
* plus the text after the breaking point into it. */
|
* plus the text after the breaking point into it. */
|
||||||
splice_node(jusline, make_new_node(jusline));
|
splice_node(*line, make_new_node(*line));
|
||||||
jusline->next->data = charalloc(lead_len + 1 + line_len - break_pos);
|
(*line)->next->data = charalloc(lead_len + line_len - break_pos + 1);
|
||||||
strncpy(jusline->next->data, lead_string, lead_len);
|
strncpy((*line)->next->data, lead_string, lead_len);
|
||||||
strcpy(jusline->next->data + lead_len, jusline->data + break_pos);
|
strcpy((*line)->next->data + lead_len, (*line)->data + break_pos);
|
||||||
|
|
||||||
/* When requested, snip all trailing blanks. */
|
/* When requested, snip all trailing blanks. */
|
||||||
if (ISSET(TRIM_BLANKS)) {
|
if (ISSET(TRIM_BLANKS)) {
|
||||||
while (break_pos > 0 &&
|
while (break_pos > 0 &&
|
||||||
is_blank_mbchar(&jusline->data[break_pos - 1]))
|
is_blank_mbchar(&(*line)->data[break_pos - 1]))
|
||||||
break_pos--;
|
break_pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now actually break the current line. */
|
/* Now actually break the current line. */
|
||||||
null_at(&jusline->data, break_pos);
|
null_at(&(*line)->data, break_pos);
|
||||||
|
|
||||||
/* Go to the next line. */
|
/* Go to the next line. */
|
||||||
jusline = jusline->next;
|
*line = (*line)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(lead_string);
|
free(lead_string);
|
||||||
|
|
||||||
/* We're on the last line of the paragraph. Save it. */
|
|
||||||
*line = jusline;
|
|
||||||
|
|
||||||
/* If possible, go to the next line. */
|
/* If possible, go to the next line. */
|
||||||
if ((*line)->next != NULL)
|
if ((*line)->next != NULL)
|
||||||
*line = (*line)->next;
|
*line = (*line)->next;
|
||||||
|
|
Loading…
Reference in New Issue