diff --git a/include/villas/io.h b/include/villas/io.h index d073283c3..7405eec91 100644 --- a/include/villas/io.h +++ b/include/villas/io.h @@ -84,10 +84,6 @@ int io_print(struct io *io, struct sample *smps[], unsigned cnt); int io_scan(struct io *io, struct sample *smps[], unsigned cnt); -int io_scan_lines(struct io *io, struct sample *smps[], unsigned cnt); - -int io_print_lines(struct io *io, struct sample *smps[], unsigned cnt); - int io_eof(struct io *io); void io_rewind(struct io *io); diff --git a/lib/io.c b/lib/io.c index 2716122d8..07094b2fd 100644 --- a/lib/io.c +++ b/lib/io.c @@ -31,6 +31,54 @@ #include #include +static int io_print_lines(struct io *io, struct sample *smps[], unsigned cnt) +{ + int ret, i; + + FILE *f = io_stream_output(io); + + for (i = 0; i < cnt; i++) { + size_t wbytes; + + ret = format_type_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, &smps[i], 1, io->flags); + if (ret < 0) + return ret; + + fwrite(io->output.buffer, wbytes, 1, f); + } + + return i; +} + +static int io_scan_lines(struct io *io, struct sample *smps[], unsigned cnt) +{ + int ret, i; + + FILE *f = io_stream_input(io); + + for (i = 0; i < cnt; i++) { + size_t rbytes; + ssize_t bytes; + char *ptr; + +skip: bytes = getdelim(&io->input.buffer, &io->input.buflen, io->delimiter, f); + if (bytes < 0) + return -1; /* An error or eof occured */ + + /* Skip whitespaces, empty and comment lines */ + for (ptr = io->input.buffer; isspace(*ptr); ptr++); + + if (ptr[0] == '\0' || ptr[0] == '#') + goto skip; + + ret = format_type_sscan(io->_vt, io->input.buffer, bytes, &rbytes, &smps[i], 1, io->flags); + if (ret < 0) + return ret; + } + + return i; +} + int io_init(struct io *io, struct format_type *fmt, int flags) { io->_vt = fmt; @@ -353,54 +401,6 @@ int io_scan(struct io *io, struct sample *smps[], unsigned cnt) return ret; } -int io_print_lines(struct io *io, struct sample *smps[], unsigned cnt) -{ - int ret, i; - - FILE *f = io_stream_output(io); - - for (i = 0; i < cnt; i++) { - size_t wbytes; - - ret = format_type_sprint(io->_vt, io->output.buffer, io->output.buflen, &wbytes, &smps[i], 1, io->flags); - if (ret < 0) - return ret; - - fwrite(io->output.buffer, wbytes, 1, f); - } - - return i; -} - -int io_scan_lines(struct io *io, struct sample *smps[], unsigned cnt) -{ - int ret, i; - - FILE *f = io_stream_input(io); - - for (i = 0; i < cnt; i++) { - size_t rbytes; - ssize_t bytes; - char *ptr; - -skip: bytes = getdelim(&io->input.buffer, &io->input.buflen, io->delimiter, f); - if (bytes < 0) - return -1; /* An error or eof occured */ - - /* Skip whitespaces, empty and comment lines */ - for (ptr = io->input.buffer; isspace(*ptr); ptr++); - - if (ptr[0] == '\0' || ptr[0] == '#') - goto skip; - - ret = format_type_sscan(io->_vt, io->input.buffer, bytes, &rbytes, &smps[i], 1, io->flags); - if (ret < 0) - return ret; - } - - return i; -} - FILE * io_stream_output(struct io *io) { return io->mode == IO_MODE_ADVIO ? io->output.stream.adv->file