int io_template_set_template_string(io_template_t *T, const char *tpl) { if (T == NULL) { return -1; } sdsfree(T->name); sdsfree(T->code); T->name = sdsnew("(Io:main)"); T->code = io_parser_parse(tpl, T->config); return 0; }
static void test_parser_parse(const char *tpl, const char *exp, const char *msg) { sds code; io_config_t *config = io_config_new_default(); code = io_parser_parse(tpl, config); if (code) { str_eq(code, exp, msg); } io_config_free(config); sdsfree(code); }
/** * io_input_process - process currently available input */ int io_input_process(struct io_input *input, int *error) { enum io_parser_ret eret; bool end_of_input; int ret; *error = 0; ret = io_input_read(input, error); /* non-blocking */ if (ret == 0) { /* no new input */ return 0; } /* End of input, let parser handle end of file */ end_of_input = (ret < 0); /* might modify buffer or leave as is if not enough input yet */ eret = io_parser_parse(input->parser, &input->inbuf, end_of_input); if (end_of_input && ds_append_buffer_length(&input->inbuf) > 0) { /* * At end of data, clear buffer. * Parser had chance to handle the data. */ ds_append_buffer_free(&input->inbuf); ds_append_buffer_init(&input->inbuf); } switch (eret) { case IO_PARSER_RET_CONTINUE: if (end_of_input) return -1; return 0; case IO_PARSER_RET_QUEUE_FULL: return 1; case IO_PARSER_RET_ERROR: default: return -1; } }