From: Eric Sunshine Date: Mon, 23 Apr 2018 00:24:55 GMT Subject: Re: [PATCH v2 4/6] grep.c: display column number of first match Message-ID: In-Reply-To: <4531659687de87b1bc143cb5cb364b691a58c6c9.1524429778.git.me@ttaylorr.com> On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau wrote: > Building upon our work in the previous commit to add members 'columnnum' > and 'color_columno' to 'grep_opt', we teach show_line() how to respect > those options. > > When requested, show_line() will display the column number of the first > match on a non-context line. show_line() differentiates between context > and non-context lines through the '&& cno' check. 'cno' will be equal to > zero if and only if show_line() is invoked on a context line. It will be > a non-zero value otherwise. This interpretation of 'cno' seems important enough to deserve an in-code comment. (And, you may be able to drop some of the same information from the commit message if it merely duplicates the in-code comment.) > Signed-off-by: Taylor Blau > --- > diff --git a/grep.c b/grep.c > @@ -1404,6 +1404,12 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, > + if (opt->columnnum && cno) { > + char buf[32]; > + xsnprintf(buf, sizeof(buf), "%d", cno); > + output_color(opt, buf, strlen(buf), opt->color_columnno); > + output_sep(opt, sign); > + }