*** empty log message ***
[bpt/guile.git] / libguile / print.h
index 5660fc1..149d976 100644 (file)
@@ -2,7 +2,7 @@
 
 #ifndef PRINTH
 #define PRINTH
-/*     Copyright (C) 1995,1996 Free Software Foundation, Inc.
+/*     Copyright (C) 1995,1996,1998 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
@@ -16,7 +16,8 @@
  * 
  * You should have received a copy of the GNU General Public License
  * along with this software; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
  *
  * As a special exception, the Free Software Foundation gives permission
  * for additional uses of the text contained in its release of GUILE.
  *
  * 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.  
- */
+ * If you do not wish that, delete this exception notice.  */
 \f
 
-#include "__scm.h"
+#include "libguile/__scm.h"
 
+#include "libguile/options.h"
 \f
 extern scm_option scm_print_opts[];
 
-#define SCM_PRINT_PROCNAMES_P  ((int) scm_print_opts[0].val)
-#define SCM_PRINT_CLOSURE      ((SCM) scm_print_opts[1].val)
+#define SCM_PRINT_CLOSURE      ((SCM) scm_print_opts[0].val)
+#define SCM_PRINT_SOURCE_P     ((int) scm_print_opts[1].val)
 #define SCM_N_PRINT_OPTIONS 2
 
-#ifdef __STDC__
-extern SCM scm_print_options (SCM setting);
-extern void scm_intprint (long n, int radix, SCM port);
-extern void scm_ipruk (char *hdr, SCM ptr, SCM port);
-extern void scm_iprlist (char *hdr, SCM exp, char tlr, SCM port, int writing);
-extern void scm_iprin1 (SCM exp, SCM port, int writing);
-extern SCM scm_write (SCM obj, SCM port);
-extern SCM scm_display (SCM obj, SCM port);
-extern SCM scm_newline(SCM port);
-extern SCM scm_write_char (SCM chr, SCM port);
-extern void scm_init_print (void);
+/* State information passed around during printing.
+ */
+#define SCM_PRINT_STATE_P(obj) (SCM_STRUCTP(obj) \
+                               && (SCM_STRUCT_VTABLE(obj) \
+                                   == scm_print_state_vtable))
+#define SCM_PRINT_STATE(obj) ((scm_print_state *) SCM_STRUCT_DATA (obj))
+
+#define RESET_PRINT_STATE(pstate) \
+{ \
+  pstate->list_offset = 0; \
+  pstate->top = 0; \
+}
+
+#define SCM_WRITINGP(pstate) ((pstate)->writingp)
+#define SCM_SET_WRITINGP(pstate, x) { (pstate)->writingp = (x); }
+
+#define SCM_COERCE_OUTPORT(p) ((SCM_NIMP (p) \
+                               && SCM_CONSP (p) \
+                               && SCM_PRINT_STATE_P (SCM_CDR (p))) \
+                              ? SCM_CAR (p) \
+                              : p)
+
+#define SCM_PRINT_STATE_LAYOUT "sruwuwuwuwuwpwuwuwuruopr"
+typedef struct scm_print_state {
+  SCM handle;                  /* Struct handle */
+  int revealed;                 /* Has the state escaped to Scheme? */
+  unsigned long writingp;      /* Writing? */
+  unsigned long fancyp;                /* Fancy printing? */
+  unsigned long level;         /* Max level */
+  unsigned long length;                /* Max number of objects per level */
+  SCM hot_ref;                 /* Hot reference */
+  unsigned long list_offset;
+  unsigned long top;           /* Top of reference stack */
+  unsigned long ceiling;       /* Max size of reference stack */
+  SCM *ref_stack;              /* Stack of references used during
+                                  circular reference detection */
+  SCM ref_vect;
+} scm_print_state;
 
-#else /* STDC */
-extern SCM scm_print_options ();
-extern void scm_intprint ();
-extern void scm_ipruk ();
-extern void scm_iprlist ();
-extern void scm_iprin1 ();
-extern SCM scm_write ();
-extern SCM scm_display ();
-extern SCM scm_newline();
-extern SCM scm_write_char ();
-extern void scm_init_print ();
+extern SCM scm_print_state_vtable;
 
-#endif /* STDC */
+extern SCM scm_print_options SCM_P ((SCM setting));
+SCM scm_make_print_state SCM_P ((void));
+void scm_free_print_state SCM_P ((SCM print_state));
+extern void scm_intprint SCM_P ((long n, int radix, SCM port));
+extern void scm_ipruk SCM_P ((char *hdr, SCM ptr, SCM port));
+extern void scm_iprlist SCM_P ((char *hdr, SCM exp, int tlr, SCM port, scm_print_state *pstate));
+extern void scm_prin1 SCM_P ((SCM exp, SCM port, int writingp));
+extern void scm_iprin1 SCM_P ((SCM exp, SCM port, scm_print_state *pstate));
+extern SCM scm_write SCM_P ((SCM obj, SCM port));
+extern SCM scm_display SCM_P ((SCM obj, SCM port));
+extern SCM scm_newline SCM_P ((SCM port));
+extern SCM scm_write_char SCM_P ((SCM chr, SCM port));
+extern SCM scm_printer_apply SCM_P ((SCM proc, SCM exp, SCM port,
+                                    scm_print_state *));
+extern int scm_valid_oport_value_p SCM_P ((SCM val));
+extern void scm_init_print SCM_P ((void));
 
+#ifdef GUILE_DEBUG
+extern SCM scm_current_pstate SCM_P ((void));
+#endif 
 #endif  /* PRINTH */