Add TODOs
[khatus.git] / x5 / khatus.c
index a41351a..5f283db 100644 (file)
@@ -1,6 +1,8 @@
+
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/select.h>
+#include <sys/stat.h>
 
 #include <assert.h>
 #include <ctype.h>
@@ -17,6 +19,7 @@
 
 char *argv0;
 
+/* TODO: Convert file list to file array. */
 typedef struct File File;
 struct File {
        char   *name;
@@ -235,27 +238,21 @@ opts_parse(Config *cfg, int argc, char *argv[], int i)
 void
 read_one(File *f, char *buf)
 {
-       ssize_t n;
+       ssize_t current;
+       ssize_t total;
        char *b;
+       char c;
 
+       current = 0;
+       total = 0;
+       c = '\0';
        b = buf + f->pos;
        memset(b, ' ', f->width);
-       while ((n = read(f->fd, b, f->width)) > 0) {
-               b += n;
-               debug("read %zd from %s\n", n, f->name);
-       }
-
-       if (n > -1) {
-               if (*(b - 1) == '\n')
-                       *(b - 1) = ' ';
-       } else {
-               error(
-                       "Failed to read: \"%s\". Error: %s\n",
-                       f->name,
-                       strerror(errno)
-               );
-       }
-
+       while ((current = read(f->fd, &c, 1)) && c != '\n' && c != '\0' && total++ < f->width)
+               *b++ = c;
+       if (current == -1)
+               error("Failed to read: \"%s\". Error: %s\n", f->name, strerror(errno));
+       /* TODO Record timestamp read */
        close(f->fd);
        f->fd = -1;
 }
@@ -266,11 +263,17 @@ read_all(Config *cfg, char *buf)
        fd_set fds;
        int maxfd;
        int ready;
+       struct stat st;
 
        FD_ZERO(&fds);
 
-       /* TODO: stat then check TTL */
+       /* TODO: Check TTL */
        for (File *f = cfg->files; f; f = f->next) {
+               /* TODO: Create the FIFO if it doesn't already exist. */
+               if (lstat(f->name, &st) < 0)
+                       fatal("Cannot stat \"%s\". Error: %s\n", f->name, strerror(errno));
+               if (!(st.st_mode & S_IFIFO))
+                       fatal("\"%s\" is not a FIFO\n", f->name);
                debug("opening: %s\n", f->name);
                if (f->fd < 0)
                        f->fd = open(f->name, O_RDONLY | O_NONBLOCK);
@@ -339,6 +342,9 @@ main(int argc, char *argv[])
        printf("%s\n", buf);
        /* TODO: nanosleep and nano time diff */
        for (;;) {
+               /* TODO: Check TTL and maybe blank-out */
+               /* TODO: How to trigger TTL check? On select? Alarm signal? */
+               /* TODO: Option to set X root window title or print */
                read_all(cfg, buf);
                printf("%s\n", buf);
        }
This page took 0.031705 seconds and 4 git commands to generate.