#include "libguile/read.h"
#include "libguile/root.h"
#include "libguile/strings.h"
-#include "libguile/vectors.h"
+#include "libguile/modules.h"
#include "libguile/strports.h"
when rw_active is SCM_PORT_NEITHER.
*/
+
+static scm_bits_t scm_tc16_strport;
+
+
static int
stfill_buffer (SCM port)
{
static void
st_resize_port (scm_port *pt, off_t new_size)
{
- SCM stream = SCM_PACK (pt->stream);
+ SCM old_stream = SCM_PACK (pt->stream);
+ SCM new_stream = scm_makstr (new_size, 0);
+ unsigned long int old_size = SCM_STRING_LENGTH (old_stream);
+ unsigned long int min_size = min (old_size, new_size);
+ unsigned long int i;
off_t index = pt->write_pos - pt->write_buf;
pt->write_buf_size = new_size;
- scm_vector_set_length_x (stream, SCM_MAKINUM (new_size));
+ for (i = 0; i != min_size; ++i)
+ SCM_STRING_CHARS (new_stream) [i] = SCM_STRING_CHARS (old_stream) [i];
- /* reset buffer in case reallocation moved the string. */
+ /* reset buffer. */
{
- pt->read_buf = pt->write_buf = SCM_CHARS (stream);
+ pt->stream = new_stream;
+ pt->read_buf = pt->write_buf = SCM_STRING_UCHARS (new_stream);
pt->read_pos = pt->write_pos = pt->write_buf + index;
pt->write_end = pt->write_buf + pt->write_buf_size;
pt->read_end = pt->read_buf + pt->read_buf_size;
int space = pt->write_end - pt->write_pos;
int write_len = (size > space) ? space : size;
- strncpy (pt->write_pos, input, write_len);
+ strncpy ((char *) pt->write_pos, input, write_len);
pt->write_pos += write_len;
size -= write_len;
input += write_len;
int str_len;
SCM_ASSERT (SCM_INUMP(pos) && SCM_INUM(pos) >= 0, pos, SCM_ARG1, caller);
- SCM_ASSERT (SCM_ROSTRINGP(str), str, SCM_ARG1, caller);
- str_len = SCM_ROLENGTH (str);
+ SCM_ASSERT (SCM_STRINGP (str), str, SCM_ARG1, caller);
+ str_len = SCM_STRING_LENGTH (str);
if (SCM_INUM (pos) > str_len)
scm_out_of_range (caller, pos);
if (!((modes & SCM_WRTNG) || (modes & SCM_RDNG)))
SCM_SET_CELL_TYPE (z, scm_tc16_strport | modes);
SCM_SETPTAB_ENTRY (z, pt);
SCM_SETSTREAM (z, SCM_UNPACK (str));
- pt->write_buf = pt->read_buf = SCM_ROCHARS (str);
+ pt->write_buf = pt->read_buf = SCM_STRING_UCHARS (str);
pt->read_pos = pt->write_pos = pt->read_buf + SCM_INUM (pos);
pt->write_buf_size = pt->read_buf_size = str_len;
pt->write_end = pt->read_end = pt->read_buf + pt->read_buf_size;
if (pt->rw_active == SCM_PORT_WRITE)
st_flush (port);
- return scm_makfromstr (pt->read_buf, pt->read_buf_size, 0);
+ return scm_makfromstr ((char *) pt->read_buf, pt->read_buf_size, 0);
}
SCM_DEFINE (scm_call_with_output_string, "call-with-output-string", 1, 0, 0,
SCM_DEFINE (scm_eval_string, "eval-string", 1, 0, 0,
(SCM string),
"Evaluate @var{string} as the text representation of a Scheme form\n"
- "or forms, and return whatever value they produce.")
+ "or forms, and return whatever value they produce.\n"
+ "Evaluation takes place in (interaction-environment).")
#define FUNC_NAME s_scm_eval_string
{
SCM port = scm_mkstrport (SCM_INUM0, string, SCM_OPN | SCM_RDNG,
"scm_eval_0str");
SCM form;
SCM ans = SCM_UNSPECIFIED;
+ SCM module = scm_interaction_environment ();
/* Read expressions from that port; ignore the values. */
while (!SCM_EOF_OBJECT_P (form = scm_read (port)))
- ans = scm_eval_x (form);
+ ans = scm_eval_x (form, module);
/* Don't close the port here; if we re-enter this function via a
continuation, then the next time we enter it, we'll get an error.
}
#undef FUNC_NAME
-void scm_make_stptob (void); /* Called from ports.c */
-
-void
+static scm_bits_t
scm_make_stptob ()
{
- long tc = scm_make_port_type ("string", stfill_buffer, st_write);
+ scm_bits_t tc = scm_make_port_type ("string", stfill_buffer, st_write);
+
scm_set_port_mark (tc, scm_markstream);
scm_set_port_end_input (tc, st_end_input);
scm_set_port_flush (tc, st_flush);
scm_set_port_seek (tc, st_seek);
scm_set_port_truncate (tc, st_truncate);
+
+ return tc;
}
void
scm_init_strports ()
{
+ scm_tc16_strport = scm_make_stptob ();
+
+#ifndef SCM_MAGIC_SNARFER
#include "libguile/strports.x"
+#endif
}