mirror of https://github.com/djcb/mu.git
* some further cleanups, add mu-output.h
This commit is contained in:
parent
516caccf10
commit
56f1664d8c
|
@ -229,15 +229,37 @@ db_is_ready (const char *xpath)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static MuQuery*
|
||||
get_query_obj (void)
|
||||
{
|
||||
GError *err;
|
||||
const char* xpath;
|
||||
MuQuery *mquery;
|
||||
|
||||
xpath = mu_runtime_xapian_dir ();
|
||||
if (!db_is_ready(xpath)) {
|
||||
g_warning ("database '%s' is not ready", xpath);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = NULL;
|
||||
mquery = mu_query_new (xpath, &err);
|
||||
if (!mquery) {
|
||||
g_warning ("error: %s", err->message);
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mquery;
|
||||
}
|
||||
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_find (MuConfig *opts)
|
||||
{
|
||||
GError *err;
|
||||
MuQuery *xapian;
|
||||
gboolean rv;
|
||||
gchar *query;
|
||||
const gchar *xpath;
|
||||
size_t count;
|
||||
|
||||
g_return_val_if_fail (opts, FALSE);
|
||||
|
@ -246,8 +268,8 @@ mu_cmd_find (MuConfig *opts)
|
|||
if (!query_params_valid (opts))
|
||||
return MU_EXITCODE_ERROR;
|
||||
|
||||
xpath = mu_runtime_xapian_dir ();
|
||||
if (!db_is_ready(xpath))
|
||||
xapian = get_query_obj ();
|
||||
if (!xapian)
|
||||
return MU_EXITCODE_ERROR;
|
||||
|
||||
/* first param is 'query', search params are after that */
|
||||
|
@ -255,14 +277,6 @@ mu_cmd_find (MuConfig *opts)
|
|||
if (!query)
|
||||
return MU_EXITCODE_ERROR;
|
||||
|
||||
err = NULL;
|
||||
xapian = mu_query_new (xpath, &err);
|
||||
if (!xapian) {
|
||||
g_warning ("error: %s", err->message);
|
||||
g_error_free (err);
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
if (opts->xquery)
|
||||
rv = print_xapian_query (xapian, query);
|
||||
else
|
||||
|
@ -273,9 +287,8 @@ mu_cmd_find (MuConfig *opts)
|
|||
|
||||
if (!rv)
|
||||
return MU_EXITCODE_ERROR;
|
||||
else if (count == 0)
|
||||
return MU_EXITCODE_NO_MATCHES;
|
||||
else
|
||||
return MU_EXITCODE_OK;
|
||||
return (count == 0) ?
|
||||
MU_EXITCODE_NO_MATCHES : MU_EXITCODE_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,9 +228,8 @@ config_options_group_extract(MuConfig *opts)
|
|||
}
|
||||
|
||||
|
||||
gboolean
|
||||
parse_cmd_from_params (MuConfig *opts,
|
||||
int *argcp, char ***argvp)
|
||||
static gboolean
|
||||
parse_cmd (MuConfig *opts, int *argcp, char ***argvp)
|
||||
{
|
||||
int i;
|
||||
typedef struct {
|
||||
|
@ -272,15 +271,13 @@ parse_cmd_from_params (MuConfig *opts,
|
|||
static gboolean
|
||||
parse_params (MuConfig *opts, int *argcp, char ***argvp)
|
||||
{
|
||||
GError *err;
|
||||
GError *err = NULL;
|
||||
GOptionContext *context;
|
||||
gboolean rv;
|
||||
|
||||
if (!parse_cmd_from_params (opts, argcp, argvp))
|
||||
return FALSE;
|
||||
|
||||
context = g_option_context_new("- mu general option");
|
||||
g_option_context_set_main_group(context, config_options_group_mu(opts));
|
||||
g_option_context_set_main_group(context,
|
||||
config_options_group_mu(opts));
|
||||
|
||||
switch (opts->cmd) {
|
||||
case MU_CONFIG_CMD_INDEX:
|
||||
|
@ -295,25 +292,16 @@ parse_params (MuConfig *opts, int *argcp, char ***argvp)
|
|||
case MU_CONFIG_CMD_EXTRACT:
|
||||
g_option_context_add_group(context, config_options_group_extract(opts));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
err = NULL;
|
||||
rv = g_option_context_parse(context, argcp, argvp, &err);
|
||||
g_option_context_free (context);
|
||||
if (!rv) {
|
||||
g_printerr ("mu: error in options: %s\n", err->message);
|
||||
g_error_free(err);
|
||||
g_error_free (err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* fill in the defaults if user did not specify */
|
||||
set_group_mu_defaults(opts);
|
||||
set_group_index_defaults(opts);
|
||||
set_group_find_defaults(opts);
|
||||
/* set_group_mkdir_defaults (opts); */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -322,15 +310,22 @@ mu_config_new (int *argcp, char ***argvp)
|
|||
{
|
||||
MuConfig *config;
|
||||
|
||||
g_return_val_if_fail (argcp && argvp, NULL);
|
||||
|
||||
config = g_new0 (MuConfig, 1);
|
||||
|
||||
/* defaults are set in parse_params */
|
||||
if (argcp && argvp)
|
||||
if (!parse_params(config, argcp, argvp)) {
|
||||
mu_config_destroy (config);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!parse_cmd (config, argcp, argvp) ||
|
||||
!parse_params(config, argcp, argvp)) {
|
||||
mu_config_destroy (config);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fill in the defaults if user did not specify */
|
||||
set_group_mu_defaults(config);
|
||||
set_group_index_defaults(config);
|
||||
set_group_find_defaults(config);
|
||||
/* set_group_mkdir_defaults (config); */
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -391,14 +386,12 @@ mu_config_execute (MuConfig *opts)
|
|||
}
|
||||
|
||||
switch (opts->cmd) {
|
||||
|
||||
case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts);
|
||||
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts);
|
||||
case MU_CONFIG_CMD_FIND: return mu_cmd_find (opts);
|
||||
case MU_CONFIG_CMD_INDEX: return mu_cmd_index (opts);
|
||||
case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts);
|
||||
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts);
|
||||
|
||||
case MU_CONFIG_CMD_UNKNOWN:
|
||||
g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr);
|
||||
show_usage (FALSE);
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 3, or (at your option) any
|
||||
** later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software Foundation,
|
||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_OUTPUT_H__
|
||||
#define __MU_OUTPUT_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <mu-msg-iter.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* output the search results (MsgIter) as plain text rows to standard
|
||||
* output
|
||||
*
|
||||
* @param iter iterator pointing to a message row
|
||||
* @param fields the fields to print (see MuMsgFields)
|
||||
* @param summary_len number of lines to include in message summary
|
||||
* @param count output param to receive the number of messages found, or NULL
|
||||
*
|
||||
* @return TRUE if the printing succeeded, FALSE in case of error
|
||||
*/
|
||||
gboolean mu_output_plain (MuMsgIter *iter, const char *fields,
|
||||
size_t summary_len, size_t *count);
|
||||
|
||||
/**
|
||||
* output the search results (MsgIter) as a maildir of symlinks
|
||||
*
|
||||
* @param iter iterator pointing to a message row
|
||||
* @param path of the output maildir; if the directory does not exist yet, it will be created
|
||||
* @param clearlinks; remove any existing links in the target directory
|
||||
* @param count output param to receive the number of messages found, or NULL
|
||||
*
|
||||
* @return TRUE if the linking succeeded, FALSE in case of error
|
||||
*/
|
||||
gboolean mu_output_links (MuMsgIter *iter, const char *linksdir,
|
||||
gboolean clearlinks, size_t *count);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_OUTPUT_H__*/
|
Loading…
Reference in New Issue