DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(guile.info.gz) Line/Delimited

Info Catalog (guile.info.gz) Random Access (guile.info.gz) Input and Output (guile.info.gz) Block Reading and Writing
 
 27.6 Line Oriented and Delimited Text
 =====================================
 
 The delimited-I/O module can be accessed with:
 
      (use-modules (ice-9 rdelim))
 
    It can be used to read or write lines of text, or read text
 delimited by a specified set of characters.  It's similar to the `(scsh
 rdelim)' module from guile-scsh, but does not use multiple values or
 character sets and has an extra procedure `write-line'.
 
  -- Scheme Procedure: read-line [port] [handle-delim]
      Return a line of text from PORT if specified, otherwise from the
      value returned by `(current-input-port)'.  Under Unix, a line of
      text is terminated by the first end-of-line character or by
      end-of-file.
 
      If HANDLE-DELIM is specified, it should be one of the following
      symbols:
     `trim'
           Discard the terminating delimiter.  This is the default, but
           it will be impossible to tell whether the read terminated
           with a delimiter or end-of-file.
 
     `concat'
           Append the terminating delimiter (if any) to the returned
           string.
 
     `peek'
           Push the terminating delimiter (if any) back on to the port.
 
     `split'
           Return a pair containing the string read from the port and the
           terminating delimiter or end-of-file object.
 
  -- Scheme Procedure: read-line! buf [port]
      Read a line of text into the supplied string BUF and return the
      number of characters added to BUF.  If BUF is filled, then `#f' is
      returned.  Read from PORT if specified, otherwise from the value
      returned by `(current-input-port)'.
 
  -- Scheme Procedure: read-delimited delims [port] [handle-delim]
      Read text until one of the characters in the string DELIMS is found
      or end-of-file is reached.  Read from PORT if supplied, otherwise
      from the value returned by `(current-input-port)'.  HANDLE-DELIM
      takes the same values as described for `read-line'.
 
  -- Scheme Procedure: read-delimited! delims buf [port] [handle-delim]
           [start] [end]
      Read text into the supplied string BUF and return the number of
      characters added to BUF (subject to HANDLE-DELIM, which takes the
      same values specified for `read-line'.  If BUF is filled, `#f' is
      returned for both the number of characters read and the delimiter.
      Also terminates if one of the characters in the string DELIMS is
      found or end-of-file is reached.  Read from PORT if supplied,
      otherwise from the value returned by `(current-input-port)'.
 
  -- Scheme Procedure: write-line obj [port]
  -- C Function: scm_write_line (obj, port)
      Display OBJ and a newline character to PORT.  If PORT is not
      specified, `(current-output-port)' is used.  This function is
      equivalent to:
           (display obj [port])
           (newline [port])
 
    Some of the abovementioned I/O functions rely on the following C
 primitives.  These will mainly be of interest to people hacking Guile
 internals.
 
  -- Scheme Procedure: %read-delimited! delims str gobble [port [start
           [end]]]
  -- C Function: scm_read_delimited_x (delims, str, gobble, port, start,
           end)
      Read characters from PORT into STR until one of the characters in
      the DELIMS string is encountered.  If GOBBLE is true, discard the
      delimiter character; otherwise, leave it in the input stream for
      the next read.  If PORT is not specified, use the value of
      `(current-input-port)'.  If START or END are specified, store data
      only into the substring of STR bounded by START and END (which
      default to the beginning and end of the string, respectively).
 
      Return a pair consisting of the delimiter that terminated the
      string and the number of characters read.  If reading stopped at
      the end of file, the delimiter returned is the EOF-OBJECT; if the
      string was filled without encountering a delimiter, this value is
      `#f'.
 
  -- Scheme Procedure: %read-line [port]
  -- C Function: scm_read_line (port)
      Read a newline-terminated line from PORT, allocating storage as
      necessary.  The newline terminator (if any) is removed from the
      string, and a pair consisting of the line and its delimiter is
      returned.  The delimiter may be either a newline or the
      EOF-OBJECT; if `%read-line' is called at the end of file, it
      returns the pair `(#<eof> . #<eof>)'.
 
Info Catalog (guile.info.gz) Random Access (guile.info.gz) Input and Output (guile.info.gz) Block Reading and Writing
automatically generated byinfo2html