1
/*===========================================================================
2
* FileName : nullport.c
3
* About : A ScmBytePort implementation for null read/write
5
* Copyright (C) 2005-2006 YamaKen <yamaken AT bp.iij4u.or.jp>
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
* 3. Neither the name of authors nor the names of its contributors
19
* may be used to endorse or promote products derived from this software
20
* without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
23
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
26
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
===========================================================================*/
36
* - This file is intended to be portable. Don't depend on SigScheme.
37
* - To isolate and hide implementation-dependent things, don't merge this file
43
/*=======================================
45
=======================================*/
51
/*=======================================
53
=======================================*/
54
/* To override SCM_{CHAR,BYTE}PORT_ERROR() and SCM_PORT_*ALLOC(). Don't depend
55
* on SigScheme-specific things */
56
#include "sigscheme.h"
57
#include "sigschemeinternal.h"
62
/*=======================================
63
File Local Macro Definitions
64
=======================================*/
67
/*=======================================
68
File Local Type Definitions
69
=======================================*/
70
typedef ScmBytePort ScmNullPort;
72
/*=======================================
73
File Local Function Declarations
74
=======================================*/
75
static ScmBytePort *nullport_dyn_cast(ScmBytePort *bport,
76
const ScmBytePortVTbl *dest_vptr);
77
static int nullport_close(ScmNullPort *bport);
78
static char *nullport_inspect(ScmNullPort *port);
79
static scm_ichar_t nullport_get_byte(ScmNullPort *bport);
80
static scm_ichar_t nullport_peek_byte(ScmNullPort *bport);
81
static scm_bool nullport_byte_readyp(ScmNullPort *bport);
82
static int nullport_vprintf(ScmNullPort *bport, const char *str, va_list args);
83
static int nullport_puts(ScmNullPort *bport, const char *str);
84
static size_t nullport_write(ScmNullPort *bport,
85
size_t nbytes, const char *buf);
86
static int nullport_flush(ScmNullPort *bport);
88
/*=======================================
90
=======================================*/
91
static const ScmBytePortVTbl ScmNullPort_vtbl = {
92
(ScmBytePortMethod_dyn_cast) &nullport_dyn_cast,
93
(ScmBytePortMethod_close) &nullport_close,
94
(ScmBytePortMethod_inspect) &nullport_inspect,
95
(ScmBytePortMethod_get_byte) &nullport_get_byte,
96
(ScmBytePortMethod_peek_byte) &nullport_peek_byte,
97
(ScmBytePortMethod_byte_readyp)&nullport_byte_readyp,
98
(ScmBytePortMethod_vprintf) &nullport_vprintf,
99
(ScmBytePortMethod_puts) &nullport_puts,
100
(ScmBytePortMethod_write) &nullport_write,
101
(ScmBytePortMethod_flush) &nullport_flush
103
const ScmBytePortVTbl *ScmNullPort_vptr = &ScmNullPort_vtbl;
105
/*=======================================
106
Function Implementations
107
=======================================*/
110
* Client code must call this first even if current implementation does not
111
* contain actual code.
114
scm_nullport_init(void)
119
ScmNullPort_new(void)
123
port = SCM_PORT_MALLOC(sizeof(ScmNullPort));
125
port->vptr = ScmNullPort_vptr;
127
return (ScmBytePort *)port;
131
nullport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
133
return (dst_vptr == ScmNullPort_vptr) ? bport : NULL;
137
nullport_close(ScmNullPort *port)
143
nullport_inspect(ScmNullPort *port)
145
return scm_strdup("null");
149
nullport_get_byte(ScmNullPort *port)
155
nullport_peek_byte(ScmNullPort *port)
161
nullport_byte_readyp(ScmNullPort *port)
167
nullport_vprintf(ScmNullPort *port, const char *str, va_list args)
173
nullport_puts(ScmNullPort *port, const char *str)
179
nullport_write(ScmNullPort *port, size_t nbytes, const char *buf)
185
nullport_flush(ScmNullPort *port)