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

« back to all changes in this revision

Viewing changes to src/nullport.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2006-05-23 21:46:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060523214641-6ix4gz34wpiehub8
Tags: 0.5.0-2
* debian/control (Build-Depends): Added ruby.
  Thanks to Frederik Schueler.  Closes: #368571
* debian/rules (clean): invoke 'distclean' instead of 'clean'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
 *  FileName : nullport.c
 
3
 *  About    : A ScmBytePort implementation for null read/write
 
4
 *
 
5
 *  Copyright (C) 2005-2006 YamaKen <yamaken AT bp.iij4u.or.jp>
 
6
 *
 
7
 *  All rights reserved.
 
8
 *
 
9
 *  Redistribution and use in source and binary forms, with or without
 
10
 *  modification, are permitted provided that the following conditions
 
11
 *  are met:
 
12
 *
 
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.
 
21
 *
 
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
===========================================================================*/
 
34
 
 
35
/*
 
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
 
38
 *   into another
 
39
 */
 
40
 
 
41
#include "config.h"
 
42
 
 
43
/*=======================================
 
44
  System Include
 
45
=======================================*/
 
46
#include <stdlib.h>
 
47
#include <stdio.h>
 
48
#include <stdarg.h>
 
49
#include <string.h>
 
50
 
 
51
/*=======================================
 
52
  Local Include
 
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"
 
58
 
 
59
#include "baseport.h"
 
60
#include "nullport.h"
 
61
 
 
62
/*=======================================
 
63
  File Local Macro Definitions
 
64
=======================================*/
 
65
#define OK 0
 
66
 
 
67
/*=======================================
 
68
  File Local Type Definitions
 
69
=======================================*/
 
70
typedef ScmBytePort ScmNullPort;
 
71
 
 
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);
 
87
 
 
88
/*=======================================
 
89
  Variable Declarations
 
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
 
102
};
 
103
const ScmBytePortVTbl *ScmNullPort_vptr = &ScmNullPort_vtbl;
 
104
 
 
105
/*=======================================
 
106
  Function Implementations
 
107
=======================================*/
 
108
 
 
109
/*
 
110
 * Client code must call this first even if current implementation does not
 
111
 * contain actual code.
 
112
 */
 
113
void
 
114
scm_nullport_init(void)
 
115
{
 
116
}
 
117
 
 
118
ScmBytePort *
 
119
ScmNullPort_new(void)
 
120
{
 
121
    ScmNullPort *port;
 
122
 
 
123
    port = SCM_PORT_MALLOC(sizeof(ScmNullPort));
 
124
 
 
125
    port->vptr = ScmNullPort_vptr;
 
126
 
 
127
    return (ScmBytePort *)port;
 
128
}
 
129
 
 
130
static ScmBytePort *
 
131
nullport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
 
132
{
 
133
    return (dst_vptr == ScmNullPort_vptr) ? bport : NULL;
 
134
}
 
135
 
 
136
static int
 
137
nullport_close(ScmNullPort *port)
 
138
{
 
139
    return OK;
 
140
}
 
141
 
 
142
static char *
 
143
nullport_inspect(ScmNullPort *port)
 
144
{
 
145
    return scm_strdup("null");
 
146
}
 
147
 
 
148
static scm_ichar_t
 
149
nullport_get_byte(ScmNullPort *port)
 
150
{
 
151
    return EOF;
 
152
}
 
153
 
 
154
static scm_ichar_t
 
155
nullport_peek_byte(ScmNullPort *port)
 
156
{
 
157
    return EOF;
 
158
}
 
159
 
 
160
static scm_bool
 
161
nullport_byte_readyp(ScmNullPort *port)
 
162
{
 
163
    return scm_true;
 
164
}
 
165
 
 
166
static int
 
167
nullport_vprintf(ScmNullPort *port, const char *str, va_list args)
 
168
{
 
169
    return 0;
 
170
}
 
171
 
 
172
static int
 
173
nullport_puts(ScmNullPort *port, const char *str)
 
174
{
 
175
    return 0;
 
176
}
 
177
 
 
178
static size_t
 
179
nullport_write(ScmNullPort *port, size_t nbytes, const char *buf)
 
180
{
 
181
    return nbytes;
 
182
}
 
183
 
 
184
static int
 
185
nullport_flush(ScmNullPort *port)
 
186
{
 
187
    return OK;
 
188
}