GNU logs - #15774, boring messages


Message sent to bug-diffutils@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#15774: rfc/pre-patch: automatic diff width from the terminal
Resent-From: "Dr. David Alan Gilbert" <dave@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-diffutils@HIDDEN
Resent-Date: Fri, 01 Nov 2013 01:32:02 +0000
Resent-Message-ID: <handler.15774.B.138326946911154 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 15774
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 15774 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.138326946911154
          (code B ref -1); Fri, 01 Nov 2013 01:32:02 +0000
Received: (at submit) by debbugs.gnu.org; 1 Nov 2013 01:31:09 +0000
Received: from localhost ([127.0.0.1]:55980 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1Vc3Zs-0002tq-PY
	for submit <at> debbugs.gnu.org; Thu, 31 Oct 2013 21:31:09 -0400
Received: from eggs.gnu.org ([208.118.235.92]:47562)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <dg@HIDDEN>) id 1Vc37u-0002Bu-Tj
 for submit <at> debbugs.gnu.org; Thu, 31 Oct 2013 21:02:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dg@HIDDEN>) id 1Vc37k-0004Oc-0u
 for submit <at> debbugs.gnu.org; Thu, 31 Oct 2013 21:02:09 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.8 required=5.0 tests=BAYES_50,HK_NAME_DR
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:52183)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dg@HIDDEN>) id 1Vc37j-0004OY-UM
 for submit <at> debbugs.gnu.org; Thu, 31 Oct 2013 21:02:03 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49257)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dg@HIDDEN>) id 1Vc37e-0003sj-W3
 for bug-diffutils@HIDDEN; Thu, 31 Oct 2013 21:02:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dg@HIDDEN>) id 1Vc37U-0004Lc-P7
 for bug-diffutils@HIDDEN; Thu, 31 Oct 2013 21:01:58 -0400
Received: from mx.treblig.org ([80.68.94.177]:57921)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dg@HIDDEN>) id 1Vc37U-0004LX-JG
 for bug-diffutils@HIDDEN; Thu, 31 Oct 2013 21:01:48 -0400
Received: from dg by mx.treblig.org with local (Exim 4.80)
 (envelope-from <dg@HIDDEN>) id 1Vc2tA-0001I5-Tq
 for bug-diffutils@HIDDEN; Fri, 01 Nov 2013 00:47:00 +0000
Date: Fri, 1 Nov 2013 00:47:00 +0000
From: "Dr. David Alan Gilbert" <dave@HIDDEN>
Message-ID: <20131101004700.GD24298@gallifrey>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Chocolate: 70 percent or better cocoa solids preferably
X-Operating-System: Linux/3.2.2-kvm-i386-20120306 (i686)
X-Uptime: 00:28:38 up 4 days, 9:21, 2 users, load average: 0.00, 0.01, 0.05
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic]
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Mailman-Approved-At: Thu, 31 Oct 2013 21:31:06 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

Hi,
  The patch below is a rough 1st cut of an attempt to make diff use the
terminal width as the default width.

It pinches the code from coreutils ls.c that does the same thing, and so
uses the terminal width, failing that reads the COLUMNS env variable,
and failing that falls back to the default (all of which can still be
over ridden with -w/-W).

  Other than glue, all the actual code comes straight out of ls.c

Now given that this is a first cut, is this basically the right approach,
and are people happy to change the default behaviour?

I know that there are some things I need to do:
  - figure out the autoconf magic so it works when termios isn't available
    and the 'WINSIZE_IN_PTEM' def that coreutils picks up
  - Probably more docs fixing
  - some tests
  - (Copyright assignment? Or is the code so close to coreutils it isn't
an issue?)

It's the side by side diff that I'm most interested in this for,
having nice wide cheap 1920 monitors is great for side by side diffs
and I normally want to fill whatever terminal I have.

Thanks in advance for all comments,

Dave

-----------------------
diff --git a/bootstrap.conf b/bootstrap.conf
index ac85adf..10be643 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -56,6 +56,7 @@ mkstemp
 mktime
 progname
 propername
+quotearg
 rawmemchr
 readme-release
 regex
@@ -82,6 +83,7 @@ wcwidth
 xalloc
 xfreopen
 xreadlink
+xstrtol
 xstrtoumax
 xvasprintf
 '
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 2d238dc..09dae68 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3967,8 +3967,10 @@ Ignore white space when comparing lines.  @xref{White Space}.
 
 @item -W @var{columns}
 @itemx --width=@var{columns}
-Output at most @var{columns} (default 130) print columns per line in
-side by side format.  @xref{Side by Side Format}.
+Output at most @var{columns} print columns per line in side by side format.
+The default is taken from the terminal settings if possible; otherwise the
+environment variable @env{COLUMNS} is used if it is set; otherwise the default
+is 130 columns.  @xref{Side by Side Format}.
 
 @item -x @var{pattern}
 @itemx --exclude=@var{pattern}
diff --git a/src/diff.c b/src/diff.c
index 50d0365..8d283d3 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -34,13 +34,23 @@
 #include <hard-locale.h>
 #include <prepargs.h>
 #include <progname.h>
+#include <quotearg.h>
 #include <sh-quote.h>
 #include <stat-time.h>
+#include <xstrtol.h>
 #include <timespec.h>
 #include <version-etc.h>
 #include <xalloc.h>
 #include <xreadlink.h>
 #include <binary-io.h>
+#include <termios.h>
+
+#include <sys/ioctl.h>
+#ifdef WINSIZE_IN_PTEM
+# include <sys/stream.h>
+# include <sys/ptem.h>
+#endif
+
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "diff"
@@ -255,6 +265,51 @@ exclude_options (void)
 {
   return EXCLUDE_WILDCARDS | (ignore_file_name_case ? FNM_CASEFOLD : 0);
 }
+
+/* Return the number of columns to use, based on:
+ *   a default (130)
+ *   the COLUMNS env variable
+ *   the terminal width
+ * The code is based on coreutils/ls.c - except diff has always defaulted
+ * to 130 rather than ls's 80.   I'd probably say it's better to allow
+ * overriding terminal width by COLUMNS but decided to keep it consistent
+ * with coreutils.
+ */
+static size_t
+get_default_width (void)
+{
+  size_t line_length = 130;
+
+  char const *p = getenv ("COLUMNS");
+  if (p && *p)
+    {
+      unsigned long int tmp_ulong;
+      if (xstrtoul (p, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
+          && 0 < tmp_ulong && tmp_ulong <= SIZE_MAX)
+        {
+          line_length = tmp_ulong;
+        }
+      else
+        {
+          error (0, 0,
+             _("ignoring invalid width in environment variable COLUMNS: %s"),
+                 quotearg (p));
+        }
+   }
+
+#ifdef TIOCGWINSZ
+  {
+    struct winsize ws;
+
+    if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &ws) != -1
+        && 0 < ws.ws_col && ws.ws_col == (size_t) ws.ws_col)
+      line_length = ws.ws_col;
+  }
+#endif
+
+  return line_length;
+}
+
 
 int
 main (int argc, char **argv)
@@ -668,7 +723,7 @@ main (int argc, char **argv)
   if (! tabsize)
     tabsize = 8;
   if (! width)
-    width = 130;
+    width = get_default_width ();
 
   {
     /* Maximize first the half line width, and then the gutter width,

-----------------------
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\ gro.gilbert @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.503 (Entity 5.503)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: "Dr. David Alan Gilbert" <dave@HIDDEN>
Subject: bug#15774: Acknowledgement (rfc/pre-patch: automatic diff width
 from the terminal)
Message-ID: <handler.15774.B.138326946911154.ack <at> debbugs.gnu.org>
References: <20131101004700.GD24298@gallifrey>
X-Gnu-PR-Message: ack 15774
X-Gnu-PR-Package: diffutils
Reply-To: 15774 <at> debbugs.gnu.org
Date: Fri, 01 Nov 2013 01:32:03 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-diffutils@HIDDEN

If you wish to submit further information on this problem, please
send it to 15774 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
15774: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D15774
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 30 Mar 2014 05:31:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 01:31:55 2014
Received: from localhost ([127.0.0.1]:56639 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WU8Lb-0005MJ-0w
	for submit <at> debbugs.gnu.org; Sun, 30 Mar 2014 01:31:55 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:42173)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1WU8LZ-0005MB-81
 for control <at> debbugs.gnu.org; Sun, 30 Mar 2014 01:31:54 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id C867E39E8012
 for <control <at> debbugs.gnu.org>; Sat, 29 Mar 2014 22:31:52 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id Wa+B9cCgHEu8 for <control <at> debbugs.gnu.org>;
 Sat, 29 Mar 2014 22:31:52 -0700 (PDT)
Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net
 [108.0.233.62])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6B47339E8011
 for <control <at> debbugs.gnu.org>; Sat, 29 Mar 2014 22:31:52 -0700 (PDT)
Message-ID: <5337AC47.7020103@HIDDEN>
Date: Sat, 29 Mar 2014 22:31:51 -0700
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version: 1.0
To: control <at> debbugs.gnu.org
Subject: 15774 has a patch
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.7 (--)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.7 (--)

tags 15774 + patch
thanks




Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 30 Mar 2014 05:50:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 01:50:05 2014
Received: from localhost ([127.0.0.1]:56690 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WU8dA-00070L-Fz
	for submit <at> debbugs.gnu.org; Sun, 30 Mar 2014 01:50:04 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:42624)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1WU8d6-0006zg-Fh
 for control <at> debbugs.gnu.org; Sun, 30 Mar 2014 01:50:01 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id A842739E8012
 for <control <at> debbugs.gnu.org>; Sat, 29 Mar 2014 22:49:59 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id nuq0002uLgZ4 for <control <at> debbugs.gnu.org>;
 Sat, 29 Mar 2014 22:49:59 -0700 (PDT)
Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net
 [108.0.233.62])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 68FDF39E8011
 for <control <at> debbugs.gnu.org>; Sat, 29 Mar 2014 22:49:59 -0700 (PDT)
Message-ID: <5337B087.4090300@HIDDEN>
Date: Sat, 29 Mar 2014 22:49:59 -0700
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version: 1.0
To: control <at> debbugs.gnu.org
Subject: 15774 is wishlist
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.7 (--)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.7 (--)

severity 15774 wishlist





Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.