add pic_open_input_string
This commit is contained in:
parent
83a13d4ca4
commit
0e66144a4d
|
@ -37,6 +37,7 @@ struct pic_port *pic_stdin(pic_state *);
|
||||||
struct pic_port *pic_stdout(pic_state *);
|
struct pic_port *pic_stdout(pic_state *);
|
||||||
struct pic_port *pic_stderr(pic_state *);
|
struct pic_port *pic_stderr(pic_state *);
|
||||||
|
|
||||||
|
struct pic_port *pic_open_input_string(pic_state *, const char *);
|
||||||
struct pic_port *pic_open_output_string(pic_state *);
|
struct pic_port *pic_open_output_string(pic_state *);
|
||||||
struct pic_string *pic_get_output_string(pic_state *, struct pic_port *);
|
struct pic_string *pic_get_output_string(pic_state *, struct pic_port *);
|
||||||
|
|
||||||
|
|
26
src/port.c
26
src/port.c
|
@ -54,6 +54,23 @@ port_new_stdport(pic_state *pic, xFILE *file, short dir)
|
||||||
return pic_obj_value(port);
|
return pic_obj_value(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pic_port *
|
||||||
|
pic_open_input_string(pic_state *pic, const char *str)
|
||||||
|
{
|
||||||
|
struct pic_port *port;
|
||||||
|
|
||||||
|
port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port *), PIC_TT_PORT);
|
||||||
|
port->file = xmopen();
|
||||||
|
port->flags = PIC_PORT_IN | PIC_PORT_TEXT;
|
||||||
|
port->status = PIC_PORT_OPEN;
|
||||||
|
|
||||||
|
xfputs(str, port->file);
|
||||||
|
xfflush(port->file);
|
||||||
|
xrewind(port->file);
|
||||||
|
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
struct pic_port *
|
struct pic_port *
|
||||||
pic_open_output_string(pic_state *pic)
|
pic_open_output_string(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -268,14 +285,7 @@ pic_port_open_input_string(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "z", &str);
|
pic_get_args(pic, "z", &str);
|
||||||
|
|
||||||
port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port *), PIC_TT_PORT);
|
port = pic_open_input_string(pic, str);
|
||||||
port->file = xmopen();
|
|
||||||
port->flags = PIC_PORT_IN | PIC_PORT_TEXT;
|
|
||||||
port->status = PIC_PORT_OPEN;
|
|
||||||
|
|
||||||
xfputs(str, port->file);
|
|
||||||
xfflush(port->file);
|
|
||||||
xrewind(port->file);
|
|
||||||
|
|
||||||
return pic_obj_value(port);
|
return pic_obj_value(port);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue