1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

78 commits

Author SHA1 Message Date
Mark H Weaver
cc73c2ab5d Add get-bytevector-some!.
* 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.
2019-06-18 02:05:20 -04:00
Arun Isaac
c2817dc93b Convert `close' ref to xref.
* doc/ref/api-io.texi (Ports): Convert `close' ref to xref.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:15:04 +01:00
Christopher Allan Webber
f94ea26a97 Fix small typo in suspendable-ports documentation.
* doc/ref/api-io.texi (Non-Blocking I/O): Fix example to call use-modules
  rather than use-module.
2016-12-06 13:40:13 -06:00
Andy Wingo
b8a53b98b3 Only ptob->close() after read/write finish
* 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-31 19:10:35 +02:00
Christopher Allan Webber
cc9e72bd2b Fix example in make-custom-binary-input-port documentation
* 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-31 15:51:38 +02:00
Andy Wingo
1a1c3bbe59 Implement R6RS custom binary input/output ports
* 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-08-04 22:29:51 +02:00
Andy Wingo
20718dd94b Add with-input-from-port, etc documentation
* 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-24 09:05:05 +02:00
Andy Wingo
5b6eaa91d2 Document char-ready? limitations.
* doc/ref/api-io.texi (Venerable Port Interfaces): Document limitations
  of char-ready?.  See http://debbugs.gnu.org/10627.
2016-06-20 21:21:20 +02:00
Andy Wingo
c7c11f3af9 Update port documentation, rename sports to suspendable ports
* 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-09 10:50:32 +02:00
Andy Wingo
a21f6467ac Big ports documentation update
* 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-08 10:19:27 +02:00
Andy Wingo
6eee08874b Undocument (ice-9 rw)
* 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-06-08 08:38:49 +02:00
Andy Wingo
534139e458 Support for non-blocking I/O
* 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-20 14:57:27 +02:00
Andy Wingo
1e058add7b U+FFFD is the input substitution character
* 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-16 10:48:35 +02:00
Andy Wingo
556ac9777b Document scm_c_make_port and friends
* doc/ref/api-io.texi (I/O Extensions): Document scm_c_make_port and
  friends, and document "mode bits".
2016-05-14 23:27:38 +02:00
Andy Wingo
9322902d02 Update port type documentation
* doc/ref/api-io.texi (I/O Extensions): Update for port type change.
2016-05-13 18:34:12 +02:00
Andy Wingo
af1c443f83 Update port documentation
* doc/ref/api-io.texi: Update for refactorings.
2016-05-13 16:48:02 +02:00
Andy Wingo
6ff542ee71 Add random_access_p port type method
* 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-05-13 10:05:23 +02:00
Andy Wingo
d83140890f Update port implementation documentation.
* doc/ref/api-io.texi (I/O Extensions): Update read/write
  documentation.
2016-04-12 16:31:20 +02:00
Andy Wingo
8399e7af51 Generic port facility provides buffering uniformly
* 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-06 19:21:44 +02:00
Andy Wingo
e8eeeeb1d4 Port close functions return void
* 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-05 15:16:26 +02:00
Andy Wingo
e98f64009d Remove port equal functions
* 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-04 16:30:56 +02:00
Andy Wingo
67b147fb7a Remove port free functions; just close instead
* 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-04 16:30:56 +02:00
Andy Wingo
4460f1f152 Remove port mark functions
* 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.
2016-04-04 16:30:56 +02:00
Andy Wingo
7c6ce75e2c Merge commit '7c433cbbce'
Conflicts:
	meta/Makefile.am
2015-01-22 13:32:59 +01:00
Ludovic Courtès
680135b6a3 doc: Clarify the unit of the 'offset' argument of 'seek'.
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-12-03 19:07:28 +01:00
Andy Wingo
e4eb0e39b4 Merge commit '8ca97482b0'
Conflicts:
	libguile/r6rs-ports.c
2014-02-07 14:42:40 +01:00
Ludovic Courtès
8ca97482b0 Custom binary input ports support 'setvbuf'.
* 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'.
2014-01-18 22:52:07 +01:00
Mark H Weaver
c04bf4337b Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	module/srfi/srfi-9.scm
	module/web/server.scm
