diff options
| author | Eli Zaretskii | 2015-01-15 17:50:50 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-01-15 17:50:50 +0200 |
| commit | 0f238ea450b3a976f04c95c4cf8befaadad1cdd0 (patch) | |
| tree | cd278a1441bd610bd91eb7fbd6f38aea7aa4bca8 | |
| parent | 3b7eed4ebb3c18799ec791d0c6bd53c019f48f73 (diff) | |
| download | emacs-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/ChangeLog | 5 | ||||
| -rw-r--r-- | admin/unidata/uvs.el | 1 | ||||
| -rw-r--r-- | doc/lispref/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/lispref/streams.texi | 24 | ||||
| -rw-r--r-- | etc/ChangeLog | 4 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/fileio.c | 50 |
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 @@ | |||
| 1 | 2015-01-15 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * unidata/uvs.el (uvs-print-table-ivd): Call set-binary-mode on | ||
| 4 | stdout. | ||
| 5 | |||
| 1 | 2015-01-12 Paul Eggert <eggert@cs.ucla.edu> | 6 | 2015-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 @@ | |||
| 1 | 2015-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 | |||
| 1 | 2015-01-04 Paul Eggert <eggert@cs.ucla.edu> | 7 | 2015-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 | ||
| 343 | When reading or writing from the standard input/output streams of the | ||
| 344 | Emacs process in batch mode, it is sometimes required to make sure any | ||
| 345 | arbitrary binary data will be read/written verbatim, and/or that no | ||
| 346 | translation of newlines to or from CR-LF pairs are performed. This | ||
| 347 | issue does not exist on Posix hosts, only on MS-Windows and MS-DOS. | ||
| 348 | The following function allows to control the I/O mode of any standard | ||
| 349 | stream of the Emacs process. | ||
| 350 | |||
| 351 | @defun set-binary-mode stream mode | ||
| 352 | Switch @var{stream} into binary or text I/O mode. If @var{mode} is | ||
| 353 | non-@code{nil}, switch to binary mode, otherwise switch to text mode. | ||
| 354 | The value of @var{stream} can be one of @code{stdin}, @code{stdout}, | ||
| 355 | or @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 | ||
| 357 | mode for @var{stream}. On Posix hosts, it always returns a | ||
| 358 | non-@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 | |||
| 686 | indent and fill the object to make it more readable for humans. | 705 | indent and fill the object to make it more readable for humans. |
| 687 | @end defun | 706 | @end defun |
| 688 | 707 | ||
| 708 | If you need to use binary I/O in batch mode, e.g., use the functions | ||
| 709 | described in this section to write out arbitrary binary data or avoid | ||
| 710 | conversion of newlines on non-Posix hosts, see @ref{Input Functions, | ||
| 711 | set-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 @@ | |||
| 1 | 2015-01-15 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * NEWS: Mention 'set-binary-mode'. | ||
| 4 | |||
| 1 | 2015-01-11 Paul Eggert <eggert@cs.ucla.edu> | 5 | 2015-01-11 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 6 | ||
| 3 | Default to 'configure --enable-silent-rules' | 7 | Default to 'configure --enable-silent-rules' |
| @@ -588,6 +588,10 @@ been obsoleted. | |||
| 588 | undocumented integer-pair format. Instead, they return a list of two | 588 | undocumented integer-pair format. Instead, they return a list of two |
| 589 | integers. | 589 | integers. |
| 590 | 590 | ||
| 591 | +++ | ||
| 592 | ** New function `set-binary-mode' allows to switch a standard stream | ||
| 593 | of 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 @@ | |||
| 1 | 2015-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 | |||
| 1 | 2015-01-15 Teodor Zlatanov <tzz@lifelogs.com> | 8 | 2015-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 | |||
| 5760 | DEFUN ("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. | ||
| 5762 | STREAM can be one of the symbols `stdin', `stdout', or `stderr'. | ||
| 5763 | If MODE is non-nil, switch STREAM to binary mode, otherwise switch | ||
| 5764 | it to text mode. | ||
| 5765 | |||
| 5766 | As a side effect, this function flushes any pending STREAM's data. | ||
| 5767 | |||
| 5768 | Value is the previous value of STREAM's I/O mode, nil for text mode, | ||
| 5769 | non-nil for binary mode. | ||
| 5770 | |||
| 5771 | On MS-Windows and MS-DOS, binary mode is needed to read or write | ||
| 5772 | arbitrary binary data, and for disabling translation between CR-LF | ||
| 5773 | pairs and a single newline character. Examples include generation | ||
| 5774 | of text files with Unix-style end-of-line format using `princ' in | ||
| 5775 | batch mode, with standard output redirected to a file. | ||
| 5776 | |||
| 5777 | On Posix systems, this function always returns non-nil, and has no | ||
| 5778 | effect 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 | |||
| 5757 | void | 5801 | void |
| 5758 | init_fileio (void) | 5802 | init_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 |