summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2019-07-16 14:36:21 +0200
committerPaweł Redman <pawel.redman@gmail.com>2019-07-16 14:36:21 +0200
commit5263c492592bf70d851db6f366b1d845bef98020 (patch)
treef275169e5073c11c635d15653c082e68de56045b
parent84887c191149b8b4d5a9ea4f78286477fe0a82b2 (diff)
Slightly better argv handling
-rw-r--r--src/common.h1
-rw-r--r--src/e2e.c4
-rw-r--r--src/main.c23
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"
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 <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
#include <math.h>
#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);