58
65
#define SCM_DEBUG_PORT 0
68
#define SCM_ERRMSG_OPEN_PORT "failed to open port"
69
#define SCM_ERRMSG_CLOSE_PORT "failed to close port"
70
#define SCM_ERRMSG_READ_FROM_PORT "failed to read from port"
71
#define SCM_ERRMSG_WRITE_TO_PORT "failed to write to port"
73
#if SCM_SCMPORT_USE_WITH_SIGSCHEME
74
#define SCM_PORT_ASSERT(exp) (SCM_ASSERT(exp))
76
#define SCM_PORT_ASSERT(exp) (assert(exp))
78
#define SCM_PORT_ASSERT(exp) SCM_EMPTY_EXPR
61
81
#define SCM_PORT_ERROR_INVALID_TYPE(klass, port, type) \
62
82
SCM_##klass##PORT_ERROR((port), #type ": invalid object is passed to")
63
83
#define SCM_PORT_ERROR_INVALID_OPERATION(klass, port, type) \
66
86
SCM_##klass##PORT_ERROR((port), #type ": Out of memory")
69
* To allow safe method invocation (contains from subclasses), all non-standard
89
* To allow safe method invocation (includes from subclasses), all non-standard
70
90
* method must call SCM_PORT_*DYNAMIC_CAST() explicitly.
72
92
#define SCM_CHARPORT_DYNAMIC_CAST(type, obj) \
82
102
#define SCM_CHARPORT_CLOSE(cport) ((*(cport)->vptr->close)(cport))
83
103
#define SCM_CHARPORT_CODEC(cport) ((*(cport)->vptr->codec)(cport))
104
#if SCM_USE_MULTIBYTE_CHAR
84
105
#define SCM_CHARPORT_ENCODING(cport) \
85
106
(SCM_CHARCODEC_ENCODING(SCM_CHARPORT_CODEC(cport)))
86
107
#define SCM_CHARPORT_CCS(cport) \
87
108
(SCM_CHARCODEC_CCS(SCM_CHARPORT_CODEC(cport)))
109
#else /* SCM_USE_MULTIBYTE_CHAR */
110
#define SCM_CHARPORT_ENCODING(cport) ("ISO-8859-1")
111
#define SCM_CHARPORT_CCS(cport) (SCM_CCS_ISO8859_1)
112
#endif /* SCM_USE_MULTIBYTE_CHAR */
88
113
#define SCM_CHARPORT_INSPECT(cport) ((*(cport)->vptr->inspect)(cport))
89
114
#define SCM_CHARPORT_GET_CHAR(cport) ((*(cport)->vptr->get_char)(cport))
90
115
#define SCM_CHARPORT_PEEK_CHAR(cport) ((*(cport)->vptr->peek_char)(cport))
121
146
typedef ScmCharPort *(*ScmCharPortMethod_dyn_cast)(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr);
122
typedef int (*ScmCharPortMethod_close)(ScmCharPort *cport);
147
typedef void (*ScmCharPortMethod_close)(ScmCharPort *cport);
123
148
typedef ScmCharCodec *(*ScmCharPortMethod_codec)(ScmCharPort *cport);
124
149
/* returns brief information */
125
150
typedef char *(*ScmCharPortMethod_inspect)(ScmCharPort *cport);
128
153
typedef scm_ichar_t (*ScmCharPortMethod_get_char)(ScmCharPort *cport);
129
154
typedef scm_ichar_t (*ScmCharPortMethod_peek_char)(ScmCharPort *cport);
130
typedef scm_bool (*ScmCharPortMethod_char_readyp)(ScmCharPort *cport);
155
typedef scm_bool (*ScmCharPortMethod_char_readyp)(ScmCharPort *cport);
133
typedef int (*ScmCharPortMethod_puts)(ScmCharPort *cport, const char *str);
134
typedef int (*ScmCharPortMethod_put_char)(ScmCharPort *cport, scm_ichar_t ch);
135
typedef int (*ScmCharPortMethod_flush)(ScmCharPort *cport);
158
typedef void (*ScmCharPortMethod_puts)(ScmCharPort *cport, const char *str);
159
typedef void (*ScmCharPortMethod_put_char)(ScmCharPort *cport, scm_ichar_t ch);
160
typedef void (*ScmCharPortMethod_flush)(ScmCharPort *cport);
137
162
struct ScmCharPortVTbl_ {
138
163
ScmCharPortMethod_dyn_cast dyn_cast;
155
180
const ScmCharPortVTbl *vptr;
157
182
ScmBytePort *bport; /* protected */
158
int linenum; /* protected */
183
size_t linenum; /* protected */
164
189
typedef ScmBytePort *(*ScmBytePortMethod_dyn_cast)(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr);
165
typedef int (*ScmBytePortMethod_close)(ScmBytePort *bport);
190
typedef void (*ScmBytePortMethod_close)(ScmBytePort *bport);
166
191
/* returns brief information */
167
192
typedef char *(*ScmBytePortMethod_inspect)(ScmBytePort *bport);
170
195
typedef scm_ichar_t (*ScmBytePortMethod_get_byte)(ScmBytePort *bport);
171
196
typedef scm_ichar_t (*ScmBytePortMethod_peek_byte)(ScmBytePort *bport);
172
typedef scm_bool (*ScmBytePortMethod_byte_readyp)(ScmBytePort *bport);
197
typedef scm_bool (*ScmBytePortMethod_byte_readyp)(ScmBytePort *bport);
175
typedef int (*ScmBytePortMethod_puts)(ScmBytePort *bport, const char *str);
176
typedef size_t (*ScmBytePortMethod_write)(ScmBytePort *bport,
177
size_t nbytes, const char *buf);
178
typedef int (*ScmBytePortMethod_flush)(ScmBytePort *bport);
200
typedef void (*ScmBytePortMethod_puts)(ScmBytePort *bport, const char *str);
201
typedef void (*ScmBytePortMethod_write)(ScmBytePort *bport,
202
size_t nbytes, const char *buf);
203
typedef void (*ScmBytePortMethod_flush)(ScmBytePort *bport);
180
205
struct ScmBytePortVTbl_ {
181
206
ScmBytePortMethod_dyn_cast dyn_cast;