diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-07-16 14:36:21 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-07-16 14:36:21 +0200 |
commit | 5263c492592bf70d851db6f366b1d845bef98020 (patch) | |
tree | f275169e5073c11c635d15653c082e68de56045b /src | |
parent | 84887c191149b8b4d5a9ea4f78286477fe0a82b2 (diff) |
Slightly better argv handling
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/e2e.c | 4 | ||||
-rw-r--r-- | src/main.c | 23 |
3 files changed, 20 insertions, 8 deletions
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 <inttypes.h> #include <stdio.h> #include <errno.h> +#include <string.h> #include <uthash.h> #include "eli.h" @@ -1,8 +1,4 @@ #include "common.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> #include <math.h> #include "e2e.h" @@ -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); |