parse-options: simplify usage_padding()
c512643e67 (short help: allow a gap smaller than USAGE_GAP, 2023-07-18) effectively did away with the two-space gap between options and their description; one space is enough now. Incorporate USAGE_GAP into USAGE_OPTS_WIDTH, merge the two cases with enough space on the line and incorporate the newline into the format for the remaining case. The output remains the same. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 5, 2023 at 16:52 UTC
311c8ff11cebef1219e110743d9a57cb9831ab06
1 file changed
+5
-12
parse-options.c
+5
-12
@@ -1025,21 +1025,14 @@ static int usage_indent(FILE *outfile)
1025
return fprintf(outfile, " ");
1026
}
1027
1028
-#define USAGE_OPTS_WIDTH 24
1029
-#define USAGE_GAP 2
1028
+#define USAGE_OPTS_WIDTH 26
1029
1030
static void usage_padding(FILE *outfile, size_t pos)
1031
{
1033
- int pad;
1034
- if (pos == USAGE_OPTS_WIDTH + 1)
1035
- pad = -1;
1036
- else if (pos <= USAGE_OPTS_WIDTH)
1037
- pad = USAGE_OPTS_WIDTH - pos;
1038
- else {
1039
- fputc('\n', outfile);
1040
- pad = USAGE_OPTS_WIDTH;
1041
- }
1042
- fprintf(outfile, "%*s", pad + USAGE_GAP, "");
1032
+ if (pos < USAGE_OPTS_WIDTH)
1033
+ fprintf(outfile, "%*s", USAGE_OPTS_WIDTH - (int)pos, "");
1034
+ else
1035
+ fprintf(outfile, "\n%*s", USAGE_OPTS_WIDTH, "");
1036
}
1037
1038
static const struct option *find_option_by_long_name(const struct option *opts,