-/* Copyright (C) 1995,1996,1998,1999 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999, 2000 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
\f
-#include "_scm.h"
+#include "libguile/_scm.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include "unif.h"
-#include "eval.h"
-#include "read.h"
+#include "libguile/unif.h"
+#include "libguile/eval.h"
+#include "libguile/ports.h"
+#include "libguile/read.h"
+#include "libguile/root.h"
+#include "libguile/strings.h"
+#include "libguile/modules.h"
-#include "strports.h"
+#include "libguile/strports.h"
#ifdef HAVE_STRING_H
#include <string.h>
static void
st_resize_port (scm_port *pt, off_t new_size)
{
+ 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 (pt->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 (pt->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;
if (target >= pt->write_buf_size)
{
- if (!(SCM_CARBITS (port) & SCM_WRTNG))
+ if (!(SCM_CELL_WORD_0 (port) & SCM_WRTNG))
{
if (target > pt->write_buf_size)
{
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_NEWCELL (z);
SCM_DEFER_INTS;
pt = scm_add_to_port_table (z);
- SCM_SETCAR (z, scm_tc16_strport | modes);
+ SCM_SET_CELL_TYPE (z, scm_tc16_strport | modes);
SCM_SETPTAB_ENTRY (z, pt);
- SCM_SETSTREAM (z, str);
- pt->write_buf = pt->read_buf = SCM_ROCHARS (str);
+ SCM_SETSTREAM (z, SCM_UNPACK (str));
+ pt->write_buf = pt->read_buf = SCM_ROUCHARS (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.
void
scm_init_strports ()
{
-#include "strports.x"
+#include "libguile/strports.x"
}
+
+/*
+ Local Variables:
+ c-file-style: "gnu"
+ End:
+*/