void pic_load_cstr(pic_state *pic, const char *src) { struct pic_port *port = pic_open_input_string(pic, src); pic_try { pic_load(pic, port); } pic_catch { pic_close_port(pic, port); pic_raise(pic, pic->err); } pic_close_port(pic, port); }
static pic_value pic_port_close_port(pic_state *pic) { struct pic_port *port; pic_get_args(pic, "p", &port); pic_close_port(pic, port); return pic_none_value(); }
pic_str * pic_vformat(pic_state *pic, const char *fmt, va_list ap) { struct pic_port *port; pic_str *str; port = pic_open_output_string(pic); pic_vfformat(pic, port->file, fmt, ap); str = pic_get_output_string(pic, port); pic_close_port(pic, port); return str; }
pic_value pic_xvformat(pic_state *pic, const char *fmt, va_list ap) { struct pic_port *port; pic_value irrs; port = pic_open_output_string(pic); irrs = pic_xvfformat(pic, port->file, fmt, ap); irrs = pic_cons(pic, pic_obj_value(pic_get_output_string(pic, port)), irrs); pic_close_port(pic, port); return irrs; }
static pic_value pic_port_call_with_port(pic_state *pic) { struct pic_port *port; struct pic_proc *proc; pic_value value; pic_get_args(pic, "pl", &port, &proc); value = pic_apply1(pic, proc, pic_obj_value(port)); pic_close_port(pic, port); return value; }
static pic_value pic_load_load(pic_state *pic) { pic_value envid; char *fn; struct pic_port *port; pic_get_args(pic, "z|o", &fn, &envid); port = pic_open_file(pic, fn, PIC_PORT_IN | PIC_PORT_TEXT); pic_load(pic, port); pic_close_port(pic, port); return pic_undef_value(); }
void pic_load(pic_state *pic, const char *filename) { struct pic_port *port; xFILE *file; file = xfopen(filename, "r"); if (file == NULL) { pic_errorf(pic, "could not open file: %s", filename); } port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT); port->file = file; port->flags = PIC_PORT_IN | PIC_PORT_TEXT; port->status = PIC_PORT_OPEN; pic_load_port(pic, port); pic_close_port(pic, port); }