[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/11] linux-user: Fix layout of usage table to acco
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 07/11] linux-user: Fix layout of usage table to account for option text |
Date: |
Mon, 11 Mar 2013 21:27:44 +0200 |
From: Peter Maydell <address@hidden>
The linux-user usage message attempts to line up the columns in
its table by calculating the maximum width of any item in them.
However for the 'Argument' column it was only accounting for the
length of the option switch (eg "-d"), not the additional example
text (eg "item[,...]"). This currently has no adverse effects
because the widest item in the column happens to be the argumentless
"-singlestep" option, but improving the "-d" option help to read
"-d item[,...]" exceeds that limit.
Fix this by correctly calculating maxarglen as the width of the
first column text including a possible option argument, and
adjusting its uses to match.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/main.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index d8b0cd6..4e92a0b 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3406,27 +3406,35 @@ static void usage(void)
"Options and associated environment variables:\n"
"\n");
- maxarglen = maxenvlen = 0;
+ /* Calculate column widths. We must always have at least enough space
+ * for the column header.
+ */
+ maxarglen = strlen("Argument");
+ maxenvlen = strlen("Env-variable");
for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
+ int arglen = strlen(arginfo->argv);
+ if (arginfo->has_arg) {
+ arglen += strlen(arginfo->example) + 1;
+ }
if (strlen(arginfo->env) > maxenvlen) {
maxenvlen = strlen(arginfo->env);
}
- if (strlen(arginfo->argv) > maxarglen) {
- maxarglen = strlen(arginfo->argv);
+ if (arglen > maxarglen) {
+ maxarglen = arglen;
}
}
- printf("%-*s%-*sDescription\n", maxarglen+3, "Argument",
- maxenvlen+1, "Env-variable");
+ printf("%-*s %-*s Description\n", maxarglen+1, "Argument",
+ maxenvlen, "Env-variable");
for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
if (arginfo->has_arg) {
printf("-%s %-*s %-*s %s\n", arginfo->argv,
- (int)(maxarglen-strlen(arginfo->argv)), arginfo->example,
- maxenvlen, arginfo->env, arginfo->help);
+ (int)(maxarglen - strlen(arginfo->argv) - 1),
+ arginfo->example, maxenvlen, arginfo->env, arginfo->help);
} else {
- printf("-%-*s %-*s %s\n", maxarglen+1, arginfo->argv,
+ printf("-%-*s %-*s %s\n", maxarglen, arginfo->argv,
maxenvlen, arginfo->env,
arginfo->help);
}
--
1.7.10.4
- [Qemu-devel] [PULL] linux-user updates, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 05/11] linux-user: Support setgroups syscall with no groups, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 02/11] linux-user: improve print_fcntl(), riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 03/11] linux-user/syscall.c: handle FUTEX_WAIT_BITSET in do_futex, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 04/11] linux-user: fix futex strace of FUTEX_CLOCK_REALTIME, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 09/11] linux-user: Implement sendfile and sendfile64, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 06/11] linux-user: Add more sparc syscall numbers, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 10/11] linux-user: Implement accept4, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 01/11] linux-user: Add Alpha socket constants, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 07/11] linux-user: Fix layout of usage table to account for option text,
riku . voipio <=
- [Qemu-devel] [PATCH 08/11] linux-user: make bogus negative iovec lengths fail EINVAL, riku . voipio, 2013/03/11
- [Qemu-devel] [PATCH 11/11] linux-user/syscall.c: Don't warn about unimplemented get_robust_list, riku . voipio, 2013/03/11
- Re: [Qemu-devel] [PULL] linux-user updates, Peter Maydell, 2013/03/11
- Re: [Qemu-devel] [PULL] linux-user updates, Anthony Liguori, 2013/03/15