* Get rid of calls to SCM_ROSTRINGP.
[bpt/guile.git] / libguile / ports.h
index fabb44a..0b12af5 100644 (file)
@@ -2,7 +2,7 @@
 
 #ifndef PORTSH
 #define PORTSH
-/*     Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
+/*     Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,6 +42,9 @@
  * If you write modifications of your own for GUILE, it is your choice
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
+
+/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
+   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 \f
 #include "libguile/__scm.h"
 
 
 #define SCM_INITIAL_PUTBACK_BUF_SIZE 4
 
+/* values for the rw_active flag.  */
+enum scm_port_rw_active {
+  SCM_PORT_NEITHER = 0,
+  SCM_PORT_READ = 1,
+  SCM_PORT_WRITE = 2
+};
+
 /* C representation of a Scheme port.  */
 
 typedef struct 
@@ -64,9 +74,8 @@ typedef struct
   int revealed;                        /* 0 not revealed, > 1 revealed.
                                 * Revealed ports do not get GC'd.
                                 */
-  /* data for the underlying port implementation.  may be an SCM cell or 
-     cast to a pointer to C data.  */
-  SCM stream;
+  /* data for the underlying port implementation as a raw C value. */
+  scm_bits_t stream;
 
   SCM file_name;               /* debugging support.  */
   int line_number;             /* debugging support.  */
@@ -106,32 +115,30 @@ typedef struct
 
   unsigned char shortbuf;       /* buffer for "unbuffered" streams.  */
 
-  int rw_random;                /* true if the port is bidirectional and
-                                  random access.  implies that the buffers
-                                  must be flushed before switching between
-                                  reading and writing.  */
+  int rw_random;                /* true if the port is random access.
+                                  implies that the buffers must be
+                                  flushed before switching between
+                                  reading and writing, seeking, etc.  */
+
+  enum scm_port_rw_active rw_active; /* for random access ports,
+                                       indicates which of the buffers
+                                       is currently in use.  can be
+                                       SCM_PORT_WRITE, SCM_PORT_READ,
+                                       or SCM_PORT_NEITHER.  */
 
-  int rw_active;                /* for bidirectional random ports, indicates
-                                  which of the buffers is currently in use.
-                                  can be SCM_PORT_WRITE, SCM_PORT_READ,
-                                  or 0.  */
 
   /* a buffer for un-read chars and strings.  */
   unsigned char *putback_buf;
   int putback_buf_size;        /* allocated size of putback_buf.  */
 } scm_port;
 
-/* values for the rw_active flag.  */
-#define SCM_PORT_READ 1
-#define SCM_PORT_WRITE 2
-
 extern scm_port **scm_port_table;
 extern int scm_port_table_size; /* Number of ports in scm_port_table.  */
 
 
 \f
 
-#define SCM_EOF_OBJECT_P(x) ((x) == SCM_EOF_VAL)
+#define SCM_EOF_OBJECT_P(x) (SCM_EQ_P ((x), SCM_EOF_VAL))
 
 /* PORT FLAGS
  * A set of flags characterizes a port.
@@ -142,26 +149,31 @@ extern int scm_port_table_size; /* Number of ports in scm_port_table.  */
 #define SCM_RDNG       (2L<<16) /* Is it a readable port? */
 #define SCM_WRTNG      (4L<<16) /* Is it writable? */
 #define SCM_BUF0       (8L<<16) /* Is it unbuffered? */
-/* #define SCM_CRDY    (32L<<16)  obsolete, for pushed back characters  */
 #define SCM_BUFLINE     (64L<<16) /* Is it line-buffered? */
 
-#define SCM_PORTP(x) (SCM_TYP7(x)==scm_tc7_port)
-#define SCM_OPPORTP(x) (((0x7f | SCM_OPN) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN))
-#define SCM_OPINPORTP(x) (((0x7f | SCM_OPN | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG))
-#define SCM_OPOUTPORTP(x) (((0x7f | SCM_OPN | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG))
-#define SCM_INPORTP(x) (((0x7f | SCM_RDNG) & SCM_CAR(x))==(scm_tc7_port | SCM_RDNG))
-#define SCM_OUTPORTP(x) (((0x7f | SCM_WRTNG) & SCM_CAR(x))==(scm_tc7_port | SCM_WRTNG))
-#define SCM_OPENP(x) (SCM_OPN & SCM_CAR(x))
+#define SCM_PORTP(x) (SCM_NIMP(x) && (SCM_TYP7(x)==scm_tc7_port))
+#define SCM_OPPORTP(x) (SCM_NIMP(x) && (((0x7f | SCM_OPN) & SCM_CELL_WORD_0(x))==(scm_tc7_port | SCM_OPN)))
+#define SCM_OPINPORTP(x) (SCM_NIMP(x) && (((0x7f | SCM_OPN | SCM_RDNG) & SCM_CELL_WORD_0(x))==(scm_tc7_port | SCM_OPN | SCM_RDNG)))
+#define SCM_OPOUTPORTP(x) (SCM_NIMP(x) && (((0x7f | SCM_OPN | SCM_WRTNG) & SCM_CELL_WORD_0(x))==(scm_tc7_port | SCM_OPN | SCM_WRTNG)))
+#define SCM_INPUT_PORT_P(x) \
+  (SCM_NIMP(x) \
+   && (((0x7f | SCM_RDNG) & SCM_CELL_WORD_0(x)) == (scm_tc7_port | SCM_RDNG)))
+#define SCM_OUTPUT_PORT_P(x) \
+  (SCM_NIMP(x) \
+   && (((0x7f | SCM_WRTNG) & SCM_CELL_WORD_0(x))==(scm_tc7_port | SCM_WRTNG)))
+#define SCM_OPENP(x) (SCM_NIMP(x) && (SCM_OPN & SCM_CELL_WORD_0 (x)))
 #define SCM_CLOSEDP(x) (!SCM_OPENP(x))
-#define SCM_PTAB_ENTRY(x) ((scm_port *) SCM_CDR(x))
-#define SCM_SETPTAB_ENTRY(x,ent) SCM_SETCDR ((x), (SCM)(ent))
-#define SCM_STREAM(x) SCM_PTAB_ENTRY(x)->stream
-#define SCM_SETSTREAM(x,s) (SCM_PTAB_ENTRY(x)->stream = (SCM) s)
-#define SCM_FILENAME(x) SCM_PTAB_ENTRY(x)->file_name
-#define SCM_LINUM(x) SCM_PTAB_ENTRY(x)->line_number
-#define SCM_COL(x) SCM_PTAB_ENTRY(x)->column_number
-#define SCM_REVEALED(x) SCM_PTAB_ENTRY(x)->revealed
-#define SCM_SETREVEALED(x,s) (SCM_PTAB_ENTRY(x)->revealed = s)
+
+#define SCM_PTAB_ENTRY(x)         ((scm_port *) SCM_CELL_WORD_1 (x))
+#define SCM_SETPTAB_ENTRY(x,ent)  (SCM_SET_CELL_WORD_1 ((x), (scm_bits_t) (ent)))
+#define SCM_STREAM(x)             (SCM_PTAB_ENTRY(x)->stream)
+#define SCM_SETSTREAM(x,s)        (SCM_PTAB_ENTRY(x)->stream = (scm_bits_t) (s))
+#define SCM_FILENAME(x)           (SCM_PTAB_ENTRY(x)->file_name)
+#define SCM_SET_FILENAME(x, n)    (SCM_PTAB_ENTRY(x)->file_name = (n))
+#define SCM_LINUM(x)              (SCM_PTAB_ENTRY(x)->line_number)
+#define SCM_COL(x)                (SCM_PTAB_ENTRY(x)->column_number)
+#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_INCCOL(port)       {SCM_COL (port) += 1;}
@@ -169,6 +181,7 @@ extern int scm_port_table_size; /* Number of ports in scm_port_table.  */
 
 \f
 
