* mu-cmd-find.c: some preparation for mu find --exec= (WIP)

This commit is contained in:
Dirk-Jan C. Binnema
2011-07-06 02:11:55 +03:00
parent efc7ad8af4
commit ca6212944c

View File

@ -141,7 +141,7 @@ sort_field_from_string (const char* fieldstr)
static gboolean static gboolean
run_query_format (MuMsgIter *iter, MuConfig *opts, output_query_results (MuMsgIter *iter, MuConfig *opts,
OutputFormat format, size_t *count) OutputFormat format, size_t *count)
{ {
switch (format) { switch (format) {
@ -165,14 +165,12 @@ run_query_format (MuMsgIter *iter, MuConfig *opts,
} }
static gboolean static MuMsgIter*
run_query (MuQuery *xapian, const gchar *query, MuConfig *opts, run_query (MuQuery *xapian, const gchar *query, MuConfig *opts, size_t *count)
OutputFormat format, size_t *count)
{ {
GError *err; GError *err;
MuMsgIter *iter; MuMsgIter *iter;
MuMsgFieldId sortid; MuMsgFieldId sortid;
gboolean rv;
sortid = MU_MSG_FIELD_ID_NONE; sortid = MU_MSG_FIELD_ID_NONE;
if (opts->sortfield) { if (opts->sortfield) {
@ -188,10 +186,25 @@ run_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
if (!iter) { if (!iter) {
g_warning ("error: %s", err->message); g_warning ("error: %s", err->message);
g_error_free (err); g_error_free (err);
return FALSE; return NULL;
} }
rv = run_query_format (iter, opts, format, count); return iter;
}
static gboolean
process_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
OutputFormat format, size_t *count)
{
MuMsgIter *iter;
gboolean rv;
iter = run_query (xapian, query, opts, count);
if (!iter)
return FALSE;
rv = output_query_results (iter, opts, format, count);
if (rv && count && *count == 0) if (rv && count && *count == 0)
g_warning ("no matching messages found"); g_warning ("no matching messages found");
@ -489,8 +502,6 @@ ansi_reset_maybe (MuMsgFieldId mfid, gboolean color)
} }
static const char* static const char*
display_field (MuMsgIter *iter, MuMsgFieldId mfid) display_field (MuMsgIter *iter, MuMsgFieldId mfid)
{ {
@ -853,7 +864,7 @@ mu_cmd_find (MuConfig *opts)
if (format == FORMAT_XQUERY) if (format == FORMAT_XQUERY)
rv = print_xapian_query (xapian, query, &count); rv = print_xapian_query (xapian, query, &count);
else else
rv = run_query (xapian, query, opts, format, &count); rv = process_query (xapian, query, opts, format, &count);
mu_query_destroy (xapian); mu_query_destroy (xapian);
g_free (query); g_free (query);