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

yamaken at freedesktop.org yamaken at freedesktop.org
Sun Oct 23 23:58:30 PDT 2005


Author: yamaken
Date: 2005-10-23 23:58:16 -0700 (Sun, 23 Oct 2005)
New Revision: 1878

Added:
   branches/r5rs/sigscheme/sbcport.c
   branches/r5rs/sigscheme/sbcport.h
Modified:
   branches/r5rs/sigscheme/baseport.h
Log:
* This commit adds singlebyte character port implementation

* sigscheme/baseport.h
  - (struct ScmBaseCharPort_, ScmBaseCharPort): Move to sbcport.h
* sigscheme/sbcport.h
  - New file
  - (struct ScmBaseCharPort_, ScmBaseCharPort): Moved from baseport.h
  - (ScmBaseCharPort_vptr, ScmSingleByteCharPort_vptr): New variable
    decl
  - (Scm_sbcport_init, ScmSingleByteCharPort_new): New function decl
* sigscheme/sbcport.c
  - New file
  - (struct ScmSingleByteCharPort_, ScmSingleByteCharPort): New type
  - (basecport_dyn_cast, basecport_close, basecport_get_char,
    basecport_peek_char, basecport_char_readyp, basecport_vprintf,
    basecport_flush, sbcport_dyn_cast, sbcport_encoding,
    sbcport_put_char): New static function
  - (ScmBaseCharPort_vtbl, ScmSingleByteCharPort_vtbl): New static
    variable
  - (ScmBaseCharPort_vptr, ScmSingleByteCharPort_vptr): New variable


Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h	2005-10-24 06:43:44 UTC (rev 1877)
+++ branches/r5rs/sigscheme/baseport.h	2005-10-24 06:58:16 UTC (rev 1878)
@@ -90,7 +90,6 @@
 =======================================*/
 typedef struct ScmCharPortVTbl_ ScmCharPortVTbl;
 typedef struct ScmCharPort_     ScmCharPort;
-typedef struct ScmBaseCharPort_ ScmBaseCharPort;
 typedef struct ScmBytePortVTbl_ ScmBytePortVTbl;
 typedef struct ScmBytePort_     ScmBytePort;
 
@@ -116,12 +115,6 @@
     const ScmCharPortVTbl *vptr;
 };
 
