From 7011b75694bb02fff7f98defbc11ea7260235685 Mon Sep 17 00:00:00 2001 From: MORIOKA Tomohiko Date: Tue, 16 Apr 2013 17:48:56 +0900 Subject: [PATCH] (cos_print_object): New function. --- print.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/print.c b/print.c index 2698189..0a8952b 100644 --- a/print.c +++ b/print.c @@ -234,3 +234,50 @@ cos_utf8_print_char (COS_object character, unsigned char *dest, size_t size) return i; } } + + +void +cos_print_object (COS_object obj) +{ + if ( obj == NULL ) + printf ("#", obj); + else if ( COS_OBJECT_INT_P (obj) ) + printf ("%d", cos_int_value (obj)); + else if ( COS_OBJECT_CHAR_P (obj) ) + { + char id_buf[256]; + + cos_utf8_print_char (obj, id_buf, 256); + printf ("?%s", id_buf); + } + else if ( COS_OBJECT_STRING_P (obj) ) + { + printf ("\"%s\"", cos_string_data (obj)); + } + else if ( COS_OBJECT_SYMBOL_P (obj) ) + { + printf ("%s", cos_string_data (cos_symbol_name (obj))); + } + else if ( COS_OBJECT_CONS_P (obj) ) + { + COS_object rest = COS_CDR (obj); + + printf ("("); + cos_print_object (COS_CAR (obj)); + while ( COS_OBJECT_CONS_P (rest) ) + { + printf (" "); + cos_print_object (COS_CAR (rest)); + rest = COS_CDR (rest); + } + if ( rest != cos_Qnil ) + { + printf (" . "); + cos_print_object (rest); + } + printf (")"); + } + else + printf ("Object[0x%lX] is a fat object.\n", + obj); +} -- 1.7.10.4