]> git.itanic.dy.fi Git - log-plotter/blobdiff - main.c
data.c: Add data parsing and output processing
[log-plotter] / main.c
diff --git a/main.c b/main.c
index 9ac44f9ea9487bdd7bc4887aa23468b23c08faf4..51e52605dafc2590a9cd160da1f2d014e0516d98 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,22 +1,16 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/epoll.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #include "options.h"
 #include "baud.h"
 #include "debug.h"
+#include "data.h"
 
 int main(int argc, char *argv[])
 {
-       struct epoll_event ev;
        struct plotter_options options;
-       int fd, baud, ret, out_fd = STDOUT_FILENO;
-       int epoll_fd;
-       char buf[256];
-
+       int fd, baud, ret = 0, out_fd = 0;
 
        if (read_args(argc, argv, &options))
                return 1;
@@ -47,42 +41,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       epoll_fd = epoll_create(1);
-
-       ev.events = EPOLLIN;
-       ev.data.fd = fd;
-       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
-               pr_err("epoll_ctl: %m\n");
-               return 1;
-       }
-
-       while (1) {
-               ret = epoll_wait(epoll_fd, &ev, 1, -1);
-               if (ret == 0)
-                       continue;
-
-               if (ret < 0) {
-                       pr_err("epoll: %m\n");
-                       return 1;
-               }
-
-               ret = read(fd, buf, sizeof(buf));
-               if (read < 0) {
-                       pr_err("read: %m\n");
-                       break;
-               }
-
-               if (ret == 0) {
-                       pr_err("Read EOF, stopping\n");
-                       break;
-               }
-
-               ret = write(1, buf, ret);
-               if (read < 0) {
-                       pr_err("write: %m\n");
-                       break;
-               }
-       }
+       read_data(fd, out_fd);
 
 out:
        close(fd);