summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-09-24 08:50:20 +0000
committerJim Meyering <jim@meyering.net>2002-09-24 08:50:20 +0000
commitcc0a6e14fc608e6b503136bbb8a668c14a35566f (patch)
tree4867a5786e2f973cfd14bb5614d7c4f3767e80ee
parent8683024a34c12dacff9b9f58bc1f0ef552a60ae4 (diff)
downloadcoreutils-cc0a6e14fc608e6b503136bbb8a668c14a35566f.tar.xz
fmt's -s, -t, -c options didn't work properly for long lines.
Since get_line may end up calling put_paragraph (for long lines), be sure to set global, `other_indent', before it is used there. (set_other_indent): New function, factored out of... (get_paragraph): ... here. Call it. (get_line): Call set_other_indent before calling flush_paragraph, which calls fmt_paragraph, which in turn calls put_paragraph, which uses other_indent.
-rw-r--r--src/fmt.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/fmt.c b/src/fmt.c
index fbc2c578d..986651c15 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -466,6 +466,39 @@ fmt (FILE *f)
}
}
+/* Set the global variable `other_indent' according to SAME_PARAGRAPH
+ and other global variables. */
+
+static void
+set_other_indent (bool same_paragraph)
+{
+ if (split)
+ other_indent = first_indent;
+ else if (crown)
+ {
+ other_indent = (same_paragraph ? in_column : first_indent);
+ }
+ else if (tagged)
+ {
+ if (same_paragraph && in_column != first_indent)
+ {
+ other_indent = in_column;
+ }
+
+ /* Only one line: use the secondary indent from last time if it
+ splits, or 0 if there have been no multi-line paragraphs in the
+ input so far. But if these rules make the two indents the same,
+ pick a new secondary indent. */
+
+ else if (other_indent == first_indent)
+ other_indent = first_indent == 0 ? DEF_INDENT : 0;
+ }
+ else
+ {
+ other_indent = first_indent;
+ }
+}
+
/* Read a paragraph from input file F. A paragraph consists of a
maximal number of non-blank (excluding any prefix) lines subject to:
* In split mode, a paragraph is a single non-blank line.
@@ -512,48 +545,38 @@ get_paragraph (FILE *f)
wptr = parabuf;
word_limit = word;
c = get_line (f, c);
+ set_other_indent (same_para (c));
/* Read rest of paragraph (unless split is specified). */
if (split)
- other_indent = first_indent;
+ {
+ /* empty */
+ }
else if (crown)
{
if (same_para (c))
{
- other_indent = in_column;
do
{ /* for each line till the end of the para */
c = get_line (f, c);
}
while (same_para (c) && in_column == other_indent);
}
- else
- other_indent = first_indent;
}
else if (tagged)
{
if (same_para (c) && in_column != first_indent)
{
- other_indent = in_column;
do
{ /* for each line till the end of the para */
c = get_line (f, c);
}
while (same_para (c) && in_column == other_indent);
}
-
- /* Only one line: use the secondary indent from last time if it
- splits, or 0 if there have been no multi-line paragraphs in the
- input so far. But if these rules make the two indents the same,
- pick a new secondary indent. */
-
- else if (other_indent == first_indent)
- other_indent = first_indent == 0 ? DEF_INDENT : 0;
}
else
{
- other_indent = first_indent;
while (same_para (c) && in_column == other_indent)
c = get_line (f, c);
}
@@ -627,7 +650,10 @@ get_line (FILE *f, register int c)
do
{
if (wptr == end_of_parabuf)
- flush_paragraph ();
+ {
+ set_other_indent (true);
+ flush_paragraph ();
+ }
*wptr++ = c;
c = getc (f);
}
@@ -646,7 +672,10 @@ get_line (FILE *f, register int c)
if (c == '\n' || c == EOF || uniform)
word_limit->space = word_limit->final ? 2 : 1;
if (word_limit == end_of_word)
- flush_paragraph ();
+ {
+ set_other_indent (true);
+ flush_paragraph ();
+ }
word_limit++;
if (c == EOF)
return EOF;