From patchwork Fri Dec 11 05:14:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vadim Bendebury X-Patchwork-Id: 66515 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBB5Spqq030865 for ; Fri, 11 Dec 2009 05:28:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751507AbZLKF2n (ORCPT ); Fri, 11 Dec 2009 00:28:43 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751365AbZLKF2n (ORCPT ); Fri, 11 Dec 2009 00:28:43 -0500 Received: from 216-239-44-51.google.com ([216.239.44.51]:48537 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750820AbZLKF2m convert rfc822-to-8bit (ORCPT ); Fri, 11 Dec 2009 00:28:42 -0500 X-Greylist: delayed 842 seconds by postgrey-1.27 at vger.kernel.org; Fri, 11 Dec 2009 00:28:41 EST Received: from wpaz1.hot.corp.google.com (wpaz1.hot.corp.google.com [172.24.198.65]) by smtp-out.google.com with ESMTP id nBB5EjUu000656 for ; Thu, 10 Dec 2009 21:14:45 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1260508485; bh=GMqz7zyaMVbLyjvOCt+86HIqMnw=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type: Content-Transfer-Encoding; b=R9q8QLAKt656XuekXVn5XY5Q/4hr+Jhgt8z/9jyljyI0KwDJicw1l+M7lKhgL83D2 V3PEdGF4rrMJEw6US2eFw== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:from:date:message-id:subject:to:content-type: content-transfer-encoding:x-system-of-record; b=in+t/7lXddFqc7QSk5STaLsO1jzVVjd0hbth2cAacXZd9nb8Cq5lT7YAwAWiimuWn u50aQmwyYN7wmuXsCR2EQ== Received: from qw-out-2122.google.com (qwb9.prod.google.com [10.241.193.73]) by wpaz1.hot.corp.google.com with ESMTP id nBB5EhAU000910 for ; Thu, 10 Dec 2009 21:14:43 -0800 Received: by qw-out-2122.google.com with SMTP id 9so156760qwb.23 for ; Thu, 10 Dec 2009 21:14:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.100.221 with SMTP id z29mr507747qcn.18.1260508483185; Thu, 10 Dec 2009 21:14:43 -0800 (PST) From: =?UTF-8?B?VmFkaW0gQmVuZGVidXJ5ICjQstCxKQ==?= Date: Thu, 10 Dec 2009 21:14:23 -0800 Message-ID: <3b09bd800912102114i33d90fabtb9a6fc8bde2638ff@mail.gmail.com> Subject: [PATCH] wrap long help lines To: 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..2aa49e8 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -1083,6 +1083,8 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *        }        if (expr_compare_type(prevtoken, e->type) > 0)                fn(data, NULL, ")"); + +       str_screen_wrap(data, "||");  }  static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index f379b0b..8fc69a3 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -112,6 +112,7 @@ struct gstr str_assign(const char *s);  void str_free(struct gstr *gs);  void str_append(struct gstr *gs, const char *s);  void str_printf(struct gstr *gs, const char *fmt, ...); +void str_screen_wrap(struct gstr *gs, const char *break_point);  const char *str_get(struct gstr *gs);  /* symbol.c */ diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index b6b2a46..f6c8930 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -7,6 +7,7 @@  #include  #include "lkc.h" +#include  /* file already present in list? If not add it */  struct file *file_lookup(const char *name) @@ -131,3 +132,54 @@ const char *str_get(struct gstr *gs)        return gs->s;  } +static const char string_breaker[] = { '\\', '\n' }; +#define STRING_BREAKER_SIZE sizeof(string_breaker) +/* + * wrap long lines in the passed in strings. The lines are wrapped to fit into + * the current screen width. The lines can be broken only at 'break points' - + * passed in as the second parameter. A \ (two characters) sequence is + * instered after the appropriate break points to get the line wrapped to fit + * the screen. +*/ +void str_screen_wrap(struct gstr *data, const char *break_point) +{ +       char *eol_location; +       int total_length; +       int screen_width = getmaxx(stdscr) - 10; +       int break_point_size = strlen(break_point); + +       eol_location = strrchr(data->s, '\n'); +       if (!eol_location) +               eol_location = data->s; + +       total_length = strlen(data->s) + 1; /* include trailing zero */ + +       /* while last line's length exceeds screen width */ +       while ((total_length - (eol_location - data->s) - 1) > screen_width) { +               char *prev_breakp; +               char *breakp = eol_location; +               do { +                       prev_breakp = breakp; +                       breakp = strstr(breakp + 1, break_point); +               } while (breakp && +                        ((breakp - eol_location) < screen_width)); + +               if (prev_breakp == eol_location) { +                       /* no break_points found */ +                       return; +               } + +               total_length += STRING_BREAKER_SIZE; +               if (data->len < total_length) { +                       data->s = realloc(data->s, total_length); +                       data->len = total_length; +               } +               prev_breakp += break_point_size; + +               eol_location = prev_breakp + STRING_BREAKER_SIZE; +               /* move the remainder of the string including trailing zero */ +               memmove(eol_location, prev_breakp, strlen(prev_breakp) + 1); +               /* insert the line break */ +               memcpy(prev_breakp, string_breaker, STRING_BREAKER_SIZE); +       } +}