[uim-commit] r2251 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Thu Nov 24 21:54:30 PST 2005
Author: yamaken
Date: 2005-11-24 21:54:26 -0800 (Thu, 24 Nov 2005)
New Revision: 2251
Added:
branches/r5rs/sigscheme/basecport.c
Modified:
branches/r5rs/sigscheme/Makefile.am
branches/r5rs/sigscheme/baseport.h
branches/r5rs/sigscheme/fileport.c
branches/r5rs/sigscheme/io.c
branches/r5rs/sigscheme/mbcport.c
branches/r5rs/sigscheme/operations-srfi6.c
branches/r5rs/sigscheme/read.c
branches/r5rs/sigscheme/sbcport.c
branches/r5rs/sigscheme/sbcport.h
Log:
* sigscheme/sbcport.h
- (ScmBaseCharPort, struct ScmBaseCharPort_, ScmBaseCharPort_vptr,
ScmBaseCharPort_construct, ScmBaseCharPort_inspect,
ScmBaseCharPort_line_number): Move to basecport.h
* sigscheme/baseport.h
- (ScmBaseCharPort, struct ScmBaseCharPort_, ScmBaseCharPort_vptr,
ScmBaseCharPort_construct, ScmBaseCharPort_inspect,
ScmBaseCharPort_line_number): Moved from sbcport.h
* sigscheme/sbcport.c
- (ScmBaseCharPort, struct ScmBaseCharPort_, ScmBaseCharPort_vptr,
ScmBaseCharPort_construct, ScmBaseCharPort_inspect,
ScmBaseCharPort_line_number): Move to basecport.h
- (ScmBaseCharPort_vtbl, basecport_dyn_cast, basecport_close,
basecport_encoding, basecport_inspect, basecport_get_char,
basecport_peek_char, basecport_char_readyp, basecport_vprintf,
basecport_puts, basecport_put_char, basecport_flush): Move to
basecport.h
* sigscheme/basecport.c
- New file
- (ScmBaseCharPort, struct ScmBaseCharPort_, ScmBaseCharPort_vptr,
ScmBaseCharPort_construct, ScmBaseCharPort_inspect,
ScmBaseCharPort_line_number): Moved from sbcport.c
- (ScmBaseCharPort_vtbl, basecport_dyn_cast, basecport_close,
basecport_encoding, basecport_inspect, basecport_get_char,
basecport_peek_char, basecport_char_readyp, basecport_vprintf,
basecport_puts, basecport_put_char, basecport_flush): Moved from
sbcport.c
* sigscheme/io.c
- Include sbcport.c only when !SCM_USE_MULTIBYTE_CHAR
- Remove #include "fileport.c"
* sigscheme/Makefile.am
- (libsscm_la_SOURCES): Add basecport.c fileport.c
* sigscheme/read.c
- Remove #include "sbcport.h"
* sigscheme/operations-srfi6.c
- Ditto
* sigscheme/mbcport.c
- Ditto
- (Scm_mbcport_init): Remove sbcport dependency
* sigscheme/fileport.c
- (FALSE, TRUE): New macro
Modified: branches/r5rs/sigscheme/Makefile.am
===================================================================
--- branches/r5rs/sigscheme/Makefile.am 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/Makefile.am 2005-11-25 05:54:26 UTC (rev 2251)
@@ -58,6 +58,7 @@
storage-continuation.c \
encoding.c error.c \
eval.c io.c \
+ basecport.c fileport.c \
operations.c \
read.c sigscheme.c sigschemefunctable.c \
sigscheme.h sigschemetype.h sigschemefunctable.h
Copied: branches/r5rs/sigscheme/basecport.c (from rev 2250, branches/r5rs/sigscheme/sbcport.c)
===================================================================
--- branches/r5rs/sigscheme/sbcport.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/basecport.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -0,0 +1,209 @@
+/*===========================================================================
+ * FileName : basecport.c
+ * About : ScmBaseCharPort implementation
+ *
+ * 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"
+
+/*=======================================
+ File Local Macro Definitions
+=======================================*/
+
+/*=======================================
+ File Local Type Definitions
+=======================================*/
+
+/*=======================================
+ File Local Function Declarations
+=======================================*/
+static ScmCharPort *basecport_dyn_cast(ScmCharPort *cport,
+ 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);
+static int basecport_vprintf(ScmBaseCharPort *port, const char *str,
+ va_list args);
+static int basecport_puts(ScmBaseCharPort *port, const char *str);
+static int basecport_put_char(ScmBaseCharPort *port, int ch);
+static int basecport_flush(ScmBaseCharPort *port);
+
+/*=======================================
+ Variable Declarations
+=======================================*/
+static const ScmCharPortVTbl ScmBaseCharPort_vtbl = {
+ (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,
+ (ScmCharPortMethod_vprintf) &basecport_vprintf,
+ (ScmCharPortMethod_puts) &basecport_puts,
+ (ScmCharPortMethod_put_char) &basecport_put_char,
+ (ScmCharPortMethod_flush) &basecport_flush
+};
+const ScmCharPortVTbl *ScmBaseCharPort_vptr = &ScmBaseCharPort_vtbl;
+
+/*=======================================
+ Function Implementations
+=======================================*/
+void
+ScmBaseCharPort_construct(ScmBaseCharPort *port, const ScmCharPortVTbl *vptr,
+ ScmBytePort *bport)
+{
+ port->vptr = vptr;
+ port->bport = bport;
+#if SCM_DEBUG
+ port->linenum = 1;
+#else
+ port->linenum = -1;
+#endif
+}
+
+char *
+ScmBaseCharPort_inspect(ScmBaseCharPort *port, const char *header)
+{
+ const char *encoding;
+ char *bport_part, *combined;
+ size_t size;
+
+ encoding = SCM_CHARPORT_ENCODING((ScmCharPort *)port);
+ bport_part = SCM_BYTEPORT_INSPECT((ScmBytePort *)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)
+{
+ return port->linenum;
+}
+
+static ScmCharPort *
+basecport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
+{
+ return (dst_vptr == ScmBaseCharPort_vptr) ? cport : NULL;
+}
+
+static int
+basecport_close(ScmBaseCharPort *port)
+{
+ return SCM_BYTEPORT_CLOSE(port->bport);
+}
+
+static const char *
+basecport_encoding(ScmBaseCharPort *port)
+{
+ SCM_PORT_ERROR_INVALID_OPERATION(CHAR, port, ScmBaseCharPort);
+ /* NOTREACHED */
+}
+
+static char *
+basecport_inspect(ScmBaseCharPort *port)
+{
+ return ScmBaseCharPort_inspect(port, "unknown");
+}
+
+static int
+basecport_get_char(ScmBaseCharPort *port)
+{
+ int ch;
+
+ ch = SCM_BYTEPORT_GET_BYTE(port->bport);
+#if SCM_DEBUG
+ if (ch == SCM_NEWLINE_STR[0])
+ port->linenum++;
+#endif
+
+ return ch;
+}
+
+static int
+basecport_peek_char(ScmBaseCharPort *port)
+{
+ return SCM_BYTEPORT_PEEK_BYTE(port->bport);
+}
+
+static int
+basecport_char_readyp(ScmBaseCharPort *port)
+{
+ return SCM_BYTEPORT_BYTE_READYP(port->bport);
+}
+
+static int
+basecport_vprintf(ScmBaseCharPort *port, const char *str, va_list args)
+{
+ return SCM_BYTEPORT_VPRINTF(port->bport, str, args);
+}
+
+static int
+basecport_puts(ScmBaseCharPort *port, const char *str)
+{
+ return SCM_BYTEPORT_PUTS(port->bport, str);
+}
+
+static int
+basecport_put_char(ScmBaseCharPort *port, int ch)
+{
+ SCM_PORT_ERROR_INVALID_OPERATION(CHAR, port, ScmBaseCharPort);
+ /* NOTREACHED */
+}
+
+static int
+basecport_flush(ScmBaseCharPort *port)
+{
+ return SCM_BYTEPORT_FLUSH(port->bport);
+}
Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/baseport.h 2005-11-25 05:54:26 UTC (rev 2251)
@@ -129,6 +129,7 @@
=======================================*/
typedef struct ScmCharPortVTbl_ ScmCharPortVTbl;
typedef struct ScmCharPort_ ScmCharPort;
+typedef struct ScmBaseCharPort_ ScmBaseCharPort;
typedef struct ScmBytePortVTbl_ ScmBytePortVTbl;
typedef struct ScmBytePort_ ScmBytePort;
@@ -172,6 +173,13 @@
const ScmCharPortVTbl *vptr;
};
+struct ScmBaseCharPort_ { /* inherits ScmCharPort */
+ const ScmCharPortVTbl *vptr;
+
+ ScmBytePort *bport; /* protected */
+ int linenum; /* protected */
+};
+
/*
* byte port
*/
@@ -213,10 +221,16 @@
/*=======================================
Variable Declarations
=======================================*/
+extern const ScmCharPortVTbl *ScmBaseCharPort_vptr;
/*=======================================
Function Declarations
=======================================*/
+void ScmBaseCharPort_construct(ScmBaseCharPort *port,
+ const ScmCharPortVTbl *vptr,
+ ScmBytePort *bport);
+char *ScmBaseCharPort_inspect(ScmBaseCharPort *port, const char *header);
+int ScmBaseCharPort_line_number(ScmBaseCharPort *port);
#endif /* __SCM_BASEPORT_H */
Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/fileport.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -56,6 +56,13 @@
/*=======================================
File Local Macro Definitions
=======================================*/
+#ifndef FALSE
+#define FALSE 0
+#endif /* FALSE */
+#ifndef TRUE
+#define TRUE (!FALSE)
+#endif /* TRUE */
+
#define OK 0
/*=======================================
Modified: branches/r5rs/sigscheme/io.c
===================================================================
--- branches/r5rs/sigscheme/io.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/io.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -655,8 +655,8 @@
#endif
/* FIXME: link conditionally with autoconf */
-#include "sbcport.c"
#if SCM_USE_MULTIBYTE_CHAR
#include "mbcport.c"
-#endif
-#include "fileport.c"
+#else /* SCM_USE_MULTIBYTE_CHAR */
+#include "sbcport.c"
+#endif /* SCM_USE_MULTIBYTE_CHAR */
Modified: branches/r5rs/sigscheme/mbcport.c
===================================================================
--- branches/r5rs/sigscheme/mbcport.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/mbcport.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -49,7 +49,6 @@
Local Include
=======================================*/
#include "baseport.h"
-#include "sbcport.h"
#include "encoding.h"
#include "mbcport.h"
@@ -107,10 +106,8 @@
{
ScmCharPortVTbl *vptr;
- Scm_sbcport_init();
+ ScmMultiByteCharPort_vtbl = *ScmBaseCharPort_vptr;
- ScmMultiByteCharPort_vtbl = *ScmSingleByteCharPort_vptr;
-
vptr = &ScmMultiByteCharPort_vtbl;
vptr->dyn_cast = (ScmCharPortMethod_dyn_cast)&mbcport_dyn_cast;
vptr->encoding = (ScmCharPortMethod_encoding)&mbcport_encoding;
Modified: branches/r5rs/sigscheme/operations-srfi6.c
===================================================================
--- branches/r5rs/sigscheme/operations-srfi6.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/operations-srfi6.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -42,7 +42,6 @@
#include "sigscheme.h"
#include "sigschemeinternal.h"
#include "baseport.h"
-#include "sbcport.h"
#include "strport.h"
/*=======================================
Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/read.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -65,7 +65,6 @@
=======================================*/
#include "sigscheme.h"
#include "sigschemeinternal.h"
-#include "sbcport.h"
/*=======================================
File Local Struct Declarations
Modified: branches/r5rs/sigscheme/sbcport.c
===================================================================
--- branches/r5rs/sigscheme/sbcport.c 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/sbcport.c 2005-11-25 05:54:26 UTC (rev 2251)
@@ -66,20 +66,6 @@
/*=======================================
File Local Function Declarations
=======================================*/
-static ScmCharPort *basecport_dyn_cast(ScmCharPort *cport,
- 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);
-static int basecport_vprintf(ScmBaseCharPort *port, const char *str,
- va_list args);
-static int basecport_puts(ScmBaseCharPort *port, const char *str);
-static int basecport_put_char(ScmBaseCharPort *port, int ch);
-static int basecport_flush(ScmBaseCharPort *port);
-
static ScmCharPort *sbcport_dyn_cast(ScmCharPort *cport,
const ScmCharPortVTbl *dst_vptr);
static const char *sbcport_encoding(ScmSingleByteCharPort *port);
@@ -89,21 +75,6 @@
/*=======================================
Variable Declarations
=======================================*/
-static const ScmCharPortVTbl ScmBaseCharPort_vtbl = {
- (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,
- (ScmCharPortMethod_vprintf) &basecport_vprintf,
- (ScmCharPortMethod_puts) &basecport_puts,
- (ScmCharPortMethod_put_char) &basecport_put_char,
- (ScmCharPortMethod_flush) &basecport_flush
-};
-const ScmCharPortVTbl *ScmBaseCharPort_vptr = &ScmBaseCharPort_vtbl;
-
static ScmCharPortVTbl ScmSingleByteCharPort_vtbl;
const ScmCharPortVTbl *ScmSingleByteCharPort_vptr = &ScmSingleByteCharPort_vtbl;
@@ -111,120 +82,6 @@
Function Implementations
=======================================*/
void
-ScmBaseCharPort_construct(ScmBaseCharPort *port, const ScmCharPortVTbl *vptr,
- ScmBytePort *bport)
-{
- port->vptr = vptr;
- port->bport = bport;
-#if SCM_DEBUG
- port->linenum = 1;
-#else
- port->linenum = -1;
-#endif
-}
-
-char *
-ScmBaseCharPort_inspect(ScmBaseCharPort *port, const char *header)
-{
- const char *encoding;
- char *bport_part, *combined;
- size_t size;
-
- encoding = SCM_CHARPORT_ENCODING((ScmCharPort *)port);
- bport_part = SCM_BYTEPORT_INSPECT((ScmBytePort *)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)
-{
- return port->linenum;
-}
-
-static ScmCharPort *
-basecport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
-{
- return (dst_vptr == ScmBaseCharPort_vptr) ? cport : NULL;
-}
-
-static int
-basecport_close(ScmBaseCharPort *port)
-{
- return SCM_BYTEPORT_CLOSE(port->bport);
-}
-
-static const char *
-basecport_encoding(ScmBaseCharPort *port)
-{
- SCM_PORT_ERROR_INVALID_OPERATION(CHAR, port, ScmBaseCharPort);
- /* NOTREACHED */
-}
-
-static char *
-basecport_inspect(ScmBaseCharPort *port)
-{
- return ScmBaseCharPort_inspect(port, "unknown");
-}
-
-static int
-basecport_get_char(ScmBaseCharPort *port)
-{
- int ch;
-
- ch = SCM_BYTEPORT_GET_BYTE(port->bport);
-#if SCM_DEBUG
- if (ch == SCM_NEWLINE_STR[0])
- port->linenum++;
-#endif
-
- return ch;
-}
-
-static int
-basecport_peek_char(ScmBaseCharPort *port)
-{
- return SCM_BYTEPORT_PEEK_BYTE(port->bport);
-}
-
-static int
-basecport_char_readyp(ScmBaseCharPort *port)
-{
- return SCM_BYTEPORT_BYTE_READYP(port->bport);
-}
-
-static int
-basecport_vprintf(ScmBaseCharPort *port, const char *str, va_list args)
-{
- return SCM_BYTEPORT_VPRINTF(port->bport, str, args);
-}
-
-static int
-basecport_puts(ScmBaseCharPort *port, const char *str)
-{
- return SCM_BYTEPORT_PUTS(port->bport, str);
-}
-
-static int
-basecport_put_char(ScmBaseCharPort *port, int ch)
-{
- SCM_PORT_ERROR_INVALID_OPERATION(CHAR, port, ScmBaseCharPort);
- /* NOTREACHED */
-}
-
-static int
-basecport_flush(ScmBaseCharPort *port)
-{
- return SCM_BYTEPORT_FLUSH(port->bport);
-}
-
-
-void
Scm_sbcport_init(void)
{
ScmCharPortVTbl *vptr;
Modified: branches/r5rs/sigscheme/sbcport.h
===================================================================
--- branches/r5rs/sigscheme/sbcport.h 2005-11-25 04:27:43 UTC (rev 2250)
+++ branches/r5rs/sigscheme/sbcport.h 2005-11-25 05:54:26 UTC (rev 2251)
@@ -56,20 +56,11 @@
/*=======================================
Type Definitions
=======================================*/
-typedef struct ScmBaseCharPort_ ScmBaseCharPort;
typedef struct ScmSingleByteCharPort_ ScmSingleByteCharPort;
-struct ScmBaseCharPort_ { /* inherits ScmCharPort */
- const ScmCharPortVTbl *vptr;
-
- ScmBytePort *bport; /* protected */
- int linenum; /* protected */
-};
-
/*=======================================
Variable Declarations
=======================================*/
-extern const ScmCharPortVTbl *ScmBaseCharPort_vptr;
extern const ScmCharPortVTbl *ScmSingleByteCharPort_vptr;
/*=======================================
@@ -77,12 +68,6 @@
=======================================*/
void Scm_sbcport_init(void);
-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,
const ScmCharPortVTbl *vptr,
ScmBytePort *bport);
More information about the uim-commit
mailing list