mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-30 06:50:31 +02:00
(scm_with_current_input_port, scm_with_current_output_port,
scm_with_current_error_port): New.
This commit is contained in:
parent
b57a0953fe
commit
185e369a7f
2 changed files with 60 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -31,6 +31,7 @@
|
|||
#include "libguile/objects.h"
|
||||
#include "libguile/smob.h"
|
||||
#include "libguile/chars.h"
|
||||
#include "libguile/dynwind.h"
|
||||
|
||||
#include "libguile/keywords.h"
|
||||
#include "libguile/root.h"
|
||||
|
@ -425,6 +426,60 @@ SCM_DEFINE (scm_set_current_error_port, "set-current-error-port", 1, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
typedef struct {
|
||||
SCM value;
|
||||
SCM (*getter) (void);
|
||||
SCM (*setter) (SCM);
|
||||
} swap_data;
|
||||
|
||||
static void
|
||||
swap_port (void *data)
|
||||
{
|
||||
swap_data *d = (swap_data *)data;
|
||||
SCM t;
|
||||
|
||||
t = d->getter ();
|
||||
d->setter (d->value);
|
||||
d->value = t;
|
||||
}
|
||||
|
||||
static void
|
||||
scm_with_current_foo_port (SCM port,
|
||||
SCM (*getter) (void), SCM (*setter) (SCM))
|
||||
{
|
||||
swap_data data;
|
||||
data.value = port;
|
||||
data.getter = getter;
|
||||
data.setter = setter;
|
||||
|
||||
scm_on_rewind (swap_port, &data, SCM_F_WIND_EXPLICITELY);
|
||||
scm_on_unwind (swap_port, &data, SCM_F_WIND_EXPLICITELY);
|
||||
}
|
||||
|
||||
void
|
||||
scm_with_current_input_port (SCM port)
|
||||
{
|
||||
scm_with_current_foo_port (port,
|
||||
scm_current_input_port,
|
||||
scm_set_current_input_port);
|
||||
}
|
||||
|
||||
void
|
||||
scm_with_current_output_port (SCM port)
|
||||
{
|
||||
scm_with_current_foo_port (port,
|
||||
scm_current_output_port,
|
||||
scm_set_current_output_port);
|
||||
}
|
||||
|
||||
void
|
||||
scm_with_current_error_port (SCM port)
|
||||
{
|
||||
scm_with_current_foo_port (port,
|
||||
scm_current_error_port,
|
||||
scm_set_current_error_port);
|
||||
}
|
||||
|
||||
|
||||
/* The port table --- an array of pointers to ports. */
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef SCM_PORTS_H
|
||||
#define SCM_PORTS_H
|
||||
|
||||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -235,6 +235,9 @@ SCM_API SCM scm_current_load_port (void);
|
|||
SCM_API SCM scm_set_current_input_port (SCM port);
|
||||
SCM_API SCM scm_set_current_output_port (SCM port);
|
||||
SCM_API SCM scm_set_current_error_port (SCM port);
|
||||
SCM_API void scm_with_current_input_port (SCM port);
|
||||
SCM_API void scm_with_current_output_port (SCM port);
|
||||
SCM_API void scm_with_current_error_port (SCM port);
|
||||
SCM_API SCM scm_new_port_table_entry (scm_t_bits tag);
|
||||
SCM_API void scm_remove_from_port_table (SCM port);
|
||||
SCM_API void scm_grow_port_cbuf (SCM port, size_t requested);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue