-
- /*
- * Work out how much space the cumulative index trees will
- * take; enlarge the file, and memory-map it.
- */
- if (fstat(fd, &st) < 0) {
- perror("agedu: fstat");
- return 1;
+ if (mode == LOAD) {
+ char *buf;
+ int line = 2;
+ while ((buf = fgetline(stdin)) != NULL) {
+ struct trie_file tf;
+ char *p, *q;
+
+ buf[strcspn(buf, "\r\n")] = '\0';
+
+ p = buf;
+ q = p;
+ while (*p && *p != ' ') p++;
+ if (!*p) {
+ fprintf(stderr, "%s: dump file line %d: expected at least"
+ " three fields\n", PNAME, line);
+ return 1;
+ }
+ *p++ = '\0';
+ tf.size = strtoull(q, NULL, 10);
+ q = p;
+ while (*p && *p != ' ') p++;
+ if (!*p) {
+ fprintf(stderr, "%s: dump file line %d: expected at least"
+ " three fields\n", PNAME, line);
+ return 1;
+ }
+ *p++ = '\0';
+ tf.atime = strtoull(q, NULL, 10);
+ q = buf;
+ while (*p) {
+ int c = *p;
+ if (*p == '%') {
+ int i;
+ p++;
+ c = 0;
+ for (i = 0; i < 2; i++) {
+ if (*p >= '0' && *p <= '9')
+ c += *p - '0';
+ else if (*p >= 'A' && *p <= 'F')
+ c += *p - ('A' - 10);
+ else if (*p >= 'a' && *p <= 'f')
+ c += *p - ('a' - 10);
+ else {
+ fprintf(stderr, "%s: dump file line %d: unable"
+ " to parse hex escape\n", PNAME, line);
+ }
+ p++;
+ }
+ }
+ *q++ = c;
+ p++;
+ }
+ *q = '\0';
+ triebuild_add(ctx->tb, buf, &tf);
+ sfree(buf);
+ }
+ } else {
+ du(scandir, gotdata, ctx);