2010-01-01 19:44:19 +01:00
|
|
|
/*
|
|
|
|
** Copyright (C) 2010 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
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-01-02 13:44:26 +01:00
|
|
|
static MuCmd
|
2010-01-15 21:11:51 +01:00
|
|
|
cmd_from_string (const char* cmd)
|
2010-01-01 19:44:19 +01:00
|
|
|
{
|
2010-01-28 23:35:05 +01:00
|
|
|
int i;
|
|
|
|
typedef struct {
|
|
|
|
const gchar* _name;
|
|
|
|
MuCmd _cmd;
|
|
|
|
} Cmd;
|
|
|
|
|
|
|
|
Cmd cmd_map[]= {
|
|
|
|
{ "index", MU_CMD_INDEX },
|
|
|
|
{ "find", MU_CMD_FIND },
|
|
|
|
{ "cleanup", MU_CMD_CLEANUP },
|
|
|
|
{ "mkdir", MU_CMD_MKDIR },
|
|
|
|
{ "view", MU_CMD_VIEW },
|
2010-08-20 20:38:54 +02:00
|
|
|
{ "index", MU_CMD_INDEX },
|
|
|
|
{ "extract", MU_CMD_EXTRACT }
|
|
|
|
};
|
2010-01-28 23:35:05 +01:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
|
|
|
|
if (strcmp (cmd, cmd_map[i]._name) == 0)
|
|
|
|
return cmd_map[i]._cmd;
|
2010-01-01 19:44:19 +01:00
|
|
|
|
|
|
|
return MU_CMD_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
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-08-20 20:38:54 +02:00
|
|
|
"\twhere command is one of index, find, view, mkdir, cleanup "
|
|
|
|
"or extract\n\n"
|
2010-08-14 14:31:55 +02:00
|
|
|
"see mu(1) (the mu manpage) for more information, or try "
|
|
|
|
"mu --help\n";
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
if (noerror)
|
|
|
|
g_print ("%s", usage);
|
|
|
|
else
|
|
|
|
g_printerr ("%s", usage);
|
|
|
|
|
|
|
|
return noerror;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-01-15 21:11:51 +01:00
|
|
|
show_version (void)
|
2010-01-02 13:44:26 +01:00
|
|
|
{
|
|
|
|
const char* msg =
|
|
|
|
"mu (mail indexer / searcher version) " VERSION "\n\n"
|
2010-08-14 14:31:55 +02:00
|
|
|
"Copyright (C) 2008-2010 Dirk-Jan C. Binnema\n"
|
2010-01-02 13:44:26 +01:00
|
|
|
"License GPLv3+: GNU GPL version 3 or later "
|
2010-08-23 07:23:58 +02:00
|
|
|
"<http://gnu.org/licenses/gpl.html>.";
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
g_print ("%s\n", msg);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-24 12:15:43 +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-01-02 13:44:26 +01:00
|
|
|
MuCmd cmd;
|
|
|
|
|
|
|
|
if (opts->version)
|
2010-01-15 21:11:51 +01:00
|
|
|
return show_version ();
|
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-01-15 21:11:51 +01:00
|
|
|
return show_usage (FALSE);
|
2010-02-11 19:19:20 +01:00
|
|
|
}
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2010-01-15 21:11:51 +01:00
|
|
|
cmd = cmd_from_string (opts->params[0]);
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
switch (cmd) {
|
2010-01-04 19:21:03 +01:00
|
|
|
|
2010-08-20 20:38:54 +02:00
|
|
|
case MU_CMD_CLEANUP: return mu_cmd_cleanup (opts);
|
|
|
|
case MU_CMD_EXTRACT: return mu_cmd_extract (opts);
|
|
|
|
case MU_CMD_FIND: return mu_cmd_find (opts);
|
|
|
|
case MU_CMD_INDEX: return mu_cmd_index (opts);
|
|
|
|
case MU_CMD_MKDIR: return mu_cmd_mkdir (opts);
|
|
|
|
case MU_CMD_VIEW: return mu_cmd_view (opts);
|
|
|
|
|
2010-02-11 19:19:20 +01:00
|
|
|
case MU_CMD_UNKNOWN:
|
|
|
|
return show_usage (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
|
|
|
}
|