Re: [PATCH 12/21] trailer: handle configured nondefault separators explicitly
- From
Jeff King <peff@peff.net>
- Date
- Nov 10, 2020, 20:06 UTC
- Message-ID
- <20201110200604.GE1987088@coredump.intra.peff.net>
- In-Reply-To
- <20201025212652.3003036-13-anders@0x63.nu>
On Sun, Oct 25, 2020 at 10:26:43PM +0100, Anders Waldenborg wrote:
Show 5 quoted lines
> static void print_item(FILE *outfile, const struct trailer_item *item)
> {
> if (item->token) {
> const char *tok = item->token;
> + const char *sep = (char []){separators[0], ' ', '\0'};I don't think this syntax is likely to be sufficiently portable, as you're defining a variable length array implicitly. I think:
char orig_sep[] = { separators[0], ' ', '\0' };
const char *sep = orig_sep;would work. Though I suspect that just making this:
Show 8 quoted lines
> - c = last_non_space_char(tok); > - if (!c) > - return; > - if (strchr(separators, c)) > - fputs(tok, outfile); > - else > - fprintf(outfile, "%s%c ", tok, separators[0]); > + fprintf(outfile, "%s%s", tok, sep);
into:
fprintf(outfile, "%s", tok); if (conf && conf->nondefault_separator) fprintf(outfile, "%s", conf->nondefault_separator); else fprintf(outfile, "%c ", separators[0]);
might be simpler for a reader to follow, even though it's a little more verbose.
-Peff