X-Git-Url: http://git.hcoop.net/bpt/guile.git/blobdiff_plain/cd07a09755e2ce18ad9f156d60997c3ec6695460..c69dfa6575e6de1063f91a1a9a94808e404f06d0:/libguile/strports.c diff --git a/libguile/strports.c b/libguile/strports.c index 48d5c088f..4e0ea1a8b 100644 --- a/libguile/strports.c +++ b/libguile/strports.c @@ -12,7 +12,8 @@ * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA * * As a special exception, the Free Software Foundation gives permission * for additional uses of the text contained in its release of GUILE. @@ -36,8 +37,7 @@ * * If you write modifications of your own for GUILE, it is your choice * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - */ + * If you do not wish that, delete this exception notice. */ #include @@ -229,10 +229,10 @@ scm_call_with_input_string (str, proc) -/* Given a null-terminated string EXPR containing Scheme program text, - evaluate it, and discard the result. */ -void -scm_eval_0str (expr) +/* Given a null-terminated string EXPR containing a Scheme expression + read it, and return it as an SCM value. */ +SCM +scm_read_0str (expr) char *expr; { SCM port = scm_mkstrport (SCM_MAKINUM (0), @@ -242,12 +242,46 @@ scm_eval_0str (expr) SCM form; /* Read expressions from that port; ignore the values. */ - while ((form = scm_read (port, SCM_BOOL_F, SCM_BOOL_F)) != SCM_EOF_VAL) - scm_eval_x (form); + form = scm_read (port); scm_close_port (port); + return form; } +/* Given a null-terminated string EXPR containing Scheme program text, + evaluate it, and return the result of the last expression evaluated. */ +SCM +scm_eval_0str (expr) + char *expr; +{ + return scm_eval_string (scm_makfrom0str (expr)); +} + + +SCM_PROC (s_eval_string, "eval-string", 1, 0, 0, scm_eval_string); + +SCM +scm_eval_string (string) + SCM string; +{ + SCM port = scm_mkstrport (SCM_MAKINUM (0), string, SCM_OPN | SCM_RDNG, + "scm_eval_0str"); + SCM form; + SCM ans = SCM_UNSPECIFIED; + + /* Read expressions from that port; ignore the values. */ + while (!SCM_EOF_OBJECT_P (form = scm_read (port))) + ans = scm_eval_x (form); + + /* 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. + It's a string port anyway, so there's no advantage to closing it + early. */ + + return ans; +} + + static int noop0 SCM_P ((SCM stream)); @@ -270,6 +304,7 @@ scm_ptobfuns scm_stptob = stwrite, noop0, stgetc, + scm_generic_fgets, 0 };