summaryrefslogtreecommitdiff
path: root/libguile/struct.c
diff options
context:
space:
mode:
authorMarius Vollmer <mvo@zagadka.de>1997-06-03 21:49:52 +0000
committerMarius Vollmer <mvo@zagadka.de>1997-06-03 21:49:52 +0000
commitbafcafb27071fad976c9807f24bc801e3dfbfaa2 (patch)
treed871273cd7c91d649d6efff4ce27b68b9cda9760 /libguile/struct.c
parentede1d9bf576a180882ee63c1580e55a241d5660b (diff)
downloadguile-bafcafb27071fad976c9807f24bc801e3dfbfaa2.tar.gz
* struct.c (scm_struct_ref, scm_struct_set_x): Use
scm_struct_i_n_words to get the number of fields, not -scm_struct_n_extra_words. On the route to fancier struct printing: * struct.c (scm_print_struct): New function to print a structure. Include "genio.h" to support it. This function doesn't do anything interesting right now, but I think it should be here anyway. * struct.h: Include "print.h" and add prototype for scm_print_struct. * print.c (scm_iprin1): Call scm_print_struct instead of trying to print structures ourself.
Diffstat (limited to 'libguile/struct.c')
-rw-r--r--libguile/struct.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/libguile/struct.c b/libguile/struct.c
index 525df2638..6f2261ec5 100644
--- a/libguile/struct.c
+++ b/libguile/struct.c
@@ -43,6 +43,7 @@
#include <stdio.h>
#include "_scm.h"
#include "chars.h"
+#include "genio.h"
#include "struct.h"
@@ -434,7 +435,7 @@ scm_struct_ref (handle, pos)
p = SCM_INUM (pos);
fields_desc = (unsigned char *)SCM_CHARS (layout);
- n_fields = data[- scm_struct_n_extra_words] - scm_struct_n_extra_words;
+ n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_ref);
@@ -516,7 +517,7 @@ scm_struct_set_x (handle, pos, val)
p = SCM_INUM (pos);
fields_desc = (unsigned char *)SCM_CHARS (layout);
- n_fields = data[- scm_struct_n_extra_words] - scm_struct_n_extra_words;
+ n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
SCM_ASSERT (p < n_fields, pos, SCM_OUTOFRANGE, s_struct_set_x);
@@ -595,6 +596,41 @@ scm_struct_vtable_tag (handle)
+void
+scm_print_struct (exp, port, pstate)
+ SCM exp;
+ SCM port;
+ scm_print_state *pstate;
+{
+#if 0 /* XXX - too verbose */
+ SCM * data;
+ SCM layout;
+ int p;
+ int n_fields;
+ unsigned char * fields_desc;
+ unsigned char field_type;
+
+ layout = SCM_STRUCT_LAYOUT (exp);
+ data = SCM_STRUCT_DATA (exp);
+
+ fields_desc = (unsigned char *)SCM_CHARS (layout);
+ n_fields = data[scm_struct_i_n_words] - scm_struct_n_extra_words;
+
+ scm_gen_write (scm_regular_string, "#<struct ", sizeof ("#<struct ") - 1, port);
+ for (p = 0; p < n_fields; p++)
+ {
+ if (fields_desc[2*p] == 'p')
+ scm_iprin1 (data[p], port, pstate);
+ if (p < n_fields-1)
+ scm_gen_putc (' ', port);
+ }
+ scm_gen_putc ('>', port);
+#else
+ scm_gen_write (scm_regular_string, "#<struct ", sizeof ("#<struct ") - 1, port);
+ scm_intprint (exp, 16, port);
+ scm_gen_putc ('>', port);
+#endif
+}
void
scm_init_struct ()