~ubuntu-branches/ubuntu/hardy/sigscheme/hardy-proposed

« back to all changes in this revision

Viewing changes to src/scmport.h

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2007-01-29 15:31:24 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070129153124-j5fcqyrwcfbczma7
Tags: 0.7.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  About    : Abstract base of port implementation
4
4
 *
5
5
 *  Copyright (C) 2005-2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
 
6
 *  Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
6
7
 *
7
8
 *  All rights reserved.
8
9
 *
41
42
#define __SCM_SCMPORT_H
42
43
 
43
44
#include <stddef.h>
 
45
#if (HAVE_ASSERT_H && !SCM_SOFT_ASSERT)
 
46
#include <assert.h>
 
47
#endif
44
48
 
45
 
#include "sigscheme-stdint.h"
46
49
#include "scmint.h"
47
50
#include "global.h"
 
51
#if SCM_USE_MULTIBYTE_CHAR
48
52
#include "encoding.h"
 
53
#else
 
54
#include "encoding-dummy.h"
 
55
#endif
49
56
 
50
57
#ifdef __cplusplus
51
58
extern "C" {
58
65
#define SCM_DEBUG_PORT 0
59
66
#endif
60
67
 
 
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"
 
72
 
 
73
#if SCM_SCMPORT_USE_WITH_SIGSCHEME
 
74
#define SCM_PORT_ASSERT(exp) (SCM_ASSERT(exp))
 
75
#elif HAVE_ASSERT_H
 
76
#define SCM_PORT_ASSERT(exp) (assert(exp))
 
77
#else
 
78
#define SCM_PORT_ASSERT(exp) SCM_EMPTY_EXPR
 
79
#endif
 
80
 
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")
67
87
 
68
88
/*
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.
71
91
 */
72
92
#define SCM_CHARPORT_DYNAMIC_CAST(type, obj)                                 \
81
101
 
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))
119
144
 * char port
120
145
 */
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);
127
152
/* input */
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);
131
156
 
132
157
/* output */
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);
136
161
 
137
162
struct ScmCharPortVTbl_ {
138
163
    ScmCharPortMethod_dyn_cast    dyn_cast;
155
180
    const ScmCharPortVTbl *vptr;
156
181
 
157
182
    ScmBytePort *bport;  /* protected */
158
 
    int linenum;         /* protected */
 
183
    size_t linenum;      /* protected */
159
184
};
160
185
 
161
186
/*
162
187
 * byte port
163
188
 */
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);
168
193
 
169
194
/* input */
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);
173
198
 
174
199
/* output */
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);
179
204
 
180
205
struct ScmBytePortVTbl_ {
181
206
    ScmBytePortMethod_dyn_cast    dyn_cast;
206
231
                                          ScmBytePort *bport);
207
232
SCM_EXPORT char *ScmBaseCharPort_inspect(ScmBaseCharPort *port,
208
233
                                         const char *header);
209
 
SCM_EXPORT int ScmBaseCharPort_line_number(ScmBaseCharPort *port);
 
234
SCM_EXPORT size_t ScmBaseCharPort_line_number(ScmBaseCharPort *port);
210
235
 
211
236
 
212
237
#ifdef __cplusplus