mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
Move index_file out from main() into its own function.
This is a step toward having a program that will index many messages with a single invocation.
This commit is contained in:
parent
c4812dae16
commit
3253954233
1 changed files with 92 additions and 82 deletions
|
@ -319,16 +319,18 @@ gen_terms_body (Xapian::TermGenerator term_gen,
|
|||
g_io_channel_close (channel);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
static void
|
||||
index_file (Xapian::WritableDatabase db,
|
||||
Xapian::TermGenerator term_gen,
|
||||
const char *filename)
|
||||
{
|
||||
Xapian::Document doc;
|
||||
|
||||
GMimeStream *stream;
|
||||
GMimeParser *parser;
|
||||
GMimeMessage *message;
|
||||
InternetAddressList *addresses;
|
||||
|
||||
const char *database_path, *filename;
|
||||
FILE *file;
|
||||
|
||||
const char *value, *from;
|
||||
|
@ -337,42 +339,22 @@ main (int argc, char **argv)
|
|||
struct tm gm_time_tm;
|
||||
char date_str[16]; /* YYYYMMDDHHMMSS + 1 for Y100k compatibility ;-) */
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf (stderr, "Usage: %s <path-to-xapian-database> <mail-message>\n",
|
||||
argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
database_path = argv[1];
|
||||
filename = argv[2];
|
||||
|
||||
file = fopen (filename, "r");
|
||||
if (! file) {
|
||||
fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_mime_init (0);
|
||||
|
||||
stream = g_mime_stream_file_new (file);
|
||||
|
||||
parser = g_mime_parser_new_with_stream (stream);
|
||||
|
||||
message = g_mime_parser_construct_message (parser);
|
||||
|
||||
try {
|
||||
Xapian::WritableDatabase db;
|
||||
Xapian::TermGenerator term_gen;
|
||||
Xapian::Document doc;
|
||||
|
||||
doc = Xapian::Document ();
|
||||
|
||||
doc.set_data (filename);
|
||||
|
||||
db = Xapian::WritableDatabase (database_path,
|
||||
Xapian::DB_CREATE_OR_OPEN);
|
||||
|
||||
term_gen = Xapian::TermGenerator ();
|
||||
term_gen.set_stemmer (Xapian::Stem ("english"));
|
||||
|
||||
term_gen.set_document (doc);
|
||||
|
@ -432,14 +414,42 @@ main (int argc, char **argv)
|
|||
|
||||
db.add_document (doc);
|
||||
|
||||
g_object_unref (message);
|
||||
g_object_unref (parser);
|
||||
g_object_unref (stream);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
const char *database_path, *filename;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf (stderr, "Usage: %s <path-to-xapian-database> <mail-message>\n",
|
||||
argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
database_path = argv[1];
|
||||
filename = argv[2];
|
||||
|
||||
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 ();
|
||||
|
||||
index_file (db, term_gen, filename);
|
||||
|
||||
} catch (const Xapian::Error &error) {
|
||||
cerr << "A Xapian exception occurred: " << error.get_msg () << endl;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_object_unref (message);
|
||||
g_object_unref (parser);
|
||||
g_object_unref (stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue