mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-14 23:50:19 +02:00
1999-07-04 Gary Houston <ghouston@easynet.co.uk>
* strports.c (scm_strprint_obj): bug fix: get pt from the port, not from the parameter obj. (Thanks to Eric Moore.) * ports.h: SCM_CRDY, SCM_CUC, SCM_CRDYP, SCM_SETRDY, SCM_CUNGET, SCM_CGETUN, SCM_CLRDY, SCM_TRY_CLRDY, SCM_N_READY_CHARS: deleted. * strings.c (scm_make_string): throw error if 2nd arg isn't a char. * unif.c (scm_uniform_array_read_x): fix reading from a port. allow non-fports. (scm_uniform_array_write): likewise. 1999-06-29 Gary Houston <ghouston@easynet.co.uk> * ports.c (scm_drain_input): rewritten. * fports.c (local_fclose): check putback_buf. (local_read_flush): likewise. * ports.c (scm_remove_from_port_table): maybe free putback_buf. * ports.h (scm_port): replace cbuf/cbufend/cp with putback_buf/ putback_buf_size. (SCM_INITIAL_PUTBACK_BUF_SIZE): renamed from SCM_INITIAL_CBUF_SIZE. * ports.c (scm_grow_port_cbuf): deleted. (scm_add_to_port_table): initialise putback_buf to 0. remove cbuf stuff. (scm_char_ready_p): check putback_buf (scm_fill_buffer): likewise. (scm_ungetc): rewritten. 1999-06-27 Gary Houston <ghouston@easynet.co.uk> * fports.c (local_fclose): account for push-back buffer. * ports.c (scm_char_ready_p): check the push-back buffer in a new way. * ioext.c (scm_do_read_line): remove the extra code to handle the push-back buffer. * ports.c (scm_getc): don't use SCM_CRDYP etc. * ioext.c (scm_do_read_line): call scm_fill_buffer. * ports.c (scm_ungetc): don't call SCM_CUNGET. reset the read buffer pointers. scm_fill_buffer: new procedure. (scm_getc): call scm_fill_buffer. * ports.h (struct scm_port): saved_read_buf, saved_read_pos, saved_read_end: new fields. 1999-07-04 Gary Houston <ghouston@easynet.co.uk> * configure.in: don't check for ways to violate stdio abstraction.
This commit is contained in:
parent
ab41a129a8
commit
6c9514275b
23 changed files with 631 additions and 1655 deletions
|
@ -1469,7 +1469,7 @@ scm_uniform_array_read_x (ra, port_or_fd, start, end)
|
|||
port_or_fd = scm_cur_inp;
|
||||
else
|
||||
SCM_ASSERT (SCM_INUMP (port_or_fd)
|
||||
|| (SCM_NIMP (port_or_fd) && SCM_OPINFPORTP (port_or_fd)),
|
||||
|| (SCM_NIMP (port_or_fd) && SCM_OPINPORTP (port_or_fd)),
|
||||
port_or_fd, SCM_ARG2, s_uniform_array_read_x);
|
||||
vlen = SCM_LENGTH (v);
|
||||
|
||||
|
@ -1542,18 +1542,49 @@ loop:
|
|||
|
||||
if (SCM_NIMP (port_or_fd))
|
||||
{
|
||||
/* if we have stored a character from the port in our own buffer,
|
||||
push it back onto the stream. */
|
||||
/* An ungetc before an fread will not work on some systems if
|
||||
setbuf(0). do #define NOSETBUF in scmfig.h to fix this. */
|
||||
if (SCM_CRDYP (port_or_fd))
|
||||
scm_port *pt = SCM_PTAB_ENTRY (port_or_fd);
|
||||
int remaining = (cend - offset) * sz;
|
||||
char *dest = SCM_CHARS (v) + (cstart + offset) * sz;
|
||||
|
||||
if (pt->rw_active == SCM_PORT_WRITE)
|
||||
scm_fflush (port_or_fd);
|
||||
|
||||
ans = cend - offset;
|
||||
while (remaining > 0)
|
||||
{
|
||||
ungetc (SCM_CGETUN (port_or_fd), (FILE *)SCM_STREAM (port_or_fd));
|
||||
SCM_CLRDY (port_or_fd); /* Clear ungetted char */
|
||||
if (pt->read_pos < pt->read_end)
|
||||
{
|
||||
int to_copy = min (pt->read_end - pt->read_pos,
|
||||
remaining);
|
||||
|
||||
memcpy (dest, pt->read_pos, to_copy);
|
||||
pt->read_pos += to_copy;
|
||||
remaining -= to_copy;
|
||||
dest += to_copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ch = scm_fill_buffer (port_or_fd, pt);
|
||||
|
||||
if (ch == EOF)
|
||||
{
|
||||
if (remaining % sz != 0)
|
||||
{
|
||||
scm_misc_error (s_uniform_array_read_x,
|
||||
"unexpected EOF",
|
||||
SCM_EOL);
|
||||
}
|
||||
ans -= remaining / sz;
|
||||
break;
|
||||
}
|
||||
|
||||
*dest++ = ch;
|
||||
remaining--;
|
||||
}
|
||||
}
|
||||
SCM_SYSCALL (ans = fread (SCM_CHARS (v) + (cstart + offset) * sz,
|
||||
(scm_sizet) sz, (scm_sizet) (cend - offset),
|
||||
(FILE *)SCM_STREAM (port_or_fd)));
|
||||
|
||||
if (pt->rw_random)
|
||||
pt->rw_active = SCM_PORT_READ;
|
||||
}
|
||||
else /* file descriptor. */
|
||||
{
|
||||
|
@ -1593,7 +1624,7 @@ scm_uniform_array_write (v, port_or_fd, start, end)
|
|||
port_or_fd = scm_cur_outp;
|
||||
else
|
||||
SCM_ASSERT (SCM_INUMP (port_or_fd)
|
||||
|| (SCM_NIMP (port_or_fd) && SCM_OPOUTFPORTP (port_or_fd)),
|
||||
|| (SCM_NIMP (port_or_fd) && SCM_OPOUTPORTP (port_or_fd)),
|
||||
port_or_fd, SCM_ARG2, s_uniform_array_write);
|
||||
vlen = SCM_LENGTH (v);
|
||||
|
||||
|
@ -1666,9 +1697,31 @@ loop:
|
|||
|
||||
if (SCM_NIMP (port_or_fd))
|
||||
{
|
||||
SCM_SYSCALL (ans = fwrite (SCM_CHARS (v) + (cstart + offset) * sz,
|
||||
(scm_sizet) sz, (scm_sizet) (cend - offset),
|
||||
(FILE *)SCM_STREAM (port_or_fd)));
|
||||
scm_port *pt = SCM_PTAB_ENTRY (port_or_fd);
|
||||
int remaining = (cend - offset) * sz;
|
||||
char *source = SCM_CHARS (v) + (cstart + offset) * sz;
|
||||
scm_ptobfuns *ptob = &scm_ptobs[SCM_PTOBNUM (port_or_fd)];
|
||||
|
||||
ans = cend - offset;
|
||||
if (pt->rw_active == SCM_PORT_READ)
|
||||
ptob->read_flush (port_or_fd);
|
||||
|
||||
while (remaining > 0)
|
||||
{
|
||||
int to_copy = min (pt->write_end - pt->write_pos, remaining);
|
||||
|
||||
memcpy (pt->write_pos, source, to_copy);
|
||||
pt->write_pos += to_copy;
|
||||
source += to_copy;
|
||||
remaining -= to_copy;
|
||||
if (pt->write_pos == pt->write_end)
|
||||
ptob->fflush (port_or_fd);
|
||||
}
|
||||
|
||||
if (pt->rw_random)
|
||||
{
|
||||
pt->rw_active = SCM_PORT_WRITE;
|
||||
}
|
||||
}
|
||||
else /* file descriptor. */
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue