tweaks: frob some comments, and rename two parameters to make sense

master
Benno Schulenberg 2018-05-18 12:48:45 +02:00
parent 455899fe27
commit 4d232a4aef
1 changed files with 27 additions and 36 deletions

View File

@ -1900,21 +1900,16 @@ bool indents_match(const char *a_line, size_t a_indent, const char
return (b_indent <= a_indent && strncmp(a_line, b_line, b_indent) == 0); return (b_indent <= a_indent && strncmp(a_line, b_line, b_indent) == 0);
} }
/* Is foo the beginning of a paragraph? /* Return TRUE when the given line is the beginning of a paragraph.
* *
* A line of text consists of a "quote part", followed by an * A line consists of a "quote part", followed by an "indentation part",
* "indentation part", followed by text. The functions quote_length() * followed by a "text part". Each of these parts can be empty. A line
* and indent_length() calculate these parts. * is part of a paragraph if it has a non-empty text part.
* *
* A line is "part of a paragraph" if it has a part not in the quote * A line is "the beginning of a paragraph" if it has a text part AND
* part or the indentation.
*
* A line is "the beginning of a paragraph" if it is part of a
* paragraph and
* 1) it is the top line of the file, or * 1) it is the top line of the file, or
* 2) the line above it is not part of a paragraph, or * 2) the line above it is not part of a paragraph, or
* 3) the line above it does not have precisely the same quote * 3) the line above it has a different quote part, or
* part, or
* 4) the indentation of this line is not an initial substring of * 4) the indentation of this line is not an initial substring of
* the indentation of the previous line, or * the indentation of the previous line, or
* 5) this line has no quote part and some indentation, and * 5) this line has no quote part and some indentation, and
@ -1923,52 +1918,52 @@ bool indents_match(const char *a_line, size_t a_indent, const char
* then an indented line is expected to start a paragraph, as in * then an indented line is expected to start a paragraph, as in
* books. Thus, nano can justify an indented paragraph only if * books. Thus, nano can justify an indented paragraph only if
* autoindent is turned on. */ * autoindent is turned on. */
bool begpar(const filestruct *const foo) bool begpar(const filestruct *const line)
{ {
size_t quote_len, indent_len, temp_id_len; size_t quote_len, indent_len, temp_id_len;
if (foo == NULL) if (line == NULL)
return FALSE; return FALSE;
/* Case 1). */ /* Case 1). */
if (foo == openfile->fileage) if (line == openfile->fileage)
return TRUE; return TRUE;
quote_len = quote_length(foo->data); quote_len = quote_length(line->data);
indent_len = indent_length(foo->data + quote_len); indent_len = indent_length(line->data + quote_len);
/* Not part of a paragraph. */ /* Not part of a paragraph. */
if (foo->data[quote_len + indent_len] == '\0') if (line->data[quote_len + indent_len] == '\0')
return FALSE; return FALSE;
/* Case 3). */ /* Case 3). */
if (!quotes_match(foo->data, quote_len, foo->prev->data)) if (!quotes_match(line->data, quote_len, line->prev->data))
return TRUE; return TRUE;
temp_id_len = indent_length(foo->prev->data + quote_len); temp_id_len = indent_length(line->prev->data + quote_len);
/* Case 2) or 5) or 4). */ /* Case 2) or 5) or 4). */
if (foo->prev->data[quote_len + temp_id_len] == '\0' || if (line->prev->data[quote_len + temp_id_len] == '\0' ||
(quote_len == 0 && indent_len > 0 && !ISSET(AUTOINDENT)) || (quote_len == 0 && indent_len > 0 && !ISSET(AUTOINDENT)) ||
!indents_match(foo->prev->data + quote_len, temp_id_len, !indents_match(line->prev->data + quote_len, temp_id_len,
foo->data + quote_len, indent_len)) line->data + quote_len, indent_len))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
/* Is foo inside a paragraph? */ /* Return TRUE when the given line is part of a paragraph. */
bool inpar(const filestruct *const foo) bool inpar(const filestruct *const line)
{ {
size_t quote_len; size_t quote_len;
if (foo == NULL) if (line == NULL)
return FALSE; return FALSE;
quote_len = quote_length(foo->data); quote_len = quote_length(line->data);
return (foo->data[quote_len + indent_length(foo->data + return (line->data[quote_len +
quote_len)] != '\0'); indent_length(line->data + quote_len)] != '\0');
} }
/* Move the next par_len lines, starting with first_line, into the /* Move the next par_len lines, starting with first_line, into the
@ -2045,15 +2040,11 @@ void backup_lines(filestruct *first_line, size_t par_len)
* beginning of the next paragraph if we're not. Afterwards, save the * beginning of the next paragraph if we're not. Afterwards, save the
* quote length and paragraph length in *quote and *par. Return TRUE if * quote length and paragraph length in *quote and *par. Return TRUE if
* we found a paragraph, and FALSE if there was an error or we didn't * we found a paragraph, and FALSE if there was an error or we didn't
* find a paragraph. * find a paragraph. */
*
* See the comment at begpar() for more about when a line is the
* beginning of a paragraph. */
bool find_paragraph(size_t *const quote, size_t *const par) bool find_paragraph(size_t *const quote, size_t *const par)
{ {
size_t quote_len; size_t quote_len;
/* Length of the initial quotation of the paragraph we search /* Length of the initial quotation of the paragraph we search for. */
* for. */
size_t par_len; size_t par_len;
/* Number of lines in the paragraph we search for. */ /* Number of lines in the paragraph we search for. */
filestruct *current_save; filestruct *current_save;
@ -2119,8 +2110,8 @@ bool find_paragraph(size_t *const quote, size_t *const par)
return TRUE; return TRUE;
} }
/* If full_justify is TRUE, justify the entire file. Otherwise, justify /* Justify the current paragraph, and justify the entire file when
* the current paragraph. */ * full_justify is TRUE. */
void do_justify(bool full_justify) void do_justify(bool full_justify)
{ {
filestruct *first_par_line = NULL; filestruct *first_par_line = NULL;