aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-06-20 22:01:42 +0200
committerTobias Brunner <tobias@strongswan.org>2013-06-21 16:04:46 +0200
commit5991f0956525a49e8c8139cf8e450ccd96b60e53 (patch)
tree5a319fbfef36599470669248e221d6a2725cfd86
parent5e185047e1411d57751f1d2523b7fb266f3860b5 (diff)
downloadstrongswan-5991f0956525a49e8c8139cf8e450ccd96b60e53.tar.bz2
strongswan-5991f0956525a49e8c8139cf8e450ccd96b60e53.tar.xz
charon-cmd: Use fixed number of character to align command descriptions
If the command and argument is longer than that write the first line of description to the following line.
-rw-r--r--src/charon-cmd/charon-cmd.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/charon-cmd/charon-cmd.c b/src/charon-cmd/charon-cmd.c
index d35847d25..f3059bea5 100644
--- a/src/charon-cmd/charon-cmd.c
+++ b/src/charon-cmd/charon-cmd.c
@@ -204,15 +204,9 @@ static void segv_handler(int signal)
*/
static void usage(FILE *out, char *msg, char *binary)
{
- char *pre, *post;
- int i, line, padto = 0, spacing = 2;
-
- for (i = 0; i < CMD_OPT_COUNT; i++)
- {
- padto = max(padto, strlen(cmd_options[i].name) +
- strlen(cmd_options[i].arg));
- }
- padto += spacing;
+ static const int padto = 18;
+ char cmd[64], *pre, *post;
+ int i, line, pad;
if (msg)
{
@@ -237,17 +231,22 @@ static void usage(FILE *out, char *msg, char *binary)
post = " ";
break;
}
- fprintf(out, " --%s%s%s%s %-*s%s\n",
- cmd_options[i].name,
- pre, cmd_options[i].arg, post,
- padto - strlen(cmd_options[i].name) - strlen(cmd_options[i].arg), "",
- cmd_options[i].desc);
+ snprintf(cmd, sizeof(cmd), " --%s%s%s%s", cmd_options[i].name,
+ pre, cmd_options[i].arg, post);
+ pad = padto - strlen(cmd);
+ if (pad >= 1)
+ {
+ fprintf(out, "%s%-*s%s\n", cmd, pad, "", cmd_options[i].desc);
+ }
+ else
+ { /* write description to a separate line */
+ fprintf(out, "%s\n%-*s%s\n", cmd, padto, "", cmd_options[i].desc);
+ }
for (line = 0; line < countof(cmd_options[i].lines); line++)
{
if (cmd_options[i].lines[line])
{
- fprintf(out, "%-*s %s\n",
- padto, "", cmd_options[i].lines[line]);
+ fprintf(out, "%-*s%s\n", padto, "", cmd_options[i].lines[line]);
}
}
}