1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-19 02:00:26 +02:00

1999-07-04 Gary Houston <ghouston@easynet.co.uk>

* unif.c (scm_uniform_array_write): likewise.
	* ioext.c (scm_redirect_port): likewise.
	* ports.c (scm_putc): call scm_read_flush.
	(scm_puts): likewise.
	(scm_lfwrite): likewise.
	(scm_lseek): likewise.
	(scm_ftruncate): likewise.
	* ports.c (scm_fill_buffer): don't take pt argument.  change callers.
	(read_flush_void_port): new proc, for void port ptob.
	* vports.c (sf_read_flush): likewise.
	* strports.c (st_read_flush): take offset arg.
	* fports.c (local_read_flush): use offset, don't reset putback
	buffer here.
	* ports.h (scm_ptobfuns): let read_flush take an offset argument,
	which is the number of chars from the putback buffer.
	* ports.c (scm_read_flush): new procedure, resets the putback
	buffer before calling the ptob routine.
This commit is contained in:
Gary Houston 1999-07-04 11:50:54 +00:00
parent 6c9514275b
commit 283a1a0e77
8 changed files with 73 additions and 29 deletions

View file

@ -1,5 +1,27 @@
1999-07-04 Gary Houston <ghouston@easynet.co.uk>
* unif.c (scm_uniform_array_write): likewise.
* ioext.c (scm_redirect_port): likewise.
* ports.c (scm_putc): call scm_read_flush.
(scm_puts): likewise.
(scm_lfwrite): likewise.
(scm_lseek): likewise.
(scm_ftruncate): likewise.
* ports.c (scm_fill_buffer): don't take pt argument. change callers.
(read_flush_void_port): new proc, for void port ptob.
* vports.c (sf_read_flush): likewise.
* strports.c (st_read_flush): take offset arg.
* fports.c (local_read_flush): use offset, don't reset putback
buffer here.
* ports.h (scm_ptobfuns): let read_flush take an offset argument,
which is the number of chars from the putback buffer.
* ports.c (scm_read_flush): new procedure, resets the putback
buffer before calling the ptob routine.
* strports.c (scm_strprint_obj): bug fix: get pt from the port,
not from the parameter obj. (Thanks to Eric Moore.)

View file

