From patchwork Thu Feb 14 18:46:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 220481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 63F572C0089 for ; Fri, 15 Feb 2013 05:47:12 +1100 (EST) Received: from localhost ([::1]:60343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U63pu-0005Ij-LA for incoming@patchwork.ozlabs.org; Thu, 14 Feb 2013 13:47:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U63pl-0005IM-Rb for qemu-devel@nongnu.org; Thu, 14 Feb 2013 13:47:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U63pc-0000Zq-QS for qemu-devel@nongnu.org; Thu, 14 Feb 2013 13:47:01 -0500 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:60391 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U63pc-0000XT-Jv for qemu-devel@nongnu.org; Thu, 14 Feb 2013 13:46:52 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1U63pU-00039i-0H; Thu, 14 Feb 2013 18:46:44 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 14 Feb 2013 18:46:43 +0000 Message-Id: <1360867603-12107-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Riku Voipio , patches@linaro.org Subject: [Qemu-devel] [PATCH] linux-user: Fix layout of usage table to account for option text X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- This patch doesn't affect the help output at the moment; you can test it by changing the "options" text for the "d" entry in arg_table[] to read "item[,...]", which is what my not-yet-posted update of the 'default logging to stderr' patch will do. 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 3df8aa2..b28d4fd 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3319,27 +3319,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); }