* completely remove '--xquery', re-indent mu-config.c

This commit is contained in:
Dirk-Jan C. Binnema 2011-05-22 10:40:12 +03:00
parent e478eeee6d
commit f7a39155c8
6 changed files with 284 additions and 301 deletions

1
NEWS
View File

@ -7,6 +7,7 @@
- wildcard searches for all fields (except for path/maildir) - wildcard searches for all fields (except for path/maildir)
- search for attachment file names (with 'a:'/'attach:') -- also works with - search for attachment file names (with 'a:'/'attach:') -- also works with
wildcards wildcards
- remove --xquery completely; use --output=xquery instead
** Release 0.9.5 <2011-04-25 Mon> ** Release 0.9.5 <2011-04-25 Mon>

View File

@ -326,9 +326,6 @@ Note, if you specify a sortfield, by default, messages are sorted in
descending order (e.g., from lowest to highest). This is usually a good descending order (e.g., from lowest to highest). This is usually a good
choice, but for dates it may be more useful to sort in the opposite direction. choice, but for dates it may be more useful to sort in the opposite direction.
.TP
\fB\-\-xquery\fR
.TP .TP
\fB\-k\fR, \fB\-\-summary\-len\fR=\fI<len>\fR \fB\-k\fR, \fB\-\-summary\-len\fR=\fI<len>\fR
output a summary based on up to \fI\len\fR lines of the message. The default output a summary based on up to \fI\len\fR lines of the message. The default

View File

@ -218,17 +218,6 @@ query_params_valid (MuConfig *opts)
{ {
const gchar *xpath; const gchar *xpath;
if (opts->linksdir)
if (opts->xquery) {
g_warning ("invalid option for --linksdir");
return FALSE;
}
if (opts->xquery) {
g_warning ("--xquery is obsolete; use --format=xquery instead");
return FALSE;
}
xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB); xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB);
if (mu_util_check_dir (xpath, TRUE, FALSE)) if (mu_util_check_dir (xpath, TRUE, FALSE))

View File

@ -85,7 +85,7 @@ check_index_or_cleanup_params (MuConfig *opts)
return FALSE; return FALSE;
} }
if (opts->linksdir || opts->xquery) { if (opts->linksdir) {
g_warning ("invalid option(s) for command"); g_warning ("invalid option(s) for command");
return FALSE; return FALSE;
} }

View File

