#include "common.h" #include #include #include #include #include #include "e2e.h" #include "export.h" int main(int argc, char **argv) { int ret = 0; char *inpath, outpath[4096]; int fd; struct stat st; void *input; struct e2e_data data; if (argc < 2) { fprintf(stderr, "%s [INPUT] (OUTPUT)\n", argv[0]); return 1; } inpath = argv[1]; fd = open(inpath, O_RDONLY); if (fd == -1) { perror("open"); return 1; } if (fstat(fd, &st) == -1) { perror("fstat"); ret = 1; goto error_mmap; } input = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (!input) { perror("mmap"); ret = 1; goto error_mmap; } if (errno = e2e_read(&data, input, input + st.st_size)) perror("e2e_read"); 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); munmap(input, st.st_size); error_mmap: close(fd); return ret; }