- case '-': parse_opts_opt(argc, argv, i); break;
- default : parse_opts_spec(argc, argv, i);
+ case '-': parse_opts_opt(cfg, argc, argv, i); break;
+ default : parse_opts_spec(cfg, argc, argv, i);
+ }
+ }
+}
+
+void
+opts_parse(Config *cfg, int argc, char *argv[], int i)
+{
+ opts_parse_any(cfg, argc, argv, 1);
+
+ File *last = cfg->files;
+ cfg->files = NULL;
+ for (File *f = last; f; ) {
+ File *next = f->next;
+ f->next = cfg->files;
+ cfg->files = f;
+ f = next;
+ }
+}
+
+void
+read_all(Config *cfg, char *buf)
+{
+ /* TODO: stat then check TTL */
+ for (File *f = cfg->files; f; f = f->next) {
+ if (f->fd < 0)
+ f->fd = open(f->name, O_RDONLY);
+ if (f->fd == -1) {
+ /* TODO: Consider backing off retries for failed files. */
+ fatal("Failed to open \"%s\"\n", f->name);
+ } else {
+ lseek(f->fd, 0, 0);
+ ssize_t n = read(f->fd, buf + f->pos, f->width);
+ int lasti = n + f->pos - 1;
+ char lastc = buf[lasti];
+ if (lastc == '\n')
+ buf[lasti] = ' ';