@ -1,3 +1,5 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/* /*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
@ -31,197 +33,194 @@
static void static void
set_group_mu_defaults (MuConfig *opts) set_group_mu_defaults (MuConfig *opts)
{ {
gchar *exp; gchar *exp;
if (!opts->muhome) if (!opts->muhome)
opts->muhome = mu_util_guess_mu_homedir(); opts->muhome = mu_util_guess_mu_homedir();
exp = mu_util_dir_expand(opts->muhome); exp = mu_util_dir_expand(opts->muhome);
if (exp) { if (exp) {
g_free(opts->muhome); g_free(opts->muhome);
opts->muhome = exp; opts->muhome = exp;
} }
} }
static GOptionGroup* static GOptionGroup*
config_options_group_mu (MuConfig *opts) config_options_group_mu (MuConfig *opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"debug", 'd', 0, G_OPTION_ARG_NONE, &opts->debug, {"debug", 'd', 0, G_OPTION_ARG_NONE, &opts->debug,
"print debug output to standard error (false)", NULL}, "print debug output to standard error (false)", NULL},
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &opts->quiet, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &opts->quiet,
"don't give any progress information (false)", NULL}, "don't give any progress information (false)", NULL},
{"version", 'v', 0, G_OPTION_ARG_NONE, &opts->version, {"version", 'v', 0, G_OPTION_ARG_NONE, &opts->version,
"display version and copyright information (false)", NULL}, "display version and copyright information (false)", NULL},
{"muhome", 0, 0, G_OPTION_ARG_FILENAME, &opts->muhome, {"muhome", 0, 0, G_OPTION_ARG_FILENAME, &opts->muhome,
"specify an alternative mu directory", NULL}, "specify an alternative mu directory", NULL},
{"log-stderr", 0, 0, G_OPTION_ARG_NONE, &opts->log_stderr, {"log-stderr", 0, 0, G_OPTION_ARG_NONE, &opts->log_stderr,
"log to standard error (false)", NULL}, "log to standard error (false)", NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
&opts->params, "parameters", NULL}, &opts->params, "parameters", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL} {NULL, 0, 0, 0, NULL, NULL, NULL}
}; };
og = g_option_group_new("mu", "general mu options", "", NULL, NULL); og = g_option_group_new("mu", "general mu options", "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
static void static void
set_group_index_defaults (MuConfig * opts) set_group_index_defaults (MuConfig * opts)
{ {
/* note: opts->maildir is handled in mu-cmd, as we need to /* note: opts->maildir is handled in mu-cmd, as we need to
* have a MuIndex entry for mu_index_last_used_maildir () * have a MuIndex entry for mu_index_last_used_maildir ()
*/ */
opts->xbatchsize = 0; opts->xbatchsize = 0;
} }
static GOptionGroup* static GOptionGroup*
config_options_group_index (MuConfig * opts) config_options_group_index (MuConfig * opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &opts->maildir, {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &opts->maildir,
"top of the maildir", NULL}, "top of the maildir", NULL},
{"reindex", 0, 0, G_OPTION_ARG_NONE, &opts->reindex, {"reindex", 0, 0, G_OPTION_ARG_NONE, &opts->reindex,
"index even already indexed messages (false)", NULL}, "index even already indexed messages (false)", NULL},
{"rebuild", 0, 0, G_OPTION_ARG_NONE, &opts->rebuild, {"rebuild", 0, 0, G_OPTION_ARG_NONE, &opts->rebuild,
"rebuild the database from scratch (false)", NULL}, "rebuild the database from scratch (false)", NULL},
{"autoupgrade", 0, 0, G_OPTION_ARG_NONE, &opts->autoupgrade, {"autoupgrade", 0, 0, G_OPTION_ARG_NONE, &opts->autoupgrade,
"auto-upgrade the database with new mu versions (false)", "auto-upgrade the database with new mu versions (false)",
NULL}, NULL},
{"nocleanup", 0, 0, G_OPTION_ARG_NONE, &opts->nocleanup, {"nocleanup", 0, 0, G_OPTION_ARG_NONE, &opts->nocleanup,
"don't clean up the database after indexing (false)", NULL}, "don't clean up the database after indexing (false)", NULL},
{"xbatchsize", 0, 0, G_OPTION_ARG_INT, &opts->xbatchsize, {"xbatchsize", 0, 0, G_OPTION_ARG_INT, &opts->xbatchsize,
"set transaction batchsize for xapian commits (0)", NULL}, "set transaction batchsize for xapian commits (0)", NULL},
{"max-msg-size", 0, 0, G_OPTION_ARG_INT, &opts->max_msg_size, {"max-msg-size", 0, 0, G_OPTION_ARG_INT, &opts->max_msg_size,
"set the maximum size for message files", NULL}, "set the maximum size for message files", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL} {NULL, 0, 0, 0, NULL, NULL, NULL}
}; };
og = g_option_group_new("index", og = g_option_group_new("index",
"options for the 'index' command", "options for the 'index' command",
"", NULL, NULL); "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
static void static void
set_group_find_defaults (MuConfig *opts) set_group_find_defaults (MuConfig *opts)
{ {
/* note, when no fields are specified, we use /* note, when no fields are specified, we use
* date-from-subject, and sort descending by date. If fields * date-from-subject, and sort descending by date. If fields
* *are* specified, we sort in ascending order. */ * *are* specified, we sort in ascending order. */
if (!opts->fields) { if (!opts->fields) {
opts->fields = "d f s"; opts->fields = "d f s";
if (!opts->sortfield) { if (!opts->sortfield) {
opts->sortfield = "d"; opts->sortfield = "d";
opts->descending = TRUE; opts->descending = TRUE;
}
} }
}
if (!opts->formatstr) /* by default, use plain output */ if (!opts->formatstr) /* by default, use plain output */
opts->formatstr = MU_CONFIG_FORMAT_PLAIN; opts->formatstr = MU_CONFIG_FORMAT_PLAIN;
if (opts->linksdir) { if (opts->linksdir) {
gchar *old = opts->linksdir; gchar *old = opts->linksdir;
opts->linksdir = mu_util_dir_expand(opts->linksdir); opts->linksdir = mu_util_dir_expand(opts->linksdir);
if (!opts->linksdir) /* we'll check the dir later */ if (!opts->linksdir) /* we'll check the dir later */
opts->linksdir = old; opts->linksdir = old;
else else
g_free(old); g_free(old);
} }
/* FIXME: some warning when summary_len < 0? */ /* FIXME: some warning when summary_len < 0? */
if (opts->summary_len < 1) if (opts->summary_len < 1)
opts->summary_len = 0; opts->summary_len = 0;
} }
static GOptionGroup* static GOptionGroup*
config_options_group_find (MuConfig *opts) config_options_group_find (MuConfig *opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields, {"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields,
"fields to display in the output", NULL}, "fields to display in the output", NULL},
{"sortfield", 's', 0, G_OPTION_ARG_STRING, &opts->sortfield, {"sortfield", 's', 0, G_OPTION_ARG_STRING, &opts->sortfield,
"field to sort on", NULL}, "field to sort on", NULL},
{"bookmark", 'b', 0, G_OPTION_ARG_STRING, &opts->bookmark, {"bookmark", 'b', 0, G_OPTION_ARG_STRING, &opts->bookmark,
"use a bookmarked query", NULL}, "use a bookmarked query", NULL},
{"descending", 'z', 0, G_OPTION_ARG_NONE, &opts->descending, {"descending", 'z', 0, G_OPTION_ARG_NONE, &opts->descending,
"sort in descending order (z -> a)", NULL}, "sort in descending order (z -> a)", NULL},
{"summary-len", 'k', 0, G_OPTION_ARG_INT, &opts->summary_len, {"summary-len", 'k', 0, G_OPTION_ARG_INT, &opts->summary_len,
"max number of lines for summary (0)", NULL}, "max number of lines for summary (0)", NULL},
{"linksdir", 0, 0, G_OPTION_ARG_STRING, &opts->linksdir, {"linksdir", 0, 0, G_OPTION_ARG_STRING, &opts->linksdir,
"output as symbolic links to a target maildir", NULL}, "output as symbolic links to a target maildir", NULL},
{"clearlinks", 0, 0, G_OPTION_ARG_NONE, &opts->clearlinks, {"clearlinks", 0, 0, G_OPTION_ARG_NONE, &opts->clearlinks,
"clear old links before filling a linksdir (false)", NULL}, "clear old links before filling a linksdir (false)", NULL},
{"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr, {"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr,
"output format ('plain'(*), 'links', 'xml'," "output format ('plain'(*), 'links', 'xml',"
"'json', 'sexp', 'xquery')", NULL}, "'json', 'sexp', 'xquery')", NULL},
{"xquery", 0, 0, G_OPTION_ARG_NONE, &opts->xquery, {NULL, 0, 0, 0, NULL, NULL, NULL}
"obsolete, use --format=xquery instead", NULL}, };
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
og = g_option_group_new("find", og = g_option_group_new("find",
"options for the 'find' command", "options for the 'find' command",
"", NULL, NULL); "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
static GOptionGroup * static GOptionGroup *
config_options_group_mkdir (MuConfig *opts) config_options_group_mkdir (MuConfig *opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"mode", 0, 0, G_OPTION_ARG_INT, &opts->dirmode, {"mode", 0, 0, G_OPTION_ARG_INT, &opts->dirmode,
"set the mode (as in chmod), in octal notation", NULL}, "set the mode (as in chmod), in octal notation", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL} {NULL, 0, 0, 0, NULL, NULL, NULL}
}; };
/* set dirmode before, because '0000' is a valid mode */ /* set dirmode before, because '0000' is a valid mode */
opts->dirmode = 0755; opts->dirmode = 0755;
og = g_option_group_new("mkdir", "options for the 'mkdir' command", og = g_option_group_new("mkdir", "options for the 'mkdir' command",
"", NULL, NULL); "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
static void static void
set_group_cfind_defaults (MuConfig *opts) set_group_cfind_defaults (MuConfig *opts)
{ {
if (!opts->formatstr) /* by default, use plain output */ if (!opts->formatstr) /* by default, use plain output */
opts->formatstr = MU_CONFIG_FORMAT_PLAIN; opts->formatstr = MU_CONFIG_FORMAT_PLAIN;
} }
static GOptionGroup * static GOptionGroup *
config_options_group_cfind (MuConfig *opts) config_options_group_cfind (MuConfig *opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr, {"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr,
"output format ('plain'(*), 'mutt', 'wanderlust'," "output format ('plain'(*), 'mutt', 'wanderlust',"
"'org-contact', 'csv')", NULL}, "'org-contact', 'csv')", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL} {NULL, 0, 0, 0, NULL, NULL, NULL}
}; };
og = g_option_group_new("cfind", "options for the 'cfind' command", og = g_option_group_new("cfind", "options for the 'cfind' command",
"", NULL, NULL); "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
@ -229,224 +228,224 @@ config_options_group_cfind (MuConfig *opts)
static GOptionGroup* static GOptionGroup*
config_options_group_extract(MuConfig *opts) config_options_group_extract(MuConfig *opts)
{ {
GOptionGroup *og; GOptionGroup *og;
GOptionEntry entries[] = { GOptionEntry entries[] = {
{"save-attachments", 'a', 0, G_OPTION_ARG_NONE, {"save-attachments", 'a', 0, G_OPTION_ARG_NONE,
&opts->save_attachments, &opts->save_attachments,
"save all attachments (false)", NULL}, "save all attachments (false)", NULL},
{"save-all", 0, 0, G_OPTION_ARG_NONE, &opts->save_all, {"save-all", 0, 0, G_OPTION_ARG_NONE, &opts->save_all,
"save all parts (incl. non-attachments) (false)", NULL}, "save all parts (incl. non-attachments) (false)", NULL},
{"parts", 0, 0, G_OPTION_ARG_STRING, &opts->parts, {"parts", 0, 0, G_OPTION_ARG_STRING, &opts->parts,
"save specific parts (comma-separated list)", NULL}, "save specific parts (comma-separated list)", NULL},
{"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &opts->targetdir, {"target-dir", 0, 0, G_OPTION_ARG_FILENAME, &opts->targetdir,
"target directory for saving", NULL}, "target directory for saving", NULL},
{"overwrite", 0, 0, G_OPTION_ARG_NONE, &opts->overwrite, {"overwrite", 0, 0, G_OPTION_ARG_NONE, &opts->overwrite,
"overwrite existing files (false)", NULL}, "overwrite existing files (false)", NULL},
{"play", 0, 0, G_OPTION_ARG_NONE, &opts->play, {"play", 0, 0, G_OPTION_ARG_NONE, &opts->play,
"try to 'play' (open) the extracted parts", NULL}, "try to 'play' (open) the extracted parts", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL} {NULL, 0, 0, 0, NULL, NULL, NULL}
}; };
opts->targetdir = g_strdup("."); /* default is the current dir */ opts->targetdir = g_strdup("."); /* default is the current dir */
og = g_option_group_new("extract", og = g_option_group_new("extract",
"options for the 'extract' command", "options for the 'extract' command",
"", NULL, NULL); "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
return og; return og;
} }
static gboolean static gboolean
parse_cmd (MuConfig *opts, int *argcp, char ***argvp) parse_cmd (MuConfig *opts, int *argcp, char ***argvp)
{ {
int i; int i;
typedef struct { typedef struct {
const gchar* _name; const gchar* _name;
MuConfigCmd _cmd; MuConfigCmd _cmd;
} Cmd; } Cmd;
Cmd cmd_map[] = { Cmd cmd_map[] = {
{ "index", MU_CONFIG_CMD_INDEX }, { "index", MU_CONFIG_CMD_INDEX },
{ "find", MU_CONFIG_CMD_FIND }, { "find", MU_CONFIG_CMD_FIND },
{ "cleanup", MU_CONFIG_CMD_CLEANUP }, { "cleanup", MU_CONFIG_CMD_CLEANUP },
{ "mkdir", MU_CONFIG_CMD_MKDIR }, { "mkdir", MU_CONFIG_CMD_MKDIR },
{ "view", MU_CONFIG_CMD_VIEW }, { "view", MU_CONFIG_CMD_VIEW },
{ "extract", MU_CONFIG_CMD_EXTRACT }, { "extract", MU_CONFIG_CMD_EXTRACT },
{ "cfind", MU_CONFIG_CMD_CFIND }, { "cfind", MU_CONFIG_CMD_CFIND },
}; };
opts->cmd = MU_CONFIG_CMD_NONE; opts->cmd = MU_CONFIG_CMD_NONE;
opts->cmdstr = NULL; opts->cmdstr = NULL;
if (*argcp < 2) /* no command found at all */ if (*argcp < 2) /* no command found at all */
return TRUE;
else if ((**argvp)[1] == '-')
/* if the first param starts with '-', there is no
* command, just some option (like --version, --help
* etc.)*/
return TRUE;
opts->cmd = MU_CONFIG_CMD_UNKNOWN;
opts->cmdstr = (*argvp)[1];
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (opts->cmdstr, cmd_map[i]._name) == 0)
opts->cmd = cmd_map[i]._cmd;
return TRUE; return TRUE;
else if ((**argvp)[1] == '-')
/* if the first param starts with '-', there is no
* command, just some option (like --version, --help
* etc.)*/
return TRUE;
opts->cmd = MU_CONFIG_CMD_UNKNOWN;
opts->cmdstr = (*argvp)[1];
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (opts->cmdstr, cmd_map[i]._name) == 0)
opts->cmd = cmd_map[i]._cmd;
return TRUE;
} }
static void static void
add_context_group (GOptionContext *context, MuConfig *opts) add_context_group (GOptionContext *context, MuConfig *opts)
{ {
GOptionGroup *group; GOptionGroup *group;
group = NULL; group = NULL;
switch (opts->cmd) { switch (opts->cmd) {
case MU_CONFIG_CMD_INDEX: case MU_CONFIG_CMD_INDEX:
group = config_options_group_index (opts); group = config_options_group_index (opts);
break; break;
case MU_CONFIG_CMD_FIND: case MU_CONFIG_CMD_FIND:
group = config_options_group_find (opts); group = config_options_group_find (opts);
break; break;
case MU_CONFIG_CMD_MKDIR: case MU_CONFIG_CMD_MKDIR:
group = config_options_group_mkdir (opts); group = config_options_group_mkdir (opts);
break; break;
case MU_CONFIG_CMD_EXTRACT: case MU_CONFIG_CMD_EXTRACT:
group = config_options_group_extract (opts); group = config_options_group_extract (opts);
break; break;
case MU_CONFIG_CMD_CFIND: case MU_CONFIG_CMD_CFIND:
group = config_options_group_cfind (opts); group = config_options_group_cfind (opts);
break; break;
default: break; default: break;
} }
if (group) if (group)
g_option_context_add_group(context, group); g_option_context_add_group(context, group);
} }
static gboolean static gboolean
parse_params (MuConfig *opts, int *argcp, char ***argvp) parse_params (MuConfig *opts, int *argcp, char ***argvp)
{ {
GError *err = NULL; GError *err = NULL;
GOptionContext *context; GOptionContext *context;
gboolean rv; gboolean rv;
context = g_option_context_new("- mu general option"); context = g_option_context_new("- mu general option");
g_option_context_set_main_group(context, g_option_context_set_main_group(context,
config_options_group_mu(opts)); config_options_group_mu(opts));
add_context_group (context, opts); add_context_group (context, opts);
rv = g_option_context_parse(context, argcp, argvp, &err); rv = g_option_context_parse(context, argcp, argvp, &err);
g_option_context_free (context); g_option_context_free (context);
if (!rv) { if (!rv) {
g_printerr ("mu: error in options: %s\n", err->message); g_printerr ("mu: error in options: %s\n", err->message);
g_error_free (err); g_error_free (err);
return FALSE; return FALSE;
} }
return TRUE;} return TRUE;}
MuConfig* MuConfig*
mu_config_new (int *argcp, char ***argvp) mu_config_new (int *argcp, char ***argvp)
{ {
MuConfig *config; MuConfig *config;
g_return_val_if_fail (argcp && argvp, NULL); g_return_val_if_fail (argcp && argvp, NULL);
config = g_new0 (MuConfig, 1); config = g_new0 (MuConfig, 1);
if (!parse_cmd (config, argcp, argvp) || if (!parse_cmd (config, argcp, argvp) ||
!parse_params(config, argcp, argvp)) { !parse_params(config, argcp, argvp)) {
mu_config_destroy (config); mu_config_destroy (config);
return NULL; return NULL;
} }
/* fill in the defaults if user did not specify */ /* fill in the defaults if user did not specify */
set_group_mu_defaults (config); set_group_mu_defaults (config);
set_group_index_defaults (config); set_group_index_defaults (config);
set_group_find_defaults (config); set_group_find_defaults (config);
set_group_cfind_defaults (config); set_group_cfind_defaults (config);
/* set_group_mkdir_defaults (config); */ /* set_group_mkdir_defaults (config); */
return config; return config;
} }
void void
mu_config_destroy (MuConfig *opts) mu_config_destroy (MuConfig *opts)
{ {
if (!opts) if (!opts)
return; return;
g_free (opts->muhome); g_free (opts->muhome);
g_free (opts->maildir); g_free (opts->maildir);
g_free (opts->linksdir); g_free (opts->linksdir);
g_free (opts->targetdir); g_free (opts->targetdir);
g_strfreev (opts->params); g_strfreev (opts->params);
g_free (opts); g_free (opts);
} }
static void static void
show_usage (gboolean noerror) show_usage (gboolean noerror)
{ {
const char* usage= const char* usage=
"usage: mu command [options] [parameters]\n" "usage: mu command [options] [parameters]\n"
"where command is one of index, find, cfind, view, mkdir, cleanup " "where command is one of index, find, cfind, view, mkdir, cleanup "
"or extract\n\n" "or extract\n\n"
"see the mu, mu-<command> or mu-easy manpages for " "see the mu, mu-<command> or mu-easy manpages for "
"more information\n"; "more information\n";
if (noerror) if (noerror)
g_print ("%s", usage); g_print ("%s", usage);
else else
g_printerr ("%s", usage); g_printerr ("%s", usage);
} }
static void static void
show_version (void) show_version (void)
{ {
g_print ("mu (mail indexer/searcher) " VERSION "\n" g_print ("mu (mail indexer/searcher) " VERSION "\n"
"Copyright (C) 2008-2011 Dirk-Jan C. Binnema (GPLv3+)\n"); "Copyright (C) 2008-2011 Dirk-Jan C. Binnema (GPLv3+)\n");
} }
MuExitCode MuExitCode
mu_config_execute (MuConfig *opts) mu_config_execute (MuConfig *opts)
{ {
g_return_val_if_fail (opts, MU_EXITCODE_ERROR); g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
if (opts->version) { if (opts->version) {
show_version (); show_version ();
return MU_EXITCODE_OK; return MU_EXITCODE_OK;
} }
if (!opts->params||!opts->params[0]) {/* no command? */ if (!opts->params||!opts->params[0]) {/* no command? */
show_version (); show_version ();
g_print ("\n"); g_print ("\n");
show_usage (TRUE); show_usage (TRUE);
return MU_EXITCODE_ERROR; return MU_EXITCODE_ERROR;
} }
switch (opts->cmd) { switch (opts->cmd) {
case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts); case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts);
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (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_FIND: return mu_cmd_find (opts);
case MU_CONFIG_CMD_INDEX: return mu_cmd_index (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_MKDIR: return mu_cmd_mkdir (opts);
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts); case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts);
case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts); case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts);
case MU_CONFIG_CMD_UNKNOWN: case MU_CONFIG_CMD_UNKNOWN:
g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr); g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr);
show_usage (FALSE); show_usage (FALSE);
return MU_EXITCODE_ERROR; return MU_EXITCODE_ERROR;
default: default:
g_return_val_if_reached (MU_EXITCODE_ERROR); g_return_val_if_reached (MU_EXITCODE_ERROR);
} }
} }

View File

@ -91,9 +91,6 @@ struct _MuConfig {
int max_msg_size; /* maximum size for message files */ int max_msg_size; /* maximum size for message files */
/* options for querying */ /* options for querying */
gboolean xquery; /* (obsolete) give the Xapian
query instead of search
results */
char *fields; /* fields to show in output */ char *fields; /* fields to show in output */
char *sortfield; /* field to sort by (string) */ char *sortfield; /* field to sort by (string) */
gboolean descending; /* sort descending? */ gboolean descending; /* sort descending? */