* 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.
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.)
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;
+
+ 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;
- }
if (offset > 0)
{
pt->read_pos = pt->read_end;
/* 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
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);
}
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. */
}
else
{
- c = scm_fill_buffer (port, pt);
+ c = scm_fill_buffer (port);
}
if (pt->rw_random)
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;
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++;
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;
(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);
+}
+
\f
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);
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);
{
}
+static void
+read_flush_void_port (SCM port, int offset)
+{
+}
+
static int
close_void_port (SCM port)
{
print_void_port,
0, /* equal? */
flush_void_port,
- flush_void_port,
+ read_flush_void_port,
close_void_port,
0,
0,
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);
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));
}
static void
-st_read_flush (SCM port)
+st_read_flush (SCM port, int offset)
{
scm_port *pt = SCM_PTAB_ENTRY (port);
}
else
{
- int ch = scm_fill_buffer (port_or_fd, pt);
+ int ch = scm_fill_buffer (port_or_fd);
if (ch == EOF)
{
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)
{
}
static void
-sf_read_flush (SCM port)
+sf_read_flush (SCM port, int offset)
{
}