diff options
author | Gary Houston <ghouston@arglist.com> | 1999-07-04 11:50:54 +0000 |
---|---|---|
committer | Gary Houston <ghouston@arglist.com> | 1999-07-04 11:50:54 +0000 |
commit | 283a1a0e774770476d51aa47c6ee050f42d03957 (patch) | |
tree | 4b4e869bc6ec6c9aa327b5d932745648ad6350e1 | |
parent | 6c9514275ba36bfdeb3aefae16f10bc8b462f19e (diff) | |
download | guile-283a1a0e774770476d51aa47c6ee050f42d03957.tar.gz |
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.
-rw-r--r-- | libguile/ChangeLog | 22 | ||||
-rw-r--r-- | libguile/fports.c | 16 | ||||
-rw-r--r-- | libguile/ioext.c | 4 | ||||
-rw-r--r-- | libguile/ports.c | 47 | ||||
-rw-r--r-- | libguile/ports.h | 5 | ||||
-rw-r--r-- | libguile/strports.c | 2 | ||||
-rw-r--r-- | libguile/unif.c | 4 | ||||
-rw-r--r-- | libguile/vports.c | 2 |
8 files changed, 73 insertions, 29 deletions
diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 6ae18d3f3..b0b3f17bd 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -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.) diff --git a/libguile/fports.c b/libguile/fports.c index eb3f9408a..769bf5157 100644 --- a/libguile/fports.c +++ b/libguile/fports.c @@ -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; + + 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; diff --git a/libguile/ioext.c b/libguile/ioext.c index f282d94cb..08229765a 100644 --- a/libguile/ioext.c +++ b/libguile/ioext.c @@ -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); diff --git a/libguile/ports.c b/libguile/ports.c index 3a469ec68..7454ef1ce 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -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, diff --git a/libguile/ports.h b/libguile/ports.h index 8432a10a0..b08250835 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -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)); diff --git a/libguile/strports.c b/libguile/strports.c index d70db8872..dfec4f205 100644 --- a/libguile/strports.c +++ b/libguile/strports.c @@ -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); diff --git a/libguile/unif.c b/libguile/unif.c index 210a228ae..5889405a7 100644 --- a/libguile/unif.c +++ b/libguile/unif.c @@ -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) { diff --git a/libguile/vports.c b/libguile/vports.c index c122bf1ad..8c67d8b06 100644 --- a/libguile/vports.c +++ b/libguile/vports.c @@ -96,7 +96,7 @@ sfflush (SCM port) } static void -sf_read_flush (SCM port) +sf_read_flush (SCM port, int offset) { } |