Attn: textutils maintainer (RE: grep: $ in PATTERN doesn't seem to work properly)

2004-08-29 Thread Hannu E K Nevalainen
$ cygcheck -f /bin/cat.exe
textutils-2.0.21-1

Can the attached patch be a candidate for inclusion?

It is all about cat.exe binary mode IO wrt stdin/out AFAIU.

Pierre A. H. wrote:
 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

Thanks Pierre, I'll be trying it myself as time permits. But I also hope
that it (or an adaption) gets into CVS.

/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems--72--

** mailing list preference; please keep replies on list **

-- printf(LocalTime: UTC+%02d\n,(DST)? 2:1); --
--END OF MESSAGE--


cat.c.diff
Description: Binary data
--
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/

Re: grep: $ in PATTERN doesn't seem to work properly

2004-08-28 Thread Pierre A. Humblet
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

--- cat.c.orig  2001-12-01 12:29:26.0 -0500
+++ cat.c   2004-08-23 19:28:54.0 -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
}

--
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/

RE: grep: $ in PATTERN doesn't seem to work properly

2004-08-24 Thread Hannu E K Nevalainen
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?

/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems--72--

** mailing list preference; please keep replies on list **

-- printf(LocalTime: UTC+%02d\n,(DST)? 2:1); --
--END OF MESSAGE--

--
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/



Re: grep: $ in PATTERN doesn't seem to work properly

2004-08-23 Thread Shankar Unni
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?
--
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/


RE: grep: $ in PATTERN doesn't seem to work properly

2004-08-22 Thread Hannu E K Nevalainen
 On Sat, 21 Aug 2004, Hannu E K Nevalainen wrote:
 
 Note that there is a difference depending on how you create the
 file; I'll hand over to cygwin-specialists to explain (or ponder
 on) why it has to be this way. 
 
 I'm running BINARY mounts all over, still I get the behaviour
 below.
SNIP

 On Sat, Aug 21, 2004 at 07:07:21PM -0400, Igor Pechtchanski wrote:
 This has to do with the way cat behaves.  By default, Windows sends
 textmode line endings from the console.  Most applications
 (including od, echo, bash, etc) compensate for this somehow, except
 cat, which *always* replicates the output character by character,
 doing no processing *whatsoever*.  AFAIK, this is by design.
 
 Case in point:
 
 $ od -c
 EnterCtrl-D
 000  \n
 001
 $ cat | od -c
 EnterCtrl-D
 000  \r  \n
 002
 $ perl -pe 1 | od -c
 EnterCtrl-D
 000  \n
 001
 $ # Note, however:
 $ perl -pe 1 | cat | od -c
 EnterCtrl-D
 000  \n
 001
 $

 See also http://www.cygwin.com/ml/cygwin/2003-04/msg02268.html
 I once sent a patch to a transient coreutils maintainer but
 there was no followup.
 
 Pierre

$ type -a cat
cat is /usr/bin/cat
cat is /bin/cat
$ cygcheck -f /bin/cat
textutils-2.0.21-1

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 ...


/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems--72--

** mailing list preference; please keep replies on list **

-- printf(LocalTime: UTC+%02d\n,(DST)? 2:1); --
--END OF MESSAGE--

--
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/



RE: grep: $ in PATTERN doesn't seem to work properly

2004-08-21 Thread Buchbinder, Barry (NIH/NIAID)
Sounds like a it could be a line ending issue where grep is expecting \n
(^J) at the end of a line but is being fed \r\n (^M^J).

Does
$ od -c tmp
show \r\n line endings?

How do the following work for you?
$ grep '1.$' tmp
and
$ grep -v '^.$' tmp

