diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -1,8 +1,10 @@ +#include <unistd.h> #include <errno.h> #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "io.h" static struct settings_s { size_t fetchpos; @@ -12,6 +14,9 @@ static struct settings_s { int mode; } settings = {0}; +static struct stream file_in = {.fd = -1}; +static struct stream file_out = {.fd = -1}; + static int parseargs(int argc, char **argv, struct settings_s * settings); void printhelp(const char * const name); @@ -23,7 +28,25 @@ int main(int argc, char **argv) goto out; } + file_in.name = settings.filein; + file_in.stride = 0; /* TODO */ + + if ((ret = openstream(&file_in))) { + goto out; + } + + file_out.name = settings.fileout ? settings.fileout : settings.filein; + file_out.out = 1; + file_out.n = file_in.n; + file_out.stride = 0; /* TODO */ + + if ((ret = openstream(&file_out))) { + goto out; + } + out: + close(file_in.fd); + close(file_out.fd); return ret; } @@ -39,9 +62,9 @@ static int parseargs(int argc, char **argv, struct settings_s * settings) for (i = 1; i < argc - 1; ++i) { if (!(strcmp(argv[i], "--sort"))) { - s.mode = 0; + s.mode &= ~1; } else if (!(strcmp(argv[i], "--fetch"))) { - s.mode = 1; + s.mode |= 1; } else if (!(strncmp(argv[i], "--position=", 11))) { if (strlen(argv[i]) > 11) { s.fetchpos = strtoul(argv[i] + 11, NULL, 10); @@ -71,7 +94,14 @@ static int parseargs(int argc, char **argv, struct settings_s * settings) s.filein = argv[i]; } + if (!s.fileout) { + s.fileout = s.filein; + } + + s.fetchto = s.fetchpos + s.fetchto; + *settings = s; + if (0) { err: ret = EINVAL; |