[uim-commit] r1920 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Tue Nov 1 00:00:58 PST 2005


Author: yamaken
Date: 2005-11-01 00:00:47 -0800 (Tue, 01 Nov 2005)
New Revision: 1920

Modified:
   branches/r5rs/sigscheme/baseport.h
   branches/r5rs/sigscheme/debug.c
   branches/r5rs/sigscheme/fileport.c
   branches/r5rs/sigscheme/mbcport.c
   branches/r5rs/sigscheme/sbcport.c
   branches/r5rs/sigscheme/sbcport.h
   branches/r5rs/sigscheme/sigscheme.h
   branches/r5rs/sigscheme/strport.c
Log:
* This commit adds #<iport sb US-ASCII file> style port object
  inspection

* sigscheme/sigscheme.h
  - (SCM_PORT_INSPECT): New macro
* sigscheme/baseport.h
  - (SCM_CHARPORT_INSPECT, SCM_BYTEPORT_INSPECT): New macro
  - (ScmCharPortMethod_inspect, ScmBytePortMethod_inspect): New type
  - (struct ScmCharPortVTbl_, struct ScmBytePortVTbl_): Add member
    'inspect'
* sigscheme/sbcport.h
  - (ScmBaseCharPort_inspect): New function decl
* sigscheme/sbcport.c
  - (ScmBaseCharPort_inspect): New function
  - (basecport_inspect, sbcport_inspect): New static function
  - (ScmBaseCharPort_vtbl): Add member 'inspect'
  - (Scm_sbcport_init): Add initialization for vtbl.inspect
* sigscheme/mbcport.c
  - (mbcport_inspect): New static function
  - (Scm_mbcport_init): Add initialization for vtbl.inspect
* sigscheme/fileport.c
  - (fileport_inspect): New static function
  - (ScmFilePort_vtbl): Add member 'inspect'
* sigscheme/strport.c
  - (istrport_inspect, ostrport_inspect): New static function
  - (ScmInputStrPort_vtbl, ScmOutputStrPort_vtbl): Add member
    'inspect'
* sigscheme/debug.c
  - (print_port): Add the inspection


Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/baseport.h	2005-11-01 08:00:47 UTC (rev 1920)
@@ -92,6 +92,7 @@
 
 #define SCM_CHARPORT_CLOSE(cport)        ((*cport->vptr->close)(cport))
 #define SCM_CHARPORT_ENCODING(cport)     ((*cport->vptr->encoding)(cport))
+#define SCM_CHARPORT_INSPECT(cport)      ((*cport->vptr->inspect)(cport))
 #define SCM_CHARPORT_GET_CHAR(cport)     ((*cport->vptr->get_char)(cport))
 #define SCM_CHARPORT_PEEK_CHAR(cport)    ((*cport->vptr->peek_char)(cport))
 #define SCM_CHARPORT_CHAR_READYP(cport)  ((*cport->vptr->char_readyp)(cport))
@@ -102,6 +103,7 @@
 #define SCM_CHARPORT_FLUSH(cport)        ((*cport->vptr->flush)(cport))
 
 #define SCM_BYTEPORT_CLOSE(bport)        ((*bport->vptr->close)(bport))
+#define SCM_BYTEPORT_INSPECT(bport)      ((*bport->vptr->inspect)(bport))
 #define SCM_BYTEPORT_GET_BYTE(bport)     ((*bport->vptr->get_byte)(bport))
 #define SCM_BYTEPORT_PEEK_BYTE(bport)    ((*bport->vptr->peek_byte)(bport))
 #define SCM_BYTEPORT_BYTE_READYP(bport)  ((*bport->vptr->byte_readyp)(bport))
@@ -127,6 +129,8 @@
 typedef int (*ScmCharPortMethod_close)(ScmCharPort *cport);
 /* returns "UTF-8", "eucJP" and so on */
 typedef const char *(*ScmCharPortMethod_encoding)(ScmCharPort *cport);
+/* returns brief information */
+typedef char *(*ScmCharPortMethod_inspect)(ScmCharPort *cport);
 
 /* input */
 typedef int (*ScmCharPortMethod_get_char)(ScmCharPort *cport);
@@ -144,6 +148,7 @@
     ScmCharPortMethod_dyn_cast    dyn_cast;
     ScmCharPortMethod_close       close;
     ScmCharPortMethod_encoding    encoding;
+    ScmCharPortMethod_inspect     inspect;
     ScmCharPortMethod_get_char    get_char;
     ScmCharPortMethod_peek_char   peek_char;
     ScmCharPortMethod_char_readyp char_readyp;