+/* port-type description.  */
 typedef struct scm_ptob_descriptor
 {
   char *name;
@@ -176,17 +189,22 @@ typedef struct scm_ptob_descriptor
   scm_sizet (*free) (SCM);
   int (*print) (SCM exp, SCM port, scm_print_state *pstate);
   SCM (*equalp) (SCM, SCM);
-  void (*fflush) (SCM port);
-  void (*read_flush) (SCM port, int offset);
-  int (*fclose) (SCM port);
-  int (*fill_buffer) (SCM port);
+  int (*close) (SCM port);
+
+  void (*write) (SCM port, const void *data, size_t size);
+  void (*flush) (SCM port);
+
+  void (*end_input) (SCM port, int offset);
+  int (*fill_input) (SCM port);
+  int (*input_waiting) (SCM port);
+
   off_t (*seek) (SCM port, off_t OFFSET, int WHENCE);
-  void (*ftruncate) (SCM port, off_t length);
-  int (*input_waiting_p) (SCM port);
+  void (*truncate) (SCM port, off_t length);
+
 } scm_ptob_descriptor;
 
 #define SCM_TC2PTOBNUM(x) (0x0ff & ((x) >> 8))
-#define SCM_PTOBNUM(x) (SCM_TC2PTOBNUM (SCM_CAR (x)))
+#define SCM_PTOBNUM(x) (SCM_TC2PTOBNUM (SCM_CELL_TYPE (x)))
 /* SCM_PTOBNAME can be 0 if name is missing */
 #define SCM_PTOBNAME(ptobnum) scm_ptobs[ptobnum].name
 
@@ -198,87 +216,110 @@ extern int scm_port_table_room;
 
 \f
 
-extern SCM scm_markstream SCM_P ((SCM ptr));
+extern SCM scm_markstream (SCM ptr);
 extern long scm_make_port_type (char *name,
-                               int (*fill_buffer) (SCM port),
-                               void (*write_flush) (SCM port));
-extern void scm_set_ptob_mark (long tc, SCM (*mark) (SCM));
-extern void scm_set_ptob_free (long tc, scm_sizet (*free) (SCM));
-extern void scm_set_ptob_print (long tc,
+                               int (*fill_input) (SCM port),
+                               void (*write) (SCM port, const void *data,
+                                              size_t size));
+extern void scm_set_port_mark (long tc, SCM (*mark) (SCM));
+extern void scm_set_port_free (long tc, scm_sizet (*free) (SCM));
+extern void scm_set_port_print (long tc,
                                int (*print) (SCM exp,
                                              SCM port,
                                              scm_print_state *pstate));
