Mon 20 Feb 2012 10:47:56 PM UTC, original submission:
In wrap_cstr(), when line wrapping occurs at a point in the string where there are two spaces together, the extra space causes the next line to get indented by an extra space.
You can see this occurring gengetopt's own --help text. In the description of the --unamed-opts argument, the second line is indented by an extra three spaces, rather than the usual two.
I've attached a patch that fixes this issue. It works as follows:
- preceding spaces are included in next_word
- leading spaces are trimmed from next_word when wrapping is done
Additionally, the patch makes two other changes:
- the `if (*out_buf)` test at the start of the loop was removed because, unless I missed something, it will always succeed!
- the two lines that, unless newlines were detected, always added a character to the output have been removed. It is not always ideal to add at least one character to the output: In the scenario where the next character is a space and you will be wrapping the line, that space will be outputted before the '\n'. For example, "...word word \n<indent>word...". Since preceding spaces are now included in next_word, removing this should be ok.
|