1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

io: make io_{scan,print}_lines() static

This commit is contained in:
Steffen Vogel 2018-05-12 14:12:08 +02:00
parent c0313c7963
commit 00eac5a9b1
2 changed files with 48 additions and 52 deletions

View file

@ -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);

View file

@ -31,6 +31,54 @@
#include <villas/utils.h>
#include <villas/sample.h>
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