summaryrefslogtreecommitdiff
path: root/doc/ref/api-io.texi
AgeCommit message (Collapse)AuthorFilesLines
2020-10-05Document write-line.Jan (janneke) Nieuwenhuizen1-0/+11
* libguile/rdelim.c (SCM_DEFINE): Use "procedure" rather than "function". * doc/ref/api-io.texi (Line/Delimited): Use it to document 'write-line'.
2021-03-12Revert "Handle CRLF and Unicode line endings in read-line"Andy Wingo1-7/+3
This reverts commit 0f983e3db0c43ad7c89f57ea84f792ede373ba0c. After discussing with Mike we are going to punt the read-line changes for now. Open the port in O_TEXT mode if you want to chomp the CR in CFLF sequences.
2021-03-11Handle CRLF and Unicode line endings in read-lineMike Gran1-3/+7
* libguile/rdelim.c (scm_read_line): handle CRLF, LS and PS * module/ice-9/suspendable-ports.scm (read-line): handle CRLF, LS, and PS * module/web/http.scm (read-header-line): take advantage of CRLF in read-line (read-header): don't need to test for \return * test-suite/tests/rdelim.test: new tests for read-line CRLF, LS and PS * doc/ref/api-io.texi: update doc for read-line
2021-01-12Document new interfacesAndy Wingo1-0/+13
* NEWS: Update. * doc/ref/api-io.texi (Bytevector Ports): Add docs.
2021-01-12Document call-with-portAndy Wingo1-1/+6
* doc/ref/api-io.texi (Ports): Add docs. * doc/ref/r6rs.texi (rnrs io ports): Remove docs.
2020-06-15doc: Remove copy/pasted sentence.Ludovic Courtès1-1/+1
* doc/ref/api-io.texi (I/O Extensions): Remove sentence pasted from 'read' when explaining 'write' method.
2019-06-18Add get-bytevector-some!.Mark H Weaver1-1/+9
* libguile/r6rs-ports.c (scm_get_bytevector_some_x): New procedure. * libguile/r6rs-ports.h (scm_get_bytevector_some_x): Add prototype. (scm_unget_bytevector): Move prototype next to 'scm_get_bytevector_some_x'. * module/ice-9/binary-ports.scm: Export 'get-bytevector-some!'. * doc/ref/api-io.texi (Binary I/O): Document it.
2017-11-22Convert `close' ref to xref.Arun Isaac1-3/+2
* doc/ref/api-io.texi (Ports): Convert `close' ref to xref. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2016-12-06Fix small typo in suspendable-ports documentation.Christopher Allan Webber1-1/+1
* doc/ref/api-io.texi (Non-Blocking I/O): Fix example to call use-modules rather than use-module.
2016-08-31Only ptob->close() after read/write finishAndy Wingo1-0/+7
* libguile/Makefile.am (noinst_HEADERS): Add atomics-internal.h. * libguile/atomics-internal.h: New file. * libguile/ports-internal.h (refcount): New member. * libguile/ports.c (release_port, scm_dynwind_acquire_port): New facility for acquiring a port within a dynwind. (scm_port_poll, scm_i_read_bytes, scm_setvbuf, scm_end_input) (scm_i_write_bytes, scm_char_ready_p, scm_seek) (scm_truncate_file, trampoline_to_c_read) (trampoline_to_c_write): Acquire port. (scm_c_make_port_with_encoding): Init refcount to 1. (scm_close_port): Release port. * doc/ref/api-io.texi (I/O Extensions): Add documentation
2016-08-31Fix example in make-custom-binary-input-port documentationChristopher Allan Webber1-3/+3
* doc/ref/api-io.texi (Custom Ports): Add additional argument to example's invocation of make-custom-binary-input-port. Previously had mismatched arity by missing "closed" argument.
2016-08-04Implement R6RS custom binary input/output portsAndy Wingo1-0/+12
* NEWS: Add new feature. * doc/ref/r6rs.texi (rnrs io ports): * doc/ref/api-io.texi (Custom Ports): Document new procedure. * libguile/r6rs-ports.h: * libguile/r6rs-ports.c (make_custom_binary_input_output_port) (scm_make_custom_binary_input_output_port) (custom_binary_input_output_port_random_access_p) (initialize_custom_binary_input_output_ports) (scm_init_r6rs_ports): Implement custom binary input/output ports. * module/rnrs/io/ports.scm (rnrs): * module/ice-9/binary-ports.scm (ice-9): Export make-custom-binary-input/output-port.
2016-06-24Add with-input-from-port, etc documentationAndy Wingo1-0/+8
* doc/ref/api-io.texi (Default Ports): Add documentation for with-input-from-port, with-output-to-port, and with-error-to-port. Fixes #20919.
2016-06-20Document char-ready? limitations.Andy Wingo1-0/+16
* doc/ref/api-io.texi (Venerable Port Interfaces): Document limitations of char-ready?. See http://debbugs.gnu.org/10627.
2016-06-09Update port documentation, rename sports to suspendable portsAndy Wingo1-220/+188
* module/ice-9/suspendable-ports.scm: Rename from ice-9/sports.scm, and adapt module names. Remove exports that are not related to the suspendable ports facility; we want people to continue using the port operations from their original locations. Add put-string to the replacement list. * module/Makefile.am: Adapt to rename. * test-suite/tests/suspendable-ports.test: Rename from sports.test. * test-suite/Makefile.am: Adapt to rename. * module/ice-9/textual-ports.scm (unget-char, unget-string): New functions. * doc/ref/api-io.texi (Textual I/O, Simple Output): Flesh out documentation. (Line/Delimited): Undocument write-line, read-string, and read-string!. This is handled by (ice-9 textual-ports). (Bytevector Ports): Fix duplicated section. (String Ports): Move the note about encodings down to the end. (Custom Ports): Add explanatory text. Remove mention of C functions; they should use the C port interface. (Venerable Port Interfaces): Add text, and make documentation refer to recommended interfaces. (Using Ports from C): Add documentation. (Non-Blocking I/O): Document more fully and adapt to suspendable-ports name change.
2016-06-08Big ports documentation updateAndy Wingo1-1236/+678
* doc/ref/api-io.texi: Update to document ports more thoroughly. Still some work needed. * doc/ref/r6rs.texi: Move ports documentation back to r6rs.texi, now that Guile has a more thorough binary/textual I/O story, heavily based on R6RS. * doc/ref/api-control.texi: * doc/ref/api-data.texi: * doc/ref/api-options.texi: * doc/ref/misc-modules.texi: * doc/ref/posix.texi: * doc/ref/srfi-modules.texi: Update references.
2016-06-08Undocument (ice-9 rw)Andy Wingo1-101/+0
* doc/ref/api-io.texi (Block Reading and Writing): Undocument (ice-9 rw). The R6RS routines do the same job and are not so clunky.
2016-05-20Support for non-blocking I/OAndy Wingo1-0/+87
* doc/ref/api-io.texi (I/O Extensions): Document read_wait_fd / write_wait_fd members. (Non-Blocking I/O): New section. * libguile/fports.c (fport_read, fport_write): Return -1 if the operation would block. (fport_wait_fd, scm_make_fptob): Add read/write wait-fd implementation. * libguile/ports-internal.h (scm_t_port_type): Add read_wait_fd / write_wait_fd. * libguile/ports.c (default_read_wait_fd, default_write_wait_fd): New functions. (scm_make_port_type): Initialize default read/write wait fd impls. (trampoline_to_c_read, trampoline_to_scm_read) (trampoline_to_c_write, trampoline_to_scm_write): To Scheme, a return of #f indicates EWOULDBLOCk. (scm_set_port_read_wait_fd, scm_set_port_write_wait_fd): New functions. (port_read_wait_fd, port_write_wait_fd, scm_port_read_wait_fd) (scm_port_write_wait_fd, port_poll, scm_port_poll): New functions. (scm_i_read_bytes, scm_i_write_bytes): Poll if the read or write would block. * libguile/ports.h (scm_set_port_read_wait_fd) (scm_set_port_write_wait_fd): Add declarations. * module/ice-9/ports.scm: Shunt port-poll and port-{read,write}-wait-fd to the internals module. * module/ice-9/sports.scm (current-write-waiter): (current-read-waiter): Implement. * test-suite/tests/ports.test: Adapt non-blocking test to new behavior. * NEWS: Add entry.
2016-05-16U+FFFD is the input substitution characterAndy Wingo1-34/+42
* libguile/ports.c (UNICODE_REPLACEMENT_CHARACTER): * libguile/ports.c (peek_utf8_codepoint) (scm_port_decode_char, peek_iconv_codepoint): * module/ice-9/sports.scm (peek-char-and-len/utf8): (peek-char-and-len/iconv): Return U+FFFD when we get a decoding error when reading, instead of '?', in accordance with Unicode recommendations. * test-suite/tests/iconv.test: * test-suite/tests/ports.test: * test-suite/tests/rdelim.test: Update tests. * NEWS: Update.
2016-05-14Document scm_c_make_port and friendsAndy Wingo1-1/+21
* doc/ref/api-io.texi (I/O Extensions): Document scm_c_make_port and friends, and document "mode bits".
2016-05-13Update port type documentationAndy Wingo1-12/+13
* doc/ref/api-io.texi (I/O Extensions): Update for port type change.
2016-05-13Update port documentationAndy Wingo1-79/+41
* doc/ref/api-io.texi: Update for refactorings.
2016-05-13Add random_access_p port type methodAndy Wingo1-57/+45
* doc/ref/api-io.texi (I/O Extensions): Update documentation on implementing port types. Document get_natural_buffer_sizes. Document the new random_access_p. * libguile/fports.c (scm_i_fdes_to_port, fport_random_access_p): (scm_make_fptob): Instead of frobbing rw_random manually, implement a random_access_p function. * libguile/ports.c (default_random_access_p) (scm_set_port_random_access_p): New functions. scm_make_port_type, scm_c_make_port_with_encoding): Arrange for random_access_p to work.
2016-04-12Update port implementation documentation.Andy Wingo1-8/+12
* doc/ref/api-io.texi (I/O Extensions): Update read/write documentation.
2016-04-06Generic port facility provides buffering uniformlyAndy Wingo1-212/+214
* libguile/ports.h (struct scm_t_port_buffer): New data type. (struct scm_t_port): Refactor to use port buffers instead of implementation-managed read and write pointers. Add "read_buffering" member. (SCM_INITIAL_PUTBACK_BUF_SIZE, SCM_READ_BUFFER_EMPTY_P): Remove. (scm_t_ptob_descriptor): Rename "fill_input" function to "read", and take a port buffer, returning void. Likewise "write" takes a port buffer and returns void. Remove "end_input"; instead if there is buffered input and rw_random is true, then there must be a seek function, so just seek back if needed. Remove "flush"; instead all calls to the "write" function implicitly include a "flush", since the buffering happens in the generic port code now. Remove "setvbuf", but add "get_natural_buffer_sizes"; instead the generic port code can buffer any port. (scm_make_port_type): Adapt to read and write prototype changes. (scm_set_port_flush, scm_set_port_end_input, scm_set_port_setvbuf): Remove. (scm_slow_get_byte_or_eof_unlocked) (scm_slow_get_peek_or_eof_unlocked): Remove; the slow path is to call scm_fill_input. (scm_set_port_get_natural_buffer_sizes): New function. (scm_c_make_port_buffer): New internal function. (scm_port_non_buffer): Remove. This was a function for implementations that is no longer needed. Instead open with BUF0 or use (setvbuf port 'none). (scm_fill_input, scm_fill_input_unlocked): Return the filled port buffer. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt to changes in buffering and EOF management. * libguile/ports.c: Adapt to port interface changes. (initialize_port_buffers): New function, using the port mode flags to set up appropriate initial buffering for all ports. (scm_c_make_port_with_encoding): Create port buffers here instead of delegating to implementations. (scm_close_port): Flush the port if needed instead of delegating to the implementation. * libguile/filesys.c (set_element): Adapt to buffering changes. * libguile/fports.c (fport_get_natural_buffer_sizes): New function, replacing scm_fport_buffer_add. (fport_write, fport_read): Update to let the generic ports code do the buffering. (fport_flush, fport_end_input): Remove. (fport_close): Don't flush in a dynwind; that's the core ports' job. (scm_make_fptob): Adapt. * libguile/ioext.c (scm_redirect_port): Adapt to buffering changes. * libguile/poll.c (scm_primitive_poll): Adapt to buffering changes. * libguile/ports-internal.h (struct scm_port_internal): Remove pending_eof flag; this is now set on the read buffer. * libguile/r6rs-ports.c (struct bytevector_input_port): New type. The new buffering arrangement means that there's now an intermediate buffer between the bytevector and the user of the port; this could lead to a perf degradation, but on the other hand there are some other speedups enabled by the buffering refactor, so probably the memcpy cost is dwarfed by the cost of the other parts of the ports machinery. (make_bytevector_input_port, bytevector_input_port_read): (bytevector_input_port_seek, initialize_bytevector_input_ports): Adapt to new buffering arrangement. (struct custom_binary_port): Remove read buffer, as Guile handles that now. (custom_binary_input_port_setvbuf): Remove; now handled by Guile. (make_custom_binary_input_port, custom_binary_input_port_read) (initialize_custom_binary_input_ports): Adapt. (scm_get_bytevector_some): Adapt to new EOF management. (scm_t_bytevector_output_port_buffer): Hold on to the underlying port, so we can flush it if it's open. (make_bytevector_output_port, bytevector_output_port_write): (bytevector_output_port_seek): Adapt. (bytevector_output_port_procedure): Flush the port as appropriate, so that we get all the bytes. (make_custom_binary_output_port, custom_binary_output_port_write): Adapt. (make_transcoded_port): Don't muck with buffering. (transcoded_port_write): Simply forward the write to the underlying port. (transcoded_port_read): Likewise. (transcoded_port_close): No need to flush. (initialize_transcoded_ports): Adapt. * libguile/read.c (scm_i_scan_for_encoding): Adapt to buffering changes. * libguile/rw.c (scm_write_string_partial): Adapt to buffering changes. * libguile/strports.c: Adapt to the fact that we don't manage the buffer. Probably room for speed improvements here... * libguile/vports.c (soft_port_get_natural_buffer_sizes): New function. Adapt the rest of the file for the new buffering regime. * test-suite/tests/r6rs-ports.test ("8.2.10 Output ports"): Custom binary output ports need to be flushed before you can rely on the write! procedure having been called. Add necessary flush-port invocations. ("8.2.6 Input and output ports"): Transcoded ports now have an internal buffer by default. This test checks that the characters are transcoded one at a time, so to do that, call setvbuf on the transcoded port to remove the buffer. * test-suite/tests/web-client.test (run-with-http-transcript): Fix for different flushing regime on soft ports. (The vestigial flush procedure is now called after each write, which is not what the test was expecting.) * test-suite/standalone/test-scm-c-read.c: Update for changes to the C interface for defining port types. * doc/ref/api-io.texi (Ports): Update to discuss buffering in a generic way, and to remove a hand-wavey paragraph describing string ports as "interesting and powerful". (Reading, Writing): Remove placeholder comments. Document `scm_lfwrite'. (Buffering): New section. (File Ports): Link to buffering. (I/O Extensions): Join subnodes into parent and describe new API, including buffering API. * doc/ref/posix.texi (Ports and File Descriptors): Link to buffering. Remove unread-char etc, as they are documented elsewhere. (Pipes, Network Sockets and Communication): Link to buffering.
2016-04-05Port close functions return voidAndy Wingo1-1/+1
* libguile/ports.h (scm_t_ptob_descriptor): The port close function now returns void. (scm_set_port_close): Adapt prototype. * libguile/ports.c (scm_close_port): Always return true if we managed to call the close function. There's no other sensible result; exceptions are handled, well, exceptionally. * libguile/fports.c (fport_close) * libguile/r6rs-ports.c (custom_binary_port_close, transcoded_port_close): * libguile/vports.c (soft_port_close): Adapt. * doc/ref/api-io.texi (Port Implementation): Update.
2016-04-04Remove port equal functionsAndy Wingo1-6/+0
* doc/ref/api-io.texi (Port Implementation): Remove mention of port equal functions. * NEWS: Update. * libguile/ports.c (scm_set_port_equalp): Remove. * libguile/ports.h (scm_t_ptob_descriptor): Remove equalp function.
2016-04-04Remove port free functions; just close insteadAndy Wingo1-11/+11
* libguile/ports.h (scm_t_port_type_flags): Replace SCM_PORT_TYPE_HAS_FLUSH with SCM_PORT_TYPE_NEEDS_CLOSE_ON_GC. (scm_t_ptob_descriptor): Remove free function. * libguile/ports.c (scm_set_port_needs_close_on_gc): New function. (scm_set_port_flush): Don't set flags. (scm_c_make_port_with_encoding, scm_close_port): Use the new flag to determine when to add a finalizer and also when to include the port in the weak set. (scm_set_port_free): Remove. (do_close, finalize_port): Close port instead of calling free function. * libguile/r6rs-ports.c (initialize_transcoded_ports): * libguile/vports.c (scm_make_sfptob): * libguile/fports.c (scm_make_fptob): Mark these ports as needing close on GC. * libguile/fports.c (fport_free): Remove. * NEWS: Update. * doc/ref/api-io.texi (Port Implementation): Update.
2016-04-04Remove port mark functionsAndy Wingo1-8/+0
* doc/ref/api-io.texi (Port Implementation): Remove documentation. * libguile/ports.c (scm_set_port_mark): Remove function. * libguile/ports.h (scm_t_ptob_descriptor): Remove mark function. * NEWS: Add entry.
2015-01-22Merge commit '7c433cbbce83bc9f2f9967afba00bbb68e312657'Andy Wingo1-3/+7
Conflicts: meta/Makefile.am
2014-12-03doc: Clarify the unit of the 'offset' argument of 'seek'.Ludovic Courtès1-3/+7
Reported in <http://bugs.gnu.org/18520> by David Kastrup <dak@gnu.org>. * doc/ref/api-io.texi (Random Access): Clarify the unit of the 'offset' argument to 'seek'.
2014-02-07Merge commit '8ca97482b01cf1a6aa538cc5a2d1f71fb60f080c'Andy Wingo1-0/+4
Conflicts: libguile/r6rs-ports.c
2014-01-18Custom binary input ports support 'setvbuf'.Ludovic Courtès1-0/+4
* libguile/r6rs-ports.c (CBIP_BUFFER_SIZE): Adjust comment. Set to 8KiB. (SCM_SET_CBIP_BYTEVECTOR): New macro. (cbip_setvbuf): New function. (make_cbip): Set PORT's 'setvbuf' internal field. (cbip_fill_input): Check whether PORT is buffered. When unbuffered, check whether BV can hold C_REQUESTED bytes, and allocate a new bytevector if not; copy the data back from BV to c_port->read_pos. Remove 'again' label, and don't loop there. * test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports")["custom binary input port unbuffered & 'port-position'", "custom binary input port unbuffered & 'read!' calls", "custom binary input port, unbuffered then buffered", "custom binary input port, buffered then unbuffered"]: New tests. * doc/ref/api-io.texi (R6RS Binary Input): Document the buffering of custom binary input ports, and link to 'setvbuf'.
2013-09-13Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-0/+1
Conflicts: module/srfi/srfi-9.scm module/web/server.scm
2013-09-13Fix truncated documentation for 'put-char'.Mark H Weaver1-0/+1
Fixes <http://bugs.gnu.org/15152>. Reported by Josep Portella Florit <jpf@primfilat.com>. * doc/ref/api-io.texi (R6RS Textual Output): Fix truncated docs for 'put-char'. * THANKS: Add Josep Portella Florit to fixes section.
2013-08-23Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-1/+1
2013-08-19doc: `get-string-all' takes only one argument.Ian Price1-1/+1
* doc/ref/api-io.texi (R6RS Textual Input): Remove `count' argument.
2013-08-07String ports use UTF-8; ignore %default-port-encoding.Mark H Weaver1-24/+0
* libguile/strports.c (scm_mkstrport): Use UTF-8; ignore %default-port-encoding. Rename 'str_len' and 'c_pos' to 'num_bytes' and 'c_byte_pos'. Interpret 'pos' argument as a character index instead of a byte index. * module/ice-9/boot-9.scm (%cond-expand-features): Add srfi-6 to the list of core features. * module/srfi/srfi-6.scm (open-input-string, open-output-string): Simply re-export these, since the core versions are now compliant. * doc/ref/api-io.texi (String Ports): Remove text that describes non-compliant behavior of string ports with regard to encoding. * doc/ref/srfi-modules.texi (SRFI-0): Add srfi-6 to the list of core features. (SRFI-6): Remove text that mentions non-compliant behavior of core string ports. * module/ice-9/format.scm (format): * module/ice-9/pretty-print.scm (truncated-print): * module/rnrs/io/ports.scm (open-string-input-port, open-string-output-port): * test-suite/test-suite/lib.scm (format-test-name): * test-suite/tests/chars.test ("combining accent is pretty-printed", "combining X is pretty-printed"): * test-suite/tests/ecmascript.test (eread, eread/1): * test-suite/tests/rdelim.test: * test-suite/tests/reader.test (read-string): * test-suite/tests/regexp.test: * test-suite/tests/srfi-105.test (read-string): Don't set %default-port-encoding before creating string ports. * benchmark-suite/benchmarks/ports.bm (%latin1-port): Use 'set-port-encoding!' to set the string port encoding. (%utf8/ascii-port, %utf8/wide-port, "rdelim"): Don't set %default-port-encoding before creating string ports. * test-suite/tests/r6rs-ports.test ("lookahead-u8 non-ASCII"): Don't set %default-port-encoding before creating string ports. ("put-bytevector with UTF-16 string port", "put-bytevector with wrong-encoding string port"): Use 'set-port-encoding!' to set the string port encoding. * test-suite/tests/print.test (tprint): Use 'set-port-encoding!' to set the string port encoding. ("truncated-print"): Use 'pass-if-equal'. * test-suite/tests/ports.test ("encoding failure leads to exception", "%default-port-encoding is honored", "peek-char [latin-1]", "peek-char [utf-8]", "peek-char [utf-16]"): Remove tests. ("%default-port-encoding is ignored", "peek-char"): Add tests. ("suitable encoding [latin-1]", "suitable encoding [latin-3]", "wrong encoding, error", "wrong encoding, substitute", "wrong encoding, escape"): Use 'set-port-encoding!' to set the string port encoding. ("%default-port-encoding, wrong encoding"): Rewrite to use a file port instead of a string port.
2013-04-07Add keyword arguments to file opening procedures.Mark H Weaver1-14/+47
* libguile/fports.c (scm_open_file_with_encoding): New API function, containing the code previously found in 'scm_open_file', but modified to accept the new 'guess_encoding' and 'encoding' arguments. (scm_open_file): Now just a simple wrapper that calls 'scm_open_file_with_encoding'. (scm_i_open_file): New implementation of 'open-file' that accepts keyword arguments '#:guess-encoding' and '#:encoding', and calls 'scm_open_file_with_encoding'. (scm_init_fports_keywords): New initialization function that gets called after keywords are initialized. * libguile/fports.h (scm_open_file_with_encoding, scm_init_fports_keywords): Add prototypes. * libguile/init.c (scm_i_init_guile): Call 'scm_init_fports_keywords'. * module/ice-9/boot-9.scm: Add enhanced versions of 'open-input-file', 'open-output-file', 'call-with-input-file', 'call-with-output-file', 'with-input-from-file', 'with-output-to-file', and 'with-error-to-file', that accept keyword arguments '#:binary', '#:encoding', and (for input port constructors) '#:guess-encoding'. * doc/ref/api-io.texi (File Ports): Update documentation. * test-suite/tests/ports.test ("keyword arguments for file openers"): Add tests.
2013-04-07Implement efficient 'scm_unget_bytes' and 'unget-bytevector'.Mark H Weaver1-3/+16
* libguile/ports.c (scm_i_unget_bytes): New static function. (scm_unget_bytes): New API function. (scm_unget_byte): Rewrite to simply call 'scm_i_unget_bytes'. (scm_ungetc, scm_peek_char, looking_at_bytes): Use 'scm_i_unget_bytes'. * libguile/ports.h: Add prototype for 'scm_unget_bytes'. * libguile/fports.c (scm_setvbuf): Use 'scm_unget_bytes'. * libguile/r6rs-ports.c (scm_unget_bytevector): New procedure. * module/ice-9/binary-ports.scm (unget-bytevector): New export. * doc/ref/api-io.texi (R6RS Binary Input): Add documentation. (R6RS I/O Ports): Update brief description of (ice-9 binary-ports) to reflect the new reality: it is no longer a subset of (rnrs io ports). * test-suite/tests/ports.test ("unget-bytevector"): Add test.
2013-04-07Do not scan for coding declarations in open-file.Mark H Weaver1-8/+16
* libguile/fports.c (scm_open_file): Do not scan for coding declarations. Replace 'use_encoding' local variable with 'binary'. Update documentation string. * module/ice-9/psyntax.scm (include): Add the same file-encoding logic that's used in compile-file and scm_primitive_load. * module/ice-9/psyntax-pp.scm: Regenerate. * doc/ref/api-io.texi (File Ports): Update docs. * test-suite/tests/ports.test: Change "open-file HONORS file coding declarations" test to "open-file IGNORES file coding declaration". * test-suite/tests/coding.test (scan-coding): Use 'file-encoding' to scan for the encoding, since 'open-input-file' no longer does so.
2013-04-04Improve handling of Unicode byte-order marks (BOMs).Mark H Weaver1-1/+80
* libguile/ports-internal.h (struct scm_port_internal): Add new members 'at_stream_start_for_bom_read' and 'at_stream_start_for_bom_write'. (SCM_UNICODE_BOM): New macro. (scm_i_port_iconv_descriptors): Add 'mode' parameter to prototype. * libguile/ports.c (scm_new_port_table_entry): Initialize 'at_stream_start_for_bom_read' and 'at_stream_start_for_bom_write'. (get_iconv_codepoint): Pass new 'mode' parameter to 'scm_i_port_iconv_descriptors'. (get_codepoint): After reading a codepoint at stream start, record that we're no longer at stream start, and consume a BOM where appropriate. (scm_seek): Set the stream start flags according to the new position. (looking_at_bytes): New static function. (scm_utf8_bom, scm_utf16be_bom, scm_utf16le_bom, scm_utf32be_bom, scm_utf32le_bom): New static const arrays. (decide_utf16_encoding, decide_utf32_encoding): New static functions. (scm_i_port_iconv_descriptors): Add new 'mode' parameter. If the specified encoding is UTF-16 or UTF-32, make that precise by deciding what byte order to use, and construct iconv descriptors based on the precise encoding. (scm_i_set_port_encoding_x): Record that we are now at stream start. Do not open the new iconv descriptors immediately; let them be initialized lazily. * libguile/print.c (display_string_using_iconv): Record that we're no longer at stream start. Write a BOM if appropriate. * doc/ref/api-io.texi (BOM Handling): New node. * test-suite/tests/ports.test ("set-port-encoding!, wrong encoding"): Adapt test to cope with the fact that 'set-port-encoding!' does not immediately open the iconv descriptors. (bv-read-test): New procedure. ("unicode byte-order marks (BOMs)"): New test prefix.
2013-04-01Optimize 'get-bytevector-some'; it may now read less than possible.Mark H Weaver1-3/+4
* libguile/r6rs-ports.c (scm_get_bytevector_some): Rewrite to efficiently take the contents of the read/putback buffers. In the docstring, clarify that it might not return all available bytes. * doc/ref/api-io.texi (R6RS Binary Input): Clarify that 'get-bytevector-some' might not return all available bytes. * test-suite/tests/r6rs-ports.test ("get-bytevector-some [only-some]"): Remove bogus test, which requires more than the R6RS requires.
2013-01-22add read-string and read-string! to (ice-9 rdelim)Andy Wingo1-0/+27
* module/ice-9/rdelim.scm (read-string!, read-string): New functions. * test-suite/tests/rdelim.test: Add tests. * doc/ref/api-io.texi: Add docs. * module/ice-9/iconv.scm: * module/rnrs/io/ports.scm: * module/web/uri.scm: Use the new functions.
2012-05-31Add the `%default-port-conversion-strategy' fluid.Ludovic Courtès1-0/+15
Fixes <http://bugs.gnu.org/11468>. * libguile/ports.c (scm_conversion_strategy): Remove. (default_conversion_strategy_var, sym_error, sym_substitute, sym_escape): New variables. (scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x): Remove. (scm_i_default_port_conversion_handler, scm_i_set_default_port_conversion_handler): New functions. (scm_port_conversion_strategy): Use `scm_i_default_port_conversion_handler' when PORT is #f. (scm_set_port_conversion_strategy_x): Use SYM_ERROR, SYM_SUBSTITUTE, and SYM_ESCAPE. Use `scm_i_set_default_port_conversion_handler' when PORT is #f. (scm_init_ports): Initialize DEFAULT_CONVERSION_STRATEGY_VAR. * libguile/ports.h: Update declarations accordingly. * libguile/foreign.c: Change `scm_i_get_conversion_strategy (SCM_BOOL_F)' to `scm_i_default_port_conversion_handler ()'. * libguile/strings.c: Likewise. * test-suite/tests/ports.test ("%default-port-conversion-strategy"): New test prefix. * test-suite/tests/foreign.test ("pointer<->string")["%default-port-conversion-strategy is error", "%default-port-conversion-strategy is soft"]: New tests. * test-suite/test-suite/lib.scm (exception:encoding-error): Allow the regexp to match `scm_to_stringn' error messages. * doc/ref/api-io.texi (Ports): Document `%default-port-conversion-strategy'.
2012-02-04Improve consistency of definitions of C functions in manual.Bake Timmons1-1/+1
* doc/ref/api-compound.texi * doc/ref/api-evaluation.texi * doc/ref/api-foreign.texi * doc/ref/api-io.texi * doc/ref/posix.texi * doc/ref/srfi-modules.texi: Add missing parentheses and commas to definitions of C functions. * doc/ref/api-data.texi: Change from @deffn to @deftypefn for C function with arguments not of SCM type.
2012-02-02Make consistent the usage of variable names in the function definitions ↵Bake Timmons1-28/+28
found in the Texinfo docs. * doc/r5rs/r5rs.texi: * doc/ref/api-compound.texi: * doc/ref/api-data.texi: * doc/ref/api-debug.texi: * doc/ref/api-evaluation.texi: * doc/ref/api-io.texi: * doc/ref/api-modules.texi: * doc/ref/api-procedures.texi: * doc/ref/api-scheduling.texi: * doc/ref/api-smobs.texi: * doc/ref/compiler.texi: * doc/ref/misc-modules.texi: * doc/ref/posix.texi: * doc/ref/scheme-using.texi: * doc/ref/srfi-modules.texi: * doc/ref/vm.texi: * doc/ref/web.texi: * doc/sources/env.texi: Make usage of variable names of function definitions more consistent.
2012-01-05Placate a number of `syntax-check' verifications.Ludovic Courtès1-1/+1
- "filesystem" -> "file system" - remove doubled words - use EXIT_* macros instead of literal numbers - update `syntax-check' exclusion files
2011-08-18reword open-file docsAndy Wingo1-22/+22
* doc/ref/api-io.texi (File Ports): Refactor open-file docs. Thanks to Bake Timmons for the report.
2011-05-20fix documentation for option-set! syntaxenAndy Wingo1-8/+0
* doc/ref/api-evaluation.texi (Scheme Read): Note that read-set! is syntax. (Scheme Write): Likewise for print-set!. * doc/ref/api-io.texi (Writing): Remove reference to print-options-interface. * doc/ref/repl-modules.texi (Readline Options): Update, and add entries for readline-options, readline-set! et al.