2010-01-01 19:44:19 +01:00
|
|
|
/*
|
2010-08-29 15:39:27 +02:00
|
|
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-01 19:44:19 +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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
2010-01-01 19:44:19 +01:00
|
|
|
#include <string.h>
|
2010-01-02 15:06:36 +01:00
|
|
|
#include <errno.h>
|
2010-01-25 08:28:08 +01:00
|
|
|
#include <stdlib.h>
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
#include "mu-maildir.h"
|
2010-01-01 19:44:19 +01:00
|
|
|
#include "mu-cmd.h"
|
|
|
|
|
2010-08-29 15:39:27 +02:00
|
|
|
gboolean
|
|
|
|
mu_cmd_equals (MuConfigOptions *config, const gchar *cmd)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (config, FALSE);
|
|
|
|
g_return_val_if_fail (cmd, FALSE);
|
|
|
|
|
|
|
|
if (!config->params || !config->params[0])
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (strcmp (config->params[0], cmd) == 0);
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:19:47 +02:00
|
|
|
static void
|
2010-01-15 21:11:51 +01:00
|
|
|
show_usage (gboolean noerror)
|
2010-01-02 13:44:26 +01:00
|
|
|
{
|
|
|
|
const char* usage=
|
|
|
|
"usage: mu [options] command [parameters]\n"
|
2010-10-09 12:19:47 +02:00
|
|
|
"where command is one of index, find, view, mkdir, cleanup "
|
2010-08-20 20:38:54 +02:00
|
|
|
"or extract\n\n"
|
2010-10-09 12:19:47 +02:00
|
|
|
"see the mu or mu-easy manpages for more information\n";
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
if (noerror)
|
|
|
|
g_print ("%s", usage);
|
|
|
|
else
|
|
|
|
g_printerr ("%s", usage);
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:19:47 +02:00
|
|
|
static void
|
2010-01-15 21:11:51 +01:00
|
|
|
show_version (void)
|
2010-01-02 13:44:26 +01:00
|
|
|
{
|
2010-10-09 12:19:47 +02:00
|
|
|
g_print ("mu (mail indexer/searcher) " VERSION "\n"
|
|
|
|
"Copyright (C) 2008-2010 Dirk-Jan C. Binnema (GPLv3+)\n");
|
2010-01-02 13:44:26 +01:00
|
|
|
}
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
gboolean
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_cmd_execute (MuConfigOptions *opts)
|
2010-01-01 19:44:19 +01:00
|
|
|
{
|
2010-10-09 12:19:47 +02:00
|
|
|
if (opts->version) {
|
|
|
|
show_version ();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2010-02-11 19:19:20 +01:00
|
|
|
if (!opts->params||!opts->params[0]) {/* no command? */
|
|
|
|
show_version ();
|
|
|
|
g_print ("\n");
|
2010-10-09 12:19:47 +02:00
|
|
|
show_usage (TRUE);
|
|
|
|
return FALSE;
|
2010-02-11 19:19:20 +01:00
|
|
|
}
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2011-01-02 17:10:11 +01:00
|
|
|
switch (opts->cmd) {
|
2010-01-04 19:21:03 +01:00
|
|
|
|
2011-01-02 17:10:11 +01:00
|
|
|
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);
|
2010-08-20 20:38:54 +02:00
|
|
|
|
2011-01-02 17:10:11 +01:00
|
|
|
case MU_CONFIG_CMD_UNKNOWN:
|
2010-10-09 12:19:47 +02:00
|
|
|
show_usage (FALSE);
|
|
|
|
return FALSE;
|
2010-01-01 19:44:19 +01:00
|
|
|
default:
|
2010-01-02 13:44:26 +01:00
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
2010-01-01 19:44:19 +01:00
|
|
|
}
|