aboutsummaryrefslogtreecommitdiff
path: root/modules/guile/guile.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/guile/guile.c')
-rw-r--r--modules/guile/guile.c89
1 files changed, 18 insertions, 71 deletions
diff --git a/modules/guile/guile.c b/modules/guile/guile.c
index ae63a51..2ce66c5 100644
--- a/modules/guile/guile.c
+++ b/modules/guile/guile.c
@@ -1,5 +1,5 @@
1/* This file is part of Smap. 1/* This file is part of Smap.
2 Copyright (C) 2010, 2014, 2015 Sergey Poznyakoff 2 Copyright (C) 2010, 2014, 2015, 2019 Sergey Poznyakoff
3 3
4 Smap is free software; you can redistribute it and/or modify 4 Smap is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -171,7 +171,7 @@ argv_to_scm(int argc, char **argv)
171 return scm_first; 171 return scm_first;
172} 172}
173 173
174static scm_t_bits scm_tc16_smap_output_port; 174static scm_t_port_type *scm_smap_output_port_type;
175struct _guile_smap_output_port { 175struct _guile_smap_output_port {
176 smap_stream_t stream; 176 smap_stream_t stream;
177}; 177};
@@ -180,78 +180,32 @@ static SCM
180_make_smap_output_port(smap_stream_t stream) 180_make_smap_output_port(smap_stream_t stream)
181{ 181{
182 struct _guile_smap_output_port *dp; 182 struct _guile_smap_output_port *dp;
183 SCM port;
184 scm_port *pt;
185 183
186 dp = scm_gc_malloc(sizeof (struct _guile_smap_output_port), 184 dp = scm_gc_typed_calloc (struct _guile_smap_output_port);
187 "smap-output_-port");
188 dp->stream = stream; 185 dp->stream = stream;
189 186 return scm_c_make_port (scm_smap_output_port_type,
190 port = scm_new_port_table_entry(scm_tc16_smap_output_port); 187 SCM_WRTNG | SCM_BUF0,
191 pt = SCM_PTAB_ENTRY(port); 188 (scm_t_bits) dp);
192 pt->rw_random = 0;
193 SCM_SET_CELL_TYPE(port,
194 (scm_tc16_smap_output_port |
195 SCM_OPN | SCM_WRTNG | SCM_BUF0));
196 SCM_SETSTREAM(port, dp);
197 return port;
198} 189}
199 190
200#define SMAP_OUTPUT_PORT(x) ((struct _guile_smap_output_port *) SCM_STREAM (x)) 191#define SMAP_OUTPUT_PORT(x) ((struct _guile_smap_output_port *) SCM_STREAM (x))
201 192
202static SCM
203_smap_output_port_mark(SCM port)
204{
205 return SCM_BOOL_F;
206}
207
208static void 193static void
209_smap_output_port_flush(SCM port)
210{
211 scm_port *pt = SCM_PTAB_ENTRY(port);
212 struct _guile_smap_output_port *dp = SMAP_OUTPUT_PORT(port);
213 if (dp && pt->write_pos > pt->write_buf)
214 smap_stream_write(dp->stream, "\n", 1, NULL);
215}
216
217static int
218_smap_output_port_close(SCM port) 194_smap_output_port_close(SCM port)
219{ 195{
220 struct _guile_smap_output_port *dp = SMAP_OUTPUT_PORT(port); 196 struct _guile_smap_output_port *dp = SMAP_OUTPUT_PORT(port);
221 197
222 if (dp) { 198 if (dp && dp->stream) {
223 _smap_output_port_flush(port); 199 smap_stream_flush(dp->stream);
224 SCM_SETSTREAM(port, NULL);
225 scm_gc_free(dp, sizeof(struct _guile_smap_output_port),
226 "smap-output-port");
227 } 200 }
228 return 0;
229} 201}
230 202
231static scm_sizet 203static size_t
232_smap_output_port_free(SCM port) 204_smap_output_port_write(SCM port, SCM src, size_t start, size_t count)
233{
234 _smap_output_port_close(port);
235 return 0;
236}
237
238static int
239_smap_output_port_fill_input(SCM port)
240{
241 return EOF;
242}
243
244static void
245_smap_output_port_write(SCM port, const void *data, size_t size)
246{ 205{
247 struct _guile_smap_output_port *dp = SMAP_OUTPUT_PORT(port); 206 struct _guile_smap_output_port *dp = SMAP_OUTPUT_PORT(port);
248 smap_stream_write(dp->stream, data, size, NULL); 207 smap_stream_write(dp->stream, SCM_BYTEVECTOR_CONTENTS (src) + start, count, NULL);
249} 208 return count;
250
251static scm_t_off
252_smap_output_port_seek (SCM port, scm_t_off offset, int whence)
253{
254 return -1;
255} 209}
256 210
257static int 211static int
@@ -264,19 +218,12 @@ _smap_output_port_print(SCM exp, SCM port, scm_print_state *pstate)
264static void 218static void
265_init_smap_output_port() 219_init_smap_output_port()
266{ 220{
267 scm_tc16_smap_output_port = scm_make_port_type("smap-output-port", 221 scm_smap_output_port_type = scm_make_port_type("smap-output-port",
268 _smap_output_port_fill_input, 222 NULL,
269 _smap_output_port_write); 223 _smap_output_port_write);
270 scm_set_port_mark (scm_tc16_smap_output_port, _smap_output_port_mark); 224 scm_set_port_print(scm_smap_output_port_type, _smap_output_port_print);
271 scm_set_port_free (scm_tc16_smap_output_port, _smap_output_port_free); 225 scm_set_port_close(scm_smap_output_port_type, _smap_output_port_close);
272 scm_set_port_print (scm_tc16_smap_output_port, 226 scm_set_port_needs_close_on_gc(scm_smap_output_port_type, 1);
273 _smap_output_port_print);
274 scm_set_port_flush (scm_tc16_smap_output_port,
275 _smap_output_port_flush);
276 scm_set_port_close (scm_tc16_smap_output_port,
277 _smap_output_port_close);
278 scm_set_port_seek (scm_tc16_smap_output_port,
279 _smap_output_port_seek);
280} 227}
281 228
282static void 229static void

Return to:

Send suggestions and report system problems to the System administrator.