1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
54 scm_putc (int c
, SCM port
)
62 scm_sizet i
= SCM_PTOBNUM (port
);
63 SCM_SYSCALL ((scm_ptobs
[i
].fputc
) (c
, SCM_STREAM (port
)));
69 scm_puts (char *s
, SCM port
)
77 scm_sizet i
= SCM_PTOBNUM (port
);
78 SCM_SYSCALL ((scm_ptobs
[i
].fputs
) (s
, SCM_STREAM (port
)));
79 #ifdef TRANSCRIPT_SUPPORT
80 if (scm_trans
&& (port
== def_outp
|| port
== cur_errp
))
81 SCM_SYSCALL (fputs (s
, scm_trans
));
88 scm_lfwrite (char *ptr
, scm_sizet size
, scm_sizet nitems
, SCM port
)
91 scm_lfwrite (ptr
, size
, nitems
, port
)
99 scm_sizet i
= SCM_PTOBNUM (port
);
100 SCM_SYSCALL (ret
= (scm_ptobs
[i
].fwrite(ptr
, size
, nitems
, SCM_STREAM (port
))));
101 #ifdef TRANSCRIPT_SUPPORT
102 if (scm_trans
&& (port
== def_outp
|| port
== cur_errp
))
103 SCM_SYSCALL (fwrite (ptr
, size
, nitems
, scm_trans
));
113 scm_gen_putc (int c
, SCM port
)
116 scm_gen_putc (c
, port
)
121 switch (SCM_PORT_REPRESENTATION (port
))
123 case scm_regular_port
:
125 /* Nothing good to do with extended chars here...
126 * just truncate them.
128 scm_putc ((unsigned char)c
, port
);
137 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_MAKICHR (c
),
138 "huge translation", "scm_gen_putc");
140 len
= xwctomb (buf
, c
);
142 SCM_ASSERT ((len
>= 0), SCM_MAKICHR (c
), "bogus character", "scm_gen_putc");
149 for (x
= 0; x
< len
; ++x
)
150 scm_putc (buf
[x
], port
);
157 scm_putc (((unsigned char)(c
>> 8) & 0xff), port
);
158 scm_putc ((unsigned char)(c
& 0xff), port
);
170 scm_gen_puts (enum scm_string_representation_type rep
,
175 scm_gen_puts (rep
, str_data
, port
)
176 enum scm_string_representation_type rep
;
177 unsigned char *str_data
;
184 case scm_regular_string
:
185 switch (SCM_PORT_REPRESENTATION (port
))
187 case scm_regular_port
:
189 scm_puts (str_data
, port
);
196 scm_putc (*str_data
, port
);
204 switch (SCM_PORT_REPRESENTATION (port
))
206 case scm_regular_port
:
208 scm_puts (str_data
, port
);
216 size
= strlen (str_data
);
219 len
= xmbtowc (&output
, str_data
, size
);
220 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*str_data
), "bogus character", "scm_gen_puts");
221 scm_putc ((output
>> 8) & 0xff, port
);
222 scm_putc (output
& 0xff, port
);
230 case scm_wchar_string
:
232 xwchar_t
* wstr_data
;
234 wstr_data
= (xwchar_t
*)wstr_data
;
235 switch (SCM_PORT_REPRESENTATION (port
))
237 case scm_regular_port
:
240 scm_putc ((unsigned char) *wstr_data
, port
);
248 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
249 "huge translation", "scm_gen_puts");
255 len
= xwctomb (buf
, *wstr_data
);
257 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*wstr_data
), "bogus character", "scm_gen_puts");
261 for (x
= 0; x
< len
; ++x
)
262 scm_putc (buf
[x
], port
);
272 for (len
= 0; wstr_data
[len
]; ++len
)
274 scm_lfwrite (str_data
, sizeof (xwchar_t
), len
, port
);
287 scm_gen_write (enum scm_string_representation_type rep
, char *str_data
, scm_sizet nitems
, SCM port
)
290 scm_gen_write (rep
, str_data
, nitems
, port
)
291 enum scm_string_representation_type rep
;
297 /* is nitems bytes or characters in the mb_string case? */
301 case scm_regular_string
:
302 switch (SCM_PORT_REPRESENTATION (port
))
304 case scm_regular_port
:
306 scm_lfwrite (str_data
, 1, nitems
, port
);
313 scm_putc (*str_data
, port
);
322 switch (SCM_PORT_REPRESENTATION (port
))
324 case scm_regular_port
:
326 scm_lfwrite (str_data
, 1, nitems
, port
);
336 len
= xmbtowc (&output
, str_data
, nitems
);
337 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*str_data
), "bogus character", "scm_gen_puts");
338 scm_putc ((output
>> 8) & 0xff, port
);
339 scm_putc (output
& 0xff, port
);
347 case scm_wchar_string
:
349 xwchar_t
* wstr_data
;
351 wstr_data
= (xwchar_t
*)wstr_data
;
352 switch (SCM_PORT_REPRESENTATION (port
))
354 case scm_regular_port
:
357 scm_putc ((unsigned char) *wstr_data
, port
);
366 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
367 "huge translation", "scm_gen_puts");
373 len
= xwctomb (buf
, *wstr_data
);
375 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*wstr_data
), "bogus character", "scm_gen_puts");
379 for (x
= 0; x
< len
; ++x
)
380 scm_putc (buf
[x
], port
);
390 scm_lfwrite (str_data
, sizeof (xwchar_t
), nitems
, port
);
414 f
= (FILE *)SCM_STREAM (port
);
415 i
= SCM_PTOBNUM (port
);
416 SCM_SYSCALL (c
= (scm_ptobs
[i
].fgetc
) (f
));
422 scm_gen_getc (SCM port
)
431 /* One char may be stored in the high bits of (car port) orre@nada.kth.se. */
432 if (SCM_CRDYP (port
))
434 c
= SCM_CGETUN (port
);
435 SCM_CLRDY (port
); /* Clear ungetted char */
454 switch (SCM_PORT_REPRESENTATION (port
))
456 case scm_regular_port
:
463 unsigned char buf
[256];
466 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
467 "huge translation", "scm_gen_puts");
480 if (xmbtowc (&out
, buf
, x
+ 1) > 0)
486 SCM_ASSERT (x
< sizeof (buf
), SCM_BOOL_F
,
487 "huge translation", "scm_gen_getc");
497 hi
= scm_getc (port
);
515 scm_gen_ungetc (int c
, SCM port
)
518 scm_gen_ungetc (c
, port
)
523 /* SCM_ASSERT(!SCM_CRDYP(port), port, SCM_ARG2, "too many scm_gen_ungetc");*/
524 SCM_CUNGET (c
, port
);
527 /* What should col be in this case?
528 * We'll leave it at -1.
530 SCM_LINUM (port
) -= 1;