@@ -162,6 +167,8 @@
  */
 typedef ScmBytePort *(*ScmBytePortMethod_dyn_cast)(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr);
 typedef int (*ScmBytePortMethod_close)(ScmBytePort *bport);
+/* returns brief information */
+typedef char *(*ScmBytePortMethod_inspect)(ScmBytePort *bport);
 
 /* input */
 typedef int (*ScmBytePortMethod_get_byte)(ScmBytePort *bport);
@@ -179,6 +186,7 @@
 struct ScmBytePortVTbl_ {
     ScmBytePortMethod_dyn_cast    dyn_cast;
     ScmBytePortMethod_close       close;
+    ScmBytePortMethod_inspect     inspect;
     ScmBytePortMethod_get_byte    get_byte;
     ScmBytePortMethod_peek_byte   peek_byte;
     ScmBytePortMethod_byte_readyp byte_readyp;

Modified: branches/r5rs/sigscheme/debug.c
===================================================================
--- branches/r5rs/sigscheme/debug.c	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/debug.c	2005-11-01 08:00:47 UTC (rev 1920)
@@ -469,6 +469,10 @@
 
 static void print_port(ScmObj port, ScmObj obj, enum OutputType otype)
 {
+#if SCM_USE_NEWPORT
+    char *info;
+#endif
+
     SCM_PORT_PRINT(port, "#<");
 
     /* input or output */
@@ -489,7 +493,14 @@
 
     /* file or string */
 
-#if !SCM_USE_NEWPORT
+#if SCM_USE_NEWPORT
+    info = SCM_PORT_INSPECT(obj);
+    if (*info) {
+        SCM_PORT_PRINT(port, " ");
+        SCM_PORT_PRINT(port, info);
+    }
+    free(info);
+#else /* SCM_USE_NEWPORT */
     if (SCM_PORT_PORTTYPE(obj) == PORT_FILE) {
         snprintf(scm_portbuffer, PORTBUFFER_SIZE, " file %s", SCM_PORT_FILENAME(obj));
         SCM_PORT_PRINT(port, scm_portbuffer);
@@ -497,7 +508,7 @@
         snprintf(scm_portbuffer, PORTBUFFER_SIZE, " string %s", SCM_PORT_STR(obj));
         SCM_PORT_PRINT(port, scm_portbuffer);
     }
-#endif /* !SCM_USE_NEWPORT */
+#endif /* SCM_USE_NEWPORT */
 
     SCM_PORT_PRINT(port, ">");
 }

Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/fileport.c	2005-11-01 08:00:47 UTC (rev 1920)
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <string.h>
 
 /*=======================================
   Local Include
@@ -74,6 +75,7 @@
 static ScmBytePort *fileport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
 static int fileport_close(ScmFilePort *bport);
+static char *fileport_inspect(ScmFilePort *port);
 static int fileport_get_byte(ScmFilePort *bport);
 static int fileport_peek_byte(ScmFilePort *bport);
 static int fileport_byte_readyp(ScmFilePort *bport);
@@ -89,6 +91,7 @@
 static const ScmBytePortVTbl ScmFilePort_vtbl = {
     (ScmBytePortMethod_dyn_cast)   &fileport_dyn_cast,
     (ScmBytePortMethod_close)      &fileport_close,
+    (ScmBytePortMethod_inspect)    &fileport_inspect,
     (ScmBytePortMethod_get_byte)   &fileport_get_byte,
     (ScmBytePortMethod_peek_byte)  &fileport_peek_byte,
     (ScmBytePortMethod_byte_readyp)&fileport_byte_readyp,
@@ -145,6 +148,12 @@
     return err;
 }
 
+static char *
+fileport_inspect(ScmFilePort *port)
+{
+    return strdup("file");
+}
+
 static int
 fileport_get_byte(ScmFilePort *port)
 {

Modified: branches/r5rs/sigscheme/mbcport.c
===================================================================
--- branches/r5rs/sigscheme/mbcport.c	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/mbcport.c	2005-11-01 08:00:47 UTC (rev 1920)
@@ -84,6 +84,7 @@
 static ScmCharPort *mbcport_dyn_cast(ScmCharPort *cport,
                                      const ScmCharPortVTbl *dst_vptr);
 static const char *mbcport_encoding(ScmMultiByteCharPort *port);
+static char *mbcport_inspect(ScmMultiByteCharPort *port);
 static int mbcport_get_char(ScmMultiByteCharPort *port);
 static int mbcport_peek_char(ScmMultiByteCharPort *port);
 static int mbcport_char_readyp(ScmMultiByteCharPort *port);
@@ -113,6 +114,7 @@
     vptr = &ScmMultiByteCharPort_vtbl;
     vptr->dyn_cast    = (ScmCharPortMethod_dyn_cast)&mbcport_dyn_cast;
     vptr->encoding    = (ScmCharPortMethod_encoding)&mbcport_encoding;
+    vptr->inspect     = (ScmCharPortMethod_inspect)&mbcport_inspect;
     vptr->get_char    = (ScmCharPortMethod_get_char)&mbcport_get_char;
     vptr->peek_char   = (ScmCharPortMethod_peek_char)&mbcport_peek_char;
     vptr->char_readyp = (ScmCharPortMethod_char_readyp)&mbcport_char_readyp;
@@ -159,6 +161,12 @@
     return SCM_CHARCODEC_ENCODING(port->codec);
 }
 
+static char *
+mbcport_inspect(ScmMultiByteCharPort *port)
+{
+    return ScmBaseCharPort_inspect(port, "mb");
+}
+
 static int
 mbcport_get_char(ScmMultiByteCharPort *port)
 {

Modified: branches/r5rs/sigscheme/sbcport.c
===================================================================
--- branches/r5rs/sigscheme/sbcport.c	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/sbcport.c	2005-11-01 08:00:47 UTC (rev 1920)
@@ -70,6 +70,7 @@
                                        const ScmCharPortVTbl *dst_vptr);
 static int basecport_close(ScmBaseCharPort *port);
 static const char *basecport_encoding(ScmBaseCharPort *port);
+static char *basecport_inspect(ScmBaseCharPort *port);
 static int basecport_get_char(ScmBaseCharPort *port);
 static int basecport_peek_char(ScmBaseCharPort *port);
 static int basecport_char_readyp(ScmBaseCharPort *port);
@@ -82,6 +83,7 @@
 static ScmCharPort *sbcport_dyn_cast(ScmCharPort *cport,
                                      const ScmCharPortVTbl *dst_vptr);
 static const char *sbcport_encoding(ScmSingleByteCharPort *port);
+static char *sbcport_inspect(ScmSingleByteCharPort *port);
 static int sbcport_put_char(ScmSingleByteCharPort *port, int ch);
 
 /*=======================================
@@ -91,6 +93,7 @@
     (ScmCharPortMethod_dyn_cast)   &basecport_dyn_cast,
     (ScmCharPortMethod_close)      &basecport_close,
     (ScmCharPortMethod_encoding)   &basecport_encoding,
+    (ScmCharPortMethod_inspect)    &basecport_inspect,
     (ScmCharPortMethod_get_char)   &basecport_get_char,
     (ScmCharPortMethod_peek_char)  &basecport_peek_char,
     (ScmCharPortMethod_char_readyp)&basecport_char_readyp,
@@ -120,6 +123,24 @@
 #endif
 }
 
+char *
+ScmBaseCharPort_inspect(ScmBaseCharPort *port, const char *header)
+{
+    const char *encoding;
+    char *bport_part, *combined;
+    size_t size;
+
+    encoding = SCM_CHARPORT_ENCODING(port);
+    bport_part = SCM_BYTEPORT_INSPECT(port->bport);
+    size = strlen(header) + strlen(encoding) + strlen(bport_part)
+        + sizeof("  ");
+    combined = malloc(size);
+    snprintf(combined, size, "%s %s %s", header, encoding, bport_part);
+    free(bport_part);
+
+    return combined;
+}
+
 int
 ScmBaseCharPort_line_number(ScmBaseCharPort *port)
 {
@@ -148,6 +169,12 @@
     /* NOTREACHED */
 }
 