-Original Message-
From: Koduru, Seshasai [mailto:[EMAIL PROTECTED] 
Sent: Saturday, August 21, 2004 11:43 AM
To: [EMAIL PROTECTED]
Subject: grep: $ in PATTERN doesn't seem to work properly

Hi,

When $ is used in the PATTERN of grep command, it doesn't seem to work
properly on my machine.

I have run the following under cygwin.bat shell.

$ cat tmp
Line 1
Line 2

Line 3
Line 4
Line 5

$ grep '1$' tmp
(Gives no output. It should give output as
Line 1)

$ grep -e '1$ tmp
(Gives no output. It should give output as
Line 1)

$ grep -v '^$' tmp
(Gives no output. It should give output as
Line 1
Line 2
Line 3
Line 4
Line 5)

I am also attaching the output of cygcheck -s -v -r. Can someone please
tell what's going wrong? Install problem or other?

Thanks,
Seshasai

--
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/



RE: grep: $ in PATTERN doesn't seem to work properly

2004-08-21 Thread Hannu E K Nevalainen
Koduru, Seshasai wrote:
 Hi,

 When $ is used in the PATTERN of grep command, it doesn't seem to
 work properly on my machine.

 I have run the following under cygwin.bat shell.

 $ cat tmp
 Line 1
 Line 2

 Line 3
 Line 4
 Line 5

 $ grep '1$' tmp
 (Gives no output. It should give output as
 Line 1)
SNIP

Note that there is a difference depending on how you create the file; I'll
hand over to cygwin-specialists to explain (or ponder on) why it has to be
this way.

I'm running BINARY mounts all over, still I get the behaviour below.

binmode proof:
$ mount | grep 'binmode' | wc -l
 23
$ mount | wc -l
 23

=== a) ===
$ cd# cd to $HOME
$ cat tmp
Line 1
Line 2

Line 3
Line 4
Line 5
$POSIX= - [EMAIL PROTECTED] ~ bash (P)PID=(852)2340, s=0
$ od -w8 -t x1z tmp
000 4c 69 6e 65 20 31 0d 0a  Line 1..
010 4c 69 6e 65 20 32 0d 0a  Line 2..
020 0d 0a 4c 69 6e 65 20 33  ..Line 3
030 0d 0a 4c 69 6e 65 20 34  ..Line 4
040 0d 0a 4c 69 6e 65 20 35  ..Line 5
050 0d 0a..
052
$ grep '1$' tmp
$ d2u tmp   # dos2unix
tmp: done.
$ grep '1$' tmp
Line 1

=== b) ===
$ cd
$ ls -l tmp2
ls: tmp2: No such file or directory
$ for (( i=1 ; i6 ; i++ )) do echo tmp2 Line $i;done
$ od -w7 -t x1z tmp2
000 4c 69 6e 65 20 31 0a  Line 1.
007 4c 69 6e 65 20 32 0a  Line 2.
016 4c 69 6e 65 20 33 0a  Line 3.
025 4c 69 6e 65 20 34 0a  Line 4.
034 4c 69 6e 65 20 35 0a  Line 5.
043
$ grep '1$' tmp
Line 1

$ rm tmp tmp2

/Hannu E K Nevalainen, B.Sc. EE Microcomputer systems--72--

** mailing list preference; please keep replies on list **

-- printf(LocalTime: UTC+%02d\n,(DST)? 2:1); --
--END OF MESSAGE--


--
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/



RE: grep: $ in PATTERN doesn't seem to work properly

2004-08-21 Thread Igor Pechtchanski
On Sat, 21 Aug 2004, Hannu E K Nevalainen wrote:

 Note that there is a difference depending on how you create the file; I'll
 hand over to cygwin-specialists to explain (or ponder on) why it has to be
 this way.
 
 I'm running BINARY mounts all over, still I get the behaviour below.
 [snip]
 === a) ===
 $ cd  # cd to $HOME
 $ cat tmp
 Line 1
 Line 2
 
 Line 3
 Line 4
 Line 5
 $POSIX= - [EMAIL PROTECTED] ~ bash (P)PID=(852)2340, s=0
 $ od -w8 -t x1z tmp
 000 4c 69 6e 65 20 31 0d 0a  Line 1..
 010 4c 69 6e 65 20 32 0d 0a  Line 2..
 020 0d 0a 4c 69 6e 65 20 33  ..Line 3
 030 0d 0a 4c 69 6e 65 20 34  ..Line 4
 040 0d 0a 4c 69 6e 65 20 35  ..Line 5
 050 0d 0a..
 052
 $ grep '1$' tmp
 $ d2u tmp # dos2unix
 tmp: done.
 $ grep '1$' tmp
 Line 1
 
 === b) ===
 $ cd
 $ ls -l tmp2
 ls: tmp2: No such file or directory
 $ for (( i=1 ; i6 ; i++ )) do echo tmp2 Line $i;done
 $ od -w7 -t x1z tmp2
 000 4c 69 6e 65 20 31 0a  Line 1.
 007 4c 69 6e 65 20 32 0a  Line 2.
 016 4c 69 6e 65 20 33 0a  Line 3.
 025 4c 69 6e 65 20 34 0a  Line 4.
 034 4c 69 6e 65 20 35 0a  Line 5.
 043
 $ grep '1$' tmp
 Line 1
 
 $ rm tmp tmp2

