-/* Read a line from stdin, without any line-terminator character. The
- * return value is a newly allocated string. The caller should free()
- * the string when finished with it.
- *
- * This function returns NULL if EOF is encountered before any
- * characters are input (otherwise it returns those characters).
- */
-char *
-read_line (void)
+typedef struct {
+ int total_messages;
+ int count;
+ struct timeval tv_start;
+} add_files_state_t;
+
+/* Compute the number of seconds elapsed from start to end. */
+double
+tv_elapsed (struct timeval start, struct timeval end)
+{
+ return ((end.tv_sec - start.tv_sec) +
+ (end.tv_usec - start.tv_usec) / 1e6);
+}
+
+void
+print_formatted_seconds (double seconds)
+{
+ int hours;
+ int minutes;
+
+ if (seconds > 3600) {
+ hours = (int) seconds / 3600;
+ printf ("%dh ", hours);
+ seconds -= hours * 3600;
+ }
+
+ if (seconds > 60) {
+ minutes = (int) seconds / 60;
+ printf ("%dm ", minutes);
+ seconds -= minutes * 60;
+ }
+
+ printf ("%02ds", (int) seconds);
+}
+
+void
+add_files_print_progress (add_files_state_t *state)
+{
+ struct timeval tv_now;
+ double elapsed_overall, rate_overall;
+
+ gettimeofday (&tv_now, NULL);
+
+ elapsed_overall = tv_elapsed (state->tv_start, tv_now);
+ rate_overall = (state->count) / elapsed_overall;
+
+ printf ("Added %d of %d messages (",
+ state->count, state->total_messages);
+ print_formatted_seconds ((state->total_messages - state->count) /
+ rate_overall);
+ printf (" remaining).\r");
+
+ fflush (stdout);
+}
+
+/* Recursively find all regular files in 'path' and add them to the
+ * database. */
+void
+add_files (notmuch_database_t *notmuch, const char *path,
+ add_files_state_t *state)