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: 14803 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A1B1D4C17E5 for ; Thu, 14 Feb 2013 18:46:48 +0000 (UTC) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by fiordland.canonical.com (Postfix) with ESMTP id 49C4CA1991F for ; Thu, 14 Feb 2013 18:46:48 +0000 (UTC) Received: by mail-ve0-f172.google.com with SMTP id cz11so2362555veb.31 for ; Thu, 14 Feb 2013 10:46:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=w4DU/dl7c5cIdTMpn8g83SSm9LyK+EZZeamxJ23KW7w=; b=PpFyCAYfDZc3k6oAdZOimqH1+7ZDAwHEJUN+C/d9EL0wh4B0mNOFxxZC3HH6k0e1BL VsHgnV8KXKyODEhl89vpoFeENG6teGvkagKU6dvkSJKsiwPysFrsE+ABU85XmPj2PO0D gxP8oPyG+7zu6LoPm7znfnl4stK8F+KbEY7t9B3TDo+HcQdqoTlhC8t+zBiMsmd9CQEt qaBC37exKG1M2bs+HLiOmLdybe8b/X+MP1RqwufH6G1wVyBAHV1glphSULKnm9wy1wEf qowIvgEUHNiyRpe6IDokMx4WVDUlYC0/mC7q606zxYuL71hjyp+ROh8yAK9hGw6ZdFQD HD4Q== X-Received: by 10.52.38.163 with SMTP id h3mr31783876vdk.35.1360867607783; Thu, 14 Feb 2013 10:46:47 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp278045vcb; Thu, 14 Feb 2013 10:46:47 -0800 (PST) X-Received: by 10.180.99.227 with SMTP id et3mr1415945wib.6.1360867606748; Thu, 14 Feb 2013 10:46:46 -0800 (PST) Received: from mnementh.archaic.org.uk (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]) by mx.google.com with ESMTPS id wp9si18578788wjb.22.2013.02.14.10.46.46 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 14 Feb 2013 10:46:46 -0800 (PST) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk 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 Cc: patches@linaro.org, Riku Voipio Subject: [PATCH] linux-user: Fix layout of usage table to account for option text 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-Gm-Message-State: ALoCoQnvzaaS44krtWTYN9tw1wZD+gNlkwysBPa1r7ctqbFBd7N3FJ0ce6Epw4CL4XTAWxIccM91 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); }