+static char *
+basecport_inspect(ScmBaseCharPort *port)
+{
+    return ScmBaseCharPort_inspect(port, "unknown");
+}
+
 static int
 basecport_get_char(ScmBaseCharPort *port)
 {
@@ -206,6 +233,7 @@
     ScmSingleByteCharPort_vtbl = *ScmBaseCharPort_vptr;
     ScmSingleByteCharPort_vtbl.dyn_cast = (ScmCharPortMethod_dyn_cast)&sbcport_dyn_cast;
     ScmSingleByteCharPort_vtbl.encoding = (ScmCharPortMethod_encoding)&sbcport_encoding;
+    ScmSingleByteCharPort_vtbl.inspect  = (ScmCharPortMethod_inspect)&sbcport_inspect;
     ScmSingleByteCharPort_vtbl.put_char = (ScmCharPortMethod_put_char)&sbcport_put_char;
 }
 
@@ -244,6 +272,12 @@
     return "US-ASCII";
 }
 
+static char *
+sbcport_inspect(ScmSingleByteCharPort *port)
+{
+    return ScmBaseCharPort_inspect(port, "sb");
+}
+
 static int
 sbcport_put_char(ScmSingleByteCharPort *port, int ch)
 {

Modified: branches/r5rs/sigscheme/sbcport.h
===================================================================
--- branches/r5rs/sigscheme/sbcport.h	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/sbcport.h	2005-11-01 08:00:47 UTC (rev 1920)
@@ -80,6 +80,7 @@
 void ScmBaseCharPort_construct(ScmBaseCharPort *port,
                                const ScmCharPortVTbl *vptr,
                                ScmBytePort *bport);
+char *ScmBaseCharPort_inspect(ScmBaseCharPort *port, const char *header);
 int ScmBaseCharPort_line_number(ScmBaseCharPort *port);
 
 void ScmSingleByteCharPort_construct(ScmSingleByteCharPort *port,

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/sigscheme.h	2005-11-01 08:00:47 UTC (rev 1920)
@@ -139,6 +139,8 @@
     (SCM_CHARPORT_CLOSE(SCM_PORT_IMPL(port)), SCM_PORT_SET_IMPL(port, NULL))
 #define SCM_PORT_ENCODING(port)                                              \
     (SCM_ASSERT_LIVE_PORT(port), SCM_CHARPORT_ENCODING(SCM_PORT_IMPL(port)))
+#define SCM_PORT_INSPECT(port)                                              \
+    (SCM_ASSERT_LIVE_PORT(port), SCM_CHARPORT_INSPECT(SCM_PORT_IMPL(port)))
 #define SCM_PORT_GET_CHAR(port)                                              \
     (SCM_ASSERT_LIVE_PORT(port), SCM_CHARPORT_GET_CHAR(SCM_PORT_IMPL(port)))
 #define SCM_PORT_PEEK_CHAR(port)                                             \

Modified: branches/r5rs/sigscheme/strport.c
===================================================================
--- branches/r5rs/sigscheme/strport.c	2005-11-01 06:50:56 UTC (rev 1919)
+++ branches/r5rs/sigscheme/strport.c	2005-11-01 08:00:47 UTC (rev 1920)
@@ -94,6 +94,7 @@
 static ScmBytePort *istrport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
 static int istrport_close(ScmInputStrPort *port);
+static char *istrport_inspect(ScmInputStrPort *port);
 static int istrport_get_byte(ScmInputStrPort *port);
 static int istrport_peek_byte(ScmInputStrPort *port);
 static int istrport_byte_readyp(ScmInputStrPort *port);
@@ -107,6 +108,7 @@
 static ScmBytePort *ostrport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
 static int ostrport_close(ScmOutputStrPort *port);
+static char *ostrport_inspect(ScmOutputStrPort *port);
 static int ostrport_get_byte(ScmOutputStrPort *port);
 static int ostrport_peek_byte(ScmOutputStrPort *port);
 static int ostrport_byte_readyp(ScmOutputStrPort *port);
@@ -126,6 +128,7 @@
 static const ScmBytePortVTbl ScmInputStrPort_vtbl = {
     (ScmBytePortMethod_dyn_cast)   &istrport_dyn_cast,
     (ScmBytePortMethod_close)      &istrport_close,
+    (ScmBytePortMethod_inspect)    &istrport_inspect,
     (ScmBytePortMethod_get_byte)   &istrport_get_byte,
     (ScmBytePortMethod_peek_byte)  &istrport_peek_byte,
     (ScmBytePortMethod_byte_readyp)&istrport_byte_readyp,
@@ -139,6 +142,7 @@
 static const ScmBytePortVTbl ScmOutputStrPort_vtbl = {
     (ScmBytePortMethod_dyn_cast)   &ostrport_dyn_cast,
     (ScmBytePortMethod_close)      &ostrport_close,
+    (ScmBytePortMethod_inspect)    &ostrport_inspect,
     (ScmBytePortMethod_get_byte)   &ostrport_get_byte,
     (ScmBytePortMethod_peek_byte)  &ostrport_peek_byte,
     (ScmBytePortMethod_byte_readyp)&ostrport_byte_readyp,
@@ -231,6 +235,12 @@
     return OK;
 }
 
+static char *
+istrport_inspect(ScmInputStrPort *port)
+{
+    return strdup("string");
+}
+
 static int
 istrport_get_byte(ScmInputStrPort *port)
 {
@@ -340,6 +350,12 @@
     return OK;
 }
 
+static char *
+ostrport_inspect(ScmOutputStrPort *port)
+{
+    return strdup("string");
+}
+
 static int
 ostrport_get_byte(ScmOutputStrPort *port)
 {



More information about the uim-commit mailing list