- Slot *s;
-
- argv0 = argv[0];
-
- opts_parse(&cfg, argc, argv);
- khlib_debug("argv0 = %s\n", argv0);
- config_print(&cfg);
-
- ti = khlib_timespec_of_float(cfg.interval);
-
- if (cfg.slots == NULL)
- usage("No slot specs were given!\n");
-
- /* 1st pass to check file existence and type */
- for (s = cfg.slots; s; s = s->next) {
- if (lstat(s->in_fifo, &st) < 0) {
- khlib_error(
- "Cannot stat \"%s\". Error: %s\n",
- s->in_fifo,
- strerror(errno)
- );
- errors++;
- continue;
- }
- if (!(st.st_mode & S_IFIFO)) {
- khlib_error("\"%s\" is not a FIFO\n", s->in_fifo);
- errors++;
- continue;
- }
- }
- if (errors)
- khlib_fatal(
- "Encountered errors with given file paths. See log.\n"
- );
-
- width = cfg.total_width;
- seplen = strlen(cfg.separator);
-
- /* 2nd pass to make space for separators */
- for (s = cfg.slots; s; s = s->next) {
- s->out_pos_lo += prefix;
- s->out_pos_hi += prefix;
- s->out_pos_cur = s->out_pos_lo;
- prefix += seplen;
- nslots++;
- }
- width += (seplen * (nslots - 1));
- buf = calloc(1, width + 1);
- if (buf == NULL)
- khlib_fatal(
- "[memory] Failed to allocate buffer of %d bytes",
- width
- );
- memset(buf, ' ', width);
- buf[width] = '\0';
- /* 3rd pass to set the separators */
- for (s = cfg.slots; s; s = s->next) {
- if (s->out_pos_lo) { /* Skip the first, left-most */
- /* Copying only seplen ensures we omit the '\0' byte. */
- strncpy(
- buf + (s->out_pos_lo - seplen),
- cfg.separator,
- seplen
- );
- }
- }