-extern void scm_set_ptob_equalp (long tc, SCM (*equalp) (SCM, SCM));
-extern void scm_set_ptob_flush_input (long tc,
-                                     void (*flush_input) (SCM port,
-                                                          int offset));
-extern void scm_set_ptob_close (long tc, int (*close) (SCM));
-extern void scm_set_ptob_seek (long tc,
+extern void scm_set_port_equalp (long tc, SCM (*equalp) (SCM, SCM));
+extern void scm_set_port_close (long tc, int (*close) (SCM));
+
+extern void scm_set_port_flush (long tc, 
+                               void (*flush) (SCM port));
+extern void scm_set_port_end_input (long tc,
+                                   void (*end_input) (SCM port,
+                                                      int offset));
+extern void scm_set_port_seek (long tc,
                               off_t (*seek) (SCM port,
                                              off_t OFFSET,
                                              int WHENCE));
-extern void scm_set_ptob_truncate (long tc,
+extern void scm_set_port_truncate (long tc,
                                   void (*truncate) (SCM port,
                                                     off_t length));
-extern void scm_set_ptob_input_waiting_p (long tc, int (*waitingp) (SCM));
-extern SCM scm_char_ready_p SCM_P ((SCM port));
+extern void scm_set_port_input_waiting (long tc, int (*input_waiting) (SCM));
+extern SCM scm_char_ready_p (SCM port);
 extern SCM scm_drain_input (SCM port);
-extern SCM scm_current_input_port SCM_P ((void));
-extern SCM scm_current_output_port SCM_P ((void));
-extern SCM scm_current_error_port SCM_P ((void));
-extern SCM scm_current_load_port SCM_P ((void));
-extern SCM scm_set_current_input_port SCM_P ((SCM port));
-extern SCM scm_set_current_output_port SCM_P ((SCM port));
-extern SCM scm_set_current_error_port SCM_P ((SCM port));
-extern scm_port * scm_add_to_port_table SCM_P ((SCM port));
-extern void scm_remove_from_port_table SCM_P ((SCM port));
-extern void scm_grow_port_cbuf SCM_P ((SCM port, size_t requested));
-extern SCM scm_pt_size SCM_P ((void));
-extern SCM scm_pt_member SCM_P ((SCM member));
-extern int scm_revealed_count SCM_P ((SCM port));
-extern SCM scm_port_revealed SCM_P ((SCM port));
-extern SCM scm_set_port_revealed_x SCM_P ((SCM port, SCM rcount));
-extern long scm_mode_bits SCM_P ((char *modes));
-extern SCM scm_port_mode SCM_P ((SCM port));
-extern SCM scm_close_port SCM_P ((SCM port));
-extern SCM scm_close_all_ports_except SCM_P ((SCM ports));
-extern SCM scm_input_port_p SCM_P ((SCM x));
-extern SCM scm_output_port_p SCM_P ((SCM x));
-extern SCM scm_eof_object_p SCM_P ((SCM x));
-extern SCM scm_force_output SCM_P ((SCM port));
-extern SCM scm_flush_all_ports SCM_P ((void));
-extern SCM scm_read_char SCM_P ((SCM port));
-extern void scm_putc SCM_P ((int c, SCM port));
-extern void scm_puts SCM_P ((char *str_data, SCM port));
-extern void scm_lfwrite SCM_P ((char *ptr, scm_sizet size, SCM port));
-extern void scm_fflush SCM_P ((SCM port));
-extern void scm_read_flush (SCM port);
-extern int scm_fill_buffer (SCM port);
-extern int scm_getc SCM_P ((SCM port));
-extern void scm_ungetc SCM_P ((int c, SCM port));
-extern void scm_ungets SCM_P ((char *s, int n, SCM port));
-extern SCM scm_peek_char SCM_P ((SCM port));
-extern SCM scm_unread_char SCM_P ((SCM cobj, SCM port));
-extern SCM scm_unread_string SCM_P ((SCM str, SCM port));
-extern char *scm_generic_fgets SCM_P ((SCM port, int *len));
-extern SCM scm_lseek (SCM object, SCM offset, SCM whence);
+extern SCM scm_current_input_port (void);
+extern SCM scm_current_output_port (void);
+extern SCM scm_current_error_port (void);
+extern SCM scm_current_load_port (void);
+extern SCM scm_set_current_input_port (SCM port);
+extern SCM scm_set_current_output_port (SCM port);
+extern SCM scm_set_current_error_port (SCM port);
+extern scm_port * scm_add_to_port_table (SCM port);
+extern void scm_remove_from_port_table (SCM port);
+extern void scm_grow_port_cbuf (SCM port, size_t requested);
+extern SCM scm_pt_size (void);
+extern SCM scm_pt_member (SCM member);
+extern void scm_port_non_buffer (scm_port *pt);
+extern int scm_revealed_count (SCM port);
+extern SCM scm_port_revealed (SCM port);
+extern SCM scm_set_port_revealed_x (SCM port, SCM rcount);
+extern long scm_mode_bits (char *modes);
+extern SCM scm_port_mode (SCM port);
+extern SCM scm_close_input_port (SCM port);
+extern SCM scm_close_output_port (SCM port);
+extern SCM scm_close_port (SCM port);
+extern SCM scm_close_all_ports_except (SCM ports);
+extern SCM scm_input_port_p (SCM x);
+extern SCM scm_output_port_p (SCM x);
+extern SCM scm_port_closed_p (SCM port);
+extern SCM scm_eof_object_p (SCM x);
+extern SCM scm_force_output (SCM port);
+extern SCM scm_flush_all_ports (void);
+extern SCM scm_read_char (SCM port);
+extern void scm_putc (char c, SCM port);
+extern void scm_puts (const char *str_data, SCM port);
+extern void scm_lfwrite (const char *ptr, scm_sizet size, SCM port);
+extern void scm_flush (SCM port);
+extern void scm_end_input (SCM port);
+extern int scm_fill_input (SCM port);
+extern int scm_getc (SCM port);
+extern void scm_ungetc (int c, SCM port);
+extern void scm_ungets (const char *s, int n, SCM port);
+extern SCM scm_peek_char (SCM port);
+extern SCM scm_unread_char (SCM cobj, SCM port);
+extern SCM scm_unread_string (SCM str, SCM port);
+extern SCM scm_seek (SCM object, SCM offset, SCM whence);
 extern SCM scm_truncate_file (SCM object, SCM length);
-extern SCM scm_port_line SCM_P ((SCM port));
-extern SCM scm_set_port_line_x SCM_P ((SCM port, SCM line));
-extern SCM scm_port_column SCM_P ((SCM port));
-extern SCM scm_set_port_column_x SCM_P ((SCM port, SCM line));
-extern SCM scm_port_filename SCM_P ((SCM port));
-extern SCM scm_set_port_filename_x SCM_P ((SCM port, SCM filename));
+extern SCM scm_port_line (SCM port);
+extern SCM scm_set_port_line_x (SCM port, SCM line);
+extern SCM scm_port_column (SCM port);
+extern SCM scm_set_port_column_x (SCM port, SCM line);
+extern SCM scm_port_filename (SCM port);
+extern SCM scm_set_port_filename_x (SCM port, SCM filename);
 extern int scm_port_print (SCM exp, SCM port, scm_print_state *);
 extern void scm_print_port_mode (SCM exp, SCM port);
-extern void scm_ports_prehistory SCM_P ((void));
-extern SCM scm_void_port SCM_P ((char * mode_str));
-extern SCM scm_sys_make_void_port SCM_P ((SCM mode));
-extern void scm_init_ports SCM_P ((void));
+extern void scm_ports_prehistory (void);
+extern SCM scm_void_port (char * mode_str);
+extern SCM scm_sys_make_void_port (SCM mode);
+extern void scm_init_ports (void);
 
 #ifdef GUILE_DEBUG
-extern SCM scm_pt_size SCM_P ((void));
-extern SCM scm_pt_member SCM_P ((SCM member));
+extern SCM scm_pt_size (void);
+extern SCM scm_pt_member (SCM member);
 #endif /* GUILE_DEBUG */
 
+\f
+
+#if (SCM_DEBUG_DEPRECATED == 0)
+
+/* #define SCM_CRDY    (32L<<16)  obsolete, for pushed back characters  */
+#define SCM_INPORTP(x) SCM_INPUT_PORT_P (x)
+#define SCM_OUTPORTP(x) SCM_OUTPUT_PORT_P (x)
+
+#endif  /* SCM_DEBUG_DEPRECATED == 0 */
+
 #endif  /* PORTSH */
+
+/*
+  Local Variables:
+  c-file-style: "gnu"
+  End:
+*/