+}
+
+static void
+usage (const char *argv0)
+{
+ fprintf (stderr, "Usage: %s <path-to-xapian-database>\n", argv0);
+ fprintf (stderr, "\n");
+ fprintf (stderr, "Messages to be indexed are read from stdnin as absolute filenames\n");
+ fprintf (stderr, "one file per line.");
+}
+
+int
+main (int argc, char **argv)
+{
+ const char *database_path;
+ char *filename;
+ GIOChannel *channel;
+ GIOStatus gio_status;
+ GError *error = NULL;
+ int count;
+ struct timeval tv_start, tv_last, tv_now;
+ double elapsed;
+
+ if (argc < 2) {
+ usage (argv[0]);
+ exit (1);
+ }
+
+ database_path = argv[1];
+
+ g_mime_init (0);
+
+ try {
+ Xapian::WritableDatabase db;
+ Xapian::TermGenerator term_gen;
+
+ db = Xapian::WritableDatabase (database_path,
+ Xapian::DB_CREATE_OR_OPEN);
+
+ term_gen = Xapian::TermGenerator ();
+
+ channel = g_io_channel_unix_new (fileno (stdin));
+
+ count = 0;
+
+ gettimeofday (&tv_start, NULL);
+ tv_last = tv_start;
+
+ while (1) {
+ gio_status = g_io_channel_read_line (channel, &filename,
+ NULL, NULL, &error);
+ if (gio_status == G_IO_STATUS_EOF)
+ break;
+ if (gio_status != G_IO_STATUS_NORMAL) {
+ fprintf (stderr, "An error occurred reading from stdin: %s\n",
+ error->message);
+ exit (1);
+ }
+
+ g_strchomp (filename);
+ index_file (db, term_gen, filename);
+
+ g_free (filename);
+
+ count++;
+ if (count % 1000 == 0) {
+ gettimeofday (&tv_now, NULL);
+ printf ("Indexed %d messages (%g messages/second)\n",
+ count, 1000 / ((tv_now.tv_sec - tv_last.tv_sec) +
+ (tv_now.tv_usec - tv_last.tv_usec) / 1e6));
+ tv_last = tv_now;
+ }
+ }
+
+ g_io_channel_unref (channel);
+
+ gettimeofday (&tv_now, NULL);
+ elapsed = (tv_now.tv_sec - tv_start.tv_sec +
+ (tv_now.tv_usec - tv_start.tv_usec) / 1e6);
+ printf ("Completed indexing of %d messages in %g seconds (%g messages/second)\n",
+ count, elapsed, count / elapsed);
+
+ } catch (const Xapian::Error &error) {
+ cerr << "A Xapian exception occurred: " << error.get_msg () << endl;
+ exit (1);
+ }