bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fmt gobbles leading whitespace in prefix mode


From: G.P. Halkes
Subject: Re: fmt gobbles leading whitespace in prefix mode
Date: Fri, 5 Jan 2007 09:35:09 +0100

Hi,

it appears there is another bug in fmt regarding prefixes: lines that contain
only a prefix of the prefix and whitespace will be removed. This problem does
not occur after applying the second of the two patches I sent in my previous
post. However, that particular patch will introduce an extra newline at the
end of the file, if the last line contains a prefix of the prefix followed by
the end of file.

Therefore, attached to this post are revised patches (assuming you haven't
yet applied the patches for the previous post) that will solve these issues.

Example:
--------------------------
$ cat test.txt
foo bar
bl
        blah comment here
$ fmt -p blah test.txt
foo bar

        blah comment here
--------------------------


Regards,
Gertjan Halkes


On Thu, 4 Jan 2007 16:55:30 +0100, "G.P. Halkes" <address@hidden> wrote:

>This message is a reply to:
>
>http://lists.gnu.org/archive/html/bug-coreutils/2006-01/msg00144.html
>
>I ran into the same bug recently, and as it is not fixed in CVS I decided I'd
>have a go at writing a patch.
>
>[ For those unwilling to check the previous message: fmt removes whitespace
>from lines that don't start with the specified prefix in --prefix mode ]
>
>I also found that the second testcase added in the aforementioned message is
>actually incorrect. The documentation for the prefix option says that lines
>that do not start with the prefix are not touched. Or as the info page says:
>
>`-p PREFIX'
>`--prefix=PREFIX'
>     Only lines beginning with PREFIX (possibly preceded by whitespace)
>     are subject to formatting. (...)
>
>The second testcase specifically wants to test for merging of lines that do
>NOT start with prefix which is in direct contradiction to the above
>explanation of --prefix.
>
>When making this patch I also found that fmt removes all text from lines with
>only whitespace (fine with me) and lines with a prefix followed by
>whitespace. The latter case I find strange. The user obviously typed a line
>with only the prefix, so why does fmt throw away this explicitly added line?
>
>For example:
>
>       # Function foo
>       #
>       # Args: bar which does blah
>
>Is turned into
>
>       # Function foo
>
>       # Args: bar which does blah
>
>In my opnion the example should be left unchanged. I have included two
>patches: one which only fixes the problem described in the previous post, and
>one that ALSO changes the removal of the prefix'ed but otherwise empty lines.
>The patches are mutually exclusive though, because they change the same line
>in different ways. I think the patch names are self explanatory. Both patches
>also change the testcases.
>
>Regards,
>Gertjan Halkes

Attachment: prefix_keep_space2.patch
Description: Binary data

Attachment: prefix_keep_space_keep_prefix2.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]