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

yamaken at freedesktop.org yamaken at freedesktop.org
Sat Oct 29 23:03:14 PDT 2005


Author: yamaken
Date: 2005-10-29 23:03:01 -0700 (Sat, 29 Oct 2005)
New Revision: 1890

Modified:
   branches/r5rs/sigscheme/baseport.h
   branches/r5rs/sigscheme/fileport.c
Log:
* sigscheme/baseport.h
  - (ScmCharPortMethod_dyn_cast, ScmCharPortMethod_close,
    ScmCharPortMethod_encoding, ScmCharPortMethod_get_char,
    ScmCharPortMethod_peek_char, ScmCharPortMethod_char_readyp,
    ScmCharPortMethod_vprintf, ScmCharPortMethod_put_char,
    ScmCharPortMethod_flush, ScmBytePortMethod_dyn_cast,
    ScmBytePortMethod_close, ScmBytePortMethod_get_byte,
    ScmBytePortMethod_peek_byte, ScmBytePortMethod_byte_readyp,
    ScmBytePortMethod_vprintf, ScmBytePortMethod_puts,
    ScmBytePortMethod_write, ScmBytePortMethod_flush): New type
  - (struct ScmCharPortVTbl_, struct ScmBytePortVTbl_): Simplify with
    above types
* sigscheme/fileport.c
  - (fileport_dyn_cast): Simplify
  - (fileport_close, fileport_get_byte, fileport_peek_byte,
    fileport_byte_readyp, fileport_vprintf, fileport_puts,
    fileport_write, fileport_flush): Simplify by replacing first arg
    with ScmFilePort
  - (ScmFilePort_vtbl): Follow the function type change


Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h	2005-10-30 05:42:54 UTC (rev 1889)
+++ branches/r5rs/sigscheme/baseport.h	2005-10-30 06:03:01 UTC (rev 1890)
@@ -97,42 +97,70 @@
 typedef struct ScmBytePortVTbl_ ScmBytePortVTbl;
 typedef struct ScmBytePort_     ScmBytePort;
 
+/*
+ * char port
+ */
+typedef ScmCharPort *(*ScmCharPortMethod_dyn_cast)(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr);
+typedef int (*ScmCharPortMethod_close)(ScmCharPort *cport);
+/* returns "UTF-8", "eucJP" and so on */
+typedef const char *(*ScmCharPortMethod_encoding)(ScmCharPort *cport);
 
-struct ScmCharPortVTbl_ {
-    ScmCharPort *(*dyn_cast)(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr);
-    int (*close)(ScmCharPort *cport);
-    /* returns "UTF-8", "eucJP" and so on */
-    const char *(*encoding)(ScmCharPort *cport);
+/* input */
+typedef int (*ScmCharPortMethod_get_char)(ScmCharPort *cport);
+typedef int (*ScmCharPortMethod_peek_char)(ScmCharPort *cport);
+typedef int (*ScmCharPortMethod_char_readyp)(ScmCharPort *cport);
 
-    /* input */
-    int (*get_char)(ScmCharPort *cport);
-    int (*peek_char)(ScmCharPort *cport);
-    int (*char_readyp)(ScmCharPort *cport);
+/* output */
+typedef int (*ScmCharPortMethod_vprintf)(ScmCharPort *cport,
+                                         const char *str, va_list args);
+typedef int (*ScmCharPortMethod_put_char)(ScmCharPort *cport, int ch);
+typedef int (*ScmCharPortMethod_flush)(ScmCharPort *cport);
 
-    /* output */
-    int (*vprintf)(ScmCharPort *cport, const char *str, va_list args); /* tmp */
-    int (*put_char)(ScmCharPort *cport, int ch);
-    int (*flush)(ScmCharPort *cport);
+struct ScmCharPortVTbl_ {
+    ScmCharPortMethod_dyn_cast    dyn_cast;
+    ScmCharPortMethod_close       close;
+    ScmCharPortMethod_encoding    encoding;
+    ScmCharPortMethod_get_char    get_char;
+    ScmCharPortMethod_peek_char   peek_char;
+    ScmCharPortMethod_char_readyp char_readyp;
+    ScmCharPortMethod_vprintf     vprintf;  /* tmp */
+    ScmCharPortMethod_put_char    put_char;
+    ScmCharPortMethod_flush       flush;
 };
 
 struct ScmCharPort_ {
     const ScmCharPortVTbl *vptr;
 };
 
-struct ScmBytePortVTbl_ {
-    ScmBytePort *(*dyn_cast)(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr);
-    int (*close)(ScmBytePort *bport);
+/*
+ * byte port
+ */
+typedef ScmBytePort *(*ScmBytePortMethod_dyn_cast)(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr);
+typedef int (*ScmBytePortMethod_close)(ScmBytePort *bport);
 
-    /* input */
-    int (*get_byte)(ScmBytePort *bport);
-    int (*peek_byte)(ScmBytePort *bport);
-    int (*byte_readyp)(ScmBytePort *bport);
+/* input */
+typedef int (*ScmBytePortMethod_get_byte)(ScmBytePort *bport);
+typedef int (*ScmBytePortMethod_peek_byte)(ScmBytePort *bport);
+typedef int (*ScmBytePortMethod_byte_readyp)(ScmBytePort *bport);
 
-    /* output */
-    int (*vprintf)(ScmBytePort *bport, const char *str, va_list args); /* tmp */
-    int (*puts)(ScmBytePort *bport, const char *str);
-    size_t (*write)(ScmBytePort *bport, size_t nbytes, const char *buf);
-    int (*flush)(ScmBytePort *bport);
+/* output */
+typedef int (*ScmBytePortMethod_vprintf)(ScmBytePort *bport,
+                                         const char *str, va_list args);
+typedef int (*ScmBytePortMethod_puts)(ScmBytePort *bport, const char *str);
+typedef size_t (*ScmBytePortMethod_write)(ScmBytePort *bport,
+                                          size_t nbytes, const char *buf);
+typedef int (*ScmBytePortMethod_flush)(ScmBytePort *bport);
+
+struct ScmBytePortVTbl_ {
+    ScmBytePortMethod_dyn_cast    dyn_cast;
+    ScmBytePortMethod_close       close;
+    ScmBytePortMethod_get_byte    get_byte;
+    ScmBytePortMethod_peek_byte   peek_byte;
+    ScmBytePortMethod_byte_readyp byte_readyp;
+    ScmBytePortMethod_vprintf     vprintf;  /* tmp */
+    ScmBytePortMethod_puts        puts;
+    ScmBytePortMethod_write       write;
+    ScmBytePortMethod_flush       flush;
 };
 
 struct ScmBytePort_ {

Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c	2005-10-30 05:42:54 UTC (rev 1889)
+++ branches/r5rs/sigscheme/fileport.c	2005-10-30 06:03:01 UTC (rev 1890)
@@ -73,28 +73,29 @@
 =======================================*/
 static ScmBytePort *fileport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
-static int fileport_close(ScmBytePort *bport);
-static int fileport_get_byte(ScmBytePort *bport);
-static int fileport_peek_byte(ScmBytePort *bport);
-static int fileport_byte_readyp(ScmBytePort *bport);
-static int fileport_vprintf(ScmBytePort *bport, const char *str, va_list args);
-static int fileport_puts(ScmBytePort *bport, const char *str);
-static size_t fileport_write(ScmBytePort *bport, size_t nbytes, const char *buf);
-static int fileport_flush(ScmBytePort *bport);
+static int fileport_close(ScmFilePort *bport);
+static int fileport_get_byte(ScmFilePort *bport);
+static int fileport_peek_byte(ScmFilePort *bport);
+static int fileport_byte_readyp(ScmFilePort *bport);
+static int fileport_vprintf(ScmFilePort *bport, const char *str, va_list args);
+static int fileport_puts(ScmFilePort *bport, const char *str);
+static size_t fileport_write(ScmFilePort *bport,
+                             size_t nbytes, const char *buf);
+static int fileport_flush(ScmFilePort *bport);
 
 /*=======================================
   Variable Declarations
 =======================================*/
 static const ScmBytePortVTbl ScmFilePort_vtbl = {
-    &fileport_dyn_cast,
-    &fileport_close,
-    &fileport_get_byte,
-    &fileport_peek_byte,
-    &fileport_byte_readyp,
-    &fileport_vprintf,
-    &fileport_puts,
-    &fileport_write,
-    &fileport_flush
+    (ScmBytePortMethod_dyn_cast)   &fileport_dyn_cast,
+    (ScmBytePortMethod_close)      &fileport_close,
+    (ScmBytePortMethod_get_byte)   &fileport_get_byte,
+    (ScmBytePortMethod_peek_byte)  &fileport_peek_byte,
+    (ScmBytePortMethod_byte_readyp)&fileport_byte_readyp,
+    (ScmBytePortMethod_vprintf)    &fileport_vprintf,
+    (ScmBytePortMethod_puts)       &fileport_puts,
+    (ScmBytePortMethod_write)      &fileport_write,
+    (ScmBytePortMethod_flush)      &fileport_flush
 };
 const ScmBytePortVTbl *ScmFilePort_vptr = &ScmFilePort_vtbl;
 
@@ -119,50 +120,40 @@
 static ScmBytePort *
 fileport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
 {
-    ScmBytePort *cast;
-
-    cast = (dst_vptr == ScmFilePort_vptr) ? bport : NULL;
-    if (!cast)
+    if (dst_vptr != ScmFilePort_vptr)
         SCM_BYTEPORT_ERROR(bport, "invalid object is passed to a ScmFilePort method");
 
-    return cast;
+    return bport;
 }
 
 static int
-fileport_close(ScmBytePort *bport)
+fileport_close(ScmFilePort *port)
 {
-    ScmFilePort *fport;
     int err;
 
-    fport = (ScmFilePort *)bport;
-    err = fclose(fport->file);
-    free(fport);
+    err = fclose(port->file);
+    free(port);
 
     return err;
 }
 
 static int
-fileport_get_byte(ScmBytePort *bport)
+fileport_get_byte(ScmFilePort *port)
 {
-    ScmFilePort *fport;
-
-    fport = (ScmFilePort *)bport;
-    return getc(fport->file);
+    return getc(port->file);
 }
 
 static int
-fileport_peek_byte(ScmBytePort *bport)
+fileport_peek_byte(ScmFilePort *port)
 {
-    ScmFilePort *fport;
     int ch;
 
-    fport = (ScmFilePort *)bport;
-    ch = getc(fport->file);
-    return ungetc(ch, fport->file);
+    ch = getc(port->file);
+    return ungetc(ch, port->file);
 }
 
 static int
-fileport_byte_readyp(ScmBytePort *bport)
+fileport_byte_readyp(ScmFilePort *port)
 {
     /* does not support a FILE based on a pipe, or opened by fdopen(3) */
     /* FIXME: support stdin properly */
@@ -170,37 +161,25 @@
 }
 
 static int
-fileport_vprintf(ScmBytePort *bport, const char *str, va_list args)
+fileport_vprintf(ScmFilePort *port, const char *str, va_list args)
 {
-    ScmFilePort *fport;
-
-    fport = (ScmFilePort *)bport;
-    return vfprintf(fport->file, str, args);
+    return vfprintf(port->file, str, args);
 }
 
 static int
-fileport_puts(ScmBytePort *bport, const char *str)
+fileport_puts(ScmFilePort *port, const char *str)
 {
-    ScmFilePort *fport;
-
-    fport = (ScmFilePort *)bport;
-    return fputs(str, fport->file);
+    return fputs(str, port->file);
 }
 
 static size_t
-fileport_write(ScmBytePort *bport, size_t nbytes, const char *buf)
+fileport_write(ScmFilePort *port, size_t nbytes, const char *buf)
 {
-    ScmFilePort *fport;
-
-    fport = (ScmFilePort *)bport;
-    return fwrite(buf, 1, nbytes, fport->file);
+    return fwrite(buf, 1, nbytes, port->file);
 }
 
 static int
-fileport_flush(ScmBytePort *bport)
+fileport_flush(ScmFilePort *port)
 {
-    ScmFilePort *fport;
-
-    fport = (ScmFilePort *)bport;
-    return fflush(fport->file);
+    return fflush(port->file);
 }



More information about the uim-commit mailing list