2011-05-24 20:35:36 +02:00
|
|
|
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2015-01-25 22:55:23 +01:00
|
|
|
** Copyright (C) 2008-2015 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2011-12-01 20:32:48 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
#include <glib.h>
|
2012-05-20 16:41:18 +02:00
|
|
|
#include <glib-object.h>
|
|
|
|
#include <locale.h>
|
2011-01-04 22:19:03 +01:00
|
|
|
|
2012-05-20 16:41:18 +02:00
|
|
|
#include "mu-config.h"
|
2010-01-01 19:44:19 +01:00
|
|
|
#include "mu-cmd.h"
|
2010-11-14 12:55:04 +01:00
|
|
|
#include "mu-runtime.h"
|
2009-11-29 23:05:05 +01:00
|
|
|
|
2012-05-20 16:41:18 +02:00
|
|
|
|
2012-09-09 13:21:15 +02:00
|
|
|
static void
|
|
|
|
show_version (void)
|
|
|
|
{
|
2012-09-19 09:44:16 +02:00
|
|
|
const char* blurb =
|
|
|
|
"mu (mail indexer/searcher) version " VERSION "\n"
|
2015-01-25 22:55:23 +01:00
|
|
|
"Copyright (C) 2008-2015 Dirk-Jan C. Binnema\n"
|
2012-09-19 09:44:16 +02:00
|
|
|
"License GPLv3+: GNU GPL version 3 or later "
|
|
|
|
"<http://gnu.org/licenses/gpl.html>.\n"
|
|
|
|
"This is free software: you are free to change "
|
|
|
|
"and redistribute it.\n"
|
|
|
|
"There is NO WARRANTY, to the extent permitted by law.";
|
|
|
|
|
|
|
|
g_print ("%s\n", blurb);
|
2012-09-09 13:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-03 09:49:19 +02:00
|
|
|
static void
|
2012-12-22 23:04:09 +01:00
|
|
|
handle_error (MuConfig *conf, MuError merr, GError **err)
|
2011-09-03 09:49:19 +02:00
|
|
|
{
|
2012-12-23 13:17:50 +01:00
|
|
|
if (!(err && *err))
|
2012-12-22 23:04:09 +01:00
|
|
|
return;
|
2011-09-03 09:49:19 +02:00
|
|
|
|
2012-12-22 23:04:09 +01:00
|
|
|
switch ((*err)->code) {
|
2011-09-03 09:49:19 +02:00
|
|
|
case MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK:
|
2012-10-24 22:49:54 +02:00
|
|
|
g_printerr ("maybe mu is already running?\n");
|
2012-09-17 18:53:30 +02:00
|
|
|
break;
|
2011-09-03 09:49:19 +02:00
|
|
|
case MU_ERROR_XAPIAN_CORRUPTION:
|
2013-01-06 14:53:42 +01:00
|
|
|
case MU_ERROR_XAPIAN_VERSION_MISMATCH:
|
|
|
|
g_printerr ("database needs a rebuild; "
|
2012-10-24 22:49:54 +02:00
|
|
|
"try 'mu index --rebuild'\n");
|
2012-09-17 18:53:30 +02:00
|
|
|
break;
|
2011-09-03 09:49:19 +02:00
|
|
|
case MU_ERROR_XAPIAN_IS_EMPTY:
|
2013-07-23 21:23:27 +02:00
|
|
|
g_printerr ("database is empty; try 'mu index'\n");
|
2011-09-03 09:49:19 +02:00
|
|
|
break;
|
2012-09-09 13:07:34 +02:00
|
|
|
case MU_ERROR_IN_PARAMETERS:
|
2012-10-24 22:49:54 +02:00
|
|
|
if (conf && mu_config_cmd_is_valid(conf->cmd))
|
2012-09-19 09:44:16 +02:00
|
|
|
mu_config_show_help (conf->cmd);
|
2012-09-09 13:07:34 +02:00
|
|
|
break;
|
2013-07-23 21:23:27 +02:00
|
|
|
case MU_ERROR_SCRIPT_NOT_FOUND:
|
|
|
|
g_printerr ("see the mu manpage for commands, or "
|
|
|
|
"'mu script' for the scripts\n");
|
|
|
|
break;
|
2012-10-24 22:49:54 +02:00
|
|
|
default:
|
|
|
|
break; /* nothing to do */
|
2011-09-03 09:49:19 +02:00
|
|
|
}
|
|
|
|
|
2012-12-22 23:04:09 +01:00
|
|
|
if (*err)
|
2013-12-21 19:01:04 +01:00
|
|
|
g_printerr ("mu: %s (%u)\n",
|
|
|
|
(*err)->message,
|
|
|
|
(*err)->code);
|
2011-09-03 09:49:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2011-09-03 09:49:19 +02:00
|
|
|
GError *err;
|
|
|
|
MuError rv;
|
2012-05-20 16:41:18 +02:00
|
|
|
MuConfig *conf;
|
|
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
2013-05-13 21:30:27 +02:00
|
|
|
|
|
|
|
#ifndef GLIB_VERSION_2_36
|
2012-05-20 16:41:18 +02:00
|
|
|
g_type_init ();
|
2013-05-13 21:30:27 +02:00
|
|
|
#endif /*GLIB_VERSION_2_36*/
|
2012-05-20 16:41:18 +02:00
|
|
|
|
2012-10-24 22:49:54 +02:00
|
|
|
err = NULL;
|
|
|
|
rv = MU_OK;
|
|
|
|
|
|
|
|
conf = mu_config_init (&argc, &argv, &err);
|
|
|
|
if (!conf) {
|
|
|
|
rv = err ? (MuError)err->code : MU_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
} else if (conf->version) {
|
2012-09-09 13:21:15 +02:00
|
|
|
show_version ();
|
2012-10-24 22:49:54 +02:00
|
|
|
goto cleanup;
|
2012-09-09 13:21:15 +02:00
|
|
|
}
|
2011-08-30 21:03:17 +02:00
|
|
|
|
2012-09-17 18:53:30 +02:00
|
|
|
/* nothing to do */
|
|
|
|
if (conf->cmd == MU_CONFIG_CMD_NONE)
|
|
|
|
return 0;
|
|
|
|
|
2012-05-20 16:41:18 +02:00
|
|
|
if (!mu_runtime_init (conf->muhome, PACKAGE_NAME)) {
|
|
|
|
mu_config_uninit (conf);
|
2010-01-21 19:05:19 +01:00
|
|
|
return 1;
|
2012-05-20 16:41:18 +02:00
|
|
|
}
|
2011-01-13 20:41:19 +01:00
|
|
|
|
2012-05-20 16:41:18 +02:00
|
|
|
rv = mu_cmd_execute (conf, &err);
|
2011-01-13 20:41:19 +01:00
|
|
|
|
2012-10-24 22:49:54 +02:00
|
|
|
cleanup:
|
2012-12-22 23:04:09 +01:00
|
|
|
handle_error (conf, rv, &err);
|
2011-09-03 09:49:19 +02:00
|
|
|
g_clear_error (&err);
|
2011-08-30 21:03:17 +02:00
|
|
|
|
2012-05-20 16:41:18 +02:00
|
|
|
mu_config_uninit (conf);
|
2011-09-03 09:49:19 +02:00
|
|
|
mu_runtime_uninit ();
|
2012-02-29 19:51:29 +01:00
|
|
|
|
2011-01-04 22:19:03 +01:00
|
|
|
return rv;
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|