Mail Archives: cygwin/2004/08/29/14:59:35
------=_NextPart_000_0014_01C48E0A.F3F65200
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
$ 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--
------=_NextPart_000_0014_01C48E0A.F3F65200
Content-Type: application/octet-stream;
name="cat.c.diff"
Content-Transfer-Encoding: 7bit
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
}
------=_NextPart_000_0014_01C48E0A.F3F65200
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/
------=_NextPart_000_0014_01C48E0A.F3F65200--
- Raw text -