aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2015-01-15 17:50:50 +0200
committerEli Zaretskii2015-01-15 17:50:50 +0200
commit0f238ea450b3a976f04c95c4cf8befaadad1cdd0 (patch)
treecd278a1441bd610bd91eb7fbd6f38aea7aa4bca8
parent3b7eed4ebb3c18799ec791d0c6bd53c019f48f73 (diff)
downloademacs-0f238ea450b3a976f04c95c4cf8befaadad1cdd0.tar.gz
emacs-0f238ea450b3a976f04c95c4cf8befaadad1cdd0.zip
Add set-binary-mode primitive to switch a standard stream to binary I/O.
src/fileio.c: Include binary-io.h. (Fset_binary_mode): New function. (syms_of_fileio): Defsubr it. (syms_of_fileio) <Qstdin, Qstdout, Qstderr>: DEFSYM them. admin/unidata/unidata/uvs.el (uvs-print-table-ivd): Call set-binary-mode on stdout. doc/lispref/streams.texi (Input Functions): Document 'set-binary-mode'. (Output Functions): Cross-reference to documentation of 'set-binary-mode'. etc/NEWS: Mention 'set-binary-mode'.
-rw-r--r--admin/ChangeLog5
-rw-r--r--admin/unidata/uvs.el1
-rw-r--r--doc/lispref/ChangeLog6
-rw-r--r--doc/lispref/streams.texi24
-rw-r--r--etc/ChangeLog4
-rw-r--r--etc/NEWS4
-rw-r--r--src/ChangeLog7
-rw-r--r--src/fileio.c50
8 files changed, 101 insertions, 0 deletions
diff --git a/admin/ChangeLog b/admin/ChangeLog
index 2b04281f400..70d1714f8eb 100644
--- a/admin/ChangeLog
+++ b/admin/ChangeLog
@@ -1,3 +1,8 @@
12015-01-15 Eli Zaretskii <eliz@gnu.org>
2
3 * unidata/uvs.el (uvs-print-table-ivd): Call set-binary-mode on
4 stdout.
5
12015-01-12 Paul Eggert <eggert@cs.ucla.edu> 62015-01-12 Paul Eggert <eggert@cs.ucla.edu>
2 7
3 Say "ELC foo.elc" instead of "GEN foo.elc" 8 Say "ELC foo.elc" instead of "GEN foo.elc"
diff --git a/admin/unidata/uvs.el b/admin/unidata/uvs.el
index 8bad523ce35..a6beac97db4 100644
--- a/admin/unidata/uvs.el
+++ b/admin/unidata/uvs.el
@@ -200,6 +200,7 @@ corresponding number."
200 (insert-file-contents filename) 200 (insert-file-contents filename)
201 (uvs-alist-from-ivd collection-id 201 (uvs-alist-from-ivd collection-id
202 sequence-id-to-glyph-func)))) 202 sequence-id-to-glyph-func))))
203 (set-binary-mode 'stdout t)
203 (princ "/* Automatically generated by uvs.el. */\n") 204 (princ "/* Automatically generated by uvs.el. */\n")
204 (princ 205 (princ
205 (format "static const unsigned char mac_uvs_table_%s_bytes[] =\n {\n" 206 (format "static const unsigned char mac_uvs_table_%s_bytes[] =\n {\n"
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 941be3cf582..4c0c116ba5a 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,9 @@
12015-01-15 Eli Zaretskii <eliz@gnu.org>
2
3 * streams.texi (Input Functions): Document 'set-binary-mode'.
4 (Output Functions): Cross-reference to documentation of
5 'set-binary-mode'.
6
12015-01-04 Paul Eggert <eggert@cs.ucla.edu> 72015-01-04 Paul Eggert <eggert@cs.ucla.edu>
2 8
3 batch write-region no longer says "Wrote FOO" 9 batch write-region no longer says "Wrote FOO"
diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi
index 5e4df009b73..e52a543110b 100644
--- a/doc/lispref/streams.texi
+++ b/doc/lispref/streams.texi
@@ -339,6 +339,25 @@ shared structures. @xref{Circular Objects}. Its default value is
339@code{t}. 339@code{t}.
340@end defvar 340@end defvar
341 341
342@cindex binary I/O in batch mode
343When reading or writing from the standard input/output streams of the
344Emacs process in batch mode, it is sometimes required to make sure any
345arbitrary binary data will be read/written verbatim, and/or that no
346translation of newlines to or from CR-LF pairs are performed. This
347issue does not exist on Posix hosts, only on MS-Windows and MS-DOS.
348The following function allows to control the I/O mode of any standard
349stream of the Emacs process.
350
351@defun set-binary-mode stream mode
352Switch @var{stream} into binary or text I/O mode. If @var{mode} is
353non-@code{nil}, switch to binary mode, otherwise switch to text mode.
354The value of @var{stream} can be one of @code{stdin}, @code{stdout},
355or @code{stderr}. This function flushes any pending output data of
356@var{stream} as a side effect, and returns the previous value of I/O
357mode for @var{stream}. On Posix hosts, it always returns a
358non-@code{nil} value and does nothing except flushing pending output.
359@end defun
360
342@node Output Streams 361@node Output Streams
343@section Output Streams 362@section Output Streams
344@cindex stream (for printing) 363@cindex stream (for printing)
@@ -686,6 +705,11 @@ This function outputs @var{object} to @var{stream}, just like
686indent and fill the object to make it more readable for humans. 705indent and fill the object to make it more readable for humans.
687@end defun 706@end defun
688 707
708If you need to use binary I/O in batch mode, e.g., use the functions
709described in this section to write out arbitrary binary data or avoid
710conversion of newlines on non-Posix hosts, see @ref{Input Functions,
711set-binary-mode}.
712
689@node Output Variables 713@node Output Variables
690@section Variables Affecting Output 714@section Variables Affecting Output
691@cindex output-controlling variables 715@cindex output-controlling variables
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 20f88bdecc3..681858e5977 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,7 @@
12015-01-15 Eli Zaretskii <eliz@gnu.org>
2
3 * NEWS: Mention 'set-binary-mode'.
4
12015-01-11 Paul Eggert <eggert@cs.ucla.edu> 52015-01-11 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 Default to 'configure --enable-silent-rules' 7 Default to 'configure --enable-silent-rules'
diff --git a/etc/NEWS b/etc/NEWS
index f291c0c9ad9..0bfd3fd2a2d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -588,6 +588,10 @@ been obsoleted.
588undocumented integer-pair format. Instead, they return a list of two 588undocumented integer-pair format. Instead, they return a list of two
589integers. 589integers.
590 590
591+++
592** New function `set-binary-mode' allows to switch a standard stream
593of the Emacs process to binary I/O mode.
594
591 595
592* Changes in Frames and Windows Code in Emacs 25.1 596* Changes in Frames and Windows Code in Emacs 25.1
593 597
diff --git a/src/ChangeLog b/src/ChangeLog
index 898c10a48e1..40d8b267d84 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12015-01-15 Eli Zaretskii <eliz@gnu.org>
2
3 * fileio.c: Include binary-io.h.
4 (Fset_binary_mode): New function.
5 (syms_of_fileio): Defsubr it.
6 (syms_of_fileio) <Qstdin, Qstdout, Qstderr>: DEFSYM them.
7
12015-01-15 Teodor Zlatanov <tzz@lifelogs.com> 82015-01-15 Teodor Zlatanov <tzz@lifelogs.com>
2 9
3 * gnutls.c (init_gnutls_functions): Import gnutls_x509_crt_check_issuer. 10 * gnutls.c (init_gnutls_functions): Import gnutls_x509_crt_check_issuer.
diff --git a/src/fileio.c b/src/fileio.c
index 6c443c91db7..dc67a00ed2a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -86,6 +86,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
86#include <careadlinkat.h> 86#include <careadlinkat.h>
87#include <stat-time.h> 87#include <stat-time.h>
88 88
89#include <binary-io.h>
90
89#ifdef HPUX 91#ifdef HPUX
90#include <netio.h> 92#include <netio.h>
91#endif 93#endif
@@ -5754,6 +5756,48 @@ before any other event (mouse or keypress) is handled. */)
5754 return Qnil; 5756 return Qnil;
5755} 5757}
5756 5758
5759
5760DEFUN ("set-binary-mode", Fset_binary_mode, Sset_binary_mode, 2, 2, 0,
5761 doc: /* Switch STREAM to binary I/O mode or text I/O mode.
5762STREAM can be one of the symbols `stdin', `stdout', or `stderr'.
5763If MODE is non-nil, switch STREAM to binary mode, otherwise switch
5764it to text mode.
5765
5766As a side effect, this function flushes any pending STREAM's data.
5767
5768Value is the previous value of STREAM's I/O mode, nil for text mode,
5769non-nil for binary mode.
5770
5771On MS-Windows and MS-DOS, binary mode is needed to read or write
5772arbitrary binary data, and for disabling translation between CR-LF
5773pairs and a single newline character. Examples include generation
5774of text files with Unix-style end-of-line format using `princ' in
5775batch mode, with standard output redirected to a file.
5776
5777On Posix systems, this function always returns non-nil, and has no
5778effect except for flushing STREAM's data. */)
5779 (Lisp_Object stream, Lisp_Object mode)
5780{
5781 FILE *fp = NULL;
5782 int binmode;
5783
5784 CHECK_SYMBOL (stream);
5785 if (EQ (stream, Qstdin))
5786 fp = stdin;
5787 else if (EQ (stream, Qstdout))
5788 fp = stdout;
5789 else if (EQ (stream, Qstderr))
5790 fp = stderr;
5791 else
5792 xsignal2 (Qerror, build_string ("unsupported stream"), stream);
5793
5794 binmode = NILP (mode) ? O_TEXT : O_BINARY;
5795 if (fp != stdin)
5796 fflush (fp);
5797
5798 return (set_binary_mode (fileno (fp), binmode) == O_BINARY) ? Qt : Qnil;
5799}
5800
5757void 5801void
5758init_fileio (void) 5802init_fileio (void)
5759{ 5803{
@@ -6040,6 +6084,10 @@ This includes interactive calls to `delete-file' and
6040 DEFSYM (Qsubstitute_env_in_file_name, "substitute-env-in-file-name"); 6084 DEFSYM (Qsubstitute_env_in_file_name, "substitute-env-in-file-name");
6041 DEFSYM (Qget_buffer_window_list, "get-buffer-window-list"); 6085 DEFSYM (Qget_buffer_window_list, "get-buffer-window-list");
6042 6086
6087 DEFSYM (Qstdin, "stdin");
6088 DEFSYM (Qstdout, "stdout");
6089 DEFSYM (Qstderr, "stderr");
6090
6043 defsubr (&Sfind_file_name_handler); 6091 defsubr (&Sfind_file_name_handler);
6044 defsubr (&Sfile_name_directory); 6092 defsubr (&Sfile_name_directory);
6045 defsubr (&Sfile_name_nondirectory); 6093 defsubr (&Sfile_name_nondirectory);
@@ -6089,6 +6137,8 @@ This includes interactive calls to `delete-file' and
6089 6137
6090 defsubr (&Snext_read_file_uses_dialog_p); 6138 defsubr (&Snext_read_file_uses_dialog_p);
6091 6139
6140 defsubr (&Sset_binary_mode);
6141
6092#ifdef HAVE_SYNC 6142#ifdef HAVE_SYNC
6093 defsubr (&Sunix_sync); 6143 defsubr (&Sunix_sync);
6094#endif 6144#endif