[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sed+windows/cygwin+newlines: improving documentation
From: |
Eric Blake |
Subject: |
Re: sed+windows/cygwin+newlines: improving documentation |
Date: |
Thu, 18 Oct 2018 17:03:28 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 |
On 10/18/18 4:59 PM, Assaf Gordon wrote:
Hello,
On 12/10/18 12:01 PM, Eli Zaretskii wrote:
From: Assaf Gordon <address@hidden>
Do you think it would be better to also make "-b" affect STDIN/STDOUT?
Yes, I think so. It will allow to run on Windows Sed scripts that
remove CR characters, for example.
Attached a patch to apply -b/--binary to STDIN/STDOUT under
windows/mingw.
comments (and testing) welcomed,
- assaf
+++ b/doc/sed.texi
@@ -363,8 +363,9 @@ to a non-empty value.
@opindex --binary
This option is available on every platform, but is only effective where the
operating system makes a distinction between text files and binary files.
-When such a distinction is made---as is the case for MS-DOS, Windows,
-Cygwin---text files are composed of lines separated by a carriage return
+When such a distinction is made---as is the case for MS-DOS, Windows
+(but not modern Cygwin)---text files are composed of lines separated by a
+carriage return
Modern Cygwin still has the concept of text files, which have \r\n line
endings. It is just that you have to specifically request them via mount
options (they are not default). So I don't think that excluding Cygwin
is correct here.
@emph{and} a line feed character, and @command{sed} does not see the
ending CR. When this option is specified, @command{sed} will open
input files in binary mode, thus not requesting this special processing
@@ -344,6 +353,16 @@ main (int argc, char **argv)
}
check_final_program (the_program);
+#ifdef WINDOWS_BINARY_MODE_SUPPORT
+ if (binary_mode)
+ {
+ if (_setmode ( _fileno (stdin), _O_BINARY) == -1)
+ panic (_("failed to set binary mode on STDIN"));
+ if (_setmode ( _fileno (stdout), _O_BINARY) == -1)
+ panic (_("failed to set binary mode on STDOUT"));
+ }
Isn't there a gnulib module for requesting setmode in a more portable
manner?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/09
- Re: sed+windows/cygwin+newlines: improving documentation, Eli Zaretskii, 2018/10/09
- Re: sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/09
- Re: sed+windows/cygwin+newlines: improving documentation, Eli Zaretskii, 2018/10/09
- Re: sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/12
- Re: sed+windows/cygwin+newlines: improving documentation, Eli Zaretskii, 2018/10/12
- Re: sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/18
- Re: sed+windows/cygwin+newlines: improving documentation,
Eric Blake <=
- Re: sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/18
- Re: sed+windows/cygwin+newlines: improving documentation, Assaf Gordon, 2018/10/24