From dbf73ecd7a5b12c90449e36e559165947bc55f9d Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jan 2014 00:02:58 +0900 Subject: [PATCH] refactor std ports --- src/port.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/port.c b/src/port.c index 9646a5b4..0f4a427f 100644 --- a/src/port.c +++ b/src/port.c @@ -156,7 +156,7 @@ pic_debug(pic_state *pic, pic_value obj) } static pic_value -make_port_from_fp(pic_state *pic, FILE *fp, short flags) +port_new_from_fp(pic_state *pic, FILE *fp, short flags) { struct pic_port *port; @@ -167,6 +167,12 @@ make_port_from_fp(pic_state *pic, FILE *fp, short flags) return pic_obj_value(port); } +static pic_value +port_new_stdio(pic_state *pic, FILE *fp, short dir) +{ + return port_new_from_fp(pic, fp, dir | PIC_PORT_TEXT); +} + static pic_value pic_port_input_port_p(pic_state *pic) { @@ -339,9 +345,9 @@ pic_port_close_port(pic_state *pic) void pic_init_port(pic_state *pic) { - pic_defvar(pic, "current-input-port", make_port_from_fp(pic, stdin, PIC_PORT_IN | PIC_PORT_TEXT)); - pic_defvar(pic, "current-output-port", make_port_from_fp(pic, stdout, PIC_PORT_OUT | PIC_PORT_TEXT)); - pic_defvar(pic, "current-error-port", make_port_from_fp(pic, stderr, PIC_PORT_OUT | PIC_PORT_TEXT)); + pic_defvar(pic, "current-input-port", port_new_stdio(pic, stdin, PIC_PORT_IN)); + pic_defvar(pic, "current-output-port", port_new_stdio(pic, stdout, PIC_PORT_OUT)); + pic_defvar(pic, "current-error-port", port_new_stdio(pic, stderr, PIC_PORT_OUT)); pic_defun(pic, "input-port?", pic_port_input_port_p); pic_defun(pic, "output-port?", pic_port_output_port_p);