delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/08/28/11:14:02

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sat, 28 Aug 2004 10:49:08 -0400
From: "Pierre A. Humblet" <pierre DOT humblet AT ieee DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: grep: $ in PATTERN doesn't seem to work properly
Message-ID: <20040828144908.GA928595@hpn5170>
References: <cgdmhn$3sh$1 AT sea DOT gmane DOT org> <NGBBLLIAMFLGJEOAJCCEOEEPDNAA DOT _garbage_collector_ AT telia DOT com>
Mime-Version: 1.0
In-Reply-To: <NGBBLLIAMFLGJEOAJCCEOEEPDNAA._garbage_collector_@telia.com>
User-Agent: Mutt/1.4.1i

--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Aug 24, 2004 at 10:14:52AM +0200, Hannu E K Nevalainen wrote:
> You (Shankar Unni) wrote:
> > Hannu E K Nevalainen wrote:
> > 
> >> I would appreciate if this DOS-text-ism could be removed.
> >> Would applying the above patch have hard to handle side effects?
> >> I guess some important scripts could be affected :-7 ...
> > 
> > Umm, exactly what "fix" (change in behavior) did you have in mind?
> 
>  To actually integrate the patch that Pierre mentioned.
> Pierre, do you have it 'hanging around' still?

See attached. I think it's the right one but I have not tried it recently.

Pierre


--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="cat.c.diff"

--- cat.c.orig	2001-12-01 12:29:26.000000000 -0500
+++ cat.c	2004-08-23 19:28:54.000000000 -0400
@@ -618,7 +618,6 @@ main (int argc, char **argv)
 
 #if O_BINARY
 	case 'B':
-	  ++options;
 	  binary_files = 1;
 	  break;
 #endif
@@ -676,9 +675,18 @@ main (int argc, char **argv)
      -b, -s and -E would surprise users on DOS/Windows where a line
      with only CR-LF is an empty line.  (Besides, if they ask for
      one of these options, they don't care much about the original
-     file contents anyway).  */
+     file contents anyway). 
+     Another exception is that we don't set the output to binary
+     when the only input is a tty on stdin.
+     This is so that "cat > xyzzy" can create a DOS-style text file, 
+     like people expect if it is the default.
+ */
+
   if ((!isatty (STDOUT_FILENO)
-       && !(numbers || squeeze_empty_lines || mark_line_ends))
+       && !(isatty (STDIN_FILENO) 
+            && (optind == argc
+                || (optind == (argc - 1) && !strcmp (argv[optind], "-"))) 
+	    && !(numbers || squeeze_empty_lines || mark_line_ends)))
       || binary_files)
     {
       /* Switch stdout to BINARY mode.  */
@@ -695,12 +703,6 @@ main (int argc, char **argv)
 	 But keep console output in text mode, so that LF causes
 	 both CR and LF on output, and the output is readable.  */
       file_open_mode |= O_BINARY;
-      SET_BINARY (0);
-
-      /* Setting stdin to binary switches the console device to
-	 raw I/O, which also affects stdout to console.  Undo that.  */
-      if (isatty (STDOUT_FILENO))
-	setmode (STDOUT_FILENO, O_TEXT);
     }
 #endif
 
@@ -723,28 +725,25 @@ main (int argc, char **argv)
 
 #if O_BINARY
 	  /* Switch stdin to BINARY mode if needed.  */
-	  if (binary_output)
-	    {
-	      int tty_in = isatty (input_desc);
 
-	      /* If stdin is a terminal device, and it is the ONLY
-		 input file (i.e. we didn't write anything to the
-		 output yet), switch the output back to TEXT mode.
-		 This is so "cat > xyzzy" creates a DOS-style text
-		 file, like people expect.  */
-	      if (tty_in && optind <= argc)
-		setmode (STDOUT_FILENO, O_TEXT);
-	      else
-		{
-		  SET_BINARY (input_desc);
+	  int tty_in = isatty (input_desc);
+
+	  if ((binary_output && !tty_in) || quote)
+	    {
+	      SET_BINARY (input_desc);
 # ifdef __DJGPP__
-		  /* This is DJGPP-specific.  By default, switching console
-		     to binary mode disables SIGINT.  But we want terminal
-		     reads to be interruptible.  */
-		  if (tty_in)
-		    __djgpp_set_ctrl_c (1);
+	      /* This is DJGPP-specific.  By default, switching console
+		 to binary mode disables SIGINT.  But we want terminal
+		 reads to be interruptible.  */
+	      if (tty_in)
+		__djgpp_set_ctrl_c (1);
+# endif
+# if !(defined __CYGWIN__)
+	      /* Setting stdin to binary switches the console device to
+		 raw I/O, which also affects stdout to console.  Undo that.  */
+	      if (tty_in && isatty (STDOUT_FILENO))
+		setmode (STDOUT_FILENO, O_TEXT);
 # endif
-		}
 	    }
 #endif
 	}


--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--mYCpIKhGyMATD0i+--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019