@ -505,23 +505,15 @@ local_fflush (SCM port)
pt->rw_active = 0;
}
/* clear the read buffer and adjust the file position for unread bytes.
this is only called if the port has rw_random set. */
/* clear the read buffer and adjust the file position for unread bytes. */
static void
local_read_flush (SCM port)
local_read_flush (SCM port, int offset)
{
struct scm_fport *fp = SCM_FSTREAM (port);
scm_port *pt = SCM_PTAB_ENTRY (port);
int offset = pt->read_end - pt->read_pos;
if (pt->read_buf == pt->putback_buf)
{
pt->read_buf = pt->saved_read_buf;
pt->read_pos = pt->saved_read_pos;
pt->read_end = pt->saved_read_end;
pt->read_buf_size = pt->saved_read_buf_size;
offset += pt->read_end - pt->read_pos;
}
offset += pt->read_end - pt->read_pos;
if (offset > 0)
{
pt->read_pos = pt->read_end;

View file

@ -198,7 +198,7 @@ scm_do_read_line (SCM port, int *len_p)
/* Get more characters. I think having fill_buffer return a
character is not terribly graceful... */
c = scm_fill_buffer (port, pt);
c = scm_fill_buffer (port);
if (c == EOF)
{
/* If we're missing a final newline in the file, return
@ -360,7 +360,7 @@ scm_redirect_port (old, new)
if (pt->rw_active == SCM_PORT_WRITE)
ptob->fflush (new);
else if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (new);
scm_read_flush (new);
ans = dup2 (oldfd, newfd);
if (ans == -1)
scm_syserror (s_redirect_port);

View file

@ -629,9 +629,10 @@ scm_read_char (port)
}
int
scm_fill_buffer (SCM port, scm_port *pt)
/* port and pt refer to the same port. */
scm_fill_buffer (SCM port)
{
scm_port *pt = SCM_PTAB_ENTRY (port);
if (pt->read_buf == pt->putback_buf)
{
/* finished reading put-back chars. */
@ -664,7 +665,7 @@ scm_getc (port)
}
else
{
c = scm_fill_buffer (port, pt);
c = scm_fill_buffer (port);
}
if (pt->rw_random)
@ -695,7 +696,7 @@ scm_putc (c, port)
scm_ptobfuns *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (port);
scm_read_flush (port);
*(pt->write_pos++) = (char) c;
@ -715,7 +716,8 @@ scm_puts (s, port)
scm_ptobfuns *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (port);
scm_read_flush (port);
while (*s != 0)
{
*pt->write_pos++ = *s++;
@ -741,7 +743,8 @@ scm_lfwrite (ptr, size, port)
scm_ptobfuns *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (port);
scm_read_flush (port);
while (size > 0)
{
int space = pt->write_end - pt->write_pos;
@ -772,6 +775,27 @@ scm_fflush (port)
(scm_ptobs[i].fflush) (port);
}
void
scm_read_flush (port)
SCM port;
{
int offset;
scm_port *pt = SCM_PTAB_ENTRY (port);
if (pt->read_buf == pt->putback_buf)
{
offset = pt->read_end - pt->read_pos;
pt->read_buf = pt->saved_read_buf;
pt->read_pos = pt->saved_read_pos;
pt->read_end = pt->saved_read_end;
pt->read_buf_size = pt->saved_read_buf_size;
}
else
offset = 0;
scm_ptobs[SCM_PTOBNUM (port)].read_flush (port, offset);
}
@ -956,7 +980,7 @@ scm_lseek (SCM object, SCM offset, SCM whence)
else
{
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (object);
scm_read_flush (object);
else if (pt->rw_active == SCM_PORT_WRITE)
ptob->fflush (object);
@ -994,7 +1018,7 @@ scm_ftruncate (SCM port, SCM length)
length = scm_lseek (port, SCM_INUM0, SCM_MAKINUM (SEEK_CUR));
}
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (port);
scm_read_flush (port);
else if (pt->rw_active == SCM_PORT_WRITE)
ptob->fflush (port);
@ -1165,6 +1189,11 @@ flush_void_port (SCM port)
{
}
static void
read_flush_void_port (SCM port, int offset)
{
}
static int
close_void_port (SCM port)
{
@ -1187,7 +1216,7 @@ static struct scm_ptobfuns void_port_ptob =
print_void_port,
0, /* equal? */
flush_void_port,
flush_void_port,
read_flush_void_port,
close_void_port,
0,
0,

View file

@ -176,7 +176,7 @@ typedef struct scm_ptobfuns
int (*print) (SCM exp, SCM port, scm_print_state *pstate);
SCM (*equalp) (SCM, SCM);
void (*fflush) (SCM port);
void (*read_flush) (SCM port);
void (*read_flush) (SCM port, int offset);
int (*fclose) (SCM port);
int (*fill_buffer) (SCM port);
off_t (*seek) (SCM port, off_t OFFSET, int WHENCE);
@ -227,7 +227,8 @@ extern void scm_putc SCM_P ((int c, SCM port));
extern void scm_puts SCM_P ((char *str_data, SCM port));
extern void scm_lfwrite SCM_P ((char *ptr, scm_sizet size, SCM port));
extern void scm_fflush SCM_P ((SCM port));
extern int scm_fill_buffer (SCM port, scm_port *pt);
extern void scm_read_flush (SCM port);
extern int scm_fill_buffer (SCM port);
extern int scm_getc SCM_P ((SCM port));
extern void scm_ungetc SCM_P ((int c, SCM port));
extern void scm_ungets SCM_P ((char *s, int n, SCM port));

View file

@ -114,7 +114,7 @@ st_flush (SCM port)
}
static void
st_read_flush (SCM port)
st_read_flush (SCM port, int offset)
{
scm_port *pt = SCM_PTAB_ENTRY (port);

View file

@ -1564,7 +1564,7 @@ loop:
}
else
{
int ch = scm_fill_buffer (port_or_fd, pt);
int ch = scm_fill_buffer (port_or_fd);
if (ch == EOF)
{
@ -1704,7 +1704,7 @@ loop:
ans = cend - offset;
if (pt->rw_active == SCM_PORT_READ)
ptob->read_flush (port_or_fd);
scm_read_flush (port_or_fd);
while (remaining > 0)
{

View file

@ -96,7 +96,7 @@ sfflush (SCM port)
}
static void
sf_read_flush (SCM port)
sf_read_flush (SCM port, int offset)
{
}