diff options
author | 2021-02-11 08:17:03 +0200 | |
---|---|---|
committer | 2021-02-11 08:17:03 +0200 | |
commit | 4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d (patch) | |
tree | 8d4e527e4a8ad76819e3baa1b89441eeb1081f15 /src/main.c | |
parent | 41efe7b8f9f67d5956ab677f3631478c48114ac1 (diff) | |
download | algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.tar.gz algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.tar.bz2 algos-ld1-4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d.zip |
continue the overhaul.
we can finally create a basic array input data file too!
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -26,9 +26,9 @@ static int stub_split(struct stream * const in, struct stream * const a, struct static int stub_flush(struct stream * const in); /* these need to go AFTER the stub declarations */ -static struct stream file_in = {stream_blank}; -static struct stream file_out = {stream_blank, .out = 1}; -static struct stream file_tmp = {stream_blank, .out = 2}; +static struct stream file_in = {stream_blank, .type = stream_in}; +static struct stream file_out = {stream_blank, .type = stream_out}; +static struct stream file_tmp = {stream_blank, .type = stream_outlite}; int main(int argc, char **argv) { @@ -39,10 +39,8 @@ int main(int argc, char **argv) if (settings.opmode == mode_generate) { file_in.name = randfile; - file_in.out = -1; + file_in.type = stream_chardev; file_in.n = settings.to; - file_in.cached = 1; - file_out.cached = 1; } else { file_in.name = settings.filein; } @@ -50,22 +48,22 @@ int main(int argc, char **argv) load_io_functions(&settings, &file_in); file_out.name = settings.fileout ? settings.fileout : settings.filein; - try_s((ret = stream_open(&file_in, &settings)), out); + try_s((ret = stream_open(&file_in)), out); file_out.n = file_in.n - settings.ss; - try_s((ret = stream_open(&file_out, &settings)), out); + try_s((ret = stream_open(&file_out)), out); load_io_functions(&settings, &file_out); if (settings.access == cached) { - try_s((ret = cache_create(&file_in, &settings)), out); + try_s((ret = cache_create(&file_in)), out); try_s((ret = cache_populate(&file_in)), out); switch (settings.opmode) { case mode_fetch: if (settings.format == array) { - try_s((ret = cache_block_copy(&file_in, &file_out, &settings)), out); + try_s((ret = cache_block_copy(&file_in, &file_out)), out); } else { /* settings.format == list */ - try_s((ret = cache_list_copy(&file_in, &file_out, &settings)), out); + try_s((ret = cache_list_copy(&file_in, &file_out)), out); } break; case mode_generate: @@ -76,8 +74,6 @@ int main(int argc, char **argv) ; } - try_s((ret = cache_flush(&file_out)), out); - } else { /* uncached */ /* TODO */ } @@ -88,7 +84,7 @@ int main(int argc, char **argv) while (0) { out: stream_close(&file_in); - file_out.out = 2; /* in case of error-exit, just close, don't link */ + file_out.type = stream_invalid; /* in case of error-exit, just close, don't link */ stream_close(&file_out); stream_close(&file_tmp); } @@ -184,19 +180,19 @@ int load_io_functions(struct settings const * const s, struct stream * const in) { int ret = 0; - if (in->out == 1) { + if (in->type == stream_out) { if (s->format == array) { /* TODO */ } else { /* TODO */ } - } else if (!in->out) { /* reading streams do not support dumping */ + } else if (in->type == stream_in) { /* reading streams do not support dumping */ if (s->format == array) { /* TODO */ } else { /* TODO */ } - } else { /* data generation streams do not support dumping nor any cache I/O beyond initial data generation */ + } else if (in->type == stream_chardev) { /* data generation streams do not support dumping nor any cache I/O beyond initial data generation */ if (s->format == array) { in->get_next_element_direct = gen_get_array; in->place_next_element_cache = cached_put_array; @@ -204,6 +200,8 @@ int load_io_functions(struct settings const * const s, struct stream * const in) in->get_next_element_direct = gen_get_list; in->place_next_element_cache = cached_put_list; } + } else { + ret = EINVAL; } return ret; |