2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2010-01-01 14:56:45 +01:00
|
|
|
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2009-11-25 21:55:06 +01:00
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2009-11-28 19:55:50 +01:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <string.h>
|
2009-11-29 23:05:05 +01:00
|
|
|
#include <stdio.h> /* for fileno() */
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2009-12-31 13:25:20 +01:00
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
#include "mu-config.h"
|
2010-01-01 19:44:19 +01:00
|
|
|
#include "mu-cmd.h"
|
2009-11-29 23:05:05 +01:00
|
|
|
#include "mu-log.h"
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2009-11-29 23:05:05 +01:00
|
|
|
static gboolean
|
|
|
|
init_log (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
gboolean rv;
|
|
|
|
|
|
|
|
if (opts->quiet)
|
|
|
|
rv = mu_log_init_silence ();
|
|
|
|
else if (opts->log_stderr)
|
|
|
|
rv = mu_log_init_with_fd (fileno(stderr), FALSE,
|
|
|
|
opts->debug);
|
2009-12-05 12:13:19 +01:00
|
|
|
else
|
2010-01-02 13:44:26 +01:00
|
|
|
rv = mu_log_init (opts->muhome, TRUE, opts->debug);
|
2009-11-29 23:05:05 +01:00
|
|
|
|
2009-12-05 12:13:19 +01:00
|
|
|
if (!rv)
|
|
|
|
g_print ("error: failed to initialize log\n");
|
|
|
|
|
2009-11-29 23:05:05 +01:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
|
|
|
_parse_params (MuConfigOptions *config, int *argcp, char ***argvp)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GOptionContext *context;
|
2010-01-02 13:44:26 +01:00
|
|
|
gboolean rv;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
context = g_option_context_new ("- maildir utilities");
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2009-11-28 13:06:21 +01:00
|
|
|
g_option_context_set_main_group (context,
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_config_options_group_mu(config));
|
2009-11-28 13:06:21 +01:00
|
|
|
g_option_context_add_group (context,
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_config_options_group_index(config));
|
2009-11-28 13:06:21 +01:00
|
|
|
g_option_context_add_group (context,
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_config_options_group_query(config));
|
2010-01-01 19:44:19 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
rv = g_option_context_parse (context, argcp, argvp, &error);
|
|
|
|
if (!rv) {
|
2010-01-01 19:44:19 +01:00
|
|
|
g_printerr ("error in options: %s\n", error->message);
|
2009-11-25 21:55:06 +01:00
|
|
|
g_error_free (error);
|
2010-01-02 13:44:26 +01:00
|
|
|
} else {
|
|
|
|
g_option_context_free (context);
|
|
|
|
mu_config_set_defaults (config);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
MuConfigOptions config;
|
|
|
|
gboolean rv;
|
2009-11-29 23:05:05 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
g_type_init ();
|
|
|
|
|
|
|
|
mu_config_init (&config);
|
|
|
|
|
|
|
|
if (!_parse_params (&config, &argc, &argv)) {
|
|
|
|
mu_config_uninit (&config);
|
2010-01-01 19:44:19 +01:00
|
|
|
return 1;
|
2010-01-02 13:44:26 +01:00
|
|
|
}
|
2010-01-01 19:44:19 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
if (!init_log (&config)) {
|
|
|
|
mu_config_uninit (&config);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-01-06 00:19:18 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
rv = mu_cmd_execute (&config);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2009-11-29 23:05:05 +01:00
|
|
|
mu_log_uninit();
|
2009-12-11 18:43:18 +01:00
|
|
|
mu_config_uninit(&config);
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
return rv ? 0 : 1;
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
2009-12-11 21:05:50 +01:00
|
|
|
|