From patchwork Sun Dec 20 08:29:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Bendebury X-Patchwork-Id: 68958 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id nBK8UFYd013404 for ; Sun, 20 Dec 2009 08:30:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751224AbZLTIaP (ORCPT ); Sun, 20 Dec 2009 03:30:15 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751242AbZLTIaO (ORCPT ); Sun, 20 Dec 2009 03:30:14 -0500 Received: from smtp-out.google.com ([216.239.44.51]:45799 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751224AbZLTIaN convert rfc822-to-8bit (ORCPT ); Sun, 20 Dec 2009 03:30:13 -0500 Received: from kpbe17.cbf.corp.google.com (kpbe17.cbf.corp.google.com [172.25.105.81]) by smtp-out.google.com with ESMTP id nBK8UAfG023978 for ; Sun, 20 Dec 2009 00:30:10 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1261297811; bh=S/qzaqXiZaqWm3xPSzduClOpu0o=; h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:Subject: To:Cc:Content-Type:Content-Transfer-Encoding; b=Nq0ujXbGzeignH+t43X/ukn8bu6W1Z0eMlmj4itJX/KEow7loO6C1kR7imT8O9dvn eQozs2rnXt/LP6hO0kTXQ== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:in-reply-to:references:from:date:message-id: subject:to:cc:content-type:content-transfer-encoding:x-system-of-record; b=Ax7g/xpURIKR74pLhCThTfbXS2L9lg8EGhpUPUdzxwfRg6t7Z5+X+w46bF/dz+yOQ aLoVL2WHQjW4wixL9e6tg== Received: from qyk13 (qyk13.prod.google.com [10.241.83.141]) by kpbe17.cbf.corp.google.com with ESMTP id nBK8U9Ai022636 for ; Sun, 20 Dec 2009 00:30:09 -0800 Received: by qyk13 with SMTP id 13so2058072qyk.31 for ; Sun, 20 Dec 2009 00:30:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.51.219 with SMTP id e27mr2771089qcg.7.1261297809137; Sun, 20 Dec 2009 00:30:09 -0800 (PST) In-Reply-To: <4B28CC39.9010307@suse.cz> References: <3b09bd800912142246u2d069702n759e165553bddc9f@mail.gmail.com> <4B279021.6070508@suse.cz> <3b09bd800912152056g40fab3f9q76aef60ccf525bd0@mail.gmail.com> <4B28CC39.9010307@suse.cz> From: =?UTF-8?B?VmFkaW0gQmVuZGVidXJ5ICjQstCxKQ==?= Date: Sun, 20 Dec 2009 00:29:49 -0800 Message-ID: <3b09bd800912200029u24764aeje3063fb32de0fa90@mail.gmail.com> Subject: Re: [PATCH] wrap long help lines, take two To: Michal Marek Cc: linux-kbuild@vger.kernel.org X-System-Of-Record: true Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index edd3f39..d83f232 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -1097,9 +1097,32 @@ void expr_fprint(struct expr *e, FILE *out) static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *str) { - str_append((struct gstr*)data, str); + struct gstr *gs = (struct gstr*)data; + const char *sym_str = NULL; + + if (sym) + sym_str = sym_get_string_value(sym); + + if (gs->max_width) { + unsigned extra_length = strlen(str); + const char *last_cr = strrchr(gs->s, '\n'); + unsigned last_line_length; + + if (sym_str) + extra_length += 4 + strlen(sym_str); + + if (!last_cr) + last_cr = gs->s; + + last_line_length = strlen(gs->s) - (last_cr - gs->s); + + if ((last_line_length + extra_length) > gs->max_width) + str_append(gs, "\\\n"); + } + + str_append(gs, str); if (sym) - str_printf((struct gstr*)data, " [=%s]", sym_get_string_value(sym)); + str_printf(gs, " [=%s]", sym_str); } void expr_gstr_print(struct expr *e, struct gstr *gs) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index f379b0b..95ce009 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -106,6 +106,11 @@ int file_write_dep(const char *name); struct gstr { size_t len; char *s; + /* + * when max_width is not zero long lines in string s (if any) get + * wrapped not to exceed the max_width value + */ + int max_width; }; struct gstr str_new(void); struct gstr str_assign(const char *s); diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 8413cf3..ac1e9da 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -638,6 +638,7 @@ static void show_help(struct menu *menu) { struct gstr help = str_new(); + help.max_width = getmaxx(stdscr) - 10; menu_get_ext_help(menu, &help); show_helptext(_(menu_get_prompt(menu)), str_get(&help)); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index b6b2a46..81c100d 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -78,6 +78,7 @@ struct gstr str_new(void) struct gstr gs; gs.s = malloc(sizeof(char) * 64); gs.len = 64; + gs.max_width = 0; strcpy(gs.s, "\0"); return gs; } @@ -88,6 +89,7 @@ struct gstr str_assign(const char *s) struct gstr gs; gs.s = strdup(s); gs.len = strlen(s) + 1; + gs.max_width = 0; return gs; }