mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 01:00:20 +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
|
@ -148,44 +148,8 @@ scm_do_read_line (SCM port, int *len_p)
|
|||
|
||||
/* I thought reading lines was simple. Mercy me. */
|
||||
|
||||
/* If there are any pushed-back characters, read the line character
|
||||
by character. */
|
||||
if (SCM_CRDYP (port))
|
||||
{
|
||||
int buf_size = 60;
|
||||
/* Invariant: buf always has buf_size + 1 characters allocated;
|
||||
the `+ 1' is for the final '\0'. */
|
||||
unsigned char *buf = malloc (buf_size + 1);
|
||||
int buf_len = 0;
|
||||
int c;
|
||||
|
||||
while ((c = scm_getc (port)) != EOF)
|
||||
{
|
||||
if (buf_len >= buf_size)
|
||||
{
|
||||
buf = realloc (buf, buf_size * 2 + 1);
|
||||
buf_size *= 2;
|
||||
}
|
||||
|
||||
buf[buf_len++] = c;
|
||||
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
/* Since SCM_CRDYP returned true, we ought to have gotten at
|
||||
least one character. */
|
||||
if (buf_len == 0)
|
||||
abort ();
|
||||
|
||||
buf[buf_len] = '\0';
|
||||
|
||||
*len_p = buf_len;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* The common case: no unread characters, and the buffer contains
|
||||
a complete line. This needs to be fast. */
|
||||
/* The common case: the buffer contains a complete line.
|
||||
This needs to be fast. */
|
||||
if ((end = memchr (pt->read_pos, '\n', (pt->read_end - pt->read_pos)))
|
||||
!= 0)
|
||||
{
|
||||
|
@ -202,7 +166,7 @@ scm_do_read_line (SCM port, int *len_p)
|
|||
return buf;
|
||||
}
|
||||
|
||||
/* There are no unread characters, and the buffer contains no newlines. */
|
||||
/* The buffer contains no newlines. */
|
||||
{
|
||||
/* When live, len is always the number of characters in the
|
||||
current buffer that are part of the current line. */
|
||||
|
@ -234,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_ptobs[SCM_PTOBNUM (port)].fill_buffer) (port);
|
||||
c = scm_fill_buffer (port, pt);
|
||||
if (c == EOF)
|
||||
{
|
||||
/* If we're missing a final newline in the file, return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue