indent(1): Simplify pr_comment().
commitce25346de4c5923fb1b8dbba8e508df057190187
authorpfg <pfg@FreeBSD.org>
Sun, 31 Jul 2016 20:04:18 +0000 (31 20:04 +0000)
committerpfg <pfg@FreeBSD.org>
Sun, 31 Jul 2016 20:04:18 +0000 (31 20:04 +0000)
treee9370701d77043e21124db5037d6bf509c9e6464
parent46a7ba1e31254d725b91bc50d8e1597c3ee50f91
indent(1): Simplify pr_comment().

Modify count_spaces() to take a third parameter "end" that will make the
function return when the end is reached. This lets the caller pass a
pointer to non nul-terminated sequence of characters. Rename
count_spaces() to count_spaces_until() and reinstate count_spaces(), this
time based on count_spaces_until().

Use count_spaces_until() to recalculate current column when going through
a comment just before the fragment which decides if current line of the
comment should be wrapped. This move simplifies this code by eliminating
the need for keeping the column counter up to date every time e_com is
advanced and also reduces spread of code that has to know how many columns
a tab will produce.

Deduplicate code that decided if a comment needs a blank line at the top.

References:
https://github.com/pstef/freebsd_indent/commit/d9fa3b481532a448095f8ddd14fd0797ce59230c
https://github.com/pstef/freebsd_indent/commit/27185b4b336b0e2108a3d96aee6df80cced94192

Differential Revision: https://reviews.freebsd.org/D6966  (Partial)
Submitted by: Piotr Stefaniak
usr.bin/indent/indent.h
usr.bin/indent/io.c
usr.bin/indent/pr_comment.c