add pic_open_input_string

This commit is contained in:
Yuichi Nishiwaki 2014-06-25 15:39:40 +09:00
parent 83a13d4ca4
commit 0e66144a4d
2 changed files with 19 additions and 8 deletions

View File

@ -37,6 +37,7 @@ struct pic_port *pic_stdin(pic_state *);
struct pic_port *pic_stdout(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_string *pic_get_output_string(pic_state *, struct pic_port *);

View File

@ -54,6 +54,23 @@ port_new_stdport(pic_state *pic, xFILE *file, short dir)
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 *
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);
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);
port = pic_open_input_string(pic, str);
return pic_obj_value(port);
}