-struct ScmBaseCharPort_ {
-    const ScmCharPortVTbl *vptr;
-
-    ScmBytePort *bport;
-};
-
 struct ScmBytePortVTbl_ {
     ScmBytePort *(*dyn_cast)(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr);
     int (*close)(ScmBytePort *bport);

Added: branches/r5rs/sigscheme/sbcport.c
===================================================================
--- branches/r5rs/sigscheme/sbcport.c	2005-10-24 06:43:44 UTC (rev 1877)
+++ branches/r5rs/sigscheme/sbcport.c	2005-10-24 06:58:16 UTC (rev 1878)
@@ -0,0 +1,229 @@
+/*===========================================================================
+ *  FileName : sbcport.c
+ *  About    : A ScmCharPort implementation for singlebyte character stream
+ *
+ *  Copyright (C) 2005      by YamaKen (yamaken AT bp.iij4u.or.jp)
+ *
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of authors nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ *  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===========================================================================*/
+
+/*
+ * - This file is intended to be portable. Don't depend on SigScheme.
+ * - To isolate and hide implementation-dependent things, don't merge this file
+ *   into another
+ */
+
+/*=======================================
+  System Include
+=======================================*/
+#include <stdlib.h>
+#include <stdarg.h>
+
+/*=======================================
+  Local Include
+=======================================*/
+#include "baseport.h"
+#include "sbcport.h"
+
+/*=======================================
+  File Local Macro Definitions
+=======================================*/
+
+/*=======================================
+  File Local Type Definitions
+=======================================*/
+typedef struct ScmSingleByteCharPort_ ScmSingleByteCharPort;
+
+struct ScmSingleByteCharPort_ {  /* inherits ScmBaseCharPort */
+    const ScmCharPortVTbl *vptr;
+
+    ScmBytePort *bport;  /* protected */
+};
+
+/*=======================================
+  File Local Function Declarations
+=======================================*/
+static ScmCharPort *basecport_dyn_cast(ScmCharPort *cport,
+                                       const ScmCharPortVTbl *dst_vptr);
+static int basecport_close(ScmCharPort *cport);
+static int basecport_get_char(ScmCharPort *cport);
+static int basecport_peek_char(ScmCharPort *cport);
+static int basecport_char_readyp(ScmCharPort *cport);
+static int basecport_vprintf(ScmCharPort *cport, const char *str,
+                             va_list args);
+static int basecport_flush(ScmCharPort *cport);
+
+static ScmCharPort *sbcport_dyn_cast(ScmCharPort *cport,
+                                     const ScmCharPortVTbl *dst_vptr);
+static const char *sbcport_encoding(ScmCharPort *cport);
+static int sbcport_put_char(ScmCharPort *cport, int ch);
+
+/*=======================================
+  Variable Declarations
+=======================================*/
+static const ScmCharPortVTbl ScmBaseCharPort_vtbl = {
+    &basecport_dyn_cast,
+    &basecport_close,
+    NULL,
+    &basecport_get_char,
+    &basecport_peek_char,
+    &basecport_char_readyp,
+    &basecport_vprintf,
+    NULL,
+    &basecport_flush
+};
+const ScmCharPortVTbl *ScmBaseCharPort_vptr = &ScmBaseCharPort_vtbl;
+
+static ScmCharPortVTbl ScmSingleByteCharPort_vtbl;
+const ScmCharPortVTbl *ScmSingleByteCharPort_vptr = &ScmSingleByteCharPort_vtbl;
+
+/*=======================================
+  Function Implementations
+=======================================*/
+static ScmCharPort *
+basecport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
+{
+    ScmCharPort *cast;
+
+    cast = (dst_vptr == ScmBaseCharPort_vptr) ? cport : NULL;
+    if (!cast)
+        SCM_CHARPORT_ERROR(cport, "invalid object is passed to a ScmBaseCharPort method");
+
+    return cast;
+}
+
+static int
+basecport_close(ScmCharPort *cport)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_CLOSE(basecport->bport);
+}
+
+static int
+basecport_get_char(ScmCharPort *cport)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_GET_BYTE(basecport->bport);
+}
+
+static int
+basecport_peek_char(ScmCharPort *cport)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_PEEK_BYTE(basecport->bport);
+}
+
+static int
+basecport_char_readyp(ScmCharPort *cport)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_BYTE_READYP(basecport->bport);
+}
+
+static int
+basecport_vprintf(ScmCharPort *cport, const char *str, va_list args)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_VPRINTF(basecport->bport, str, args);
+}
+
+static int
+basecport_flush(ScmCharPort *cport)
+{
+    ScmBaseCharPort *basecport;
+
+    basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, cport);
+    return SCM_BYTEPORT_FLUSH(basecport->bport);
+}
+
+
+void
+Scm_sbcport_init(void)
+{
+    ScmSingleByteCharPort_vtbl = *ScmBaseCharPort_vptr;
+    ScmSingleByteCharPort_vtbl.dyn_cast = &sbcport_dyn_cast;
+    ScmSingleByteCharPort_vtbl.encoding = &sbcport_encoding;
+    ScmSingleByteCharPort_vtbl.put_char = &sbcport_put_char;
+}
+
+ScmCharPort *
+ScmSingleByteCharPort_new(ScmBytePort *bport)
+{
+    ScmSingleByteCharPort *cport;
+
+    cport = malloc(sizeof(ScmSingleByteCharPort));
+    if (cport) {
+        cport->vptr = ScmSingleByteCharPort_vptr;
+        cport->bport = bport;
+    }
+
+    return (ScmCharPort *)cport;
+}
+
+static ScmCharPort *
+sbcport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
+{
+    ScmCharPort *cast;
+
+    cast = (dst_vptr == ScmBaseCharPort_vptr
+            || dst_vptr == ScmSingleByteCharPort_vptr) ? cport : NULL;
+    if (!cast)
+        SCM_CHARPORT_ERROR(cport, "invalid object is passed to a ScmSingleByteCharPort method");
+
+    return cast;
+}
+
+static const char *
+sbcport_encoding(ScmCharPort *cport)
+{
+    ScmSingleByteCharPort *sbcport;
+
+    sbcport = SCM_PORT_DYNAMIC_CAST(ScmSingleByteCharPort, cport);
+    return "US-ASCII";
+}
+
+static int
+sbcport_put_char(ScmCharPort *cport, int ch)
+{
+    ScmSingleByteCharPort *sbcport;
+    char buf[1];
+
+    buf[0] = ch;
+    sbcport = SCM_PORT_DYNAMIC_CAST(ScmSingleByteCharPort, cport);
+    return SCM_BYTEPORT_WRITE(sbcport->bport, 1, buf);
+}

Added: branches/r5rs/sigscheme/sbcport.h
===================================================================
--- branches/r5rs/sigscheme/sbcport.h	2005-10-24 06:43:44 UTC (rev 1877)
+++ branches/r5rs/sigscheme/sbcport.h	2005-10-24 06:58:16 UTC (rev 1878)
@@ -0,0 +1,80 @@
+/*===========================================================================
+ *  FileName : sbcport.h
+ *  About    : A ScmCharPort implementation for singlebyte character stream
+ *
+ *  Copyright (C) 2005      by YamaKen (yamaken AT bp.iij4u.or.jp)
+ *
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of authors nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ *  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===========================================================================*/
+
+/*
+ * This file is intended to be portable. Don't depend on SigScheme and don't
+ * merge into another file.
+ */
+
+#ifndef __SCM_SBCPORT_H
+#define __SCM_SBCPORT_H
+
+/*=======================================
+  System Include
+=======================================*/
+
+/*=======================================
+  Local Include
+=======================================*/
+#include "baseport.h"
+
+/*=======================================
+  Macro Definitions
+=======================================*/
+
+/*=======================================
+  Type Definitions
+=======================================*/
+typedef struct ScmBaseCharPort_ ScmBaseCharPort;
+
+struct ScmBaseCharPort_ {  /* inherits ScmCharPort */
+    const ScmCharPortVTbl *vptr;
+
+    ScmBytePort *bport;  /* protected */
+};
+
+/*=======================================
+   Variable Declarations
+=======================================*/
+extern const ScmCharPortVTbl *ScmBaseCharPort_vptr;
+extern const ScmCharPortVTbl *ScmSingleByteCharPort_vptr;
+
+/*=======================================
+   Function Declarations
+=======================================*/
+void Scm_sbcport_init(void);
+ScmCharPort *ScmSingleByteCharPort_new(ScmBytePort *bport);
+
+
+#endif /* __SCM_SBCPORT_H */



More information about the uim-commit mailing list