From 5263c492592bf70d851db6f366b1d845bef98020 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 16 Jul 2019 14:36:21 +0200 Subject: Slightly better argv handling --- src/common.h | 1 + src/e2e.c | 4 ---- src/main.c | 23 +++++++++++++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/common.h b/src/common.h index 7f1e41c..5178855 100644 --- a/src/common.h +++ b/src/common.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "eli.h" diff --git a/src/e2e.c b/src/e2e.c index d842fd8..8473d64 100644 --- a/src/e2e.c +++ b/src/e2e.c @@ -1,8 +1,4 @@ #include "common.h" -#include -#include -#include -#include #include #include "e2e.h" diff --git a/src/main.c b/src/main.c index dcb5d06..de933be 100644 --- a/src/main.c +++ b/src/main.c @@ -11,14 +11,14 @@ int main(int argc, char **argv) { int ret = 0; - char *inpath; + char *inpath, outpath[4096]; int fd; struct stat st; void *input; struct e2e_data data; if (argc < 2) { - fprintf(stderr, "%s [FILE]\n", argv[0]); + fprintf(stderr, "%s [INPUT] (OUTPUT)\n", argv[0]); return 1; } @@ -45,8 +45,23 @@ int main(int argc, char **argv) if (errno = e2e_read(&data, input, input + st.st_size)) perror("e2e_read"); - else if (errno = export(&data, "testing.mat")) - perror("export"); + else { + // FIXME: ... + if (argc >= 3) + strcpy(outpath, argv[2]); + else { + int len = strlen(inpath); + + if (len >= 3 && (!strcmp(inpath + len - 4, ".e2e") + || !strcmp(inpath + len - 4, ".E2E"))) + sprintf(outpath, "%.*s.mat", len - 4, inpath); + else + sprintf(outpath, "%s.mat", inpath); + } + + if (errno = export(&data, outpath)) + perror("export"); + } e2e_destroy(&data); -- cgit