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.
51 scm_putc (int c
, SCM port
)
59 scm_sizet i
= SCM_PTOBNUM (port
);
60 SCM_SYSCALL ((scm_ptobs
[i
].fputc
) (c
, SCM_STREAM (port
)));
66 scm_puts (char *s
, SCM port
)
74 scm_sizet i
= SCM_PTOBNUM (port
);
75 SCM_SYSCALL ((scm_ptobs
[i
].fputs
) (s
, SCM_STREAM (port
)));
76 #ifdef TRANSCRIPT_SUPPORT
77 if (scm_trans
&& (port
== def_outp
|| port
== cur_errp
))
78 SCM_SYSCALL (fputs (s
, scm_trans
));
85 scm_lfwrite (char *ptr
, scm_sizet size
, scm_sizet nitems
, SCM port
)
88 scm_lfwrite (ptr
, size
, nitems
, port
)
96 scm_sizet i
= SCM_PTOBNUM (port
);
97 SCM_SYSCALL (ret
= (scm_ptobs
[i
].fwrite(ptr
, size
, nitems
, SCM_STREAM (port
))));
98 #ifdef TRANSCRIPT_SUPPORT
99 if (scm_trans
&& (port
== def_outp
|| port
== cur_errp
))
100 SCM_SYSCALL (fwrite (ptr
, size
, nitems
, scm_trans
));
110 scm_gen_putc (int c
, SCM port
)
113 scm_gen_putc (c
, port
)
118 switch (SCM_PORT_REPRESENTATION (port
))
120 case scm_regular_port
:
122 /* Nothing good to do with extended chars here...
123 * just truncate them.
125 scm_putc ((unsigned char)c
, port
);
134 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_MAKICHR (c
),
135 "huge translation", "scm_gen_putc");
137 len
= xwctomb (buf
, c
);
139 SCM_ASSERT ((len
>= 0), SCM_MAKICHR (c
), "bogus character", "scm_gen_putc");
146 for (x
= 0; x
< len
; ++x
)
147 scm_putc (buf
[x
], port
);
154 scm_putc (((unsigned char)(c
>> 8) & 0xff), port
);
155 scm_putc ((unsigned char)(c
& 0xff), port
);
167 scm_gen_puts (enum scm_string_representation_type rep
,
172 scm_gen_puts (rep
, str_data
, port
)
173 enum scm_string_representation_type rep
;
174 unsigned char *str_data
;
181 case scm_regular_string
:
182 switch (SCM_PORT_REPRESENTATION (port
))
184 case scm_regular_port
:
186 scm_puts (str_data
, port
);
193 scm_putc (*str_data
, port
);
201 switch (SCM_PORT_REPRESENTATION (port
))
203 case scm_regular_port
:
205 scm_puts (str_data
, port
);
213 size
= strlen (str_data
);
216 len
= xmbtowc (&output
, str_data
, size
);
217 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*str_data
), "bogus character", "scm_gen_puts");
218 scm_putc ((output
>> 8) & 0xff, port
);
219 scm_putc (output
& 0xff, port
);
227 case scm_wchar_string
:
229 xwchar_t
* wstr_data
;
231 wstr_data
= (xwchar_t
*)wstr_data
;
232 switch (SCM_PORT_REPRESENTATION (port
))
234 case scm_regular_port
:
237 scm_putc ((unsigned char) *wstr_data
, port
);
245 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
246 "huge translation", "scm_gen_puts");
252 len
= xwctomb (buf
, *wstr_data
);
254 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*wstr_data
), "bogus character", "scm_gen_puts");
258 for (x
= 0; x
< len
; ++x
)
259 scm_putc (buf
[x
], port
);
269 for (len
= 0; wstr_data
[len
]; ++len
)
271 scm_lfwrite (str_data
, sizeof (xwchar_t
), len
, port
);
284 scm_gen_write (enum scm_string_representation_type rep
, char *str_data
, scm_sizet nitems
, SCM port
)
287 scm_gen_write (rep
, str_data
, nitems
, port
)
288 enum scm_string_representation_type rep
;
294 /* is nitems bytes or characters in the mb_string case? */
298 case scm_regular_string
:
299 switch (SCM_PORT_REPRESENTATION (port
))
301 case scm_regular_port
:
303 scm_lfwrite (str_data
, 1, nitems
, port
);
310 scm_putc (*str_data
, port
);
319 switch (SCM_PORT_REPRESENTATION (port
))
321 case scm_regular_port
:
323 scm_lfwrite (str_data
, 1, nitems
, port
);
333 len
= xmbtowc (&output
, str_data
, nitems
);
334 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*str_data
), "bogus character", "scm_gen_puts");
335 scm_putc ((output
>> 8) & 0xff, port
);
336 scm_putc (output
& 0xff, port
);
344 case scm_wchar_string
:
346 xwchar_t
* wstr_data
;
348 wstr_data
= (xwchar_t
*)wstr_data
;
349 switch (SCM_PORT_REPRESENTATION (port
))
351 case scm_regular_port
:
354 scm_putc ((unsigned char) *wstr_data
, port
);
363 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
364 "huge translation", "scm_gen_puts");
370 len
= xwctomb (buf
, *wstr_data
);
372 SCM_ASSERT ((len
> 0), SCM_MAKINUM (*wstr_data
), "bogus character", "scm_gen_puts");
376 for (x
= 0; x
< len
; ++x
)
377 scm_putc (buf
[x
], port
);
387 scm_lfwrite (str_data
, sizeof (xwchar_t
), nitems
, port
);
411 f
= (FILE *)SCM_STREAM (port
);
412 i
= SCM_PTOBNUM (port
);
413 SCM_SYSCALL (c
= (scm_ptobs
[i
].fgetc
) (f
));
419 scm_gen_getc (SCM port
)
428 /* One char may be stored in the high bits of (car port) orre@nada.kth.se. */
429 if (SCM_CRDYP (port
))
431 c
= SCM_CGETUN (port
);
432 SCM_CLRDY (port
); /* Clear ungetted char */
451 switch (SCM_PORT_REPRESENTATION (port
))
453 case scm_regular_port
:
460 unsigned char buf
[256];
463 SCM_ASSERT (XMB_CUR_MAX
< sizeof (buf
), SCM_BOOL_F
,
464 "huge translation", "scm_gen_puts");
477 if (xmbtowc (&out
, buf
, x
+ 1) > 0)
483 SCM_ASSERT (x
< sizeof (buf
), SCM_BOOL_F
,
484 "huge translation", "scm_gen_getc");
494 hi
= scm_getc (port
);
512 scm_gen_ungetc (int c
, SCM port
)
515 scm_gen_ungetc (c
, port
)
520 /* SCM_ASSERT(!SCM_CRDYP(port), port, SCM_ARG2, "too many scm_gen_ungetc");*/
521 SCM_CUNGET (c
, port
);
524 /* What should col be in this case?
525 * We'll leave it at -1.
527 SCM_LINUM (port
) -= 1;