This has to do with the way cat behaves.  By default, Windows sends 
textmode line endings from the console.  Most applications (including od, 
echo, bash, etc) compensate for this somehow, except cat, which *always* 
replicates the output character by character, doing no processing 
*whatsoever*.  AFAIK, this is by design.

Case in point:

$ od -c
EnterCtrl-D
000  \n
001
$ cat | od -c
EnterCtrl-D
000  \r  \n
002
$ perl -pe 1 | od -c
EnterCtrl-D
000  \n
001
$ # Note, however:
$ perl -pe 1 | cat | od -c
EnterCtrl-D
000  \n
001
$ 

HTH,
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_[EMAIL PROTECTED]
 |,4-  ) )-,_. ,\ (  `'-'   Igor Pechtchanski, Ph.D.
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing.  -- Dr. Jubal Harshaw

--
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/



Re: grep: $ in PATTERN doesn't seem to work properly

2004-08-21 Thread Pierre A. Humblet
On Sat, Aug 21, 2004 at 07:07:21PM -0400, Igor Pechtchanski wrote:
 On Sat, 21 Aug 2004, Hannu E K Nevalainen wrote:
 
  Note that there is a difference depending on how you create the file; I'll
  hand over to cygwin-specialists to explain (or ponder on) why it has to be
  this way.
  
  I'm running BINARY mounts all over, still I get the behaviour below.
  [snip]
  === a) ===
  $ cd# cd to $HOME
  $ cat tmp
  Line 1
  Line 2
  
  Line 3
  Line 4
  Line 5
  $POSIX= - [EMAIL PROTECTED] ~ bash (P)PID=(852)2340, s=0
  $ od -w8 -t x1z tmp
  000 4c 69 6e 65 20 31 0d 0a  Line 1..
  010 4c 69 6e 65 20 32 0d 0a  Line 2..
  020 0d 0a 4c 69 6e 65 20 33  ..Line 3
  030 0d 0a 4c 69 6e 65 20 34  ..Line 4
  040 0d 0a 4c 69 6e 65 20 35  ..Line 5
  050 0d 0a..
  052
  $ grep '1$' tmp
  $ d2u tmp   # dos2unix
  tmp: done.
  $ grep '1$' tmp
  Line 1
  
  === b) ===
  $ cd
  $ ls -l tmp2
  ls: tmp2: No such file or directory
  $ for (( i=1 ; i6 ; i++ )) do echo tmp2 Line $i;done
  $ od -w7 -t x1z tmp2
  000 4c 69 6e 65 20 31 0a  Line 1.
  007 4c 69 6e 65 20 32 0a  Line 2.
  016 4c 69 6e 65 20 33 0a  Line 3.
  025 4c 69 6e 65 20 34 0a  Line 4.
  034 4c 69 6e 65 20 35 0a  Line 5.
  043
  $ grep '1$' tmp
  Line 1
  
  $ rm tmp tmp2
 
 This has to do with the way cat behaves.  By default, Windows sends 
 textmode line endings from the console.  Most applications (including od, 
 echo, bash, etc) compensate for this somehow, except cat, which *always* 
 replicates the output character by character, doing no processing 
 *whatsoever*.  AFAIK, this is by design.
 
 Case in point:
 
 $ od -c
 EnterCtrl-D
 000  \n
 001
 $ cat | od -c
 EnterCtrl-D
 000  \r  \n
 002
 $ perl -pe 1 | od -c
 EnterCtrl-D
 000  \n
 001
 $ # Note, however:
 $ perl -pe 1 | cat | od -c
 EnterCtrl-D
 000  \n
 001
 $ 

See also http://www.cygwin.com/ml/cygwin/2003-04/msg02268.html
I once sent a patch to a transient coreutils maintainer but
there was no followup.

Pierre

--
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/