Add `scm_i_set_default_port_encoding' and `scm_i_default_port_encoding'.
[bpt/guile.git] / libguile / ports.h
index 8a21b09..cc0b987 100644 (file)
@@ -3,7 +3,8 @@
 #ifndef SCM_PORTS_H
 #define SCM_PORTS_H
 
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004,
+ *   2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
 
 #include "libguile/__scm.h"
 
+#include <unistd.h>
 #include "libguile/print.h"
 #include "libguile/struct.h"
 #include "libguile/threads.h"
-
+#include "libguile/strings.h"
 
 \f
 
@@ -56,6 +58,10 @@ typedef struct
   long line_number;            /* debugging support.  */
   int column_number;           /* debugging support.  */
 
+  /* Character encoding support  */
+  char *encoding;
+  scm_t_string_failed_conversion_handler ilseq_handler;
+
   /* port buffers.  the buffer(s) are set up for all ports.  
      in the case of string ports, the buffer is the string itself.
      in the case of unbuffered file ports, the buffer is a
@@ -105,6 +111,10 @@ typedef struct
   /* a buffer for un-read chars and strings.  */
   unsigned char *putback_buf;
   size_t putback_buf_size;        /* allocated size of putback_buf.  */
+
+  /* input/output iconv conversion descriptors */
+  void *input_cd;
+  void *output_cd;
 } scm_t_port;
 
 
@@ -155,11 +165,11 @@ SCM_INTERNAL SCM scm_i_port_weak_hash;
 #define SCM_REVEALED(x)           (SCM_PTAB_ENTRY(x)->revealed)
 #define SCM_SETREVEALED(x, s)      (SCM_PTAB_ENTRY(x)->revealed = (s))
 
-#define SCM_INCLINE(port)      {SCM_LINUM (port) += 1; SCM_COL (port) = 0;}
-#define SCM_ZEROCOL(port)      {SCM_COL (port) = 0;}
-#define SCM_INCCOL(port)       {SCM_COL (port) += 1;}
-#define SCM_DECCOL(port)       {if (SCM_COL (port) > 0) SCM_COL (port) -= 1;}
-#define SCM_TABCOL(port)       {SCM_COL (port) += 8 - SCM_COL (port) % 8;}
+#define SCM_INCLINE(port)      do {SCM_LINUM (port) += 1; SCM_COL (port) = 0;} while (0)
+#define SCM_ZEROCOL(port)      do {SCM_COL (port) = 0;} while (0)
+#define SCM_INCCOL(port)       do {SCM_COL (port) += 1;} while (0)
+#define SCM_DECCOL(port)       do {if (SCM_COL (port) > 0) SCM_COL (port) -= 1;} while (0)
+#define SCM_TABCOL(port)       do {SCM_COL (port) += 8 - SCM_COL (port) % 8;} while (0)
 
 /* Maximum number of port types.  */
 #define SCM_I_MAX_PORT_TYPE_COUNT  256
@@ -197,7 +207,6 @@ typedef struct scm_t_ptob_descriptor
 
 SCM_API scm_t_ptob_descriptor *scm_ptobs;
 SCM_API long scm_numptob;
-SCM_INTERNAL long scm_i_port_table_room;
 
 \f
 
@@ -266,13 +275,17 @@ SCM_API SCM scm_eof_object_p (SCM x);
 SCM_API SCM scm_force_output (SCM port);
 SCM_API SCM scm_flush_all_ports (void);
 SCM_API SCM scm_read_char (SCM port);
+SCM_API scm_t_wchar scm_getc (SCM port);
 SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size);
 SCM_API void scm_c_write (SCM port, const void *buffer, size_t size);
 SCM_API void scm_lfwrite (const char *ptr, size_t size, SCM port);
+SCM_INTERNAL void scm_lfwrite_substr (SCM str, size_t start, size_t end,
+                                     SCM port);
 SCM_API void scm_flush (SCM port);
 SCM_API void scm_end_input (SCM port);
 SCM_API int scm_fill_input (SCM port);
-SCM_API void scm_ungetc (int c, SCM port);
+SCM_INTERNAL void scm_unget_byte (int c, SCM port); 
+SCM_API void scm_ungetc (scm_t_wchar c, SCM port);
 SCM_API void scm_ungets (const char *s, int n, SCM port);
 SCM_API SCM scm_peek_char (SCM port);
 SCM_API SCM scm_unread_char (SCM cobj, SCM port);
@@ -285,16 +298,24 @@ SCM_API SCM scm_port_column (SCM port);
 SCM_API SCM scm_set_port_column_x (SCM port, SCM line);
 SCM_API SCM scm_port_filename (SCM port);
 SCM_API SCM scm_set_port_filename_x (SCM port, SCM filename);
+SCM_INTERNAL const char *scm_i_default_port_encoding (void);
+SCM_INTERNAL void scm_i_set_default_port_encoding (const char *);
+SCM_INTERNAL void scm_i_set_port_encoding_x (SCM port, const char *str);
+SCM_API SCM scm_port_encoding (SCM port);
+SCM_API SCM scm_set_port_encoding_x (SCM port, SCM encoding);
+SCM_INTERNAL scm_t_string_failed_conversion_handler scm_i_get_conversion_strategy (SCM port);
+SCM_INTERNAL void scm_i_set_conversion_strategy_x (SCM port, 
+                                                  scm_t_string_failed_conversion_handler h);
+SCM_API SCM scm_port_conversion_strategy (SCM port);
+SCM_API SCM scm_set_port_conversion_strategy_x (SCM port, SCM behavior);
 SCM_API int scm_port_print (SCM exp, SCM port, scm_print_state *);
 SCM_API void scm_print_port_mode (SCM exp, SCM port);
-SCM_API void scm_ports_prehistory (void);
 SCM_API SCM scm_void_port (char * mode_str);
 SCM_API SCM scm_sys_make_void_port (SCM mode);
 SCM_INTERNAL void scm_init_ports (void);
 
-
 #if SCM_ENABLE_DEPRECATED==1
-SCM_API scm_t_port * scm_add_to_port_table (SCM port);
+SCM_DEPRECATED scm_t_port * scm_add_to_port_table (SCM port);
 #endif
 
 #ifdef GUILE_DEBUG