2013-09-13 00:24:04 -04:00
Mark H Weaver
803c087e6b Fix truncated documentation for 'put-char'.
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-09-13 00:00:43 -04:00
Mark H Weaver
453acfacf4 Merge remote-tracking branch 'origin/stable-2.0' 2013-08-23 22:36:02 -04:00
Ian Price
1fcf690929 doc: `get-string-all' takes only one argument.
* doc/ref/api-io.texi (R6RS Textual Input): Remove `count' argument.
2013-08-19 22:25:41 +01:00
Mark H Weaver
6dce942c46 String ports use UTF-8; ignore %default-port-encoding.
* 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-08-07 01:22:22 -04:00
Mark H Weaver
3ace9a8e4e Add keyword arguments to file opening procedures.
* 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-07 15:37:23 -04:00
Mark H Weaver
7f6c3f8f00 Implement efficient 'scm_unget_bytes' and 'unget-bytevector'.
* 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-07 10:14:44 -04:00
Mark H Weaver
9a334eb3ab Do not scan for coding declarations in open-file.
* 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-07 10:11:41 -04:00
Mark H Weaver
cdd3d6c9f4 Improve handling of Unicode byte-order marks (BOMs).
* 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-04 21:40:28 -04:00
Mark H Weaver
21bbe22a14 Optimize 'get-bytevector-some'; it may now read less than possible.
* 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-04-01 16:46:25 -04:00
Andy Wingo
5a35d42aa5 add read-string and read-string! to (ice-9 rdelim)
* 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.
2013-01-22 15:15:43 +01:00
Ludovic Courtès
b22e94db7c Add the `%default-port-conversion-strategy' fluid.
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-05-31 00:50:36 +02:00
Bake Timmons
5f6ffd6652 Improve consistency of definitions of C functions in manual.
* 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-04 00:10:14 +01:00
Bake Timmons
64de6db5c6 Make consistent the usage of variable names in the function definitions 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-02-02 12:04:16 +01:00
Ludovic Courtès
b3da54d181 Placate a number of `syntax-check' verifications.
- "filesystem" -> "file system"
  - remove doubled words
  - use EXIT_* macros instead of literal numbers
  - update `syntax-check' exclusion files
2012-01-05 23:38:10 +01:00
Andy Wingo
5261e74281 reword open-file docs
* doc/ref/api-io.texi (File Ports): Refactor open-file docs.  Thanks to
  Bake Timmons for the report.
2011-08-18 11:13:34 +02:00
Andy Wingo
1233b38393 fix documentation for option-set! syntaxen
* 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.
2011-05-20 11:54:46 +02:00
Andreas Rottmann
040dfa6f37 More completely document the `(rnrs io ports)' library
* doc/ref/api-io.texi (R6RS I/O Ports): Transcribe missing parts from
  the R6RS document.
2011-05-07 22:30:40 +02:00
Ludovic Courtès
de424d9594 Document `(ice-9 binary-ports)'.
* doc/ref/api-io.texi (R6RS I/O Ports): Mention `(ice-9 binary-ports)'.

* NEWS: Update.
2011-04-27 22:14:31 +02:00
Ludovic Courtès
96128014bf Make sure binary ports pass `binary-port?' regardless of the locale.
* libguile/r6rs-ports.c (make_bip, make_cbip, make_bop, make_cbop):
  Set `c_port->encoding' to NULL.

* test-suite/tests/r6rs-ports.test ("7.2.7 Input
  Ports")["bytevector-input-port is binary"]: New test.
  ("7.2.7 Input Ports")["make-custom-binary-input-port"]: Make sure PORT
  passes `binary-port?' and `input-port?'.
  ("8.2.10 Output ports")["bytevector-output-port is binary"]: New test.
  ["make-custom-binary-output"]: Rename to...
  ["make-custom-binary-output-port"]: ... this.

* test-suite/tests/ports.test ("string ports")["read-char, wrong
  encoding, error", "read-char, wrong encoding, escape", "read-char,
  wrong encoding, substitute", "peek-char, wrong encoding, error"]: Use
  `set-port-encoding!' instead of `%default-port-encoding' to set the
  encoding of bytevector input ports.

* test-suite/tests/rdelim.test ("read-line")["decoding error", "decoding
  error, substitute"]: Likewise.

* doc/ref/api-io.texi (R6RS Port Manipulation): Document `binary-port?'
  and `textual-port?'.

* doc/ref/r6rs.texi (R6RS Incompatibilities): Mention the soft
  distinction between textual and binary ports.
2011-04-22 23:58:00 +02:00
Ludovic Courtès
958173e489 doc: Remove "lack of support for Unicode I/O and strings".
* doc/ref/api-io.texi (R6RS I/O Ports): Remove 1.8ish comment.
2011-03-13 23:21:07 +01:00
Andy Wingo
ac012a27a2 update port-filename docs
* doc/ref/api-io.texi (File Ports):
* libguile/ports.c (scm_port_filename): Fix docs to match
  implementation.
2011-02-28 20:54:03 +01:00
Ralf Wildenhues
ecb8733562 docs: fix typos in manual, and a couple in code comments.
* doc/ref/api-binding.texi, doc/ref/api-compound.texi,
doc/ref/api-control.texi, doc/ref/api-debug.texi,
doc/ref/api-io.texi, doc/ref/api-macros.texi,
doc/ref/api-procedures.texi, doc/ref/api-scheduling.texi,
doc/ref/api-undocumented.texi, doc/ref/api-utility.texi,
doc/ref/compiler.texi, doc/ref/goops.texi,
doc/ref/libguile-concepts.texi, doc/ref/misc-modules.texi,
doc/ref/posix.texi, doc/ref/r6rs.texi, doc/ref/slib.texi,
doc/ref/srfi-modules.texi, doc/ref/sxml-match.texi,
doc/ref/tools.texi, doc/ref/vm.texi, doc/ref/web.texi,
doc/sources/env.texi, doc/sources/jimb-org.texi,
doc/sources/scheme-concepts.texi, doc/sources/unix.texi,
module/ice-9/optargs.scm: Fix typos.
* doc/r4rs/r5rs.texi: Likewise.  Do not capitalize code symbols
even at the start of a sentence.
* doc/ref/api-data.texi: Likewise.  Also, remove executable bit.
2011-02-09 22:28:49 +00:00